C# Class Loyc.Syntax.LNodeExt

Standard extension methods for LNode.
Exibir arquivo Open project: qwertie/ecsharp Class Usage Examples

Public Methods

Method Description
ArgCount ( this node ) : int
ArgNamed ( this self, Symbol name ) : LNode
Args ( this node ) : NegListSlice
AsLNode ( this list, Symbol listIdentifier ) : LNode

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.

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

AsList ( this block, Symbol listIdentifier ) : VList

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.

AttrCount ( this node ) : int
AttrNamed ( this node, Symbol name ) : ILNode
AttrNamed ( this self, Symbol name ) : LNode
Attrs ( this node ) : NegListSlice
BaseStyle ( this node ) : NodeStyle
Calls ( this node, Symbol name ) : bool
GetCaptureIdentifier ( LNode pattern, bool identifierRequired = true ) : LNode

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.

GetTrailingTrivia ( this node ) : IListSource
GetTrailingTrivia ( this node ) : VList

Gets all trailing trivia attached to the specified node.

GetTrailingTrivia ( this attrs ) : VList

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.

GetTrivia ( this node ) : VList
GetTrivia ( this attrs ) : VList
HasAttrs ( this node ) : bool
HasPAttrs ( this node ) : bool
HasSpecialName ( this node ) : bool
InParens ( this node ) : LNode

Returns the same node with a parentheses attribute added.

InParens ( this node, ISourceFile file, int startIndex, int endIndex ) : LNode

Returns the same node with a parentheses attribute added.

InParens ( this node, SourceRange range ) : LNode

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.

IndexWithName ( this self, Symbol name, int resultIfNotFound = -1 ) : int
IsCall ( this node ) : bool
IsId ( this node ) : bool
IsIdNamed ( this node, Symbol name ) : bool
IsIdNamed ( this node, string name ) : bool
IsLiteral ( this node ) : bool
IsParenthesizedExpr ( this node ) : bool
IsTrivia ( this node ) : bool
MatchesPattern ( this candidate, LNode pattern, LNode>.IDictionary &captures ) : bool
MatchesPattern ( this candidate, LNode pattern, LNode>.IDictionary &captures, VList &unmatchedAttrs ) : bool
MatchesPattern ( this candidate, LNode pattern, LNode>.MMap &captures, VList &unmatchedAttrs ) : bool

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.

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.

NodeNamed ( this self, Symbol name ) : ILNode
NodeNamed ( this self, Symbol name ) : LNode
PlusTrailingTrivia ( this node, LNode trivia ) : LNode

Adds additional trailing trivia to a node.

PlusTrailingTrivia ( this node, VList trivia ) : LNode

Adds additional trailing trivia to a node.

PlusTrailingTrivia ( this attrs, LNode trivia ) : VList

Adds additional trailing trivia to an attribute list.

PlusTrailingTrivia ( this attrs, VList trivia ) : VList

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.

SpliceAdd ( this list, LNode node, Symbol listName = null ) : void
SpliceInsert ( this list, int index, LNode node, Symbol listName = null ) : void
ToLNode ( ILNode node ) : LNode

Converts ILNode to LNode recursively. If the specified node is already an LNode, this method simply does a cast.

WithSpliced ( this list, LNode node, Symbol listName = null ) : VList
WithSpliced ( this list, int index, LNode node, Symbol listName = null ) : VList
WithTrailingTrivia ( this node, VList trivia ) : LNode

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

WithTrailingTrivia ( this attrs, VList trivia ) : VList

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.

Without ( this list, LNode node ) : VList
WithoutAttr ( this self, LNode node ) : LNode
WithoutAttrNamed ( this self, Symbol name ) : LNode
WithoutAttrNamed ( this self, Symbol name, LNode &removedAttr ) : LNode
WithoutNodeNamed ( this a, Symbol name ) : VList
WithoutNodeNamed ( this list, Symbol name, LNode &removedNode ) : VList
WithoutOuterParens ( this self ) : LNode

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

WithoutTrailingTrivia ( this attrs ) : VList

Gets a new list with any #trivia_trailing attributes removed.

WithoutTrailingTrivia ( this attrs, VList &trailingTrivia ) : VList

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

Private Methods

Method Description
AddCapture ( LNode>.MMap captures, LNode cap, Slice_ items ) : void
AddCapture ( LNode>.MMap captures, Symbol capName, LNode candidate ) : void
AttributesMatch ( LNode candidate, LNode pattern, LNode>.MMap &captures, VList &unmatchedAttrs ) : bool
CaptureGroup ( int &c, int &p, VList cArgs, VList pArgs, LNode>.MMap &captures, VList &attrs ) : bool
IsParamsCapture ( LNode pattern ) : bool
ListMatches ( VList candidates, VList patterns, LNode>.MMap &captures, VList &unmatchedAttrs ) : bool
MatchThenParams ( VList cArgs, VList pArgs, LNode paramsCap, LNode>.MMap &captures, VList &attrs ) : bool
MatchesPatternNested ( LNode candidate, LNode pattern, LNode>.MMap &captures, VList &trivia ) : bool
ToLNodeCore ( ILNode node ) : LNode

Method Details

ArgCount() public static method

public static ArgCount ( this node ) : int
node this
return int

ArgNamed() public static method

public static ArgNamed ( this self, Symbol name ) : LNode
self this
name Symbol
return LNode

Args() public static method

public static Args ( this node ) : NegListSlice
node this
return NegListSlice

AsLNode() public static method

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.
This is the reverse of the operation performed by AsList(LNode,Symbol).
public static AsLNode ( this list, Symbol listIdentifier ) : LNode
list this
listIdentifier Symbol Target of the node that is created if list /// does not contain exactly one item. Typical values include "'{}" and "#splice".
return LNode

AsList() public static method

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.
public static AsList ( this block, Symbol listIdentifier ) : VList
block this
listIdentifier Symbol
return VList

AttrCount() public static method

public static AttrCount ( this node ) : int
node this
return int

AttrNamed() public static method

public static AttrNamed ( this node, Symbol name ) : ILNode
node this
name Symbol
return ILNode

AttrNamed() public static method

public static AttrNamed ( this self, Symbol name ) : LNode
self this
name Symbol
return LNode

Attrs() public static method

public static Attrs ( this node ) : NegListSlice
node this
return NegListSlice

BaseStyle() public static method

public static BaseStyle ( this node ) : NodeStyle
node this
return NodeStyle

Calls() public static method

public static Calls ( this node, Symbol name ) : bool
node this
name Symbol
return bool

GetCaptureIdentifier() public static method

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.
public static GetCaptureIdentifier ( LNode pattern, bool identifierRequired = true ) : LNode
pattern LNode
identifierRequired bool
return LNode

GetTrailingTrivia() public static method

public static GetTrailingTrivia ( this node ) : IListSource
node this
return IListSource

GetTrailingTrivia() public static method

Gets all trailing trivia attached to the specified node.
public static GetTrailingTrivia ( this node ) : VList
node this
return VList

GetTrailingTrivia() public static method

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.
public static GetTrailingTrivia ( this attrs ) : VList
attrs this
return VList

GetTrivia() public static method

public static GetTrivia ( this node ) : VList
node this
return VList

GetTrivia() public static method

public static GetTrivia ( this attrs ) : VList
attrs this
return VList

HasAttrs() public static method

public static HasAttrs ( this node ) : bool
node this
return bool

HasPAttrs() public static method

public static HasPAttrs ( this node ) : bool
node this
return bool

HasSpecialName() public static method

public static HasSpecialName ( this node ) : bool
node this
return bool

InParens() public static method

Returns the same node with a parentheses attribute added.
public static InParens ( this node ) : LNode
node this
return LNode

InParens() public static method

Returns the same node with a parentheses attribute added.
public static InParens ( this node, ISourceFile file, int startIndex, int endIndex ) : LNode
node this
file ISourceFile
startIndex int
endIndex int
return LNode

InParens() public static method

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.
public static InParens ( this node, SourceRange range ) : LNode
node this
range SourceRange
return LNode

IndexWithName() public static method

public static IndexWithName ( this self, Symbol name, int resultIfNotFound = -1 ) : int
self this
name Symbol
resultIfNotFound int
return int

IsCall() public static method

public static IsCall ( this node ) : bool
node this
return bool

IsId() public static method

public static IsId ( this node ) : bool
node this
return bool

IsIdNamed() public static method

public static IsIdNamed ( this node, Symbol name ) : bool
node this
name Symbol
return bool

IsIdNamed() public static method

public static IsIdNamed ( this node, string name ) : bool
node this
name string
return bool

IsLiteral() public static method

public static IsLiteral ( this node ) : bool
node this
return bool

IsParenthesizedExpr() public static method

public static IsParenthesizedExpr ( this node ) : bool
node this
return bool

IsTrivia() public static method

public static IsTrivia ( this node ) : bool
node this
return bool

MatchesPattern() public static method

public static MatchesPattern ( this candidate, LNode pattern, LNode>.IDictionary &captures ) : bool
candidate this
pattern LNode
captures LNode>.IDictionary
return bool

MatchesPattern() public static method

public static MatchesPattern ( this candidate, LNode pattern, LNode>.IDictionary &captures, VList &unmatchedAttrs ) : bool
candidate this
pattern LNode
captures LNode>.IDictionary
unmatchedAttrs VList
return bool

MatchesPattern() public static method

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.
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.
public static MatchesPattern ( this candidate, LNode pattern, LNode>.MMap &captures, VList &unmatchedAttrs ) : bool
candidate this A node that you want to compare with a 'pattern'.
pattern LNode 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 LNode>.MMap 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 VList On return, a list of trivia attributes in /// candidate that were not present in pattern.
return bool

NodeNamed() public static method

public static NodeNamed ( this self, Symbol name ) : ILNode
self this
name Symbol
return ILNode

NodeNamed() public static method

public static NodeNamed ( this self, Symbol name ) : LNode
self this
name Symbol
return LNode

PlusTrailingTrivia() public static method

Adds additional trailing trivia to a node.
public static PlusTrailingTrivia ( this node, LNode trivia ) : LNode
node this
trivia LNode
return LNode

PlusTrailingTrivia() public static method

Adds additional trailing trivia to a node.
public static PlusTrailingTrivia ( this node, VList trivia ) : LNode
node this
trivia VList
return LNode

PlusTrailingTrivia() public static method

Adds additional trailing trivia to an attribute list.
public static PlusTrailingTrivia ( this attrs, LNode trivia ) : VList
attrs this
trivia LNode
return VList

PlusTrailingTrivia() public static method

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.
public static PlusTrailingTrivia ( this attrs, VList trivia ) : VList
attrs this
trivia VList
return VList

SpliceAdd() public static method

public static SpliceAdd ( this list, LNode node, Symbol listName = null ) : void
list this
node LNode
listName Symbol
return void

SpliceInsert() public static method

public static SpliceInsert ( this list, int index, LNode node, Symbol listName = null ) : void
list this
index int
node LNode
listName Symbol
return void

ToLNode() public static method

Converts ILNode to LNode recursively. If the specified node is already an LNode, this method simply does a cast.
public static ToLNode ( ILNode node ) : LNode
node ILNode
return LNode

WithSpliced() public static method

public static WithSpliced ( this list, LNode node, Symbol listName = null ) : VList
list this
node LNode
listName Symbol
return VList

WithSpliced() public static method

public static WithSpliced ( this list, int index, LNode node, Symbol listName = null ) : VList
list this
index int
node LNode
listName Symbol
return VList

WithTrailingTrivia() public static method

Removes a node's trailing trivia and adds a new list of trailing trivia.
public static WithTrailingTrivia ( this node, VList trivia ) : LNode
node this
trivia VList
return LNode

WithTrailingTrivia() public static method

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.
public static WithTrailingTrivia ( this attrs, VList trivia ) : VList
attrs this
trivia VList
return VList

Without() public static method

public static Without ( this list, LNode node ) : VList
list this
node LNode
return VList

WithoutAttr() public static method

public static WithoutAttr ( this self, LNode node ) : LNode
self this
node LNode
return LNode

WithoutAttrNamed() public static method

public static WithoutAttrNamed ( this self, Symbol name ) : LNode
self this
name Symbol
return LNode

WithoutAttrNamed() public static method

public static WithoutAttrNamed ( this self, Symbol name, LNode &removedAttr ) : LNode
self this
name Symbol
removedAttr LNode
return LNode

WithoutNodeNamed() public static method

public static WithoutNodeNamed ( this a, Symbol name ) : VList
a this
name Symbol
return VList

WithoutNodeNamed() public static method

public static WithoutNodeNamed ( this list, Symbol name, LNode &removedNode ) : VList
list this
name Symbol
removedNode LNode
return VList

WithoutOuterParens() public static method

Removes a single pair of parentheses, if the node has a #trivia_inParens attribute. Returns the same node when no parens are present.
public static WithoutOuterParens ( this self ) : LNode
self this
return LNode

WithoutTrailingTrivia() public static method

Gets a new list with any #trivia_trailing attributes removed.
public static WithoutTrailingTrivia ( this attrs ) : VList
attrs this
return VList

WithoutTrailingTrivia() public static method

Gets a new list with any #trivia_trailing attributes removed. Those trivia are returned in an `out` parameter.
public static WithoutTrailingTrivia ( this attrs, VList &trailingTrivia ) : VList
attrs this
trailingTrivia VList
return VList