Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
ebe3a90b
Commit
ebe3a90b
authored
Aug 27, 2017
by
Eckhart Arnold
Browse files
- parser.py: added explanation or last_rb__loc__ to docstring of Grammar-class
parent
bd0e6011
Changes
1
Hide whitespace changes
Inline
Side-by-side
DHParser/parser.py
View file @
ebe3a90b
...
...
@@ -231,7 +231,7 @@ def add_parser_guard(parser_func):
"""
def
guarded_call
(
parser
:
'Parser'
,
text
:
str
)
->
Tuple
[
Node
,
str
]:
try
:
location
=
len
(
text
)
location
=
len
(
text
)
# mind that location is always the distance to the end
grammar
=
parser
.
grammar
# grammar may be 'None' for unconnected parsers!
if
not
grammar
.
moving_forward__
:
...
...
@@ -266,7 +266,7 @@ def add_parser_guard(parser_func):
# 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!
if
node
is
None
and
not
grammar
.
left_recursion_encountered__
:
# o
r
therwise also cache None-results
# otherwise also cache None-results
parser
.
visited
[
location
]
=
None
,
rest
else
:
# variable manipulating parsers will be excluded, though,
...
...
@@ -353,7 +353,7 @@ class Parser(ParserBase, metaclass=ParserMetaClass):
contained parser is repeated zero times.
Attributes:
visted: Dictionary of places this parser has already been to
vis
i
ted: Dictionary of places this parser has already been to
during the current parsing process and the results the
parser returned at the respective place. This dictionary
is used to implement memoizing.
...
...
@@ -363,7 +363,7 @@ class Parser(ParserBase, metaclass=ParserMetaClass):
is needed to implement left recursion. The number of
calls becomes irrelevant once a resault has been memoized.
cycle_detection: The apply()-method uses this variable to make
cycle_detection:
The apply()-method uses this variable to make
sure that one and the same function will not be applied
(recursively) a second time, if it has already been
applied to this parser.
...
...
@@ -586,6 +586,14 @@ class Grammar:
process reaches a dead end then all rollback-functions up to
the point to which it retreats will be called and the state
of the variable stack restored accordingly.
last_rb__loc__: The last, i.e. most advanced location in the text
where a variable changing operation occurred. If the parser
backtracks to a location at or before `last_rb__loc__` (which,
since locations are counted from the reverse, means:
`location >= last_rb__loc__`) then a rollback of all variable
changing operations is necessary that occurred after the
location to which the parser backtracks. This is done by
calling method `.rollback_to__(location)`.
call_stack__: A stack of all parsers that have been called. This
is required for recording the parser history (for debugging)
and, eventually, i.e. one day in the future, for tracing through
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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