Enhanced C#
Language of your choice: library documentation
|
Base class of all nodes that represent calls such as f(x)
, operator calls such as x + y
, braced blocks, and all other things that are not simple symbols and literals.
More...
Base class of all nodes that represent calls such as f(x)
, operator calls such as x + y
, braced blocks, and all other things that are not simple symbols and literals.
Public fields | |
override object | Value => NoValue.Value |
override UString | TextValue => default(UString) |
override Symbol | TypeMarker => null |
Public fields inherited from Loyc.Syntax.LNode | |
virtual UString | TextValue => default(UString) |
If this node IsLiteral, gets the original text of the literal, if it is available. This property is empty if the node was created programmatically from a value, or if the parser did not save the original text, or if this is not a literal. More... | |
virtual Symbol | TypeMarker => null |
If this node IsLiteral, gets the type marker associated with the literal. This property is null if the node was created programmatically from a value, or if the parser did not save the type marker, or if this is not a literal. More... | |
Properties | |
sealed override LNodeKind | Kind [get] |
override Symbol | Name [get] |
abstract override LNode | Target [get] |
abstract override LNodeList | Args [get] |
Properties inherited from Loyc.Syntax.LNode | |
virtual SourceRange | Range [get] |
Returns the location and range in source code of this node. More... | |
ISourceFile | Source [get] |
Returns the source file (shortcut for Range.Source ). More... | |
NodeStyle | Style [get, set] |
Indicates the preferred style to use when printing the node to a text string. More... | |
NodeStyle | BaseStyle [get, set] |
virtual LNodeList | Attrs [get] |
Returns the attribute list for this node. More... | |
virtual bool | IsFrozen [get] |
Returns true if the node is immutable, and false if any part of it can be edited. Currently, mutable nodes are not implemented. More... | |
abstract LNodeKind | Kind [get] |
Returns the LNodeKind: Symbol, Literal, or Call. More... | |
bool | IsCall [get] |
bool | IsId [get] |
bool | IsLiteral [get] |
abstract Symbol | Name [get] |
Returns the Symbol if IsId. If this node is a call (IsCall) and Target.IsId is true, this property returns Target.Name . In all other cases, the name is GSymbol.Empty. Shall not return null. More... | |
bool | HasSpecialName [get] |
Returns true if Name is a "special" name (i.e. starts with '#' or '\'' or '.' or any character below 48 in ASCII). More... | |
bool | HasValue [get] |
abstract object | Value [get] |
Returns the value of a literal node, or NoValue.Value if this node is not a literal (IsLiteral is false). More... | |
abstract LNode | Target [get] |
Returns the target of a method call, or null if IsCall is false. The target can be a symbol with no name (GSymbol.Empty) to represent a parenthesized expression, if there is one argument. More... | |
abstract LNodeList | Args [get] |
Returns the argument list of this node. Always empty when IsCall==false . More... | |
static ILNodePrinter?? | Printer [get, set] |
Gets or sets the default node printer on the current thread, which controls how nodes are serialized to text by default. More... | |
virtual object | TriviaValue [get] |
Gets the value of Args[0].Value , if Args[0] exists; otherwise, returns NoValue.Value. More... | |
int | ArgCount [get] |
int | AttrCount [get] |
bool | HasAttrs [get] |
bool | IsTrivia [get] |
int | Min [get] |
virtual int? | Max [get] |
LNode | this[int index] [get] |
int | Count [get] |
Properties inherited from Loyc.Syntax.ILNode | |
LNodeKind | Kind [get] |
Symbol | Name [get] |
ILNode | Target [get] |
ISourceRange | Range [get] |
NodeStyle | Style [get, set] |
Properties inherited from Loyc.Syntax.IUninterpretedLiteral | |
UString | TextValue [get] |
Represents the serialized text of the value. More... | |
Symbol | TypeMarker [get] |
Represents the type of the value. More... | |
Properties inherited from Loyc.IHasValue< object > | |
T | Value [get] |
Properties inherited from Loyc.Collections.INegListSource< ILNode > | |
int | Min [get] |
Returns the minimum valid index in the collection. More... | |
int | Max [get] |
Returns the maximum valid index in the collection. More... | |
Properties inherited from Loyc.IHasLocation | |
object | Location [get] |
Properties inherited from Loyc.Collections.INegListSource< LNode > | |
int | Min [get] |
Returns the minimum valid index in the collection. More... | |
int | Max [get] |
Returns the maximum valid index in the collection. More... | |
Public Member Functions | |
override LNode | WithName (Symbol name) |
Creates a node with a new value for Name. More... | |
override LiteralNode | WithValue (object value) |
Creates a new literal node with a different Value than the current literal node. More... | |
override CallNode | WithArgs (LNodeList args) |
Creates a Node with a new argument list. If this node is not a call, a new node is created using this node as its target. Otherwise, the existing argument list is replaced. More... | |
sealed override void | Call (LNodeVisitor visitor) |
sealed override void | Call (ILNodeVisitor visitor) |
abstract override LNode | Clone () |
Creates a copy of the node. Since nodes are immutable, there is little reason for an end-user to call this, but Clone() is used internally as a helper method by the WithXyz() methods. More... | |
abstract override LNode | WithAttrs (LNodeList attrs) |
override bool | Calls (Symbol name, int argCount) |
Returns true if Name == name and Max + 1 == argCount (which implies Kind == LNodeKind.Call if argCount != -1). More... | |
override bool | Calls (string name, int argCount) |
override bool | Calls (Symbol name) |
override bool | Calls (string name) |
override bool | CallsMin (Symbol name, int argCount) |
Returns true if this is a call with the specified name and the specified minimum number of arguments. More... | |
override bool | CallsMin (string name, int argCount) |
Returns true if this is a call with the specified name and the specified minimum number of arguments. More... | |
override bool | HasSimpleHead () |
Returns true if this is not a call, or if the call's Target is an Id or a Literal. More... | |
override bool | HasSimpleHeadWithoutPAttrs () |
Returns true if this is not a call, or if the call's Target is an Id or a Literal, and the Target has only trivia attributes. More... | |
sealed override LNode | WithArgs (Func< LNode, Maybe< LNode >> selector) |
sealed override LNode | Select (Func< LNode, Maybe< LNode >> selector, ReplaceOpt options=ReplaceOpt.ProcessAttrs) |
Transforms the Target, parameters, and optionally the attributes of an LNode, returning another LNode of the same Kind. If the selector makes no changes, Select() returns this . More... | |
override LNode | SelectMany (Func< LNode, IReadOnlyList< LNode >> selector, ReplaceOpt options=ReplaceOpt.ProcessAttrs) |
Public Member Functions inherited from Loyc.Syntax.LNode | |
LNode | SetBaseStyle (NodeStyle s) |
LNode | SetStyle (NodeStyle s) |
virtual CallNode | WithTarget (LNode target) |
virtual CallNode | WithTarget (Symbol name) |
virtual CallNode | With (LNode target, LNodeList args) |
Creates a CallNode with the same attributes and Range, but a different target and argument list. If the current node is not a CallNode, it becomes one (the Range, Style and attributes of the current node are kept, but the Kind, Value, and Name are discarded.) More... | |
virtual CallNode | With (Symbol target, LNodeList args) |
Creates a CallNode with the same attributes and Range, but a different target and argument list. If the current node is not a CallNode, it becomes one (the Range, Style and attributes of the current node are kept, but the Kind, Value, and Name are discarded.) More... | |
CallNode | With (Symbol target, params LNode[] args) |
LNode | WithRange (SourceRange range) |
virtual LNode | WithRange (int startIndex, int endIndex) |
LNode | WithStyle (NodeStyle style) |
virtual LNode | With (SourceRange range, NodeStyle style) |
virtual LNode | WithoutAttrs () |
LNode | WithAttrs (params LNode[] attrs) |
CallNode | WithArgs (params LNode[] args) |
LNode | PlusAttr (LNode attr) |
LNode | PlusAttrs (IEnumerable< LNode > attrs) |
LNode | PlusAttrs (params LNode[] attrs) |
LNode | PlusAttrs (LNodeList attrs) |
LNode | PlusAttrsBefore (LNodeList attrs) |
LNode | PlusAttrsBefore (params LNode[] attrs) |
LNode | PlusAttrBefore (LNode attr) |
LNode | PlusArg (LNode arg) |
LNode | PlusArgs (LNodeList args) |
LNode | PlusArgs (IEnumerable< LNode > args) |
LNode | PlusArgs (params LNode[] args) |
LNode | WithArgChanged (int index, Func< LNode, LNode > selector) |
LNode | WithArgChanged (int index, LNode newValue) |
LNode | WithAttrChanged (int index, LNode newValue) |
LNode | WithChildChanged (int index, LNode newValue) |
virtual string | Print (ParsingMode mode=null, ILNodePrinterOptions options=null) |
override string | ToString () |
virtual bool | Equals (ILNode other, CompareMode mode) |
Compares two nodes for structural equality. Two nodes are considered equal if they have the same kind, the same name, the same value, the same arguments, and the same attributes. More... | |
bool | Equals (LNode other) |
bool | Equals (ILNode other) |
override bool | Equals (object other) |
override int | GetHashCode () |
Gets the hash code based on the structure of the tree. More... | |
bool | HasPAttrs () |
LNodeList | PAttrs () |
virtual LNode | WithAttrs (Func< LNode, Maybe< LNode >> selector) |
virtual LNode | WithAttrs (Func< LNode, IReadOnlyList< LNode >> selector) |
virtual bool | IsIdWithoutPAttrs () |
virtual bool | IsIdWithoutPAttrs (Symbol name) |
virtual bool | IsIdNamed (Symbol name) |
virtual bool | IsIdNamed (string name) |
CallNode | WithSplicedArgs (int index, LNode from, Symbol listName) |
CallNode | WithSplicedArgs (LNode from, Symbol listName) |
LNode | WithSplicedAttrs (int index, LNode from, Symbol listName) |
LNode | WithSplicedAttrs (LNode from, Symbol listName) |
NestedEnumerable< DescendantsFrame, LNode > | Descendants (NodeScanMode mode=NodeScanMode.YieldAllChildren) |
NestedEnumerable< DescendantsFrame, LNode > | DescendantsAndSelf () |
LNode | TryGet (int index, out bool fail) |
IRange< LNode > | Slice (int start, int count=int.MaxValue) |
IEnumerator< LNode > | GetEnumerator () |
Maybe< LNode > | ReplaceRecursive (Func< LNode, Maybe< LNode >> matcher, ReplaceOpt options=ReplaceOpt.Default) |
Performs a recursive find-and-replace operation, by attempting to replace each child (among Attrs, Target, Args) using the specified selector. This method can also be used for simple searching, by giving a selector that always returns null. More... | |
LNode | ReplaceRecursive (Func< LNode, LNode > matcher, ReplaceOpt options=ReplaceOpt.Default) |
LNodeList | RecursiveReplace (Func< LNode, LNodeList?> matcher, ReplaceOpt options=ReplaceOpt.Default) |
Public Member Functions inherited from Loyc.Collections.INegListSource< ILNode > | |
IRange< T > | Slice (int start, int count=int.MaxValue) |
Returns a sub-range of this list. More... | |
Public Member Functions inherited from Loyc.ICloneable< LNode > | |
T | Clone () |
Public Member Functions inherited from Loyc.Collections.INegListSource< LNode > | |
IRange< T > | Slice (int start, int count=int.MaxValue) |
Returns a sub-range of this list. More... | |
Protected Member Functions | |
CallNode (LNode ras) | |
CallNode (SourceRange range, NodeStyle style) | |
Protected Member Functions inherited from Loyc.Syntax.LNode | |
LNode (LNode prototype) | |
LNode (SourceRange range, NodeStyle style) | |
Protected fields | |
int | _hashCode = -1 |
Protected fields inherited from Loyc.Syntax.LNode | |
RangeAndStyle | RAS |
Additional Inherited Members | |
Public Types inherited from Loyc.Syntax.LNode | |
enum | CompareMode { Normal = 0, Styles = 1, IgnoreTrivia = 2 } |
enum | ReplaceOpt { ReplaceOpt.ReplaceRoot = 1, ReplaceOpt.ProcessAttrs = 2, ReplaceOpt.Default = ReplaceRoot | ProcessAttrs } |
Public static fields inherited from Loyc.Syntax.LNode | |
static readonly EmptySourceFile | SyntheticSource = new EmptySourceFile("<Synthetic Code>") |
static readonly IdNode | Missing = Id(CodeSymbols.Missing) |
The empty identifier, used to represent missing information. More... | |
static readonly LNode | InParensTrivia = Id(CodeSymbols.TriviaInParens) |
Used by the quote {...} macro. More... | |
Static Public Member Functions inherited from Loyc.Syntax.LNode | |
static IdNode | Id (Symbol name, LNode prototype) |
static IdNode | Id (string name, LNode prototype) |
static IdNode | Id (LNodeList attrs, Symbol name, LNode prototype) |
static IdNode | Id (LNodeList attrs, string name, LNode prototype) |
static LiteralNode | Literal< V > (V value, LNode prototype) |
static LiteralNode | Literal< V > (LNodeList attrs, V value, LNode prototype) |
static CallNode | Call (Symbol name, LNode prototype) |
static CallNode | Call (LNode target, LNode prototype) |
static CallNode | Call (Symbol name, LNodeList args, LNode prototype) |
static CallNode | Call (LNode target, LNodeList args, LNode prototype) |
static CallNode | Call (LNodeList attrs, Symbol name, LNodeList args, LNode prototype) |
static CallNode | Call (LNodeList attrs, LNode target, LNodeList args, LNode prototype) |
static CallNode | Trivia (Symbol name, object value, LNode prototype) |
static IdNode | Id (Symbol name, SourceRange range, NodeStyle style=NodeStyle.Default) |
static IdNode | Id (string name, SourceRange range, NodeStyle style=NodeStyle.Default) |
static IdNode | Id (LNodeList attrs, Symbol name, SourceRange range, NodeStyle style=NodeStyle.Default) |
static IdNode | Id (LNodeList attrs, string name, SourceRange range, NodeStyle style=NodeStyle.Default) |
static LiteralNode | Literal< V > (V value, SourceRange range, NodeStyle style=NodeStyle.Default) |
static LiteralNode | Literal (SourceRange range, LiteralValue value, NodeStyle style=NodeStyle.Default) |
static LiteralNode | Literal< P > (SourceRange range, P valueProvider, NodeStyle style=NodeStyle.Default) |
static LiteralNode | Literal< V > (LNodeList attrs, V value, SourceRange range, NodeStyle style=NodeStyle.Default) |
static LiteralNode | Literal (LNodeList attrs, SourceRange range, LiteralValue value, NodeStyle style=NodeStyle.Default) |
static LiteralNode | Literal< P > (LNodeList attrs, SourceRange range, P valueProvider, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (Symbol name, SourceRange range, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (Symbol name, SourceRange range, int targetStart, int targetEnd, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (LNode target, SourceRange range, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (Symbol name, LNodeList args, SourceRange range, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (Symbol name, LNodeList args, SourceRange range, int targetStart, int targetEnd, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (LNode target, LNodeList args, SourceRange range, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (LNodeList attrs, Symbol name, LNodeList args, SourceRange range, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (LNodeList attrs, LNode target, LNodeList args, SourceRange range, NodeStyle style=NodeStyle.Default) |
static CallNode | Trivia (Symbol name, object value, SourceRange range, NodeStyle style=NodeStyle.Default) |
static IdNode | Id (Symbol name, ISourceFile file=null) |
static IdNode | Id (string name, ISourceFile file=null) |
static IdNode | Id (LNodeList attrs, Symbol name, ISourceFile file=null) |
static IdNode | Id (LNodeList attrs, string name, ISourceFile file=null) |
static LiteralNode | Literal< V > (V value, ISourceFile file=null, NodeStyle style=NodeStyle.Default) |
static LiteralNode | Literal< V > (LNodeList attrs, V value, ISourceFile file=null, NodeStyle style=NodeStyle.Default) |
static LiteralNode | Literal (object value, ISourceFile file=null, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (Symbol name, ISourceFile file=null, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (LNode target, ISourceFile file=null, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (Symbol name, LNodeList args, ISourceFile file=null, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (LNode target, LNodeList args, ISourceFile file=null, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (LNodeList attrs, Symbol name, ISourceFile file=null, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (LNodeList attrs, LNode target, ISourceFile file=null, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (LNodeList attrs, Symbol name, LNodeList args, ISourceFile file=null, NodeStyle style=NodeStyle.Default) |
static CallNode | Call (LNodeList attrs, LNode target, LNodeList args, ISourceFile file=null, NodeStyle style=NodeStyle.Default) |
static CallNode | Trivia (Symbol name, object value, ISourceFile file=null, NodeStyle style=NodeStyle.Default) |
static LNodeList | List () |
static LNodeList | List (LNode item_0) |
static LNodeList | List (LNode item_0, LNode item_1) |
static LNodeList | List (params LNode[] list) |
static LNodeList | List (IEnumerable< LNode > list) |
static LNodeList | List (VList< LNode > list) |
static bool | IsSpecialName (string name) |
Returns true if name is considered a "special" name that starts with any character below 48 in ASCII, such as '#', '\'', and '.'. More... | |
static bool | IsSpecialName (Symbol name) |
static SavedValue< ILNodePrinter > | SetPrinter (ILNodePrinter newValue) |
static PushedPrinter | PushPrinter (ILNodePrinter printer) |
Helps you change printers temporarily. Usage in C#: using (LNode.PushPrinter(myPrinter)) { ... } More... | |
static bool | Equals (LNodeList a, LNodeList b, CompareMode mode=CompareMode.Normal) |
Compares two lists of nodes for structural equality. More... | |
static bool | Equals (ILNode a, ILNode b, CompareMode mode=CompareMode.Normal) |
static LNode | MergeLists (LNode node1, LNode node2, Symbol listName) |
Some CallNodes are used to represent lists. This method merges two nodes, forming or appending a list (see remarks). More... | |
static LNode | MergeBinary (LNode node1, LNode node2, Symbol binaryOpName) |
Combines two nodes using a binary operator or function. More... | |
static List< LNode > | FlattenBinaryOpSeq (LNode expr, Symbol opName, bool? rightAssociative=null) |
Converts a sequence of the same operator (e.g. x+y+z ) to a list (e.g. x, y, z). More... | |
Static Protected Member Functions inherited from Loyc.Syntax.LNode | |
static void | NoNulls (LNodeList list, string propName) |
Protected static fields inherited from Loyc.Syntax.LNode | |
static readonly CallNode | EmptySplice = Call(CodeSymbols.Splice) |
|
inlinevirtual |
Returns true if Name == name
and Max + 1 == argCount
(which implies Kind == LNodeKind.Call
if argCount != -1).
This could have been an extension method, but when verifying that you have a certain kind of node, it's common to check both the Name and ArgCount(); checking both in one call avoids extra interface invocations.
Reimplemented from Loyc.Syntax.LNode.
|
inlinevirtual |
Returns true if this is a call with the specified name and the specified minimum number of arguments.
Reimplemented from Loyc.Syntax.LNode.
References Loyc.Symbol.Name.
|
inlinevirtual |
Returns true if this is a call with the specified name and the specified minimum number of arguments.
Reimplemented from Loyc.Syntax.LNode.
|
pure virtual |
Creates a copy of the node. Since nodes are immutable, there is little reason for an end-user to call this, but Clone() is used internally as a helper method by the WithXyz() methods.
Implements Loyc.Syntax.LNode.
|
inlinevirtual |
Returns true if this is not a call, or if the call's Target is an Id or a Literal.
Reimplemented from Loyc.Syntax.LNode.
|
inlinevirtual |
Returns true if this is not a call, or if the call's Target is an Id or a Literal, and the Target has only trivia attributes.
Reimplemented from Loyc.Syntax.LNode.
|
inlinevirtual |
Transforms the Target, parameters, and optionally the attributes of an LNode, returning another LNode of the same Kind. If the selector makes no changes, Select() returns this
.
The selector is not allowed to return null, but it can return NoValue.Value
to delete a parameter or target. If the current node is a target, it cannot be deleted, so it is replaced with #splice()
which, by convention, represents an empty list. If you're wondering why we don't use null
for deletions, it is because the functionality of this method is actually implemented by VList<T>.WhereSelect(Func<T, Maybe<T>>); since T could be a value type, that method cannot use null as a signal to delete items from the collection.
It is not possible to delete the Target of a call, and if the selector returns NoValue.Value
for the Target, the target is replaced with an empty call to #splice()
.
Reimplemented from Loyc.Syntax.LNode.
References Loyc.Syntax.LNode.Target, Loyc.Syntax.LNodeList.WhereSelect(), Loyc.Syntax.LNode.With(), and Loyc.Syntax.CallNode.WithArgs().
Creates a Node with a new argument list. If this node is not a call, a new node is created using this node as its target. Otherwise, the existing argument list is replaced.
args | New argument list |
Implements Loyc.Syntax.LNode.
References Loyc.Syntax.LNode.With().
Referenced by Loyc.LLPG.Macros.LllpgMacro(), and Loyc.Syntax.CallNode.Select().
Creates a node with a new value for Name.
If IsId, the Name is simply changed. If IsCall, this method returns the equivalent of WithTarget(Target.WithName(name))
(which may be optimized for the particular call type). If IsLiteral, the Kind changes to LNodeKind.Id in order to set the name.
Reimplemented from Loyc.Syntax.LNode.
References Loyc.Syntax.LNode.WithName().
|
inlinevirtual |
Creates a new literal node with a different Value than the current literal node.
InvalidOperationException | The node was not a literal already. |
Implements Loyc.Syntax.LNode.