|
The rules I use for this type of thing look like:
re = require "re" -- it's still part of LPeg.
-- and I find it easier to follow the grammar
parser = re.compile [[
expr <- term (termop term)*
term <- factor (factorop factor)*
factor <- number / open expr close
space <- %s*
number <- space {'-'^-1 [0-9]^+1} space
termop <- space {[+-]} space
factorop <- space {[*/]} space
open <- space '(' space
close <- space ')' space
]]