public void TestParseException() { var rules = new Dictionary <Label, IDfa <Optional <Rule <Label> >, Label> >(); var dfa = new IntDfa(); rules.Add(Label.A, dfa); var grammar = new CompiledGrammar <Label>() { Rules = rules, StartSymbol = Label.A }; var parseTable = new Dictionary <Tuple <IDfa <Optional <Rule <Label> >, Label>, IState, Label>, ParseAction <Label> > { { new Tuple <IDfa <Optional <Rule <Label> >, Label>, IState, Label>(dfa, new IntState(0), Label.B), new ParseAction <Label>() { Kind = ParseAction <Label> .ActionKind.Shift } } }; var parser = new Parser <Label>(grammar, parseTable); var tokens = new List <Token <Label> > { new Token <Label>() { Category = Label.B } }; var diag = new Moq.Mock <IDiagnostics>(); Assert.ThrowsException <ParseException>(() => parser.Parse(tokens, diag.Object)); MockDiagnostics.Verify(diag, Parser <Label> .PrematureEofDiagnosticType); }
public void TestInputRange() { var rules = new Dictionary <Label, IDfa <Optional <Rule <Label> >, Label> >(); var dfa = new IntDfa(); rules.Add(Label.A, dfa); var grammar = new CompiledGrammar <Label>() { Rules = rules, StartSymbol = Label.A }; var parseTable = new Dictionary <Tuple <IDfa <Optional <Rule <Label> >, Label>, IState, Label>, ParseAction <Label> > { { new Tuple <IDfa <Optional <Rule <Label> >, Label>, IState, Label>(dfa, new IntState(0), Label.B), new ParseAction <Label> { Kind = ParseAction <Label> .ActionKind.Shift } }, { new Tuple <IDfa <Optional <Rule <Label> >, Label>, IState, Label>(dfa, new IntState(0), Label.Eof), new ParseAction <Label> { Kind = ParseAction <Label> .ActionKind.Reduce } } }; var parser = new Parser <Label>(grammar, parseTable); var tokenRange = new Range(new StringLocation(0), new StringLocation(1)); var tokens = new List <Token <Label> > { new Token <Label> { Category = Label.B, InputRange = tokenRange }, new Token <Label> { Category = Label.Eof } }; var root = parser.Parse(tokens, null); Assert.AreEqual(tokenRange, root.InputRange); }