diff options
Diffstat (limited to 'src/examples')
-rw-r--r-- | src/examples/eval_arith.py | 12 | ||||
-rw-r--r-- | src/examples/excelExpr.py | 6 | ||||
-rw-r--r-- | src/examples/idlParse.py | 2 | ||||
-rw-r--r-- | src/examples/invRegex.py | 4 | ||||
-rw-r--r-- | src/examples/lucene_grammar.py | 4 | ||||
-rw-r--r-- | src/examples/oc.py | 2 | ||||
-rw-r--r-- | src/examples/select_parser.py | 2 | ||||
-rw-r--r-- | src/examples/simpleArith.py | 12 | ||||
-rw-r--r-- | src/examples/simpleSQL.py | 14 | ||||
-rw-r--r-- | src/examples/verilogParse.py | 2 |
10 files changed, 30 insertions, 30 deletions
diff --git a/src/examples/eval_arith.py b/src/examples/eval_arith.py index 85566c7..9562253 100644 --- a/src/examples/eval_arith.py +++ b/src/examples/eval_arith.py @@ -9,7 +9,7 @@ # operands
#
from pyparsing import Word, nums, alphas, Combine, oneOf, \
- opAssoc, operatorPrecedence, Literal
+ opAssoc, infixNotation, Literal
class EvalConstant(object):
"Class to evaluate a parsed constant or variable"
@@ -120,7 +120,7 @@ expop = Literal('**') # use parse actions to attach EvalXXX constructors to sub-expressions
operand.setParseAction(EvalConstant)
-arith_expr = operatorPrecedence(operand,
+arith_expr = infixNotation(operand,
[
(signop, 1, opAssoc.RIGHT, EvalSignOp),
(expop, 2, opAssoc.LEFT, EvalPowerOp),
@@ -129,7 +129,7 @@ arith_expr = operatorPrecedence(operand, ])
comparisonop = oneOf("< <= > >= != = <> LT GT LE GE EQ NE")
-comp_expr = operatorPrecedence(arith_expr,
+comp_expr = infixNotation(arith_expr,
[
(comparisonop, 2, opAssoc.LEFT, EvalComparisonOp),
])
@@ -210,14 +210,14 @@ def main(): for test,expected in tests:
ret = comp_expr.parseString(test)[0]
parsedvalue = ret.eval()
- print(test, expected, parsedvalue, end=' ')
+ print(test, expected, parsedvalue)
if parsedvalue != expected:
print("<<< FAIL")
failed += 1
else:
- print()
+ print('')
- print()
+ print('')
if failed:
print(failed, "tests FAILED")
else:
diff --git a/src/examples/excelExpr.py b/src/examples/excelExpr.py index 39af365..2700100 100644 --- a/src/examples/excelExpr.py +++ b/src/examples/excelExpr.py @@ -6,7 +6,7 @@ #
from pyparsing import (CaselessKeyword, Suppress, Word, alphas,
alphanums, nums, Optional, Group, oneOf, Forward, Regex,
- operatorPrecedence, opAssoc, dblQuotedString, delimitedList,
+ infixNotation, opAssoc, dblQuotedString, delimitedList,
Combine, Literal, QuotedString, ParserElement)
ParserElement.enablePackrat()
@@ -43,14 +43,14 @@ multOp = oneOf("* /") addOp = oneOf("+ -")
numericLiteral = Regex(r"\-?\d+(\.\d+)?")
operand = numericLiteral | funcCall | cellRange | cellRef
-arithExpr = operatorPrecedence(operand,
+arithExpr = infixNotation(operand,
[
(multOp, 2, opAssoc.LEFT),
(addOp, 2, opAssoc.LEFT),
])
textOperand = dblQuotedString | cellRef
-textExpr = operatorPrecedence(textOperand,
+textExpr = infixNotation(textOperand,
[
('&', 2, opAssoc.LEFT),
])
diff --git a/src/examples/idlParse.py b/src/examples/idlParse.py index 419e56f..dd556e5 100644 --- a/src/examples/idlParse.py +++ b/src/examples/idlParse.py @@ -6,7 +6,7 @@ # Copyright (c) 2003, Paul McGuire
#
-from pyparsing import Literal, CaselessLiteral, Word, Upcase, OneOrMore, ZeroOrMore, \
+from pyparsing import Literal, CaselessLiteral, Word, OneOrMore, ZeroOrMore, \
Forward, NotAny, delimitedList, oneOf, Group, Optional, Combine, alphas, nums, restOfLine, cStyleComment, \
alphanums, printables, empty, quotedString, ParseException, ParseResults, Keyword, Regex
import pprint
diff --git a/src/examples/invRegex.py b/src/examples/invRegex.py index 26d12ed..5d9a393 100644 --- a/src/examples/invRegex.py +++ b/src/examples/invRegex.py @@ -14,7 +14,7 @@ __all__ = ["count","invert"]
from pyparsing import (Literal, oneOf, printables, ParserElement, Combine,
- SkipTo, operatorPrecedence, ParseFatalException, Word, nums, opAssoc,
+ SkipTo, infixNotation, ParseFatalException, Word, nums, opAssoc,
Suppress, ParseResults, srange)
class CharacterRangeEmitter(object):
@@ -172,7 +172,7 @@ def parser(): reDot.setParseAction(handleDot)
reTerm = ( reLiteral | reRange | reMacro | reDot | reNonCaptureGroup)
- reExpr = operatorPrecedence( reTerm,
+ reExpr = infixNotation( reTerm,
[
(repetition, 1, opAssoc.LEFT, handleRepetition),
(None, 2, opAssoc.LEFT, handleSequence),
diff --git a/src/examples/lucene_grammar.py b/src/examples/lucene_grammar.py index 85e294b..179f25e 100644 --- a/src/examples/lucene_grammar.py +++ b/src/examples/lucene_grammar.py @@ -8,7 +8,7 @@ #
from pyparsing import (Literal, CaselessKeyword, Forward, Regex, QuotedString, Suppress,
- Optional, Group, FollowedBy, operatorPrecedence, opAssoc, ParseException, ParserElement)
+ Optional, Group, FollowedBy, infixNotation, opAssoc, ParseException, ParserElement)
ParserElement.enablePackrat()
COLON,LBRACK,RBRACK,LBRACE,RBRACE,TILDE,CARAT = map(Literal,":[]{}~^")
@@ -49,7 +49,7 @@ term << (Optional(field_name("field") + COLON) + Optional(boost))
term.setParseAction(lambda t:[t] if 'field' in t or 'boost' in t else None)
-expression << operatorPrecedence(term,
+expression << infixNotation(term,
[
(required_modifier | prohibit_modifier, 1, opAssoc.RIGHT),
((not_ | '!').setParseAction(lambda:"NOT"), 1, opAssoc.RIGHT),
diff --git a/src/examples/oc.py b/src/examples/oc.py index 1d49190..77ea195 100644 --- a/src/examples/oc.py +++ b/src/examples/oc.py @@ -92,7 +92,7 @@ TYPE = Group((INT | CHAR) + ZeroOrMore("*")) expr = Forward()
operand = NAME | integer | char | string_
-expr << (operatorPrecedence(operand,
+expr << (infixNotation(operand,
[
(oneOf('! - *'), 1, opAssoc.RIGHT),
(oneOf('++ --'), 1, opAssoc.RIGHT),
diff --git a/src/examples/select_parser.py b/src/examples/select_parser.py index 677fd11..7c53325 100644 --- a/src/examples/select_parser.py +++ b/src/examples/select_parser.py @@ -63,7 +63,7 @@ expr_term = ( )
UNARY,BINARY,TERNARY=1,2,3
-expr << operatorPrecedence(expr_term,
+expr << infixNotation(expr_term,
[
(oneOf('- + ~') | NOT, UNARY, opAssoc.RIGHT),
(ISNULL | NOTNULL | NOT + NULL, UNARY, opAssoc.LEFT),
diff --git a/src/examples/simpleArith.py b/src/examples/simpleArith.py index 09c32d3..825956b 100644 --- a/src/examples/simpleArith.py +++ b/src/examples/simpleArith.py @@ -2,7 +2,7 @@ # simpleArith.py
#
# Example of defining an arithmetic expression parser using
-# the operatorPrecedence helper method in pyparsing.
+# the infixNotation helper method in pyparsing.
#
# Copyright 2006, by Paul McGuire
#
@@ -19,11 +19,11 @@ multop = oneOf('* /') plusop = oneOf('+ -')
factop = Literal('!')
-# To use the operatorPrecedence helper:
+# To use the infixNotation helper:
# 1. Define the "atom" operand term of the grammar.
# For this simple grammar, the smallest operand is either
# and integer or a variable. This will be the first argument
-# to the operatorPrecedence method.
+# to the infixNotation method.
# 2. Define a list of tuples for each level of operator
# precendence. Each tuple is of the form
# (opExpr, numTerms, rightLeftAssoc, parseAction), where
@@ -37,13 +37,13 @@ factop = Literal('!') # - parseAction is the parse action to be associated with
# expressions matching this operator expression (the
# parse action tuple member may be omitted)
-# 3. Call operatorPrecedence passing the operand expression and
+# 3. Call infixNotation passing the operand expression and
# the operator precedence list, and save the returned value
# as the generated pyparsing expression. You can then use
# this expression to parse input strings, or incorporate it
# into a larger, more complex grammar.
#
-expr = operatorPrecedence( operand,
+expr = infixNotation( operand,
[("!", 1, opAssoc.LEFT),
("^", 2, opAssoc.RIGHT),
(signop, 1, opAssoc.RIGHT),
@@ -63,5 +63,5 @@ test = ["9 + 2 + 3", for t in test:
print(t)
print(expr.parseString(t))
- print()
+ print('')
diff --git a/src/examples/simpleSQL.py b/src/examples/simpleSQL.py index 62f9928..e19d5c2 100644 --- a/src/examples/simpleSQL.py +++ b/src/examples/simpleSQL.py @@ -5,12 +5,12 @@ #
# Copyright (c) 2003, Paul McGuire
#
-from pyparsing import Literal, CaselessLiteral, Word, Upcase, delimitedList, Optional, \
+from pyparsing import Literal, CaselessLiteral, Word, delimitedList, Optional, \
Combine, Group, alphas, nums, alphanums, ParseException, Forward, oneOf, quotedString, \
- ZeroOrMore, restOfLine, Keyword
+ ZeroOrMore, restOfLine, Keyword, upcaseTokens
def test( str ):
- print(str,"->")
+ print(str + " ->")
try:
tokens = simpleSQL.parseString( str )
print("tokens = ", tokens)
@@ -18,9 +18,9 @@ def test( str ): print("tokens.tables =", tokens.tables)
print("tokens.where =", tokens.where)
except ParseException as err:
- print(" "*err.loc + "^\n" + err.msg)
+ print(" "*err.loc + "^")
print(err)
- print()
+ print('')
# define SQL tokens
@@ -29,9 +29,9 @@ selectToken = Keyword("select", caseless=True) fromToken = Keyword("from", caseless=True)
ident = Word( alphas, alphanums + "_$" ).setName("identifier")
-columnName = Upcase( delimitedList( ident, ".", combine=True ) )
+columnName = ( delimitedList( ident, ".", combine=True ) ).addParseAction(upcaseTokens)
columnNameList = Group( delimitedList( columnName ) )
-tableName = Upcase( delimitedList( ident, ".", combine=True ) )
+tableName = ( delimitedList( ident, ".", combine=True ) ).addParseAction(upcaseTokens)
tableNameList = Group( delimitedList( tableName ) )
whereExpression = Forward()
diff --git a/src/examples/verilogParse.py b/src/examples/verilogParse.py index 5eaf14f..2b7fd35 100644 --- a/src/examples/verilogParse.py +++ b/src/examples/verilogParse.py @@ -68,7 +68,7 @@ import sys __version__ = "1.0.11"
-from pyparsing import Literal, CaselessLiteral, Keyword, Word, Upcase, OneOrMore, ZeroOrMore, \
+from pyparsing import Literal, CaselessLiteral, Keyword, Word, OneOrMore, ZeroOrMore, \
Forward, NotAny, delimitedList, Group, Optional, Combine, alphas, nums, restOfLine, cStyleComment, \
alphanums, printables, dblQuotedString, empty, ParseException, ParseResults, MatchFirst, oneOf, GoToColumn, \
ParseResults,StringEnd, FollowedBy, ParserElement, And, Regex, cppStyleComment#,__version__
|