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
11cb5c7e
Commit
11cb5c7e
authored
Jun 10, 2020
by
eckhart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parse.py: ensure cache neutrality for retrieved values
parent
4f3afbd8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
7 deletions
+31
-7
DHParser/parse.py
DHParser/parse.py
+7
-2
tests/test_parse.py
tests/test_parse.py
+24
-5
No files found.
DHParser/parse.py
View file @
11cb5c7e
...
@@ -1230,7 +1230,7 @@ class Grammar:
...
@@ -1230,7 +1230,7 @@ class Grammar:
# variables stored and recalled by Capture and Retrieve parsers
# variables stored and recalled by Capture and Retrieve parsers
self
.
variables__
=
defaultdict
(
lambda
:
[])
# type: DefaultDict[str, List[str]]
self
.
variables__
=
defaultdict
(
lambda
:
[])
# type: DefaultDict[str, List[str]]
self
.
rollback__
=
[]
# type: List[Tuple[int, Callable]]
self
.
rollback__
=
[]
# type: List[Tuple[int, Callable]]
self
.
last_rb__loc__
=
-
1
# type: int
self
.
last_rb__loc__
=
-
2
# type: int
# support for call stack tracing
# support for call stack tracing
self
.
call_stack__
=
[]
# type: List[CallItem] # tag_name, location
self
.
call_stack__
=
[]
# type: List[CallItem] # tag_name, location
# snapshots of call stacks
# snapshots of call stacks
...
@@ -1460,7 +1460,7 @@ class Grammar:
...
@@ -1460,7 +1460,7 @@ class Grammar:
# *line_col(self.document__, len(self.document__) - self.last_rb__loc__))
# *line_col(self.document__, len(self.document__) - self.last_rb__loc__))
rollback_func
()
rollback_func
()
self
.
last_rb__loc__
=
self
.
rollback__
[
-
1
][
0
]
if
self
.
rollback__
\
self
.
last_rb__loc__
=
self
.
rollback__
[
-
1
][
0
]
if
self
.
rollback__
\
else
-
1
# (self.document__.__len__() + 1)
else
-
2
# (self.document__.__len__() + 1)
def
as_ebnf
(
self
)
->
str
:
def
as_ebnf
(
self
)
->
str
:
...
@@ -3024,6 +3024,8 @@ class Retrieve(UnaryParser):
...
@@ -3024,6 +3024,8 @@ class Retrieve(UnaryParser):
def
_parse
(
self
,
text
:
StringView
)
->
Tuple
[
Optional
[
Node
],
StringView
]:
def
_parse
(
self
,
text
:
StringView
)
->
Tuple
[
Optional
[
Node
],
StringView
]:
# auto-capture on first use if symbol was not captured before
# auto-capture on first use if symbol was not captured before
# ("or"-clause needed, because Forward parsers do not have a pname)
# ("or"-clause needed, because Forward parsers do not have a pname)
self
.
grammar
.
last_rb__loc__
=
self
.
grammar
.
document_length__
-
text
.
_len
# set last_rb__loc__ to avoid caching of retrieved results
if
len
(
self
.
grammar
.
variables__
[
self
.
symbol_pname
])
==
0
:
if
len
(
self
.
grammar
.
variables__
[
self
.
symbol_pname
])
==
0
:
node
,
text_
=
self
.
parser
(
text
)
# auto-capture value
node
,
text_
=
self
.
parser
(
text
)
# auto-capture value
if
node
is
None
:
if
node
is
None
:
...
@@ -3096,6 +3098,9 @@ class Pop(Retrieve):
...
@@ -3096,6 +3098,9 @@ class Pop(Retrieve):
if
node
is
not
None
and
not
id
(
node
)
in
self
.
grammar
.
tree__
.
error_nodes
:
if
node
is
not
None
and
not
id
(
node
)
in
self
.
grammar
.
tree__
.
error_nodes
:
self
.
values
.
append
(
self
.
grammar
.
variables__
[
self
.
symbol_pname
].
pop
())
self
.
values
.
append
(
self
.
grammar
.
variables__
[
self
.
symbol_pname
].
pop
())
self
.
grammar
.
push_rollback__
(
rollback_location
(
self
,
text
,
text_
),
self
.
_rollback
)
self
.
grammar
.
push_rollback__
(
rollback_location
(
self
,
text
,
text_
),
self
.
_rollback
)
else
:
# set last_rb__loc__ to avoid caching of retrieved results
self
.
grammar
.
last_rb__loc__
=
self
.
grammar
.
document_length__
-
text
.
_len
return
node
,
text_
return
node
,
text_
def
__repr__
(
self
):
def
__repr__
(
self
):
...
...
tests/test_parse.py
View file @
11cb5c7e
...
@@ -868,12 +868,31 @@ class TestPopRetrieve:
...
@@ -868,12 +868,31 @@ class TestPopRetrieve:
st
=
gr
(
case
)
st
=
gr
(
case
)
assert
not
st
.
errors
assert
not
st
.
errors
case
=
'AXX!'
case
=
'AXX!'
set_config_value
(
'history_tracking'
,
True
)
#
set_config_value('history_tracking', True)
start_logging
(
'LOGS'
)
#
start_logging('LOGS')
set_tracer
(
gr
,
trace_history
)
#
set_tracer(gr, trace_history)
st
=
gr
(
case
)
st
=
gr
(
case
)
log_parsing_history
(
gr
,
'test_cache_neutrality_2'
)
# log_parsing_history(gr, 'test_cache_neutrality_2')
print
(
st
.
as_sxpr
())
assert
not
st
.
errors
assert
str
(
st
)
==
"AXX!"
# print(st.as_sxpr())
def
test_cache_neutrality_3
(
selfself
):
lang
=
r'''document = variantA | variantB
variantA = delimiter `X` check ::delimiter `!`
variantB = `A` delimiter check ::delimiter `!`
check = :delimiter
delimiter = `A` | `X`
'''
gr
=
grammar_provider
(
lang
)()
case
=
'AXXX!'
# set_config_value('history_tracking', True)
# start_logging('LOGS')
# set_tracer(gr, trace_history)
st
=
gr
(
case
)
# log_parsing_history(gr, 'test_cache_neutrality_3')
assert
not
st
.
errors
# print(st.as_sxpr())
def
test_single_line
(
self
):
def
test_single_line
(
self
):
teststr
=
"Anfang ```code block `` <- keine Ende-Zeichen ! ``` Ende"
teststr
=
"Anfang ```code block `` <- keine Ende-Zeichen ! ``` Ende"
...
...
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