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
        public void Grammar_RefAs_SetsRefNameOnRuleRef()
        {
            var grammar = new AdHocGrammar();
            var ruleRef = grammar.Ref("test").As("handle");

            ruleRef.RefName.Should().Be("handle");
            ((RuleRef <CstNode>)ruleRef).IsResolved.Should().BeFalse();
        }
Ejemplo n.º 3
0
        public void Grammar_ReferencingUndefinedRule_ReturnsUnresolvedRef()
        {
            var grammar = new AdHocGrammar();
            var ruleRef = grammar.Ref("test");

            ruleRef.Name.Should().BeNull();
            ((RuleRef <CstNode>)ruleRef).IsResolved.Should().BeFalse();
        }
Ejemplo n.º 4
0
        public void Grammar_RefReduceWith_SetsReducerOnRuleRef()
        {
            var grammar = new AdHocGrammar();
            Reducer <CstNode> reducer = (IRule rule, INodeContext <CstNode> page) => EnumSequence.Of(new CstNode("Dummy", "Dummy"));
            var ruleRef = grammar.Ref("test").ReduceWith(reducer);

            ruleRef.Reducer.Should().Be(reducer);
            ((RuleRef <CstNode>)ruleRef).IsResolved.Should().BeFalse();
        }