[erlang-questions] Start Conditions in Lexical Analyzer Generator (leex)
Xiao Jia
me@REDACTED
Sat Jan 18 02:25:28 CET 2014
On Fri, Jan 17, 2014 at 10:53 PM, Dmitry Kolesnikov
<dmkolesnikov@REDACTED> wrote:
> Hello,
>
> Probably, I've missed something… The start condition is the literal part of lex regex.
> e.g.
>
> Definitions.
>
> WSS = [\x20\x09\x0A\x0D]+
> VAR = [a-zA-Z.]+
>
> Rules.
>
> {if{WSS}{VAR}} : {token, {'if', TokenLine, TokenChars}}.
>
> this matches token is it starts with if
That's probably not what Vance Shipley wants. Using start conditions
is sort of moving between state machines. See below example excerpted
from http://flex.sourceforge.net/manual/Start-Conditions.html#Start-Conditions
"/*" BEGIN(comment);
<comment>[^*\n]* /* eat anything that's not a '*' */
<comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
<comment>\n ++line_num;
<comment>"*"+"/" BEGIN(INITIAL);
>
> - Dmitry
>
> On Jan 17, 2014, at 4:42 PM, Vance Shipley <vances@REDACTED> wrote:
>
>> I've never tried using leex before but since the job at hand is
>> to parse a language file, where the reference implementation uses
>> flex, it seemed like porting their lex input file for use with leex
>> would be the way to go.
>>
>> However I got stuck right away in that leex doesn't seem to support
>> "start conditions":
>>
>> http://flex.sourceforge.net/manual/Start-Conditions.html#Start-Conditions
>>
>> Am I missing something?
>From http://erlang.org/doc/man/leex.html rules have the following format:
<Regexp> : <Erlang code>.
and apparently start conditions are not regular expressions... so
probably there is no support for that.
--
Regards,
Xiao Jia
More information about the erlang-questions
mailing list