[erlang-questions] leex and case-insensitive match

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Thu Jun 4 20:15:26 CEST 2015

On Thu, Jun 4, 2015 at 7:06 PM, Knut Nesheim <knutin@REDACTED> wrote:

> For my use case "select", "SELECT", "SeLeCt" means exactly the
> same.

I'm not sure I understand this:

[jlouis@REDACTED ~]$ cat z.xrl
%% Test



[sS][eE][lL][eE][cC][tT] : {token, select}.

Erlang code.

%% Nothing

in an erl shell:

4> leex:file("z").
6> c("z.erl").
9> [z:string(Str) || Str <- ["select", "SELECT", "SeLeCt"]].

Note how the token parses as the same thing.

[sS][eE][lL][eE][cC][tT] : {token, {identifier,

should also work, if select is not a keyword, but you want to handle it as
an identifier.

some Regex engines provides convenience notation for [sS], [eE] etc, but it
tends to be rare enough for keywords that you skip it. Another path through
the game is the following age-old lexer hack:

[jlouis@REDACTED ~]$ cat y.xrl
%% Test


ALPHA = [a-zA-Z]


{ALPHA}* : {token, analyze_alpha(string:to_lower(TokenChars))}.

Erlang code.

%% Match keywords, and if no keyword matches, regard the token as an
analyze_alpha("select") -> select;
analyze_alpha(Otherwise) -> {identifier, Otherwise}.

13> leex:file("y").
14> c("y.erl").
15> [y:string(Str) || Str <- ["select", "SELECT", "SeLeCt"]].

Do any of these work for you?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150604/23c678ff/attachment.htm>

More information about the erlang-questions mailing list