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
8a420675
Commit
8a420675
authored
Jul 12, 2018
by
eckhart
Browse files
- added a few remarks to the source code
parent
522259cb
Changes
4
Show whitespace changes
Inline
Side-by-side
DHParser/parse.py
View file @
8a420675
...
@@ -109,7 +109,7 @@ def add_parser_guard(parser_func):
...
@@ -109,7 +109,7 @@ def add_parser_guard(parser_func):
# if location has already been visited by the current parser,
# if location has already been visited by the current parser,
# return saved result
# return saved result
if
location
in
parser
.
visited
:
if
location
in
parser
.
visited
:
# no history recording in case of me
o
mized results
# no history recording in case of mem
o
ized results
return
parser
.
visited
[
location
]
return
parser
.
visited
[
location
]
if
grammar
.
history_tracking__
:
if
grammar
.
history_tracking__
:
...
@@ -123,7 +123,7 @@ def add_parser_guard(parser_func):
...
@@ -123,7 +123,7 @@ def add_parser_guard(parser_func):
return
None
,
text
return
None
,
text
parser
.
recursion_counter
[
location
]
+=
1
parser
.
recursion_counter
[
location
]
+=
1
# run original __call__ method
#
PARSER CALL:
run original __call__ method
node
,
rest
=
parser_func
(
parser
,
text
)
node
,
rest
=
parser_func
(
parser
,
text
)
if
grammar
.
left_recursion_handling__
:
if
grammar
.
left_recursion_handling__
:
...
@@ -151,9 +151,11 @@ def add_parser_guard(parser_func):
...
@@ -151,9 +151,11 @@ def add_parser_guard(parser_func):
# because caching would interfere with changes of variable state
# because caching would interfere with changes of variable state
# - in case of left recursion, the first recursive step that
# - in case of left recursion, the first recursive step that
# matches will store its result in the cache
# matches will store its result in the cache
# TODO: need a test concerning interference of variable manipulation and left recursion algorithm?
parser
.
visited
[
location
]
=
(
node
,
rest
)
parser
.
visited
[
location
]
=
(
node
,
rest
)
# Mind that meomized parser calls will not appear in the history record!
# Mind that memoized parser calls will not appear in the history record!
# Does this make sense? Or should it be changed?
if
grammar
.
history_tracking__
:
if
grammar
.
history_tracking__
:
# don't track returning parsers except in case an error has occurred
# don't track returning parsers except in case an error has occurred
# remaining = len(rest)
# remaining = len(rest)
...
...
DHParser/syntaxtree.py
View file @
8a420675
...
@@ -206,6 +206,8 @@ class Node(collections.abc.Sized):
...
@@ -206,6 +206,8 @@ class Node(collections.abc.Sized):
"""
"""
Represents a node in the concrete or abstract syntax tree.
Represents a node in the concrete or abstract syntax tree.
TODO: Add some documentation and doc-tests here...
Attributes:
Attributes:
tag_name (str): The name of the node, which is either its
tag_name (str): The name of the node, which is either its
parser's name or, if that is empty, the parser's class name
parser's name or, if that is empty, the parser's class name
...
...
examples/LaTeX/LaTeXCompiler.py
View file @
8a420675
...
@@ -237,13 +237,11 @@ class LaTeXGrammar(Grammar):
...
@@ -237,13 +237,11 @@ class LaTeXGrammar(Grammar):
paragraph
=
Forward
()
paragraph
=
Forward
()
tabular_config
=
Forward
()
tabular_config
=
Forward
()
text_element
=
Forward
()
text_element
=
Forward
()
source_hash__
=
"
1329c620430169c2cbeff23b05e049c3
"
source_hash__
=
"
840c0f34c77bbbe0433e7691fe68f884
"
parser_initialization__
=
"upon instantiation"
parser_initialization__
=
"upon instantiation"
COMMENT__
=
r
'%.*'
COMMENT__
=
r
'%.*'
WHITESPACE__
=
r
'[ \t]*(?:\n(?![ \t]*\n)[ \t]*)?'
WHITESPACE__
=
r
'[ \t]*(?:\n(?![ \t]*\n)[ \t]*)?'
WSP_RE__
=
mixin_comment
(
whitespace
=
WHITESPACE__
,
comment
=
COMMENT__
)
WSP_RE__
=
mixin_comment
(
whitespace
=
WHITESPACE__
,
comment
=
COMMENT__
)
wspL__
=
''
wspR__
=
WSP_RE__
wsp__
=
Whitespace
(
WSP_RE__
)
wsp__
=
Whitespace
(
WSP_RE__
)
EOF
=
RegExp
(
'(?!.)'
)
EOF
=
RegExp
(
'(?!.)'
)
BACKSLASH
=
RegExp
(
'[
\\\\
]'
)
BACKSLASH
=
RegExp
(
'[
\\\\
]'
)
...
...
examples/XML/XMLCompiler.py
View file @
8a420675
...
@@ -277,13 +277,11 @@ class XMLGrammar(Grammar):
...
@@ -277,13 +277,11 @@ class XMLGrammar(Grammar):
extSubsetDecl
=
Forward
()
extSubsetDecl
=
Forward
()
ignoreSectContents
=
Forward
()
ignoreSectContents
=
Forward
()
markupdecl
=
Forward
()
markupdecl
=
Forward
()
source_hash__
=
"
8bfb22526aa4f9b2b66e9aba5ffccf06
"
source_hash__
=
"
205ce13682b5d466a39069a1c1c6108b
"
parser_initialization__
=
"upon instantiation"
parser_initialization__
=
"upon instantiation"
COMMENT__
=
r
''
COMMENT__
=
r
''
WHITESPACE__
=
r
'\s*'
WHITESPACE__
=
r
'\s*'
WSP_RE__
=
mixin_comment
(
whitespace
=
WHITESPACE__
,
comment
=
COMMENT__
)
WSP_RE__
=
mixin_comment
(
whitespace
=
WHITESPACE__
,
comment
=
COMMENT__
)
wspL__
=
''
wspR__
=
''
wsp__
=
Whitespace
(
WSP_RE__
)
wsp__
=
Whitespace
(
WSP_RE__
)
EOF
=
NegativeLookahead
(
RegExp
(
'.'
))
EOF
=
NegativeLookahead
(
RegExp
(
'.'
))
S
=
RegExp
(
'
\\
s+'
)
S
=
RegExp
(
'
\\
s+'
)
...
...
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