Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
DHParser
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
badw-it
DHParser
Commits
ccf7d3fe
Commit
ccf7d3fe
authored
Aug 30, 2017
by
di68kap
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- parser.py: full memoization, different algorithm; little memory usage
parent
93a863ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
DHParser/parser.py
DHParser/parser.py
+10
-7
No files found.
DHParser/parser.py
View file @
ccf7d3fe
...
...
@@ -240,7 +240,9 @@ def add_parser_guard(parser_func):
# if location has already been visited by the current parser,
# return saved result
if
location
in
parser
.
visited
:
return
parser
.
visited
[
location
]
node
,
rlen
=
parser
.
visited
[
location
]
rest
=
grammar
.
document__
[
-
rlen
:]
if
rlen
else
''
return
node
,
rest
# break left recursion at the maximum allowed depth
if
parser
.
recursion_counter
.
setdefault
(
location
,
0
)
>
LEFT_RECURSION_DEPTH
:
...
...
@@ -258,13 +260,14 @@ def add_parser_guard(parser_func):
if
node
is
None
:
# retrieve an earlier match result (from left recursion) if it exists
node
,
rest
=
parser
.
visited
.
get
(
location
,
(
None
,
rest
))
node
,
rlen
=
parser
.
visited
.
get
(
location
,
(
None
,
len
(
rest
)))
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!
# TODO: uncomment the following for full memoizazion
#
if node is None and location not in grammar.recursion_locations__:
#
# otherwise also cache None-results
# parser.visited[location] = None, rest
if
node
is
None
and
location
not
in
grammar
.
recursion_locations__
:
# otherwise also cache None-results
parser
.
visited
[
location
]
=
None
,
len
(
rest
)
else
:
# variable manipulating parsers will be excluded, though,
# because caching would interfere with changes of variable state
...
...
@@ -272,8 +275,8 @@ def add_parser_guard(parser_func):
# in case of left recursion, the first recursive step that
# matches will store its result in the cache
# TODO: remove if clause for full memoization
if
location
in
grammar
.
recursion_locations__
:
parser
.
visited
[
location
]
=
(
node
,
rest
)
#
if location in grammar.recursion_locations__:
parser
.
visited
[
location
]
=
(
node
,
len
(
rest
)
)
parser
.
recursion_counter
[
location
]
-=
1
...
...
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