summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2020-04-07 15:25:08 -0500
committerptmcg <ptmcg@austin.rr.com>2020-04-07 15:25:08 -0500
commit72f2c5a67b4a26f584104b9ff63e1f272f54c5df (patch)
tree029f9fbacee8f4b378d3a9759979c5d2c60826d9 /examples
parent1881e43c10c34c0d24a6e3ecea7b4da710f9c790 (diff)
downloadpyparsing-git-72f2c5a67b4a26f584104b9ff63e1f272f54c5df.tar.gz
enable packrat parsing in all examples using infixNotation
Diffstat (limited to 'examples')
-rw-r--r--examples/bigquery_view_parser.py2
-rw-r--r--examples/eval_arith.py3
-rw-r--r--examples/invRegex.py6
-rw-r--r--examples/simpleArith.py10
-rw-r--r--examples/simpleBool.py4
-rw-r--r--examples/simpleSQL.py3
6 files changed, 23 insertions, 5 deletions
diff --git a/examples/bigquery_view_parser.py b/examples/bigquery_view_parser.py
index 085552b..cf23818 100644
--- a/examples/bigquery_view_parser.py
+++ b/examples/bigquery_view_parser.py
@@ -13,6 +13,8 @@ from pyparsing import QuotedString, CharsNotIn, Optional, Group, ZeroOrMore
from pyparsing import oneOf, delimitedList, restOfLine, cStyleComment
from pyparsing import infixNotation, opAssoc, Regex, nums
+ParserElement.enablePackrat()
+
class BigQueryViewParser:
"""Parser to extract table info from BigQuery view definitions"""
diff --git a/examples/eval_arith.py b/examples/eval_arith.py
index 6a747f3..4f6082f 100644
--- a/examples/eval_arith.py
+++ b/examples/eval_arith.py
@@ -17,8 +17,11 @@ from pyparsing import (
opAssoc,
infixNotation,
Literal,
+ ParserElement,
)
+ParserElement.enablePackrat()
+
class EvalConstant:
"Class to evaluate a parsed constant or variable"
diff --git a/examples/invRegex.py b/examples/invRegex.py
index f0bfe31..b9d6cfb 100644
--- a/examples/invRegex.py
+++ b/examples/invRegex.py
@@ -30,6 +30,8 @@ from pyparsing import (
srange,
)
+ParserElement.enablePackrat()
+
class CharacterRangeEmitter:
def __init__(self, chars):
@@ -279,9 +281,7 @@ def main():
[ABCDEFG](?:#|##|b|bb)?(?:maj|min|m|sus|aug|dim)?[0-9]?(?:/[ABCDEFG](?:#|##|b|bb)?)?
(Fri|Mon|S(atur|un)|T(hur|ue)s|Wednes)day
A(pril|ugust)|((Dec|Nov|Sept)em|Octo)ber|(Febr|Jan)uary|Ju(ly|ne)|Ma(rch|y)
- """.split(
- "\n"
- )
+ """.splitlines()
for t in tests:
t = t.strip()
diff --git a/examples/simpleArith.py b/examples/simpleArith.py
index af3f904..4539018 100644
--- a/examples/simpleArith.py
+++ b/examples/simpleArith.py
@@ -6,9 +6,12 @@
#
# Copyright 2006, by Paul McGuire
#
-
+import sys
from pyparsing import *
+ParserElement.enablePackrat()
+sys.setrecursionlimit(3000)
+
integer = Word(nums).setParseAction(lambda t: int(t[0]))
variable = Word(alphas, exact=1)
operand = integer | variable
@@ -64,6 +67,11 @@ test = [
"M*X + B",
"M*(X + B)",
"1+2*-3^4*5+-+-6",
+ "(a + b)",
+ "((a + b))",
+ "(((a + b)))",
+ "((((a + b))))",
+ "((((((((((((((a + b))))))))))))))",
]
for t in test:
print(t)
diff --git a/examples/simpleBool.py b/examples/simpleBool.py
index f47e090..5ff1728 100644
--- a/examples/simpleBool.py
+++ b/examples/simpleBool.py
@@ -12,7 +12,9 @@
# Copyright 2006, by Paul McGuire
# Updated 2013-Sep-14 - improved Python 2/3 cross-compatibility
#
-from pyparsing import infixNotation, opAssoc, Keyword, Word, alphas
+from pyparsing import infixNotation, opAssoc, Keyword, Word, alphas, ParserElement
+
+ParserElement.enablePackrat()
# define classes to be built at parse time, as each matching
# expression type is parsed
diff --git a/examples/simpleSQL.py b/examples/simpleSQL.py
index a806ad6..ebed658 100644
--- a/examples/simpleSQL.py
+++ b/examples/simpleSQL.py
@@ -19,9 +19,12 @@ from pyparsing import (
opAssoc,
restOfLine,
CaselessKeyword,
+ ParserElement,
pyparsing_common as ppc,
)
+ParserElement.enablePackrat()
+
# define SQL tokens
selectStmt = Forward()
SELECT, FROM, WHERE, AND, OR, IN, IS, NOT, NULL = map(