C# Class LeMP.MacroContext

Standard extension methods for IMacroContext.
Mostra file Open project: qwertie/ecsharp Class Usage Examples

Public Methods

Method Description
CurrentNode ( this ctx ) : LNode
GetArgsAndBody ( this ctx, bool orRemainingNodes ) : VList>.Pair

Splits the current node into a pair of "argument" and "body" lists, potentially treating ctx.RemainingNodes as the "body" list.

EC# supports a syntax specially designed for macro calls: macroName(args) { stmts; } This is stored as a call node with a body, in braces, as its final parameter, i.e. it is equivalent to macroName(args, { stmts; }); 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. macroName(args); stmts; 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.

GetOptions ( VList optionList ) : LNode>>.IEnumerable

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 #namedArg(option1, v1), #namedArg(option2, v2) in EC# or @`':`(option1, v1), @`':`(option2, v2) in LES. This function recognizes both forms.

Method Details

CurrentNode() public static method

public static CurrentNode ( this ctx ) : LNode
ctx this
return LNode

GetArgsAndBody() public static method

Splits the current node into a pair of "argument" and "body" lists, potentially treating ctx.RemainingNodes as the "body" list.
EC# supports a syntax specially designed for macro calls: macroName(args) { stmts; } This is stored as a call node with a body, in braces, as its final parameter, i.e. it is equivalent to macroName(args, { stmts; }); 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. macroName(args); stmts; 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.
public static GetArgsAndBody ( this ctx, bool orRemainingNodes ) : VList>.Pair
ctx this Context of the current macro.
orRemainingNodes bool Whether to use ctx.RemainingNodes as /// the second list if there is no {braces node} at the end of /// ctx.CurrentNode().Args.
return VList>.Pair

GetOptions() public static method

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 #namedArg(option1, v1), #namedArg(option2, v2) in EC# or @`':`(option1, v1), @`':`(option2, v2) in LES. This function recognizes both forms.
public static GetOptions ( VList optionList ) : LNode>>.IEnumerable
optionList VList
return LNode>>.IEnumerable