void CheckTokens(VBLexer lexer, params int[] tokens) { for (int i = 0; i < tokens.Length; i++) { int token = tokens[i]; Token t = lexer.NextToken(); int next = t.Kind; Assert.IsEmpty(lexer.Errors.ErrorOutput); Assert.AreEqual(token, next, "{2} of {3}: expected: \"{0}\", was: \"{1}\"; at {4}", Tokens.GetTokenString(token), Tokens.GetTokenString(next), i + 1, tokens.Length, t.Location); } }
void CheckHead(VBLexer lexer) { CheckTokens(lexer, Tokens.Class, Tokens.Identifier, Tokens.EOL, Tokens.Sub, Tokens.Identifier, Tokens.EOL); }
void CheckFoot(VBLexer lexer) { CheckTokens(lexer, Tokens.EOL, Tokens.End, Tokens.Sub, Tokens.EOL, Tokens.End, Tokens.Class); }
VBLexer GenerateLexerForSnippet(StringReader sr, SnippetType type) { var lexer = new VBLexer(sr); lexer.SetInitialContext(type); return lexer; }
void RunTest(string code, string expectedOutput) { ExpressionFinder p = new ExpressionFinder(); VBLexer lexer = new VBLexer(new StringReader(code)); Token t; do { t = lexer.NextToken(); p.InformToken(t); } while (t.Kind != Tokens.EOF); Console.WriteLine(p.Output); Assert.IsEmpty(p.Errors); Assert.AreEqual(expectedOutput.Replace("\r", ""), p.Output.Replace("\r", "")); }
void CheckTokens(VBLexer lexer, params int[] tokens) { for (int i = 0; i < tokens.Length; i++) { int token = tokens[i]; Token t = lexer.NextToken(); int next = t.Kind; Assert.AreEqual(token, next, "{2} of {3}: {0} != {1}; at {4}", Tokens.GetTokenString(token), Tokens.GetTokenString(next), i + 1, tokens.Length, t.Location); } }