Helper class invoked just after StageTwoParser. Its job is to create variables referenced by labels (label:item) and by code blocks ($RuleName), to modify the code blocks to remove the $ operator, and to update the ResultSaver of each labeled predicate. Also supports $result.
Labels and $substitutions can also be used with Preds constructed by hand, except that referencing tokens directly from code blocks (e.g. $'#') won't work unless the corresponding grammar Pred has a Pred.Basis is an equal syntax tree.
Inheritance: Loyc.LLParserGenerator.RecursivePredVisitor
Esempio n. 1
0
		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();
			}
		}
Esempio n. 2
0
        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();
            }
        }