Hi,
the problem appears to be in the macro definition. To refer to a macro you need to enclose it in braces, i.e. {NameLower} instead of just NameLower. The latter matches the literal string "NameLower" instead of the macro.
This means, if you replace
> NameLowerQualified = ((NameLower | NameUpper) ".")+ NameLower
> NameUpperQualified = ((NameLower | NameUpper) ".")+ NameUpper
by
> NameLowerQualified = (({NameLower} | {NameUpper}) ".")+ {NameLower}
> NameUpperQualified = (({NameLower} | {NameUpper}) ".")+ {NameUpper}
you should get the expected behaviour.
Cheers,
Gerwin
On 21/08/2013, at 10:28 PM, de....@io... wrote:
> Hello.
>
> I have the following macros:
>
> NameLower = [a-z] ([a-z] | [0-9] | "_" | "-")*
> NameUpper = [A-Z] ([a-z] | [A-Z] | [0-9] | "_" | "-")*
> NameLowerQualified = ((NameLower | NameUpper) ".")+ NameLower
> NameUpperQualified = ((NameLower | NameUpper) ".")+ NameUpper
>
> (Note that I really do want [a-z] and [A-Z], as the target language
> only allows ASCII identifiers).
>
> I then have the following rules:
>
> <YYINITIAL> {
> { NameUpperQualified } { return tokenIdentifierUpperQualified (yytext(), this.position()); }
> { NameLowerQualified } { return tokenIdentifierLowerQualified (yytext(), this.position()); }
> { NameUpper } { return tokenIdentifierUpper (yytext(), this.position()); }
> { NameLower } { return tokenIdentifierLower (yytext(), this.position()); }
> }
>
> <<EOF>> { return tokenEOF (this.position()); }
>
> /* error fallback */
> .|\n { throw LexerError.error("Illegal character <"+ yytext()+">"); }
>
> The manual says:
>
> "When consuming its input, the scanner determines the regular
> expression that matches the longest portion of the input (longest match
> rule). If there is more than one regular expression that matches the
> longest portion of input (i.e. they all match the same input), the
> generated scanner chooses the expression that appears first in the
> specification."
>
> However, when the generated lexer is given some input:
>
>> a
> TokenIdentifierLower(Position(0,0),UnqualifiedNameLower(a))
>> a.b
> TokenIdentifierLower(Position(1,0),UnqualifiedNameLower(a))
> Exception in thread "main" LexerError: Illegal character <.>
>
> So why is the NameLowerQualified regex not matching "a.b"? The regex
> appears to be correct (if I've understood the documentation correctly),
> and although NameLower would match the "a" part of the input, the
> NameLowerQualified regex both matches the longer portion of the input
> and is placed before NameLower in the rules. What's going on?
>
> ------------------------------------------------------------------------------
> Introducing Performance Central, a new site from SourceForge and
> AppDynamics. Performance Central is your source for news, insights,
> analysis and resources for efficient Application Performance Management.
> Visit us today!
> http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
> --
> jflex-users mailing list
> https://lists.sourceforge.net/lists/listinfo/jflex-users
________________________________
The information in this e-mail may be confidential and subject to legal professional privilege and/or copyright. National ICT Australia Limited accepts no liability for any damage caused by this email or its attachments.
|