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
7a65086b
Commit
7a65086b
authored
Jan 09, 2018
by
eckhart
Browse files
- bug fix: parse.History.excerpt: str not representation of StringView objects needed
parent
4160b2ae
Changes
2
Show whitespace changes
Inline
Side-by-side
DHParser/parse.py
View file @
7a65086b
...
@@ -232,7 +232,7 @@ class HistoryRecord:
...
@@ -232,7 +232,7 @@ class HistoryRecord:
@
property
@
property
def
excerpt
(
self
):
def
excerpt
(
self
):
length
=
len
(
self
.
node
)
if
self
.
node
else
len
(
self
.
text
)
length
=
len
(
self
.
node
)
if
self
.
node
else
len
(
self
.
text
)
excerpt
=
str
(
self
.
node
)[:
min
(
length
,
20
)]
if
self
.
node
else
self
.
text
[:
20
]
excerpt
=
str
(
self
.
node
)[:
min
(
length
,
20
)]
if
self
.
node
else
str
(
self
.
text
[:
20
]
)
excerpt
=
escape_control_characters
(
excerpt
)
excerpt
=
escape_control_characters
(
excerpt
)
if
length
>
20
:
if
length
>
20
:
excerpt
+=
'...'
excerpt
+=
'...'
...
@@ -301,6 +301,7 @@ def add_parser_guard(parser_func):
...
@@ -301,6 +301,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 meomized results
return
parser
.
visited
[
location
]
return
parser
.
visited
[
location
]
if
grammar
.
history_tracking__
:
if
grammar
.
history_tracking__
:
...
@@ -343,6 +344,7 @@ def add_parser_guard(parser_func):
...
@@ -343,6 +344,7 @@ def add_parser_guard(parser_func):
# matches will store its result in the cache
# matches will store its result in the cache
parser
.
visited
[
location
]
=
(
node
,
rest
)
parser
.
visited
[
location
]
=
(
node
,
rest
)
# Mind that meomized parser calls will not appear in the history record!
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
)
...
...
test/test_parse.py
View file @
7a65086b
...
@@ -84,6 +84,9 @@ class TestInfiLoopsAndRecursion:
...
@@ -84,6 +84,9 @@ class TestInfiLoopsAndRecursion:
syntax_tree
=
parser
(
snippet
)
syntax_tree
=
parser
(
snippet
)
assert
not
syntax_tree
.
error_flag
,
syntax_tree
.
collect_errors
()
assert
not
syntax_tree
.
error_flag
,
syntax_tree
.
collect_errors
()
assert
snippet
==
str
(
syntax_tree
)
assert
snippet
==
str
(
syntax_tree
)
if
is_logging
():
syntax_tree
.
log
(
"test_LeftRecursion_indirect.cst"
)
parser
.
log_parsing_history__
(
"test_LeftRecursion_indirect"
)
def
test_inifinite_loops
(
self
):
def
test_inifinite_loops
(
self
):
minilang
=
"""not_forever = { // }
\n
"""
minilang
=
"""not_forever = { // }
\n
"""
...
...
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