Beispiel #1
0
        public void GrammarModelToGrammarShouldResolverProductionReferencesFromOtherGrammars()
        {
            var S = ProductionModel.From(new QualifiedName("ns1", "S"));
            var A = ProductionModel.From(new QualifiedName("ns1", "A"));

            S.Alterations.Add(
                new AlterationModel(
                    new[] { A }));
            A.Alterations.Add(
                new AlterationModel(
                    new[] { new LexerRuleModel(
                                new StringLiteralLexerRule("a")) })
                );
            var ns1GrammarModel = new GrammarModel
            {
                Start = S
            };

            ns1GrammarModel.AddProduction(S);
            ns1GrammarModel.AddProduction(A);

            var ns1ProductionReference = new GrammarReferenceModel(ns1GrammarModel.ToGrammar());

            var Z = ProductionModel.From(new QualifiedName("ns2", "Z"));
            var X = ProductionModel.From(new QualifiedName("ns2", "X"));

            X.Alterations.Add(
                new AlterationModel(
                    new SymbolModel[]
            {
                Z, ns1ProductionReference
            }));

            var ns2GrammarModel = new GrammarModel
            {
                Start = Z
            };

            ns2GrammarModel.AddProduction(Z);
            ns2GrammarModel.AddProduction(X);

            var ns2Grammar = ns2GrammarModel.ToGrammar();

            Assert.AreEqual(4, ns2Grammar.Productions.Count);
        }
Beispiel #2
0
 public GrammarReferenceExpression(Grammar grammar)
 {
     GrammarReferenceModel = new GrammarReferenceModel(grammar);
 }