Enhanced C#
Language of your choice: library documentation
|
Standard extension methods for LNode. More...
Standard extension methods for LNode.
Static Public Member Functions | |
static LNodeList | GetTrivia (this LNode node) |
static LNodeList | GetTrivia (this LNodeList attrs) |
static LNodeList | GetTrailingTrivia (this LNode node) |
Gets all trailing trivia attached to the specified node. More... | |
static LNodeList | GetTrailingTrivia (this LNodeList attrs) |
Gets all trailing trivia attached to the specified node. More... | |
static LNode | WithTrailingTrivia (this LNode node, LNodeList trivia) |
Removes a node's trailing trivia and adds a new list of trailing trivia. More... | |
static LNodeList | WithTrailingTrivia (this LNodeList attrs, LNodeList trivia) |
Removes all existing trailing trivia from an attribute list and adds a new list of trailing trivia. More... | |
static LNodeList | WithoutTrailingTrivia (this LNodeList attrs) |
Gets a new list with any trailing attributes removed. More... | |
static LNodeList | WithoutTrailingTrivia (this LNodeList attrs, out LNodeList trailingTrivia) |
Gets a new list with any trailing attributes removed. Trailing trivia inside those attributes are returned in an out parameter. More... | |
static LNode | PlusTrailingTrivia (this LNode node, LNodeList 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 LNodeList | PlusTrailingTrivia (this LNodeList attrs, LNodeList trivia) |
Adds additional trailing trivia to an attribute list. Has no effect if trivia is empty. More... | |
static LNodeList | PlusTrailingTrivia (this LNodeList attrs, LNode trivia) |
Adds additional trailing trivia to an attribute list. More... | |
static LNodeList | AsList (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 LNodeList | Unsplice (this LNode node) |
Converts an expression to a list. Similar to calling AsList(block, CodeSymbols.Splice) , if the expression calls #splice then the arguments of the splice are returned, and if not then the argument is converted to a list with one item. However, if the call to #splice has attached trivia/attributes, those attributes are attached to the output list using PlusAttributes(LNodeList, LNodeList). More... | |
static LNode | IncludingTriviaFrom (this LNode node, LNode otherNode) |
Finds trivia attributes attached directly to otherNode , and returns a new version of node with these attributes added. More... | |
static LNodeList | IncludingAttributes (this LNodeList list, LNodeList attributes) |
Prepends attributes to the first item in a list, except for trailing trivia (trailing(...)), which is appended to the last item in the list. If the list is empty, the attributes are ignored. More... | |
static LNode | AsLNode (this LNodeList 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 LNodeList | WithSpliced (this LNodeList list, int index, LNode node, Symbol listName=null) |
static LNodeList | WithSpliced (this LNodeList 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 LNodeList | Without (this LNodeList list, LNode node) |
static LNode | WithoutAttr (this LNode self, LNode node) |
static LNode | WithoutAttrNamed (this LNode self, Symbol name, out LNode removedAttr) |
static LNodeList | WithoutNodeNamed (this LNodeList a, Symbol name) |
static LNodeList | WithoutNodeNamed (this LNodeList list, Symbol name, out LNode removedNode) |
static LNode | ArgNamed (this LNode self, Symbol name) |
static int | IndexWithName (this LNodeList self, Symbol name, int resultIfNotFound=-1) |
static LNode | NodeNamed (this LNodeList self, Symbol name) |
static LNodeList | RecursiveReplace (this LNodeList self, Func< LNode, LNodeList?> matcher, LNode.ReplaceOpt options=LNode.ReplaceOpt.Default) |
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 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 LNodeList 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 LNodeList 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< ILNode > | Attrs (this ILNode node) |
static NegListSlice< ILNode > | Args (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< ILNode > | GetTrailingTrivia (this ILNode node) |
static LNode | ToLNode (this ILNode node) |
Converts ILNode to LNode recursively. More... | |
static VList< LNode > | ToVList (this LNodeList list) |
static FVList< LNode > | ToFVList (this LNodeList list) |
static WList< LNode > | ToWList (this LNodeList list) |
static LNodeList | ToLNodeList (this WList< LNode > list) |
static LNodeList | ToLNodeList (this VList< LNode > list) |
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.
|
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.
listIdentifier | Target 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.Syntax.LNode.Range.
|
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.
x
in the examples above), or null if pattern
was not a match.References Loyc.Syntax.LNode.Args, and Loyc.Syntax.LNode.Calls().
Referenced by Loyc.Syntax.LNodeExt.MatchesPattern().
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().
Gets all trailing trivia attached to the specified node.
Trailing trivia is represented by a call to trailing
in a node's attribute list; each argument to trailing represents one piece of trivia. If the attribute list has multiple calls to trailing, this method combines those lists into a single list.
|
inlinestatic |
Prepends attributes to the first item in a list, except for trailing trivia (trailing(...)), which is appended to the last item in the list. If the list is empty, the attributes are ignored.
list
is returned unchanged.
|
inlinestatic |
Finds trivia attributes attached directly to otherNode
, and returns a new version of node
with these attributes added.
Returns the same node with a parentheses attribute added.
Referenced by Loyc.Syntax.LNodeExt.InParens().
|
inlinestatic |
Returns the same node with a parentheses attribute added.
References Loyc.Syntax.LNodeExt.InParens().
|
inlinestatic |
Returns the same node with a parentheses attribute added.
The node's range is changed to the provided SourceRange.
|
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.
candidate | A node that you want to compare with a 'pattern'. |
pattern | A 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 . |
captures | A 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. |
unmatchedAttrs | On return, a list of trivia attributes in candidate that were not present in pattern . |
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.LNodeExt.GetCaptureIdentifier(), Loyc.Syntax.LNode.Kind, Loyc.Syntax.LNode.Name, Loyc.Syntax.LNode.Target, and Loyc.Syntax.LNode.Value.
Adds additional trailing trivia to a node.
References Loyc.Syntax.LNode.Attrs, and Loyc.Syntax.LNodeExt.PlusTrailingTrivia().
|
inlinestatic |
Adds additional trailing trivia to a node.
References Loyc.Syntax.LNode.Attrs.
Referenced by Loyc.Syntax.LNodeExt.PlusTrailingTrivia().
|
inlinestatic |
Adds additional trailing trivia to an attribute list.
References Loyc.Syntax.CodeSymbols.Add, and Loyc.Syntax.LNodeExt.WithoutTrailingTrivia().
|
inlinestatic |
Adds additional trailing trivia to an attribute list. Has no effect if trivia
is empty.
Trailing trivia is represented by a call to trailing
in a node's attribute list; each argument to trailing represents one piece of trivia.
In the current design, this method has a side-effect of recreating the trailing node at the end of the attribute list, and if there are multiple trailing lists, consolidating them into a single list, but only if the specified trivia
list is not empty.
References Loyc.Syntax.LNodeExt.WithoutTrailingTrivia().
Converts an expression to a list. Similar to calling AsList(block, CodeSymbols.Splice)
, if the expression calls #splice then the arguments of the splice are returned, and if not then the argument is converted to a list with one item. However, if the call to #splice has attached trivia/attributes, those attributes are attached to the output list using PlusAttributes(LNodeList, LNodeList).
block | A node that may or may not be a call to #splice |
block
is equivalent to.Attributes attached to #splice are ordinarily attached to the first item in the output list, but any trailing attribute is attached to the last item instead. If the #splice() call has no arguments, then (i) if it has no trivia attributes, an empty list is returned, but (ii) if it has trivia attributes, the attributes themselves are returned as the content of the list. This assumes that printers can print
References Loyc.Syntax.LNode.Attrs, and Loyc.Syntax.CodeSymbols.Splice.
Removes a single pair of parentheses, if the node has a inParens attribute. Returns the same node when no parens are present.
Gets a new list with any trailing attributes removed.
References Loyc.Syntax.LNodeList.SmartWhere().
Referenced by Loyc.Syntax.LNodeExt.PlusTrailingTrivia(), and Loyc.Syntax.LNodeExt.WithTrailingTrivia().
|
inlinestatic |
Gets a new list with any trailing attributes removed. Trailing trivia inside those attributes are returned in an out
parameter.
References Loyc.Syntax.LNodeList.SmartWhere().
|
inlinestatic |
Removes a node's trailing trivia and adds a new list of trailing trivia.
References Loyc.Syntax.LNode.Attrs.
|
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 trailing node, if there is one, at the end of the attribute list. If trivia
is empty then all calls to trailing are removed.
References Loyc.Syntax.LNodeExt.WithoutTrailingTrivia().