Enhanced C#
Language of your choice: library documentation
Public static fields | Static Public Member Functions | List of all members
Loyc.LLPG.Macros Class Reference

Macros for using LLLPG in LeMP. More...


Source file:

Remarks

Macros for using LLLPG in LeMP.

Example:

class Foo {
[DefaultK(2)] LLLPG lexer
{
private rule Int '0'..'9'+ };
private rule Id 'a'..'z'|'A'..'Z' ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* };
token Token Int | Id };
};
};

Up to three macros are used to invoke LLLPG.

  1. there is a macro to recognize the pattern LLLPG(lexer, {...}) and translate "lexer" to an unprintable literal of type IntStreamCodeGenHelper, and another macro for LLLPG(parser(Symbol, false), {...})"</c> that creates a <see cref="GeneralCodeGenHelper"/> (this is the default helper).</li> <li>The stage-one rule() macro uses <see cref="StageOneParser"/> to translate token trees into expressions, e.g. <c>@[ ("Foo" | bar)* ~';' ]</c> is currently translated to <c>@'tuple(@`'suf*`("Foo" | bar), ~';').
  2. The stage-two macro is named run_LLLPG(). It accepts the code-gen helper created by the LLLPG(lexer) or LLLPG(parser) macro, and it has the ProcessChildrenBefore flag so that the stage-1 rule() macros run first. run_LLLPG calls StageTwoParser to translate expressions into Pred objects, and then invokes LLParserGenerator to analyze the grammar and generate code.

Public static fields

static readonly Symbol MacroNamespace = GSymbol.Get("Loyc.LLPG")
 

Static Public Member Functions

static LNode LLLPG_lexer (LNode node, IMacroContext context)
 Helper macro that translates lexer in LLLPG(lexer, {...}) into a IntStreamCodeGenHelper object. More...
 
static LNode LLLPG_parser (LNode node, IMacroContext context)
 Helper macro that translates parser in LLLPG(parser, {...}) into a GeneralCodeGenHelper object. More...
 
static LNode LllpgMacro (LNode node, IMacroContext context, Symbol expectedCodeGenMode, Func< LNode, IPGCodeGenHelper > makeCodeGenHelper, bool isDefault=false)
 This method helps do the stage-one transform from LLLPG (config) {...} to run_LLLPG (helper literal) {...} and also invokes the ANTLR-style parser if the second argument is a token literal. If node[0] calls expectedConfigNode then the delegate is called to construct a code generation helper object; otherwise, this method has no effect and returns null. More...
 
static LNode rule (LNode node, IMacroContext context)
 
static LNode ECSharpRule (LNode node, IMacroContext context)
 
static LNode run_LLLPG (LNode node, IMacroContext context)
 

Member Function Documentation

◆ LLLPG_lexer()

static LNode Loyc.LLPG.Macros.LLLPG_lexer ( LNode  node,
IMacroContext  context 
)
inlinestatic

Helper macro that translates lexer in LLLPG(lexer, {...}) into a IntStreamCodeGenHelper object.

References LeMP.MacroContext.GetOptions(), Loyc.LLPG.Macros.LllpgMacro(), Loyc.Syntax.LNode.Missing, Loyc.Symbol.Name, LeMP.IMacroContext.Sink, and Loyc.Syntax.LNode.Value.

◆ LLLPG_parser()

static LNode Loyc.LLPG.Macros.LLLPG_parser ( LNode  node,
IMacroContext  context 
)
inlinestatic

Helper macro that translates parser in LLLPG(parser, {...}) into a GeneralCodeGenHelper object.

References LeMP.MacroContext.GetOptions(), Loyc.LLPG.Macros.LllpgMacro(), Loyc.Syntax.LNode.Missing, Loyc.Symbol.Name, LeMP.IMacroContext.Sink, and Loyc.Syntax.LNode.Value.

◆ LllpgMacro()

static LNode Loyc.LLPG.Macros.LllpgMacro ( LNode  node,
IMacroContext  context,
Symbol  expectedCodeGenMode,
Func< LNode, IPGCodeGenHelper makeCodeGenHelper,
bool  isDefault = false 
)
inlinestatic

This method helps do the stage-one transform from LLLPG (config) {...} to run_LLLPG (helper literal) {...} and also invokes the ANTLR-style parser if the second argument is a token literal. If node[0] calls expectedConfigNode then the delegate is called to construct a code generation helper object; otherwise, this method has no effect and returns null.

References Loyc.Syntax.LNode.Args, LeMP.IMacroContext.Sink, Loyc.Syntax.LNode.Value, and Loyc.Syntax.CallNode.WithArgs().

Referenced by Loyc.LLPG.Macros.LLLPG_lexer(), and Loyc.LLPG.Macros.LLLPG_parser().