Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
b25f87b6
Commit
b25f87b6
authored
Jan 25, 2019
by
di68kap
Browse files
- DHParser.testing Lookahead checking bug fixed
parent
98fc3fa7
Changes
1
Show whitespace changes
Inline
Side-by-side
DHParser/testing.py
View file @
b25f87b6
...
...
@@ -308,33 +308,31 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
parser
=
parser_factory
()
transform
=
transformer_factory
()
is_lookahead
=
set
()
# type:
Dic
t[str] # Dictionary of parser names
is_lookahead
=
set
()
# type:
Se
t[str] # Dictionary of parser names
with_lookahead
=
set
()
# type: Set[Parser]
visited
=
set
()
# type: Set[Parser]
lookahead_flag
=
False
# type: bool
def
find_lookahead
(
p
:
Parser
):
"""Raises a StopIterationError if parser `p` is or contains
a Lookahead-parser."""
nonlocal
is_lookahead
,
with_lookahead
,
visited
if
p
in
visite
d
:
raise
StopIteration
visited
.
add
(
p
)
nonlocal
is_lookahead
,
with_lookahead
,
lookahead_flag
if
p
in
with_lookahea
d
:
lookahead_flag
=
True
else
:
if
isinstance
(
p
,
Lookahead
):
is_lookahead
.
add
(
p
.
tag_name
)
with_lookahead
.
add
(
p
)
lookahead_flag
=
True
def
has_lookahead
(
parser_name
:
str
):
"""Returns `True`, if given parser is or contains a Lookahead-parser."""
nonlocal
is_lookahead
,
with_lookahead
,
visited
,
parser
nonlocal
is_lookahead
,
with_lookahead
,
lookahead_flag
,
parser
p
=
parser
[
parser_name
]
num_lookaheads
=
len
(
is_lookahead
)
if
p
in
with_lookahead
:
return
True
try
:
lookahead_flag
=
False
p
.
apply
(
find_lookahead
)
except
StopIteration
:
pass
if
len
(
is_lookahead
)
>
num_lookaheads
:
if
lookahead_flag
:
with_lookahead
.
add
(
p
)
return
True
return
False
...
...
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