class 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));
            }
        }
        
        // We cannot memomize literal identifiers since .equals(...) ignores aliases
        // but .toString() returns the (raw) lexeme;
        return List.of(new Token(new Identifier(Type.LITERAL, lexeme, identifiers[0]), aliases));
    }

}