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
a007b727
Commit
a007b727
authored
Jun 09, 2020
by
eckhart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parser.py: added function rollback_location()
parent
3b2f0626
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
9 deletions
+23
-9
DHParser/parse.pxd
DHParser/parse.pxd
+3
-0
DHParser/parse.py
DHParser/parse.py
+20
-9
No files found.
DHParser/parse.pxd
View file @
a007b727
...
@@ -120,6 +120,9 @@ cdef class Lookbehind(FlowParser):
...
@@ -120,6 +120,9 @@ cdef class Lookbehind(FlowParser):
cdef
class
NegativeLookbehind
(
Lookbehind
):
cdef
class
NegativeLookbehind
(
Lookbehind
):
pass
pass
@
cython
.
locals
(
L
=
cython
.
int
,
rb_loc
=
cython
.
int
)
cdef
int
rollback_location
(
p
,
text
,
rest
)
cdef
class
Capture
(
UnaryParser
):
cdef
class
Capture
(
UnaryParser
):
pass
pass
...
...
DHParser/parse.py
View file @
a007b727
...
@@ -2873,6 +2873,22 @@ class NegativeLookbehind(Lookbehind):
...
@@ -2873,6 +2873,22 @@ class NegativeLookbehind(Lookbehind):
########################################################################
########################################################################
@
cython
.
locals
(
L
=
cython
.
int
,
rb_loc
=
cython
.
int
)
def
rollback_location
(
p
:
Parser
,
text
:
StringView
,
rest
:
StringView
)
->
int
:
"""
Determines the rollback location for variable manipulating parsers.
Usually, this is exactly the location, where the parser started parsing.
However, since the rollback-location must lie before the location where
the parser stopped, 1 is subtracted from the start-position in case the
it is the same as the stop position (i.e. len(node) == 0).
"""
L
=
text
.
_len
rb_loc
=
p
.
grammar
.
document_length__
-
L
if
rest
.
_len
==
text
.
_len
:
rb_loc
-=
1
return
rb_loc
class
Capture
(
UnaryParser
):
class
Capture
(
UnaryParser
):
"""
"""
Applies the contained parser and, in case of a match, saves the result
Applies the contained parser and, in case of a match, saves the result
...
@@ -2892,8 +2908,7 @@ class Capture(UnaryParser):
...
@@ -2892,8 +2908,7 @@ class Capture(UnaryParser):
assert
not
self
.
parser
.
drop_content
,
\
assert
not
self
.
parser
.
drop_content
,
\
"Cannot capture content from parsers that drop content!"
"Cannot capture content from parsers that drop content!"
self
.
grammar
.
variables__
[
self
.
pname
].
append
(
node
.
content
)
self
.
grammar
.
variables__
[
self
.
pname
].
append
(
node
.
content
)
location
=
self
.
grammar
.
document_length__
-
text
.
__len__
()
self
.
grammar
.
push_rollback__
(
rollback_location
(
self
,
text
,
text_
),
self
.
_rollback
)
self
.
grammar
.
push_rollback__
(
location
,
self
.
_rollback
)
# lambda: stack.pop())
# caching will be blocked by parser guard (see way above),
# caching will be blocked by parser guard (see way above),
# because it would prevent recapturing of rolled back captures
# because it would prevent recapturing of rolled back captures
return
self
.
_return_value
(
node
),
text_
return
self
.
_return_value
(
node
),
text_
...
@@ -3077,15 +3092,11 @@ class Pop(Retrieve):
...
@@ -3077,15 +3092,11 @@ class Pop(Retrieve):
self
.
grammar
.
variables__
[
self
.
symbol_pname
].
append
(
self
.
values
.
pop
())
self
.
grammar
.
variables__
[
self
.
symbol_pname
].
append
(
self
.
values
.
pop
())
def
_parse
(
self
,
text
:
StringView
)
->
Tuple
[
Optional
[
Node
],
StringView
]:
def
_parse
(
self
,
text
:
StringView
)
->
Tuple
[
Optional
[
Node
],
StringView
]:
node
,
t
xt
=
self
.
retrieve_and_match
(
text
)
node
,
t
ext_
=
self
.
retrieve_and_match
(
text
)
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
())
location
=
self
.
grammar
.
document_length__
-
text
.
__len__
()
self
.
grammar
.
push_rollback__
(
rollback_location
(
self
,
text
,
text_
),
self
.
_rollback
)
# if node is not EMPTY_NODE and len(node) == 0:
return
node
,
text_
# location = self.grammar.document_length__ - txt.__len__() - 1
# print('PUSH:', self.symbol_pname, location, self.values[-1])
self
.
grammar
.
push_rollback__
(
location
,
self
.
_rollback
)
# lambda: stack.append(value))
return
node
,
txt
def
__repr__
(
self
):
def
__repr__
(
self
):
stack
=
self
.
grammar
.
variables__
.
get
(
self
.
symbol_pname
,
[])
stack
=
self
.
grammar
.
variables__
.
get
(
self
.
symbol_pname
,
[])
...
...
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