Esempio n. 1
0
        private Choice CreateAOrBRule()
        {
            var ruleA = new SimpleRef(new Terminal("A"));
            var ruleB = new SimpleRef(new Terminal("B"));

            return(new Choice("TEST", EnumSequence.Of(ruleA, ruleB)));
        }
Esempio n. 2
0
        private Sequence CreateAbbaRule()
        {
            var ruleA = new SimpleRef(new Terminal("A", "A"));
            var ruleB = new SimpleRef(new Terminal("B", "B"));

            return(new Sequence("TEST", EnumSequence.Of(ruleA, ruleB, ruleB, ruleA)));
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        public void RuleRef_ReduceWith_SetsReducer()
        {
            var ruleRef = new RuleRef <string>();
            Reducer <string> reducer = (IRule rule, INodeContext <string> page) => EnumSequence.Of(String.Empty);

            ruleRef.ReduceWith(reducer);

            ruleRef.Reducer.Should().Be(reducer);
            ruleRef.ToDisplayText().Should().Be(IRuleRef.UndefinedRef);
        }
Esempio n. 5
0
        public override IEnumerable <Node> DefaultReducer(IRule rule, INodeContext <Node> page)
        {
            if (page.HasLift())
            {
                return(page.GetLift());
            }

            if (rule.RuleType == RuleType.SingleMatch)
            {
                return(page.GetAll());
            }

            return(EnumSequence.Of(new CollectionNode(page.GetAll())));
        }
Esempio n. 6
0
        public void RuleRef_CloneWithRule_PointsToSameTargetRuleAndReducer()
        {
            var ruleName             = "TEST";
            var mockRule             = new MockRule(ruleName);
            var ruleRef              = new RuleRef <string>(mockRule);
            Reducer <string> reducer = (IRule rule, INodeContext <string> page) => EnumSequence.Of(String.Empty);

            ruleRef
            .As(nameof(RuleRef_CloneWithRule_PointsToSameTargetRuleAndReducer))
            .ReduceWith(reducer);

            var clone = (RuleRef <string>)ruleRef.CloneRule();

            clone.RefName.Should().BeNull();
            clone.Name.Should().Be(ruleName);
            clone.Rule.Should().Be(mockRule);
            clone.Reducer.Should().Be(reducer);
        }
Esempio n. 7
0
 public override IEnumerable <Node> TerminalReducer(IRule rule, IToken token)
 {
     return(EnumSequence.Of(new TokenNode(token)));
 }
Esempio n. 8
0
 public static IRuleRef <TNode> ReduceWith <TNode>(this IRuleRef <TNode> ruleRef, SingleReducer <TNode> reducer)
 {
     return(ruleRef.ReduceWith((rule, page) => EnumSequence.Of(reducer(rule, page))));
 }
Esempio n. 9
0
 public override IEnumerable <CstNode> DefaultReducer(IRule rule, INodeContext <CstNode> page)
 {
     return(EnumSequence.Of(new CstNode(rule.Name, page.GetAll())));
 }
Esempio n. 10
0
 public override IEnumerable <CstNode> TerminalReducer(IRule rule, IToken token)
 {
     ArgAssert.NotNull(nameof(token.Value), token.Value);
     return(EnumSequence.Of(new CstNode(rule.Name, token.Value)));
 }