Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
fa071299
Commit
fa071299
authored
Apr 03, 2018
by
di68kap
Browse files
- Autor/Werk wieder getrennt
parent
beb4bedc
Changes
3
Hide whitespace changes
Inline
Side-by-side
DHParser/log.py
View file @
fa071299
...
...
@@ -378,7 +378,7 @@ LOG_SIZE_THRESHOLD = 100000 # maximum number of history records to log
LOG_TAIL_THRESHOLD
=
500
# maximum number of history recors for "tail log"
def
log_parsing_history
(
grammar
,
log_file_name
:
str
=
''
,
html
:
bool
=
Fals
e
)
->
None
:
def
log_parsing_history
(
grammar
,
log_file_name
:
str
=
''
,
html
:
bool
=
Tru
e
)
->
None
:
"""
Writes a log of the parsing history of the most recently parsed document.
...
...
DHParser/testing.py
View file @
fa071299
...
...
@@ -298,13 +298,14 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
cst
=
parser
(
test_code
,
parser_name
)
except
UnknownParserError
as
upe
:
cst
=
Node
(
ZOMBIE_PARSER
,
""
).
add_error
(
str
(
upe
)).
init_pos
(
0
)
log_ST
(
cst
,
"match_%s_%s.cst"
%
(
parser_name
,
test_name
))
clean_test_name
=
test_name
.
replace
(
'*'
,
''
)
log_ST
(
cst
,
"match_%s_%s.cst"
%
(
parser_name
,
clean_test_name
))
tests
.
setdefault
(
'__cst__'
,
{})[
test_name
]
=
cst
if
"ast"
in
tests
or
report
:
ast
=
copy
.
deepcopy
(
cst
)
transform
(
ast
)
tests
.
setdefault
(
'__ast__'
,
{})[
test_name
]
=
ast
log_ST
(
ast
,
"match_%s_%s.ast"
%
(
parser_name
,
test_name
))
log_ST
(
ast
,
"match_%s_%s.ast"
%
(
parser_name
,
clean_
test_name
))
if
is_error
(
cst
.
error_flag
):
errors
=
adjust_error_locations
(
cst
.
collect_errors
(),
test_code
)
errata
.
append
(
'Match test "%s" for parser "%s" failed:
\n\t
Expr.: %s
\n\n\t
%s
\n\n
'
%
...
...
@@ -313,7 +314,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
tests
.
setdefault
(
'__err__'
,
{})[
test_name
]
=
errata
[
-
1
]
# write parsing-history log only in case of failure!
if
is_logging
():
log_parsing_history
(
parser
,
"match_%s_%s.log"
%
(
parser_name
,
test_name
))
log_parsing_history
(
parser
,
"match_%s_%s.log"
%
(
parser_name
,
clean_
test_name
))
elif
"cst"
in
tests
and
mock_syntax_tree
(
tests
[
"cst"
][
test_name
])
!=
cst
:
errata
.
append
(
'Concrete syntax tree test "%s" for parser "%s" failed:
\n
%s'
%
(
test_name
,
parser_name
,
cst
.
as_sxpr
()))
...
...
DHParser/transform.py
View file @
fa071299
...
...
@@ -592,7 +592,7 @@ def flatten(context: List[Node], condition: Callable=is_anonymous, recursive: bo
Applying flatten recursively will result in these kinds of
structural transformation::
(1 (+ 2) (+ 3)
-> (1 + 2 + 3)
(1 (+ 2) (+ 3)
)
-> (1 + 2 + 3)
(1 (+ (2 + (3)))) -> (1 + 2 + 3)
"""
node
=
context
[
-
1
]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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