Prev Next

Helper Functions

These functions are helpful in mFQL query compositions.

GetByAddress

The getByAddress function is used in applying the results of one query to another. For example, we might have a node of particular interest, and we want our query to return only nodes that join (in some way) to the specified node.

     getByAddress(node: number)

This sample builds a set containing the single node related to the address specified:

     getByAddress(11256)

To create a set of more than one node, use several calls to the node function from within a union join.  This sample creates a set of three specific nodes:

     union(

     getByAddress(11256),

     getByAddress(55388),

     getByAddress(117740)

     )

GetByPosition

getByPosition(File: String, Offset: Number)

The getByPosition function is used to return the inner most node that covers a certain position in a file.  This function is useful for locating a position in the AST based upon a file position.

Distinct

distinct(source: set)

The distinct function ensures that a set has no duplicate values.  All duplicate values are excluded from the result set.

This function is required to handle a side effect of the move function; it can create a set that includes duplicate nodes.  The move function operates in this manner by design – it should only remove nodes that fail the specified traversal, ensuring the resulting set is discrete is beyond its scope and (in some cases) undesirable behavior.