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< LNodeList, LNodeList > | 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< LNode, LNode > > | GetOptions (LNodeList 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 (node, null) . 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.
References Loyc.Syntax.LNode.Args, Loyc.Syntax.CodeSymbols.Braces, LeMP.IMacroContext.DropRemainingNodes, and LeMP.IMacroContext.RemainingNodes.
|
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 (node, null)
.
option1: v1, option2: v2
is parsed into ‘’::=
in LES. (option1, v1), @
'::=(option2, v2)</c> in EC# or <c>@
':(option1, v1), @
':`(option2, v2)
References Loyc.Syntax.LNode.Args, and Loyc.Syntax.CodeSymbols.NamedArg.
Referenced by Loyc.LLPG.Macros.LLLPG_lexer(), and Loyc.LLPG.Macros.LLLPG_parser().