Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
badw-it
DHParser
Commits
6c20ccf3
Commit
6c20ccf3
authored
Jul 05, 2017
by
Eckhart Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better tests for left recursion
parent
5bf393d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
5 deletions
+5
-5
DHParser/parsers.py
DHParser/parsers.py
+2
-2
test/test_parsers.py
test/test_parsers.py
+3
-3
No files found.
DHParser/parsers.py
View file @
6c20ccf3
...
...
@@ -198,7 +198,7 @@ def add_parser_guard(parser_func):
# because caching would interfere with changes of variable state
if
not
(
grammar
.
rollback__
and
grammar
.
rollback__
[
-
1
][
0
]
<=
location
):
parser
.
visited
[
location
]
=
(
node
,
rest
)
grammar
.
last_node__
=
node
# store last node for Lookbehind
operato
r
grammar
.
last_node__
=
node
# store last node for Lookbehind
parse
r
elif
location
in
parser
.
visited
:
# if parser did non match but a saved result exits, assume
# left recursion and use the saved result
...
...
@@ -1293,7 +1293,7 @@ def compile_source(source: str,
transformer (function): A transformation function that takes
the root-node of the concrete syntax tree as an argument and
transforms it (in place) into an abstract syntax tree.
compiler (function): A compiler function or compiler class
compiler (function): A compiler function or compiler class
instance
Returns (tuple):
...
...
test/test_parsers.py
View file @
6c20ccf3
...
...
@@ -79,11 +79,11 @@ ARITHMETIC2_EBNF = """
class
TestInfiLoopsAndRecursion
:
def
test_direct_left_recursion
(
self
):
minilang
=
ARITHMETIC_EBNF
snippet
=
"5 + 3 * 4"
snippet
=
"
9 + 8 + 7 + 6 +
5 + 3 * 4"
parser
=
parser_factory
(
minilang
)()
assert
parser
syntax_tree
=
parser
(
snippet
)
assert
not
syntax_tree
.
collect_errors
()
assert
not
syntax_tree
.
error_flag
,
str
(
syntax_tree
.
collect_errors
()
)
assert
snippet
==
str
(
syntax_tree
)
if
is_logging
():
syntax_tree
.
log
(
"test_LeftRecursion_direct.cst"
)
...
...
@@ -91,7 +91,7 @@ class TestInfiLoopsAndRecursion:
def
test_indirect_left_recursion
(
self
):
minilang
=
ARITHMETIC2_EBNF
snippet
=
"5 + 3 * 4"
snippet
=
"
9 + 8 + 7 + 6 +
5 + 3 * 4"
parser
=
parser_factory
(
minilang
)()
assert
parser
syntax_tree
=
parser
(
snippet
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment