@Test void unterminatedComment() { final Lexer lexer = new Lexer("reduction /* test:\n x -> x", errors::add); final List<Token> expectedTokens = Arrays.asList( new Token(REDUCTION, "reduction", 0), new Token(EOF, "", 26) ); assertEquals(expectedTokens, lexer.lex()); final List<DslError> expectedErrors = Collections.singletonList( new UnterminatedComment(10) ); assertEquals(expectedErrors, errors); }
public List<Token> lex() { if (used) { throw new IllegalStateException("Lexer.lex can only be called once per instance"); } used = true; while (!atEnd()) { startOfLexeme = curPosition; lexAndHandleErrors(); } reportAndClearUnexpectedCharacters(); tokens.add(new Token(EOF, "", source.length())); return tokens; }
Lexer { public List<Token> lex() { if (used) { throw new IllegalStateException("Lexer.lex can only be called once per instance"); } used = true; while (!atEnd()) { startOfLexeme = curPosition; lexAndHandleErrors(); } reportAndClearUnexpectedCharacters(); tokens.add(new Token(EOF, "", source.length())); return tokens; } }
Lexer { public List<Token> lex() { if (used) { throw new IllegalStateException("Lexer.lex can only be called once per instance"); } used = true; while (!atEnd()) { startOfLexeme = curPosition; lexAndHandleErrors(); } reportAndClearUnexpectedCharacters(); tokens.add(new Token(EOF, "", source.length())); return tokens; } Lexer(final String source, final Consumer<? super DslError> errorReporter); }
Lexer { public List<Token> lex() { if (used) { throw new IllegalStateException("Lexer.lex can only be called once per instance"); } used = true; while (!atEnd()) { startOfLexeme = curPosition; lexAndHandleErrors(); } reportAndClearUnexpectedCharacters(); tokens.add(new Token(EOF, "", source.length())); return tokens; } Lexer(final String source, final Consumer<? super DslError> errorReporter); List<Token> lex(); }
Lexer { public List<Token> lex() { if (used) { throw new IllegalStateException("Lexer.lex can only be called once per instance"); } used = true; while (!atEnd()) { startOfLexeme = curPosition; lexAndHandleErrors(); } reportAndClearUnexpectedCharacters(); tokens.add(new Token(EOF, "", source.length())); return tokens; } Lexer(final String source, final Consumer<? super DslError> errorReporter); List<Token> lex();  }