public ProductionReferenceExpression(IGrammar grammar)
 {
     ProductionReferenceModel = new ProductionReferenceModel(grammar);
 }
Пример #2
0
        public void GrammarModelToGrammarShouldResolverProductionReferencesFromOtherGrammars()
        {
            var S = new ProductionModel { LeftHandSide = new NonTerminalModel(new FullyQualifiedName("ns1", "S")) };
            var A = new ProductionModel { LeftHandSide = new NonTerminalModel(new FullyQualifiedName("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.Productions.Add(S);
            ns1GrammarModel.Productions.Add(A);

            var ns1ProductionReferece = new ProductionReferenceModel(ns1GrammarModel.ToGrammar());

            var Z = new ProductionModel { LeftHandSide = new NonTerminalModel(new FullyQualifiedName("ns2", "Z")) };
            var X = new ProductionModel { LeftHandSide = new NonTerminalModel(new FullyQualifiedName("ns2", "X")) };
            X.Alterations.Add(
                new AlterationModel(
                    new SymbolModel[]
                    {
                        Z, ns1ProductionReferece
                    }));

            var ns2GrammarModel = new GrammarModel
            {
                Start = Z
            };
            ns2GrammarModel.Productions.Add(Z);
            ns2GrammarModel.Productions.Add(X);

            var ns2Grammar = ns2GrammarModel.ToGrammar();

            Assert.AreEqual(4, ns2Grammar.Productions.Count);
        }