From a2535fb4570dde1e67c8a448d99b5d9887f874bb Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Sun, 5 Feb 2012 01:25:36 +0100 Subject: [PATCH] Fix LPeg precedence for Lua dot operators 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). --- macro/lexer.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/macro/lexer.lua b/macro/lexer.lua index 11c4907..88d187d 100644 --- a/macro/lexer.lua +++ b/macro/lexer.lua @@ -53,8 +53,8 @@ function lexer.init () OT = OT + P(ex) end end - local operator = token('operator', OT + P '.' + P '~=' + P '<=' + P '>=' + P '...' - + P '..' + S '+-*/%^#=<>;:,.{}[]()') + local operator = token('operator', OT + '~=' + '<=' + '>=' + '...' + + '..' + S '+-*/%^#=<>;:,.{}[]()') -- identifiers local ident = token('iden', idsafe * (idsafe + digit) ^ 0)