@Test void emptyInput() { final Lexer lexer = new Lexer("", errors::add); final List<Token> expected = Collections.singletonList( new Token(EOF, "", 0) ); assertEquals(expected, lexer.lex()); }
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();  }