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
a3bbb083
Commit
a3bbb083
authored
May 21, 2019
by
di68kap
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- DHParser/parse.py: better lookahead failure detection
parent
8aa3ba60
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
8 deletions
+13
-8
DHParser/log.py
DHParser/log.py
+0
-1
DHParser/parse.py
DHParser/parse.py
+12
-7
DHParser/testing.py
DHParser/testing.py
+1
-0
No files found.
DHParser/log.py
View file @
a3bbb083
...
@@ -262,7 +262,6 @@ class HistoryRecord:
...
@@ -262,7 +262,6 @@ class HistoryRecord:
(
repr
(
self
.
call_stack
),
repr
(
self
.
node
),
repr
(
self
.
text
),
(
repr
(
self
.
call_stack
),
repr
(
self
.
node
),
repr
(
self
.
text
),
repr
(
self
.
line_col
),
repr
(
self
.
errors
))
repr
(
self
.
line_col
),
repr
(
self
.
errors
))
def
as_tuple
(
self
)
->
'Snapshot'
:
def
as_tuple
(
self
)
->
'Snapshot'
:
"""
"""
Returns history record formatted as a snapshot tuple.
Returns history record formatted as a snapshot tuple.
...
...
DHParser/parse.py
View file @
a3bbb083
...
@@ -362,6 +362,7 @@ class Parser:
...
@@ -362,6 +362,7 @@ class Parser:
visited
[
location
]
=
(
None
,
rest
)
visited
[
location
]
=
(
None
,
rest
)
else
:
else
:
# assert node._pos < 0 or node == EMPTY_NODE
# assert node._pos < 0 or node == EMPTY_NODE
# if node._pos != EMPTY_NODE:
node
.
_pos
=
location
node
.
_pos
=
location
# assert node._pos >= 0 or node == EMPTY_NODE, \
# assert node._pos >= 0 or node == EMPTY_NODE, \
# str("%i < %i" % (grammar.document_length__, location))
# str("%i < %i" % (grammar.document_length__, location))
...
@@ -933,8 +934,9 @@ class Grammar:
...
@@ -933,8 +934,9 @@ class Grammar:
and
any
(
self
.
history__
[
i
].
status
==
HistoryRecord
.
MATCH
and
any
(
self
.
history__
[
i
].
status
==
HistoryRecord
.
MATCH
and
((
self
.
history__
[
i
].
node
.
pos
+
len
(
self
.
history__
[
i
].
node
))
and
((
self
.
history__
[
i
].
node
.
pos
+
len
(
self
.
history__
[
i
].
node
))
if
self
.
history__
[
i
].
node
else
0
)
>=
len
(
self
.
document__
)
if
self
.
history__
[
i
].
node
else
0
)
>=
len
(
self
.
document__
)
and
any
(
tn
in
self
and
isinstance
(
self
[
tn
],
Lookahead
)
and
any
((
tn
in
self
and
isinstance
(
self
[
tn
],
Lookahead
)
or
tn
[
0
]
==
':'
and
issubclass
(
eval
(
tn
[
1
:]),
Lookahead
)
or
tn
[
0
]
==
':'
and
issubclass
(
eval
(
tn
[
1
:]),
Lookahead
))
and
self
.
history__
[
i
].
node
.
pos
==
len
(
self
.
document__
)
for
tn
in
self
.
history__
[
i
].
call_stack
)
for
tn
in
self
.
history__
[
i
].
call_stack
)
for
i
in
range
(
-
2
,
-
len
(
self
.
history__
)
-
1
,
-
1
))
for
i
in
range
(
-
2
,
-
len
(
self
.
history__
)
-
1
,
-
1
))
...
@@ -997,8 +999,11 @@ class Grammar:
...
@@ -997,8 +999,11 @@ class Grammar:
error_code
=
Error
.
PARSER_DID_NOT_MATCH
error_code
=
Error
.
PARSER_DID_NOT_MATCH
else
:
else
:
stitches
.
append
(
result
)
stitches
.
append
(
result
)
h
=
HistoryRecord
.
most_advanced_match
(
self
.
history__
)
\
for
h
in
reversed
(
self
.
history__
):
if
self
.
history__
else
HistoryRecord
([],
None
,
StringView
(
''
),
(
0
,
0
))
if
h
.
node
and
h
.
node
.
tag_name
!=
EMPTY_NODE
.
tag_name
:
break
else
:
h
=
HistoryRecord
([],
None
,
StringView
(
''
),
(
0
,
0
))
if
h
.
status
==
h
.
MATCH
and
(
h
.
node
.
pos
+
len
(
h
.
node
)
==
len
(
self
.
document__
)):
if
h
.
status
==
h
.
MATCH
and
(
h
.
node
.
pos
+
len
(
h
.
node
)
==
len
(
self
.
document__
)):
# TODO: this case still needs unit-tests and support in testing.py
# TODO: this case still needs unit-tests and support in testing.py
error_msg
=
"Parser stopped before end, but matched with lookahead."
error_msg
=
"Parser stopped before end, but matched with lookahead."
...
@@ -1023,9 +1028,9 @@ class Grammar:
...
@@ -1023,9 +1028,9 @@ class Grammar:
# if record.node and record.node._pos < 0:
# if record.node and record.node._pos < 0:
# record.node.with_pos(0)
# record.node.with_pos(0)
# print(self.call_stack__)
# print(self.call_stack__)
record
=
HistoryRecord
(
self
.
call_stack__
.
copy
(),
stitches
[
-
1
],
rest
,
#
record = HistoryRecord(self.call_stack__.copy(), stitches[-1], rest,
self
.
line_col__
(
rest
))
#
self.line_col__(rest))
self
.
history__
.
append
(
record
)
#
self.history__.append(record)
# stop history tracking when parser returned too early
# stop history tracking when parser returned too early
self
.
history_tracking__
=
False
self
.
history_tracking__
=
False
if
stitches
:
if
stitches
:
...
...
DHParser/testing.py
View file @
a3bbb083
...
@@ -478,6 +478,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report='REPORT'
...
@@ -478,6 +478,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report='REPORT'
errata
.
append
(
'Unknown parser "{}" in fail test "{}"!'
.
format
(
parser_name
,
test_name
))
errata
.
append
(
'Unknown parser "{}" in fail test "{}"!'
.
format
(
parser_name
,
test_name
))
tests
.
setdefault
(
'__err__'
,
{})[
test_name
]
=
errata
[
-
1
]
tests
.
setdefault
(
'__err__'
,
{})[
test_name
]
=
errata
[
-
1
]
if
not
(
is_error
(
cst
.
error_flag
)
and
not
lookahead_artifact
(
cst
)):
if
not
(
is_error
(
cst
.
error_flag
)
and
not
lookahead_artifact
(
cst
)):
print
(
test_name
,
cst
.
errors_sorted
)
errata
.
append
(
'Fail test "%s" for parser "%s" yields match instead of '
errata
.
append
(
'Fail test "%s" for parser "%s" yields match instead of '
'expected failure!'
%
(
test_name
,
parser_name
))
'expected failure!'
%
(
test_name
,
parser_name
))
tests
.
setdefault
(
'__err__'
,
{})[
test_name
]
=
errata
[
-
1
]
tests
.
setdefault
(
'__err__'
,
{})[
test_name
]
=
errata
[
-
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