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
6d96b270
Commit
6d96b270
authored
Aug 30, 2017
by
di68kap
Browse files
- parser.py: full memoization with assertions
parent
ccf7d3fe
Changes
1
Show whitespace changes
Inline
Side-by-side
DHParser/parser.py
View file @
6d96b270
...
...
@@ -241,6 +241,7 @@ def add_parser_guard(parser_func):
# return saved result
if
location
in
parser
.
visited
:
node
,
rlen
=
parser
.
visited
[
location
]
assert
rlen
==
location
-
(
0
if
node
is
None
else
node
.
len
)
rest
=
grammar
.
document__
[
-
rlen
:]
if
rlen
else
''
return
node
,
rest
...
...
@@ -261,6 +262,7 @@ def add_parser_guard(parser_func):
if
node
is
None
:
# retrieve an earlier match result (from left recursion) if it exists
node
,
rlen
=
parser
.
visited
.
get
(
location
,
(
None
,
len
(
rest
)))
assert
rlen
==
location
-
(
0
if
node
is
None
else
node
.
len
)
rest
=
grammar
.
document__
[
-
rlen
:]
if
rlen
else
''
# don't overwrite any positive match (i.e. node not None) in the cache
# and don't add empty entries for parsers returning from left recursive calls!
...
...
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