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))); }
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))); }
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(); }
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); }
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()))); }
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); }
public override IEnumerable <Node> TerminalReducer(IRule rule, IToken token) { return(EnumSequence.Of(new TokenNode(token))); }
public static IRuleRef <TNode> ReduceWith <TNode>(this IRuleRef <TNode> ruleRef, SingleReducer <TNode> reducer) { return(ruleRef.ReduceWith((rule, page) => EnumSequence.Of(reducer(rule, page)))); }
public override IEnumerable <CstNode> DefaultReducer(IRule rule, INodeContext <CstNode> page) { return(EnumSequence.Of(new CstNode(rule.Name, page.GetAll()))); }
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))); }