C# Класс Loyc.Syntax.LNodeExt

Standard extension methods for LNode.
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
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

Описание методов

ArgCount() публичный статический Метод

public static ArgCount ( this node ) : int
node this
Результат int

ArgNamed() публичный статический Метод

public static ArgNamed ( this self, Symbol name ) : LNode
self this
name Symbol
Результат LNode

Args() публичный статический Метод

public static Args ( this node ) : NegListSlice
node this
Результат NegListSlice

AsLNode() публичный статический Метод

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".
Результат LNode

AsList() публичный статический Метод

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
Результат VList

AttrCount() публичный статический Метод

public static AttrCount ( this node ) : int
node this
Результат int

AttrNamed() публичный статический Метод

public static AttrNamed ( this node, Symbol name ) : ILNode
node this
name Symbol
Результат ILNode

AttrNamed() публичный статический Метод

public static AttrNamed ( this self, Symbol name ) : LNode
self this
name Symbol
Результат LNode

Attrs() публичный статический Метод

public static Attrs ( this node ) : NegListSlice
node this
Результат NegListSlice

BaseStyle() публичный статический Метод

public static BaseStyle ( this node ) : NodeStyle
node this
Результат NodeStyle

Calls() публичный статический Метод

public static Calls ( this node, Symbol name ) : bool
node this
name Symbol
Результат bool

GetCaptureIdentifier() публичный статический Метод

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
Результат LNode

GetTrailingTrivia() публичный статический Метод

public static GetTrailingTrivia ( this node ) : IListSource
node this
Результат IListSource

GetTrailingTrivia() публичный статический Метод

Gets all trailing trivia attached to the specified node.
public static GetTrailingTrivia ( this node ) : VList
node this
Результат VList

GetTrailingTrivia() публичный статический Метод

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
Результат VList

GetTrivia() публичный статический Метод

public static GetTrivia ( this node ) : VList
node this
Результат VList

GetTrivia() публичный статический Метод

public static GetTrivia ( this attrs ) : VList
attrs this
Результат VList

HasAttrs() публичный статический Метод

public static HasAttrs ( this node ) : bool
node this
Результат bool

HasPAttrs() публичный статический Метод

public static HasPAttrs ( this node ) : bool
node this
Результат bool

HasSpecialName() публичный статический Метод

public static HasSpecialName ( this node ) : bool
node this
Результат bool

InParens() публичный статический Метод

Returns the same node with a parentheses attribute added.
public static InParens ( this node ) : LNode
node this
Результат LNode

InParens() публичный статический Метод

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
Результат LNode

InParens() публичный статический Метод

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
Результат LNode

IndexWithName() публичный статический Метод

public static IndexWithName ( this self, Symbol name, int resultIfNotFound = -1 ) : int
self this
name Symbol
resultIfNotFound int
Результат int

IsCall() публичный статический Метод

public static IsCall ( this node ) : bool
node this
Результат bool

IsId() публичный статический Метод

public static IsId ( this node ) : bool
node this
Результат bool

IsIdNamed() публичный статический Метод

public static IsIdNamed ( this node, Symbol name ) : bool
node this
name Symbol
Результат bool

IsIdNamed() публичный статический Метод

public static IsIdNamed ( this node, string name ) : bool
node this
name string
Результат bool

IsLiteral() публичный статический Метод

public static IsLiteral ( this node ) : bool
node this
Результат bool

IsParenthesizedExpr() публичный статический Метод

public static IsParenthesizedExpr ( this node ) : bool
node this
Результат bool

IsTrivia() публичный статический Метод

public static IsTrivia ( this node ) : bool
node this
Результат bool

MatchesPattern() публичный статический Метод

public static MatchesPattern ( this candidate, LNode pattern, LNode>.IDictionary &captures ) : bool
candidate this
pattern LNode
captures LNode>.IDictionary
Результат bool

MatchesPattern() публичный статический Метод

public static MatchesPattern ( this candidate, LNode pattern, LNode>.IDictionary &captures, VList &unmatchedAttrs ) : bool
candidate this
pattern LNode
captures LNode>.IDictionary
unmatchedAttrs VList
Результат bool

MatchesPattern() публичный статический Метод

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.
Результат bool

NodeNamed() публичный статический Метод

public static NodeNamed ( this self, Symbol name ) : ILNode
self this
name Symbol
Результат ILNode

NodeNamed() публичный статический Метод

public static NodeNamed ( this self, Symbol name ) : LNode
self this
name Symbol
Результат LNode

PlusTrailingTrivia() публичный статический Метод

Adds additional trailing trivia to a node.
public static PlusTrailingTrivia ( this node, LNode trivia ) : LNode
node this
trivia LNode
Результат LNode

PlusTrailingTrivia() публичный статический Метод

Adds additional trailing trivia to a node.
public static PlusTrailingTrivia ( this node, VList trivia ) : LNode
node this
trivia VList
Результат LNode

PlusTrailingTrivia() публичный статический Метод

Adds additional trailing trivia to an attribute list.
public static PlusTrailingTrivia ( this attrs, LNode trivia ) : VList
attrs this
trivia LNode
Результат VList

PlusTrailingTrivia() публичный статический Метод

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
Результат VList

SpliceAdd() публичный статический Метод

public static SpliceAdd ( this list, LNode node, Symbol listName = null ) : void
list this
node LNode
listName Symbol
Результат void

SpliceInsert() публичный статический Метод

public static SpliceInsert ( this list, int index, LNode node, Symbol listName = null ) : void
list this
index int
node LNode
listName Symbol
Результат void

ToLNode() публичный статический Метод

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
Результат LNode

WithSpliced() публичный статический Метод

public static WithSpliced ( this list, LNode node, Symbol listName = null ) : VList
list this
node LNode
listName Symbol
Результат VList

WithSpliced() публичный статический Метод

public static WithSpliced ( this list, int index, LNode node, Symbol listName = null ) : VList
list this
index int
node LNode
listName Symbol
Результат VList

WithTrailingTrivia() публичный статический Метод

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
Результат LNode

WithTrailingTrivia() публичный статический Метод

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
Результат VList

Without() публичный статический Метод

public static Without ( this list, LNode node ) : VList
list this
node LNode
Результат VList

WithoutAttr() публичный статический Метод

public static WithoutAttr ( this self, LNode node ) : LNode
self this
node LNode
Результат LNode

WithoutAttrNamed() публичный статический Метод

public static WithoutAttrNamed ( this self, Symbol name ) : LNode
self this
name Symbol
Результат LNode

WithoutAttrNamed() публичный статический Метод

public static WithoutAttrNamed ( this self, Symbol name, LNode &removedAttr ) : LNode
self this
name Symbol
removedAttr LNode
Результат LNode

WithoutNodeNamed() публичный статический Метод

public static WithoutNodeNamed ( this a, Symbol name ) : VList
a this
name Symbol
Результат VList

WithoutNodeNamed() публичный статический Метод

public static WithoutNodeNamed ( this list, Symbol name, LNode &removedNode ) : VList
list this
name Symbol
removedNode LNode
Результат VList

WithoutOuterParens() публичный статический Метод

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
Результат LNode

WithoutTrailingTrivia() публичный статический Метод

Gets a new list with any #trivia_trailing attributes removed.
public static WithoutTrailingTrivia ( this attrs ) : VList
attrs this
Результат VList

WithoutTrailingTrivia() публичный статический Метод

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
Результат VList