ArgumentLexer extends MemoizeLexer { @Override public List<Token> lex(Logger logger, String lexeme) { if (!lexeme.startsWith("<") || !lexeme.endsWith(">")) { logger.error(lexeme, "is an invalid argument", "should be enclosed by \"<\" and \">\""); return EMPTY_LIST; } if (lexeme.contains("|")) { logger.error(lexeme, "contains \"|\"", "an argument should not have aliases"); return EMPTY_LIST; } var argument = lexeme.substring(1, lexeme.length() - 1); if (argument.isEmpty()) { logger.error(lexeme, "is empty", "an argument should not be empty"); return EMPTY_LIST; } if (argument.startsWith("<") || argument.endsWith(">")) { logger.error(lexeme, "contains trailing \"<\"s or \">\"s"); } return List.of(token(ARGUMENT, lexeme, argument, Set.of())); }  @Override List<Token> lex(Logger logger, String lexeme);  }
@Test void lex() { var tokens = lexer.lex(environment, location, "<argument>"); var token = tokens.get(0); assertEquals(1, tokens.size()); assertEquals(location, token.location); assertEquals("<argument>", token.literal); assertEquals("argument", token.lexeme); }