/// <summary>This method helps do the stage-one transform from <c>LLLPG (config) {...}</c> /// to <c>run_LLLPG (helper literal) {...}</c> and also invokes the ANTLR-style /// parser if the second argument is a token literal. If <c>node[0]</c> /// calls <c>expectedConfigNode</c> then the delegate is called to /// construct a code generation helper object; otherwise, this method has /// no effect and returns null.</summary> public static LNode LllpgMacro(LNode node, IMacroContext context, Symbol expectedCodeGenMode, Func <LNode, IPGCodeGenHelper> makeCodeGenHelper, bool isDefault = false) { LNodeList args, body; LNode tokenTree = null, codeGenOptions = null; if (node.ArgCount >= 1 && (tokenTree = node.Args.Last).Value is TokenTree) { args = node.Args.WithoutLast(1); body = LNodeList.Empty; } else { tokenTree = null; var p = context.GetArgsAndBody(orRemainingNodes: true); args = p.A; body = p.B; } if ((args.Count == 1 && (codeGenOptions = args[0]).Name == expectedCodeGenMode) || (args.Count == 0 && isDefault)) { if (tokenTree != null) { body = AntlrStyleParser.ParseTokenTree(tokenTree.Value as TokenTree, context.Sink); } IPGCodeGenHelper helper = makeCodeGenHelper(codeGenOptions); return(node.WithTarget(_run_LLLPG).WithArgs(F.Literal(helper), F.Braces(body))); } return(null); }
public static void Run(Rule rule, IMessageSink sink, IDictionary<Symbol, Rule> rules, IPGCodeGenHelper codeGen) { // 1. Scan for a list of code blocks that use $labels, and a list of rules referenced. var data = new DataGatheringVisitor(rules, rule); if (data.RulesReferenced.Count != 0 || data.OtherReferences.Count != 0 || data.ProperLabels.Count != 0) { var vsv = new AutoValueSaverVisitor(data, sink, rules, codeGen); // 2. Create $result variable if it was used // 3. Scan for predicates with labels, and RuleRefs referenced by // code blocks. For each such predicate, generate a variable at // the beginning of the rule and set the ResultSaver. vsv.Process(rule); // 4. Replace recognized $substitutions in code blocks vsv.ReplaceSubstitutionsInCodeBlocks(); } }
public static void Run(Rule rule, IMessageSink sink, IDictionary <Symbol, Rule> rules, IPGCodeGenHelper codeGen) { // 1. Scan for a list of code blocks that use $labels, and a list of rules referenced. var data = new DataGatheringVisitor(rules, rule); if (data.RulesReferenced.Count != 0 || data.OtherReferences.Count != 0 || data.ProperLabels.Count != 0) { var vsv = new AutoValueSaverVisitor(data, sink, rules, codeGen); // 2. Create $result variable if it was used // 3. Scan for predicates with labels, and RuleRefs referenced by // code blocks. For each such predicate, generate a variable at // the beginning of the rule and set the ResultSaver. vsv.Process(rule); // 4. Replace recognized $substitutions in code blocks vsv.ReplaceSubstitutionsInCodeBlocks(); } }
AutoValueSaverVisitor(DataGatheringVisitor data, IMessageSink sink, IDictionary <Symbol, Rule> rules, IPGCodeGenHelper codeGen) { _data = data; _sink = sink; _rules = rules; _codeGen = codeGen; }
public StageTwoParser(IPGCodeGenHelper helper, IMessageSink sink) { _helper = helper; _sink = sink; }
AutoValueSaverVisitor(DataGatheringVisitor data, IMessageSink sink, IDictionary<Symbol, Rule> rules, IPGCodeGenHelper codeGen) { _data = data; _sink = sink; _rules = rules; _codeGen = codeGen; }