Enhanced C#
Language of your choice: library documentation
Static Public Member Functions | List of all members
Loyc.Syntax.LNodeExt Class Reference

Standard extension methods for LNode. More...


Source file:

Remarks

Standard extension methods for LNode.

Static Public Member Functions

static VList< LNodeGetTrivia (this LNode node)
 
static VList< LNodeGetTrivia (this VList< LNode > attrs)
 
static VList< LNodeGetTrailingTrivia (this LNode node)
 Gets all trailing trivia attached to the specified node. More...
 
static VList< LNodeGetTrailingTrivia (this VList< LNode > attrs)
 Gets all trailing trivia attached to the specified node. More...
 
static LNode WithTrailingTrivia (this LNode node, VList< LNode > trivia)
 Removes a node's trailing trivia and adds a new list of trailing trivia. More...
 
static VList< LNodeWithTrailingTrivia (this VList< LNode > attrs, VList< LNode > trivia)
 Removes all existing trailing trivia from an attribute list and adds a new list of trailing trivia. More...
 
static VList< LNodeWithoutTrailingTrivia (this VList< LNode > attrs)
 Gets a new list with any #trivia_trailing attributes removed. More...
 
static VList< LNodeWithoutTrailingTrivia (this VList< LNode > attrs, out VList< LNode > trailingTrivia)
 Gets a new list with any #trivia_trailing attributes removed. Those trivia are returned in an out parameter. More...
 
static LNode PlusTrailingTrivia (this LNode node, VList< LNode > trivia)
 Adds additional trailing trivia to a node. More...
 
static LNode PlusTrailingTrivia (this LNode node, LNode trivia)
 Adds additional trailing trivia to a node. More...
 
static VList< LNodePlusTrailingTrivia (this VList< LNode > attrs, VList< LNode > trivia)
 Adds additional trailing trivia to an attribute list. Has no effect if trivia is empty. More...
 
static VList< LNodePlusTrailingTrivia (this VList< LNode > attrs, LNode trivia)
 Adds additional trailing trivia to an attribute list. More...
 
static VList< LNodeAsList (this LNode block, Symbol listIdentifier)
 Interprets a node as a list by returning block.Args if block.Calls(listIdentifier), otherwise returning a one-item list of nodes with block as the only item. More...
 
static LNode AsLNode (this VList< LNode > list, Symbol listIdentifier)
 Converts a list of LNodes to a single LNode by using the list as the argument list in a call to the specified identifier, or, if the list contains a single item, by returning that single item. More...
 
static VList< LNodeWithSpliced (this VList< LNode > list, int index, LNode node, Symbol listName=null)
 
static VList< LNodeWithSpliced (this VList< LNode > list, LNode node, Symbol listName=null)
 
static void SpliceInsert (this WList< LNode > list, int index, LNode node, Symbol listName=null)
 
static void SpliceAdd (this WList< LNode > list, LNode node, Symbol listName=null)
 
static LNode AttrNamed (this LNode self, Symbol name)
 
static LNode WithoutAttrNamed (this LNode self, Symbol name)
 
static VList< LNodeWithout (this VList< LNode > list, LNode node)
 
static LNode WithoutAttr (this LNode self, LNode node)
 
static LNode WithoutAttrNamed (this LNode self, Symbol name, out LNode removedAttr)
 
static VList< LNodeWithoutNodeNamed (this VList< LNode > a, Symbol name)
 
static VList< LNodeWithoutNodeNamed (this VList< LNode > list, Symbol name, out LNode removedNode)
 
static LNode ArgNamed (this LNode self, Symbol name)
 
static int IndexWithName (this VList< LNode > self, Symbol name, int resultIfNotFound=-1)
 
static LNode NodeNamed (this VList< LNode > self, Symbol name)
 
static bool IsParenthesizedExpr (this LNode node)
 
static LNode InParens (this LNode node)
 Returns the same node with a parentheses attribute added. More...
 
static LNode InParens (this LNode node, SourceRange range)
 Returns the same node with a parentheses attribute added. More...
 
static LNode InParens (this LNode node, ISourceFile file, int startIndex, int endIndex)
 Returns the same node with a parentheses attribute added. More...
 
static LNode WithoutOuterParens (this LNode self)
 Removes a single pair of parentheses, if the node has a #trivia_inParens attribute. Returns the same node when no parens are present. More...
 
static bool MatchesPattern (this LNode candidate, LNode pattern, ref MMap< Symbol, LNode > captures, out VList< LNode > unmatchedAttrs)
 Determines whether one Loyc tree "matches" another. This is different from a simple equality test in that (1) trivia atributes do not have to match, and (2) the pattern can contain placeholders represented by calls to $ (the substitution operator) with an identifier as a parameter. Placeholders match any subtree, and are saved to the captures map. More...
 
static bool MatchesPattern (this LNode candidate, LNode pattern, out IDictionary< Symbol, LNode > captures, out VList< LNode > unmatchedAttrs)
 
static bool MatchesPattern (this LNode candidate, LNode pattern, out IDictionary< Symbol, LNode > captures)
 
static LNode GetCaptureIdentifier (LNode pattern, bool identifierRequired=true)
 Checks if pattern matches one of the syntax trees $x or $(..x) or $(...x) for some identifier x. These are conventionally used to represent partial syntax trees. More...
 
static bool IsCall (this ILNode node)
 
static bool IsId (this ILNode node)
 
static bool IsLiteral (this ILNode node)
 
static int ArgCount (this ILNode node)
 
static int AttrCount (this ILNode node)
 
static NegListSlice< ILNodeAttrs (this ILNode node)
 
static NegListSlice< ILNodeArgs (this ILNode node)
 
static bool IsTrivia (this ILNode node)
 
static NodeStyle BaseStyle (this ILNode node)
 
static bool IsIdNamed (this ILNode node, Symbol name)
 
static bool IsIdNamed (this ILNode node, string name)
 
static bool Calls (this ILNode node, Symbol name)
 
static bool IsParenthesizedExpr (this ILNode node)
 
static bool HasSpecialName (this ILNode node)
 
static bool HasAttrs (this ILNode node)
 
static bool HasPAttrs (this ILNode node)
 
static ILNode AttrNamed (this ILNode node, Symbol name)
 
static ILNode NodeNamed (this NegListSlice< ILNode > self, Symbol name)
 
static IListSource< ILNodeGetTrailingTrivia (this ILNode node)
 
static LNode ToLNode (ILNode node)
 Converts ILNode to LNode recursively. If the specified node is already an LNode, this method simply does a cast. More...
 

Member Function Documentation

static VList<LNode> Loyc.Syntax.LNodeExt.AsList ( this LNode  block,
Symbol  listIdentifier 
)
inlinestatic

Interprets a node as a list by returning block.Args if block.Calls(listIdentifier), otherwise returning a one-item list of nodes with block as the only item.

References Loyc.Syntax.LNode.Args, and Loyc.Syntax.LNode.Calls().

static LNode Loyc.Syntax.LNodeExt.AsLNode ( this VList< LNode list,
Symbol  listIdentifier 
)
inlinestatic

Converts a list of LNodes to a single LNode by using the list as the argument list in a call to the specified identifier, or, if the list contains a single item, by returning that single item.

Parameters
listIdentifierTarget of the node that is created if list does not contain exactly one item. Typical values include "'{}" and "#splice".

This is the reverse of the operation performed by AsList(LNode,Symbol).

References Loyc.Collections.VList< T >.Add(), Loyc.Syntax.LNode.Args, Loyc.Syntax.LNode.Attrs, Loyc.Syntax.LNode.Calls(), Loyc.Collections.VList< T >.Last, Loyc.Syntax.LNode.Name, Loyc.Syntax.CodeSymbols.Splice, and Loyc.Collections.VList< T >.ToFVList().

static LNode Loyc.Syntax.LNodeExt.GetCaptureIdentifier ( LNode  pattern,
bool  identifierRequired = true 
)
inlinestatic

Checks if pattern matches one of the syntax trees $x or $(..x) or $(...x) for some identifier x. These are conventionally used to represent partial syntax trees.

Returns
The matched identifier (x in the examples above), or null if pattern was not a match.

References Loyc.Syntax.LNode.Args, Loyc.Syntax.ILNode.Calls(), Loyc.Syntax.LNode.Calls(), Loyc.Syntax.ILNode.CallsMin(), Loyc.Syntax.LNode.IsSpecialName(), Loyc.Syntax.ILNode.Kind, Loyc.Collections.VList< T >.Last, Loyc.Collections.INegListSource< out out T >.Max, Loyc.Collections.INegListSource< out out T >.Min, Loyc.Syntax.ILNode.Name, Loyc.Symbol.Name, and Loyc.Syntax.ILNode.Style.

static VList<LNode> Loyc.Syntax.LNodeExt.GetTrailingTrivia ( this LNode  node)
inlinestatic

Gets all trailing trivia attached to the specified node.

References Loyc.Syntax.LNode.Attrs, and Loyc.Syntax.LNodeExt.GetTrailingTrivia().

Referenced by Loyc.Syntax.LNodeExt.GetTrailingTrivia().

static VList<LNode> Loyc.Syntax.LNodeExt.GetTrailingTrivia ( this VList< LNode attrs)
inlinestatic

Gets all trailing trivia attached to the specified node.

Trailing trivia is represented by a call to #trivia_trailing in a node's attribute list; each argument to #trivia_trailing represents one piece of trivia. If the attribute list has multiple calls to #trivia_trailing, this method combines those lists into a single list.

static LNode Loyc.Syntax.LNodeExt.InParens ( this LNode  node)
inlinestatic

Returns the same node with a parentheses attribute added.

Referenced by Loyc.Syntax.LNodeFactory.Trivia().

static LNode Loyc.Syntax.LNodeExt.InParens ( this LNode  node,
SourceRange  range 
)
inlinestatic

Returns the same node with a parentheses attribute added.

The node's range is changed to the provided SourceRange and the original range of the node is assigned to the parentheses attribute.

static LNode Loyc.Syntax.LNodeExt.InParens ( this LNode  node,
ISourceFile  file,
int  startIndex,
int  endIndex 
)
inlinestatic

Returns the same node with a parentheses attribute added.

static bool Loyc.Syntax.LNodeExt.MatchesPattern ( this LNode  candidate,
LNode  pattern,
ref MMap< Symbol, LNode captures,
out VList< LNode unmatchedAttrs 
)
inlinestatic

Determines whether one Loyc tree "matches" another. This is different from a simple equality test in that (1) trivia atributes do not have to match, and (2) the pattern can contain placeholders represented by calls to $ (the substitution operator) with an identifier as a parameter. Placeholders match any subtree, and are saved to the captures map.

Parameters
candidateA node that you want to compare with a 'pattern'.
patternA syntax tree that may contain placeholders. A placeholder is a call to the $ operator with one parameter, which must be either (A) a simple identifier, or (B) the ".." operator with a simple identifier as its single parameter. Otherwise, the $ operator is treated literally as something that must exist in candidate). The subtree in candidate corresponding to the placeholder is saved in captures.
capturesA table that maps placeholder names from pattern to subtrees in candidate. You can set your map to null and a map will be created for you if necessary. If you already have a map, you should clear it before calling this method.
unmatchedAttrsOn return, a list of trivia attributes in candidate that were not present in pattern.
Returns
true if pattern matches candidate, false otherwise.

Attributes in patterns are not yet supported.

This method supports multi-part captures, which are matched to placeholders whose identifier either (A) has a #params attribute or (B) has the unary ".." operator applied to it (for example, if the placeholder is called p, this is written as $(params p) in EC#.) A placeholder that looks like this can match multiple arguments or multiple statements in the candidate (or no arguments, or no statements), and will become a #splice(...) node in captures if it matches multiple items. Multi-part captures are often useful for getting lists of statements before and after some required element, e.g. { $(params before); MatchThis($something); $(params after); }

If the same placeholder appears twice then the two matching items are combined into a single output node (calling #splice).

If matching is unsuccessful, captures and unmatchedAttrs may contain irrelevant information gathered during the attempt to match.

In EC#, the quote(...) macro can be used to create the LNode object for a pattern.

References Loyc.Syntax.LNode.Args, Loyc.Syntax.LNode.Attrs, Loyc.Syntax.LNode.Calls(), Loyc.Syntax.LNode.Kind, Loyc.Collections.VList< T >.Last, Loyc.Syntax.LNode.MergeLists(), Loyc.Syntax.LNode.Name, Loyc.Syntax.LNode.Target, and Loyc.Syntax.LNode.Value.

static LNode Loyc.Syntax.LNodeExt.PlusTrailingTrivia ( this LNode  node,
VList< LNode trivia 
)
inlinestatic

Adds additional trailing trivia to a node.

References Loyc.Syntax.LNode.Attrs.

static LNode Loyc.Syntax.LNodeExt.PlusTrailingTrivia ( this LNode  node,
LNode  trivia 
)
inlinestatic

Adds additional trailing trivia to a node.

References Loyc.Syntax.LNode.Attrs.

static VList<LNode> Loyc.Syntax.LNodeExt.PlusTrailingTrivia ( this VList< LNode attrs,
VList< LNode trivia 
)
inlinestatic

Adds additional trailing trivia to an attribute list. Has no effect if trivia is empty.

Trailing trivia is represented by a call to #trivia_trailing in a node's attribute list; each argument to #trivia_trailing represents one piece of trivia.

In the current design, this method has a side-effect of recreating the #trivia_trailing node at the end of the attribute list, and if there are multiple #trivia_trailing lists, consolidating them into a single list, but only if the specified trivia list is not empty.

References Loyc.Collections.VList< T >.Add().

static VList<LNode> Loyc.Syntax.LNodeExt.PlusTrailingTrivia ( this VList< LNode attrs,
LNode  trivia 
)
inlinestatic

Adds additional trailing trivia to an attribute list.

References Loyc.Collections.VList< T >.Add().

static LNode Loyc.Syntax.LNodeExt.ToLNode ( ILNode  node)
inlinestatic
static LNode Loyc.Syntax.LNodeExt.WithoutOuterParens ( this LNode  self)
inlinestatic

Removes a single pair of parentheses, if the node has a #trivia_inParens attribute. Returns the same node when no parens are present.

static VList<LNode> Loyc.Syntax.LNodeExt.WithoutTrailingTrivia ( this VList< LNode attrs)
inlinestatic

Gets a new list with any #trivia_trailing attributes removed.

References Loyc.Collections.VList< T >.Transform().

static VList<LNode> Loyc.Syntax.LNodeExt.WithoutTrailingTrivia ( this VList< LNode attrs,
out VList< LNode trailingTrivia 
)
inlinestatic

Gets a new list with any #trivia_trailing attributes removed. Those trivia are returned in an out parameter.

References Loyc.Collections.VList< T >.Transform().

static LNode Loyc.Syntax.LNodeExt.WithTrailingTrivia ( this LNode  node,
VList< LNode trivia 
)
inlinestatic

Removes a node's trailing trivia and adds a new list of trailing trivia.

References Loyc.Syntax.LNode.Attrs.

static VList<LNode> Loyc.Syntax.LNodeExt.WithTrailingTrivia ( this VList< LNode attrs,
VList< LNode trivia 
)
inlinestatic

Removes all existing trailing trivia from an attribute list and adds a new list of trailing trivia.

This method has a side-effect of recreating the #trivia_trailing node, if there is one, at the end of the attribute list. If trivia is empty then all calls to #trivia_trailing are removed.