Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LPeg precedence for Lua dot operators #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix LPeg precedence for Lua dot operators #1

wants to merge 1 commit into from

Conversation

xolox
Copy link

@xolox xolox commented Feb 5, 2012

Hi Steve,

I saw your LuaMacro 2.4 announcement on luarocks-dev:

This fixes some nasty bugs, some of them on the lexical level (like fred.dog being lexed as a single identifier!), and some improvements.

I seem to remember taking this shortcut in my original Lua lexer and indeed, I fixed the same bug in LXSH. Sorry about that :-). Anyway, I was curious how you changed it and think I found a minor bug in the change: The matching of the . operator prevents the .. operator from ever being matched. Here's the explanation I wrote in the commit message:

LPeg doesn't have a "longest match is preferred" rule which means that when the LPeg pattern "operator" in the Lua lexer first tries to match the Lua dot operator and then tries to match the double dot operator, the second match can never succeed because the first sub-pattern (the single dot) has already been matched and will be returned as a successful match. Because the single dot is already included in the last sub-pattern (the set of single-character operators) I've just removed the P '.' sub-pattern. I also removed the P prefixes because they're not needed (as long as an LPeg pattern is on the left side of the long expression of valid multi-character operators).

In the 10 minutes I spend on this I didn't figure out how to install LuaMacro + run the tests (I've not used LuaMacro before), so please run them before merging my change to make sure I didn't break them with my suggested change :-].

LPeg doesn't have a "longest match is preferred" rule which means that
when the LPeg pattern "operator" in the Lua lexer first tries to match
the Lua dot operator and then tries to match the double dot operator,
the second match can never succeed because the first sub-pattern (the
single dot) has already been matched and will be returned as a
successful match. Because the single dot is already included in the last
sub-pattern (the set of single-character operators) I've just removed
the P '.' sub-pattern. I also removed the P prefixes because they're not
needed (as long as an LPeg pattern is on the left side of the long
expression of valid multi-character operators).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant