Ejemplo n.º 1
0
        public void StartWith_GrammarWithUnresovedRules_ThrowsException()
        {
            var grammar = new AdHocGrammar();

            grammar.Sequence("start", grammar.Ref("item"));

            grammar.Invoking(g => g.StartWith("start")).Should().Throw <GrammarException>().Where(e => e.Id == GrammarExceptionId.GrammarContainsUnresolvedRule);
        }
Ejemplo n.º 2
0
        private static IGrammar <CstNode> SimpleGrammar()
        {
            var grammar = new AdHocGrammar();

            // main   := A choose R{2,5} .
            // choose := U | V
            grammar.Sequence("main",
                             grammar.TerminalType("A"),
                             grammar.Choice("choose",
                                            grammar.TerminalValue("U"),
                                            grammar.TerminalValue("V")
                                            ),
                             grammar.Repeat(null, grammar.TerminalType("R"), 2, 5),
                             grammar.Any(null)
                             );

            grammar.StartWith("main");

            return(grammar);
        }