Enhanced C#
Language of your choice: library documentation
Properties | Public Member Functions | List of all members
Loyc.Syntax.ILNode Interface Reference

A read-only interface for objects that act as Loyc trees. More...


Source file:
Inheritance diagram for Loyc.Syntax.ILNode:
Loyc.Syntax.ILiteralValue Loyc.Collections.INegListSource< ILNode > Loyc.IHasLocation Loyc.Syntax.IUninterpretedLiteral Loyc.IHasValue< object > Loyc.Syntax.LNode Loyc.Syntax.CallNode Loyc.Syntax.IdNode Loyc.Syntax.LiteralNode

Remarks

A read-only interface for objects that act as Loyc trees.

To simplify implementations of this interface, there is no separate list of attributes and arguments; ILNode itself acts as a list of child nodes. The argument list is numbered from 0 to Max, so the number of arguments is Max + 1 (which is what the ArgCount() extension method returns).

A node with no children must report Min = -1 and Max = -2, or some extension methods will malfunction.

You can think of any node N as having a single contiguous list of child nodes indexed from N.Min to N.Max. Items with non-negative indexes (e.g. N[0], N[1]) are arguments; N[-1] is an alias for Target; and indexes below -1 refer to attributes (e.g. N[-2] is the last attribute in the attribute list)

ArgCount() and AttrCount() are implemented as extension methods; they return Max + 1 and -Min - 1 respectively (note: ArgCount() is different from LNode.ArgCount in case Kind != LNodeKind.Call: ArgCount() returns -1 in that case while LNode.ArgCount reurns zero.

The IsId(), IsLiteral() and IsCall() extension methods are useful shorthand for testing the Kind property.

The Attrs() and Args() extension methods return slices of this node corresponding to the attributes and arguments.

Tip: the LES node printer can print any ILNode as a string. See Loyc.Syntax.Les.Les3LanguageService.Print(ILNode, StringBuilder, IMessageSink, ParsingMode, ILNodePrinterOptions)

Properties

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 >
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]
 

Public Member Functions

bool CallsMin (Symbol name, int argCount)
 Returns true if Kind == LNodeKind.Call, Name == name, and Max + 1 >= argCount. More...
 
bool Calls (Symbol name, int argCount)
 Returns true if Name == name and Max + 1 == argCount (which implies Kind == LNodeKind.Call if argCount != -1). More...
 
- 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...
 

Member Function Documentation

◆ Calls()

bool Loyc.Syntax.ILNode.Calls ( Symbol  name,
int  argCount 
)

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.

Implemented in Loyc.Syntax.LNode, and Loyc.Syntax.CallNode.

◆ CallsMin()

bool Loyc.Syntax.ILNode.CallsMin ( Symbol  name,
int  argCount 
)

Returns true if Kind == LNodeKind.Call, Name == name, and Max + 1 >= argCount.

See also
LNodeExt.Calls

Implemented in Loyc.Syntax.LNode, and Loyc.Syntax.CallNode.