LiteralLexer implements Lexer { @Override public List<Token> lex(Logger logger, String lexeme) { if (lexeme.contains("<") || lexeme.contains(">")) { logger.error(lexeme, "contains \"<\"s and \">\"s", "a literal should not contain \"<\"s and \">\"s"); return EMPTY_LIST; } var identifiers = lexeme.split("\\|", -1); for (var identifier : identifiers) { if (identifier.isEmpty()) { logger.error(lexeme, "contains an empty literal alias or name", "should not be empty"); return EMPTY_LIST; } } var aliases = new HashSet<String>(); for (int i = 1; i < identifiers.length; i++) { var alias = identifiers[i]; if (!aliases.add(alias)) { logger.warn("Duplicate alias: " + quote(alias)); } } return List.of(new Token(new Identifier(Type.LITERAL, lexeme, identifiers[0]), aliases)); }  @Override List<Token> lex(Logger logger, String lexeme);  }
@Test void lex() { var tokens = lexer.lex(environment, location, "a|b|c"); var token = tokens.get(0); verifyNoInteractions(environment); assertEquals(1, tokens.size()); assertEquals(location, token.location); assertEquals("a|b|c", token.literal); assertEquals("a", token.lexeme); assertEquals(Set.of("b", "c"), token.aliases); }
@Test void lex_warnings() { var tokens = lexer.lex(environment, location, "a|b|b"); var token = tokens.get(0); verify(environment).warn(location, "Duplicate alias: \"b\""); assertEquals(1, tokens.size()); assertEquals(location, token.location); assertEquals("a|b|b", token.literal); assertEquals("a", token.lexeme); assertEquals(Set.of("b"), token.aliases); }