Lexer macros don't seem to work
- From:
- Dan Rumney
- Date:
- 2010-03-12 @ 15:53
Hi,
I've been playing with JISON for a while now: great piece of software.
Problem is, I've hit a snag. I have the following LEX:
NUM [0-9]+("."[0-9]+)?
%%
(
\d+\s*"'"\s*\d+\s*"\""\s*\d+\s*"s"
|\d+\s*"'"\s*\d+\s*"\""\s*
|\d+\s*"\""\s*\d+\s*"s"
|\d+\s*"'"\s*
|\d+\s*"\""\s*
|\d+\s*"s"
)
{return 'FIS';}
{NUM}\b {return 'NUMBER';}
\s+ {/* skip whitespace */}
"*" {return '*';}
"/" {return '/';}
"-" {return '-';}
"+" {return '+';}
"(" {return '(';}
")" {return ')';}
<<EOF>> {return 'EOF';}
%%
When I run JISON, it doesn't complain or anything, but when I take a
look at the generated code, I find:
lexer.rules =
[/^(\d+\s*'\s*\d+\s*"\s*\d+\s*s|\d+\s*'\s*\d+\s*"\s*|\d+\s*"\s*\d+\s*s|\d+\s*'\s*|\d+\s*"\s*|\d+\s*s)/,/^{NUM}\b\b/,/^\s+/,/^\*/,/^\//,/^-/,/^\+/,/^\(/,/^\)/,/^$/]
You'll see that the macro, NUM, hasn't been expanded.
I invoked JISON like so:
narwhal bin/jison fisCalc.jison fisCalc.jisonlex
Do I need to feed it some extra parameters in order to expand macros? Or
is there something wrong with me LEX?
Thanks,
Dan
Re: [jison] Lexer macros don't seem to work
- From:
- Zachary Carter
- Date:
- 2010-03-12 @ 19:32
On Fri, Mar 12, 2010 at 10:53 AM, Dan Rumney <danrumney@warpmail.net> wrote:
> Hi,
> ....
>
> You'll see that the macro, NUM, hasn't been expanded.
>
> I invoked JISON like so:
>
> narwhal bin/jison fisCalc.jison fisCalc.jisonlex
>
> Do I need to feed it some extra parameters in order to expand macros? Or
> is there something wrong with me LEX?
>
> Thanks,
>
> Dan
>
On the contrary, you have done nothing wrong Dan. This seems to be an error
in my jisonlex parser. I create an array tuple ([key, regex]) when I
*really* meant to create a object ({key: regex})! Good catch, and as always,
the one case that went untested. I'm preparing a fix now, thanks.
--
Zach Carter