Enhanced C#
Language of your choice: library documentation
|
Standard extension methods for IMacroContext. More...
Standard extension methods for IMacroContext.
Static Public Member Functions | |
static LNode | CurrentNode (this IMacroContext ctx) |
static Pair< VList< LNode > , VList< LNode > > | GetArgsAndBody (this IMacroContext ctx, bool orRemainingNodes) |
Splits the current node into a pair of "argument" and "body" lists, potentially treating ctx.RemainingNodes as the "body" list. More... | |
static IEnumerable < KeyValuePair< Symbol, LNode > > | GetOptions (VList< LNode > optionList) |
Transforms an option list in the format option1(v1), option2(v2) or option1: v1, option2: v2 into a sequence of (key, value) pairs. If the format of a given node is invalid, this function yields (null, node) . More... | |
|
inlinestatic |
Splits the current node into a pair of "argument" and "body" lists, potentially treating ctx.RemainingNodes as the "body" list.
ctx | Context of the current macro. |
orRemainingNodes | Whether to use ctx.RemainingNodes as the second list if there is no {braces node} at the end of ctx.CurrentNode().Args. |
EC# supports a syntax specially designed for macro calls:
This is stored as a call node with a body, in braces, as its final parameter, i.e. it is equivalent to
A similar, but more general feature called "superexpressions" exists in LES.
Some macros would additionally like to apply themselves to all remaining nodes in the current list of statements or expressions, i.e.
LeMP supports this through the IMacroContext.DropRemainingNodes and IMacroContext.RemainingNodes APIs. If your macro wants to apply itself to all remaining statements or expressions in the current sequence of nodes, it can set the DropRemainingNodes property to true and then simply incorporate RemainingNodes into its own output (if you need to return multiple statements from your macro, use list.AsLNode(CodeSymbols.Splice)
to convert a VList{LNode} to an LNode.)
This extension method helps you by detecting whether the current node has a body in braces or not. If the braces are present, the returned pair consists of the args shortened by one (i.e. ctx.CurrentNode().Args.WithoutLast(1)
) and the Args of the "{}" braces node. Otherwise, ctx.CurrentNode().Args
is the first item in the pair.
In the latter case, if orRemainingNodes
then this method sets ctx.DropRemainingNodes
to true and uses ctx.RemainingNodes
as the second list. Otherwise the second list is left blank.
|
inlinestatic |
Transforms an option list in the format option1(v1), option2(v2)
or option1: v1, option2: v2
into a sequence of (key, value) pairs. If the format of a given node is invalid, this function yields (null, node)
.
option1: v1, option2: v2
is parsed into #namedArg(option1, v1), #namedArg(option2, v2)
in EC# or @:(option1, v1), @:(option2, v2)
in LES. This function recognizes both forms.
References Loyc.Syntax.CodeSymbols.NamedArg.
Referenced by Loyc.LLPG.Macros.LLLPG_lexer(), and Loyc.LLPG.Macros.LLLPG_parser().