public void Grammar_WithoutStartRule_ThrowsExceptionOnStart() { var grammar = new AdHocGrammar(); grammar.TerminalType("A", "start"); grammar.Invoking(g => g.Start()).Should().Throw <GrammarException>().Where(e => e.Id == GrammarExceptionId.StartRuleNotDefined); }
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); }
public void Grammar_WithStartRule_ReturnsStartRefOnStart() { var grammar = new AdHocGrammar(); grammar.TerminalType("A", "start"); grammar.StartWith("start"); var ruleRef = grammar.Start(); ruleRef.Should().NotBeNull(); ruleRef.RefName.Should().Be("start"); ruleRef.Name.Should().Be("start"); }