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
5290fee7
Commit
5290fee7
authored
May 23, 2021
by
Eckhart Arnold
Browse files
small refactorings
parent
93a3868b
Changes
5
Hide whitespace changes
Inline
Side-by-side
DHParser/error.py
View file @
5290fee7
...
...
@@ -62,7 +62,7 @@ __all__ = ('ErrorCode',
'is_warning'
,
'has_errors'
,
'only_errors'
,
'ad
just_error
_locations'
,
'ad
d_source
_locations'
,
'canonical_error_strings'
,
'NO_ERROR'
,
'NOTICE'
,
...
...
@@ -377,7 +377,7 @@ def only_errors(messages: Iterable[Error], level: int = ERROR) -> Iterator[Error
#######################################################################
def
ad
just_error
_locations
(
errors
:
List
[
Error
],
source_mapping
:
SourceMapFunc
):
def
ad
d_source
_locations
(
errors
:
List
[
Error
],
source_mapping
:
SourceMapFunc
):
"""Adds (or adjusts) line and column numbers of error messages inplace.
Args:
...
...
DHParser/syntaxtree.py
View file @
5290fee7
...
...
@@ -591,7 +591,7 @@ from typing import Callable, cast, Iterator, Sequence, List, Set, Union, \
from
DHParser.configuration
import
get_config_value
,
ALLOWED_PRESET_VALUES
from
DHParser.error
import
Error
,
ErrorCode
,
ERROR
,
PARSER_STOPPED_BEFORE_END
,
\
ad
just_error
_locations
ad
d_source
_locations
from
DHParser.preprocess
import
SourceMapFunc
,
SourceLocation
,
gen_neutral_srcmap_func
from
DHParser.stringview
import
StringView
# , real_indices
from
DHParser.toolkit
import
re
,
cython
,
linebreaks
,
line_col
,
JSONnull
,
\
...
...
@@ -2794,7 +2794,7 @@ class RootNode(Node):
if
id
(
node
)
in
self
.
error_nodes
:
self
.
error_nodes
[
id
(
self
)]
=
self
.
error_nodes
[
id
(
node
)]
if
self
.
source
:
ad
just_error
_locations
(
self
.
errors
,
self
.
source_mapping
)
ad
d_source
_locations
(
self
.
errors
,
self
.
source_mapping
)
return
self
def
add_error
(
self
,
node
:
Optional
[
Node
],
error
:
Error
)
->
'RootNode'
:
...
...
@@ -2832,7 +2832,7 @@ class RootNode(Node):
if
node
.
pos
==
error
.
pos
:
self
.
error_positions
.
setdefault
(
error
.
pos
,
set
()).
add
(
id
(
node
))
if
self
.
source
:
ad
just_error
_locations
([
error
],
self
.
source_mapping
)
ad
d_source
_locations
([
error
],
self
.
source_mapping
)
self
.
errors
.
append
(
error
)
self
.
error_flag
=
max
(
self
.
error_flag
,
error
.
code
)
return
self
...
...
DHParser/testing.py
View file @
5290fee7
...
...
@@ -40,7 +40,7 @@ import time
from
typing
import
Dict
,
List
,
Union
,
Deque
,
cast
from
DHParser.configuration
import
get_config_value
from
DHParser.error
import
Error
,
is_error
,
ad
just_error
_locations
,
PARSER_LOOKAHEAD_MATCH_ONLY
,
\
from
DHParser.error
import
Error
,
is_error
,
ad
d_source
_locations
,
PARSER_LOOKAHEAD_MATCH_ONLY
,
\
PARSER_LOOKAHEAD_FAILURE_ONLY
,
MANDATORY_CONTINUATION_AT_EOF
,
AUTORETRIEVED_SYMBOL_NOT_CLEARED
from
DHParser.log
import
is_logging
,
clear_logs
,
local_log_dir
,
log_parsing_history
from
DHParser.parse
import
Lookahead
...
...
@@ -440,7 +440,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report='REPORT'
errors
=
[]
# type: List[Error]
if
is_error
(
cst
.
error_flag
)
and
not
lookahead_artifact
(
cst
):
errors
=
[
e
for
e
in
cst
.
errors_sorted
if
e
.
code
not
in
POSSIBLE_ARTIFACTS
]
ad
just_error
_locations
(
errors
,
source_mapper
)
ad
d_source
_locations
(
errors
,
source_mapper
)
errata
.
append
(
'Match test "%s" for parser "%s" failed:'
'
\n
Expr.: %s
\n\n
%s
\n\n
'
%
(
test_name
,
parser_name
,
md_codeblock
(
test_code
),
...
...
@@ -459,7 +459,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report='REPORT'
ast_errors
=
[
e
for
e
in
ast
.
errors
if
e
not
in
old_errors
]
ast_errors
.
sort
(
key
=
lambda
e
:
e
.
pos
)
if
is_error
(
max
(
e
.
code
for
e
in
ast_errors
)
if
ast_errors
else
0
):
ad
just_error
_locations
(
ast_errors
,
source_mapper
)
ad
d_source
_locations
(
ast_errors
,
source_mapper
)
if
ast_errors
:
if
errata
:
errata
[
-
1
]
=
errata
[
-
1
].
rstrip
(
'
\n
'
)
ast_errors
.
append
(
'
\n
'
)
...
...
@@ -541,7 +541,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report='REPORT'
with
local_log_dir
(
'./LOGS'
):
log_parsing_history
(
parser
,
"fail_%s_%s.log"
%
(
parser_name
,
test_name
))
if
cst
.
error_flag
:
ad
just_error
_locations
(
cst
.
errors
,
source_mapper
)
ad
d_source
_locations
(
cst
.
errors
,
source_mapper
)
tests
.
setdefault
(
'__msg__'
,
{})[
test_name
]
=
\
"
\n
"
.
join
(
str
(
e
)
for
e
in
cst
.
errors_sorted
)
if
verbose
:
...
...
tests/test_error.py
View file @
5290fee7
...
...
@@ -31,7 +31,7 @@ try:
except
ImportError
:
import
re
from
DHParser.error
import
Error
,
ERROR
,
ad
just_error
_locations
from
DHParser.error
import
Error
,
ERROR
,
ad
d_source
_locations
from
DHParser.preprocess
import
gen_neutral_srcmap_func
from
DHParser.toolkit
import
linebreaks
,
line_col
...
...
@@ -76,11 +76,11 @@ class TestErrorSupport:
def
test_boundary_cases
(
self
):
err
=
Error
(
'Error-Test'
,
1
,
ERROR
)
source_mapping
=
gen_neutral_srcmap_func
(
' '
)
ad
just_error
_locations
([
err
],
source_mapping
)
ad
d_source
_locations
([
err
],
source_mapping
)
err
=
Error
(
'Error-Test'
,
2
,
ERROR
)
try
:
ad
just_error
_locations
([
err
],
source_mapping
)
ad
d_source
_locations
([
err
],
source_mapping
)
assert
False
,
"Error-location outside text. ValueError was expected but not raised"
except
ValueError
:
pass
...
...
tests/test_parse.py
View file @
5290fee7
...
...
@@ -31,7 +31,7 @@ sys.path.append(os.path.abspath(os.path.join(scriptpath, '..')))
from
DHParser.configuration
import
get_config_value
,
set_config_value
from
DHParser.toolkit
import
compile_python_object
,
re
from
DHParser.log
import
is_logging
,
log_ST
,
log_parsing_history
,
start_logging
from
DHParser.error
import
Error
,
is_error
,
ad
just_error
_locations
,
MANDATORY_CONTINUATION
,
\
from
DHParser.error
import
Error
,
is_error
,
ad
d_source
_locations
,
MANDATORY_CONTINUATION
,
\
MALFORMED_ERROR_STRING
,
MANDATORY_CONTINUATION_AT_EOF
,
RESUME_NOTICE
,
PARSER_STOPPED_BEFORE_END
,
\
PARSER_NEVER_TOUCHES_DOCUMENT
,
CAPTURE_DROPPED_CONTENT_WARNING
from
DHParser.parse
import
ParserError
,
Parser
,
Grammar
,
Forward
,
TKN
,
ZeroOrMore
,
RE
,
\
...
...
@@ -1375,7 +1375,7 @@ def next_valid_letter(text, start, end):
gr
=
copy
.
deepcopy
(
get_ebnf_grammar
())
resume_notices_on
(
gr
)
cst
=
gr
(
EBNF_with_Errors
)
ad
just_error
_locations
(
cst
.
errors
,
gen_neutral_srcmap_func
(
EBNF_with_Errors
))
ad
d_source
_locations
(
cst
.
errors
,
gen_neutral_srcmap_func
(
EBNF_with_Errors
))
locations
=
[]
for
error
in
cst
.
errors_sorted
:
locations
.
append
((
error
.
line
,
error
.
column
))
...
...
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