Parses LNodes such as (x | ("foo", y)) / z into Pred objects.
コード例 #1
0
        void TestStage2(bool lexerMode, params Tuple <string, string, string>[] ruleTuples)
        {
            var helper = lexerMode ? (IPGCodeGenHelper) new IntStreamCodeGenHelper() : new GeneralCodeGenHelper();
            var rules  = new List <Pair <Rule, LNode> >();

            foreach (var tuple in ruleTuples)
            {
                string ruleName = tuple.Item1, inputExpr = tuple.Item2;
                var    node = LesLanguageService.Value.ParseSingle(inputExpr, ConsoleMessageSink.Value, ParsingMode.Expressions);
                var    rule = new Rule(node, GSymbol.Get(ruleName), null);
                rules.Add(Pair.Create(rule, node));
            }

            var parser = new StageTwoParser(helper, ConsoleMessageSink.Value);

            parser.Parse(rules);
            for (int i = 0; i < rules.Count; i++)
            {
                var rule         = rules[i].A;
                var ruleAsString = rule.Pred.ToString();
                var expected     = ruleTuples[i].Item3;
                if (expected == null)
                {
                    ConsoleMessageSink.Value.Warning(ruleTuples[i].Item1, ruleAsString);
                }
                else
                {
                    AreEqual(expected, ruleAsString);
                }
            }
        }
コード例 #2
0
ファイル: LlpgParserTests.cs プロジェクト: qwertie/ecsharp
		void TestStage2(bool lexerMode, params Tuple<string,string,string>[] ruleTuples)
		{
			var helper = lexerMode ? (IPGCodeGenHelper)new IntStreamCodeGenHelper() : new GeneralCodeGenHelper();
			var rules = new List<Pair<Rule,LNode>>();
			foreach (var tuple in ruleTuples)
			{
				string ruleName = tuple.Item1, inputExpr = tuple.Item2;
				var node = LesLanguageService.Value.ParseSingle(inputExpr, ConsoleMessageSink.Value, ParsingMode.Expressions);
				var rule = new Rule(node, GSymbol.Get(ruleName), null);
				rules.Add(Pair.Create(rule, node));
			}
			
			var parser = new StageTwoParser(helper, ConsoleMessageSink.Value);
			parser.Parse(rules);
			for (int i = 0; i < rules.Count; i++) {
				var rule = rules[i].A;
				var ruleAsString = rule.Pred.ToString();
				var expected = ruleTuples[i].Item3;
				if (expected == null)
					ConsoleMessageSink.Value.Warning(ruleTuples[i].Item1, ruleAsString);
				else
					AreEqual(expected, ruleAsString);
			}
		}