Пример #1
0
        public void ShouldConvertToGrammarString()
        {
            var expr = new OrderedChoice(
                new LiteralTerminal("a"),
                new LiteralTerminal("b"));

            // Create a parser to ensure the expression is compiled
            new Parser<Token>((token, ctx, args) => token, new ParseRule("A", expr));

            Assert.Equal("('a' || 'b')", expr.ToString());
        }
Пример #2
0
        public void ShouldNotAllowZeroSubExpressions()
        {
            var expr = new OrderedChoice();

            try {
                new Parser<Token>((token, ctx, args) => token, new ParseRule("A", expr));
                Assert.True(false, "Expression without subexpressions was allowed but should have been rejected");
            }
            catch (EmptyCompositeException e) {
                Assert.Equal(expr, e.Expression);
            }
        }