public void It_Can_Expect_A_Sequence_Of_Tokens() { IEnumerable <RuleResult> SequenceRule(CurrentTokenCallback t) { yield return(Expect.Symbol(t(), "(")); yield return(Expect.Symbol(t(), ")")); yield return(Expect.Symbol(t(), "{", true)); } var parser = new RuleCoroutineParser(SequenceRule); var tokens = new[] { "(", ")", "{" }.Select(t => new Token(new CodePos(0, 0), TokenType.Symbol, t)); // Feed all the tokens to the parser RuleResult result = default; foreach (Token t in tokens) { result = parser.FeedToken(t); } // Assert that it completed and returned the node. // In this test, the "node" is just a boolean. result.AssertComplete(); Assert.Equal(true, result.node); }
private IEnumerable <RuleResult> ParseClass(string src) { var lexer = new Lexer(); var tokens = lexer.ToTokens(src); var rule = new RuleCoroutineParser(RuleCoroutines.ParseClass); foreach (Token t in tokens) { var result = rule.FeedToken(t); if (result.status == RuleStatus.Failed) { throw result.error; } yield return(result); } }