Пример #1
0
        public void GrammarModelToGrammarShouldCreateGrammar()
        {
            var grammarModel = new GrammarModel();

            var S = ProductionModel.From("S");
            var A = ProductionModel.From("A");
            var B = ProductionModel.From("B");

            var a     = new StringLiteralLexerRule("a");
            var b     = new StringLiteralLexerRule("b");
            var space = new StringLiteralLexerRule(" ");

            S.AddWithAnd(A.LeftHandSide);
            S.AddWithAnd(B.LeftHandSide);
            S.AddWithOr(B.LeftHandSide);
            A.AddWithAnd(new LexerRuleModel(a));
            B.AddWithAnd(new LexerRuleModel(b));

            grammarModel.AddProduction(S);
            grammarModel.AddProduction(A);
            grammarModel.AddProduction(B);

            var lexerRuleModel = new LexerRuleModel(space);

            grammarModel.AddLexerRule(lexerRuleModel);
            grammarModel.AddIgnoreSetting(new IgnoreSettingModel(new QualifiedName(lexerRuleModel.LexerRule.TokenName.Id)));

            grammarModel.Start = S;

            var grammar = grammarModel.ToGrammar();

            Assert.AreEqual(4, grammar.Productions.Count);
            Assert.AreEqual(1, grammar.Ignores.Count);
        }
Пример #2
0
        public void GrammarModelToGrammarShouldCreateGrammar()
        {
            var grammarModel = new GrammarModel();

            var S = new ProductionModel("S");
            var A = new ProductionModel("A");
            var B = new ProductionModel("B");

            var a     = new StringLiteralLexerRule("a");
            var b     = new StringLiteralLexerRule("b");
            var space = new StringLiteralLexerRule(" ");

            S.AddWithAnd(A.LeftHandSide);
            S.AddWithAnd(B.LeftHandSide);
            S.AddWithOr(B.LeftHandSide);
            A.AddWithAnd(new LexerRuleModel(a));
            B.AddWithAnd(new LexerRuleModel(b));

            grammarModel.Productions.Add(S);
            grammarModel.Productions.Add(A);
            grammarModel.Productions.Add(B);

            var lexerRuleModel = new LexerRuleModel(space);

            grammarModel.LexerRules.Add(lexerRuleModel);
            grammarModel.IgnoreSettings.Add(
                new IgnoreSettingModel(lexerRuleModel));

            grammarModel.Start = S;

            var grammar = grammarModel.ToGrammar();

            Assert.AreEqual(4, grammar.Productions.Count);
            Assert.AreEqual(1, grammar.Ignores.Count);
        }
Пример #3
0
        public void GrammarModelShouldAddIgnoreLexerRuleModel()
        {
            var grammar        = new GrammarModel();
            var lexerRuleModel = new LexerRuleModel(new StringLiteralLexerRule("this is a literal"));

            grammar.AddIgnoreSetting(new IgnoreSettingModel(new QualifiedName("AAA")));
            grammar.AddLexerRule(lexerRuleModel);
            Assert.AreEqual(1, grammar.LexerRuleModels.Count);
            Assert.AreEqual(1, grammar.IgnoreSettings.Count);
        }
Пример #4
0
        public void GrammarModelShouldAddIgnoreLexerRuleModel()
        {
            var grammar        = new GrammarModel();
            var lexerRuleModel = new LexerRuleModel {
                Value = new StringLiteralLexerRule("this is a literal")
            };

            grammar.IgnoreSettings.Add(
                new IgnoreSettingModel(
                    lexerRuleModel));
            grammar.LexerRules.Add(lexerRuleModel);
            Assert.AreEqual(1, grammar.LexerRules.Count);
            Assert.AreEqual(1, grammar.IgnoreSettings.Count);
        }