From d56dee3d3cc7e2d8f9ee05edcdba1a659d449216 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Sun, 23 Apr 2017 03:19:05 +0000 Subject: Update oc.py example: fix regex for '==' operator, add packrat parsing and function call as expression operand git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@462 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b --- src/examples/oc.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/examples/oc.py b/src/examples/oc.py index 42b9d48..cf656ec 100644 --- a/src/examples/oc.py +++ b/src/examples/oc.py @@ -71,6 +71,7 @@ The following is a description of the OC grammar: """ from pyparsing import * +ParserElement.enablePackrat() LPAR,RPAR,LBRACK,RBRACK,LBRACE,RBRACE,SEMI,COMMA = map(Suppress, "()[]{};,") INT, CHAR, WHILE, DO, IF, ELSE, RETURN = map(Keyword, @@ -82,10 +83,10 @@ char = Regex(r"'.'") string_ = dblQuotedString TYPE = Group((INT | CHAR) + ZeroOrMore("*")) - expr = Forward() -operand = NAME | integer | char | string_ -expr << (infixNotation(operand, +func_call = Group(NAME + LPAR + Group(Optional(delimitedList(expr))) + RPAR) +operand = func_call | NAME | integer | char | string_ +expr <<= (infixNotation(operand, [ (oneOf('! - *'), 1, opAssoc.RIGHT), (oneOf('++ --'), 1, opAssoc.RIGHT), @@ -93,7 +94,7 @@ expr << (infixNotation(operand, (oneOf('* / %'), 2, opAssoc.LEFT), (oneOf('+ -'), 2, opAssoc.LEFT), (oneOf('< == > <= >= !='), 2, opAssoc.LEFT), - (Regex(r'=[^=]'), 2, opAssoc.LEFT), + (Regex(r'(?