[erlang-questions] Parsing UUIDs with Leex

Massimo Cesaro massimo.cesaro@REDACTED
Fri Oct 11 16:22:32 CEST 2019

I'm developing the transpiler for an IoT oriented DSL to Erlang.
The idea is to take a domain specific language in input and create the
erlang source code in output.
In my erlang project, I'm using the venerable Leex and Yecc tools to build
the lexer and parser.
Using Erlang/OTP 22 [erts-10.5.2], so far, so good.

Today I was trying to define a UUID data type in the DSL language using the
following definition in the leex .xlr file:


and the corresponding rule:
{UUID}       : {token, {uuid, TokenChars, TokenLine}}.

in the same file there is also the definition for an atom type:

ATOM = [a-zA-Z0-9_]*

with the rule
{ATOM}       : {token, {atom, list_to_atom(TokenChars), TokenLine}}.

I found that the generated lexer cannot match this UUID
3eeb8daf-4e66-4c02-bb28-68934157e36e in input,

but it matches the following tokens sequence:

The minus token is present because I'm implementing also unary and
arithmetic expressions.

I tested my definition with re:
7> re:run("3eeb8daf-4e66-4c02-bb28-68934157e36e",

8> re:run("3eeb8daf-4e66-4c02-bb28-68934157e36e",

so I guess that at least the definition should be right.

My workaround is to include the UUIDs in the source code between double
quotes and then parsing UUIDs as strings, but I'm still wondering if I'm
doing something wrong.

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

More information about the erlang-questions mailing list