Language of your choice: library documentation
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.Max. Items with non-negative indexes (e.g.
N, N) 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.LesLanguageService.Print(ILNode, StringBuilder, IMessageSink, ParsingMode, ILNodePrinterOptions)
|Properties inherited from Loyc.IHasValue< object >|
|Properties inherited from Loyc.Collections.INegListSource< ILNode >|
|Returns the minimum valid index in the collection. More...|
|Returns the maximum valid index in the collection. More...|
|Gets the item at the specified index. More...|
|Properties inherited from Loyc.IHasLocation|
|bool||CallsMin (Symbol name, int argCount)|
|Returns true if |
|bool||Calls (Symbol name, int argCount)|
|Returns true if |
|Public Member Functions inherited from Loyc.Syntax.IToLNode|
|Converts this object to an LNode, or returns |
|Public Member Functions inherited from Loyc.Collections.INegListSource< ILNode >|
|T||TryGet (int index, out bool fail)|
|Gets the item at the specified index, and does not throw an exception on failure. More...|
|IRange< T >||Slice (int start, int count=int.MaxValue)|
|Returns a sub-range of this list. More...|
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.
Referenced by Loyc.Syntax.LNodeExt.GetCaptureIdentifier().