Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
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< LNodeAsList (this LNode block, Symbol braces)
 Interprets a node as a list by returning block.Args if block.Calls(braces), 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 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 WithoutOuterParens (this LNode self)
 
static LNode ArgNamed (this LNode self, Symbol name)
 
static int IndexWithName (this VList< LNode > self, Symbol name)
 
static LNode NodeNamed (this VList< LNode > self, Symbol name)
 
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 MMap< Symbol, LNode > captures)
 

Member Function Documentation

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

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

References Loyc.Syntax.LNode.Args.

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).

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.Kind, Loyc.Syntax.LNode.Name, and Loyc.Syntax.LNode.Target.