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
93a3868b
Commit
93a3868b
authored
May 23, 2021
by
Eckhart Arnold
Browse files
bugfixes
parent
19cfca77
Changes
5
Hide whitespace changes
Inline
Side-by-side
DHParser/compile.py
View file @
93a3868b
...
...
@@ -46,6 +46,7 @@ from DHParser.preprocess import with_source_mapping, PreprocessorFunc, SourceMap
from
DHParser.syntaxtree
import
Node
,
RootNode
,
EMPTY_PTYPE
,
TreeContext
from
DHParser.transform
import
TransformationFunc
from
DHParser.parse
import
Grammar
from
DHParser.preprocess
import
gen_neutral_srcmap_func
from
DHParser.error
import
is_error
,
is_fatal
,
Error
,
\
TREE_PROCESSING_CRASH
,
COMPILER_CRASH
,
AST_TRANSFORM_CRASH
from
DHParser.log
import
log_parsing_history
,
log_ST
,
is_logging
...
...
@@ -357,7 +358,8 @@ def compile_source(source: str,
if
preprocessor
is
None
:
source_text
=
original_text
# type: str
source_mapping
=
lambda
i
:
SourceLocation
(
source_name
,
0
,
i
)
# type: SourceMapFunc
source_mapping
=
gen_neutral_srcmap_func
(
source_text
,
source_name
)
# lambda i: SourceLocation(source_name, 0, i) # type: SourceMapFunc
else
:
source_text
,
source_mapping
=
with_source_mapping
(
preprocessor
(
original_text
,
source_name
))
...
...
DHParser/error.py
View file @
93a3868b
...
...
@@ -392,8 +392,8 @@ def adjust_error_locations(errors: List[Error], source_mapping: SourceMapFunc):
assert
err
.
pos
>=
0
err
.
orig_doc
,
lbreaks
,
err
.
orig_pos
=
source_mapping
(
err
.
pos
)
err
.
line
,
err
.
column
=
line_col
(
lbreaks
,
err
.
orig_pos
)
if
err
.
orig_pos
+
err
.
length
>
l
en
(
err
.
orig_doc
)
:
err
.
length
=
l
en
(
err
.
orig_doc
)
-
err
.
orig_pos
# err.length should not exceed text length
if
err
.
orig_pos
+
err
.
length
>
l
breaks
[
-
1
]
:
err
.
length
=
l
breaks
[
-
1
]
-
err
.
orig_pos
# err.length should not exceed text length
err
.
end_line
,
err
.
end_column
=
line_col
(
lbreaks
,
err
.
orig_pos
+
err
.
length
)
...
...
DHParser/testing.py
View file @
93a3868b
...
...
@@ -519,6 +519,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report='REPORT'
# run fail tests
for
test_name
,
test_code
in
tests
.
get
(
'fail'
,
dict
()).
items
():
source_mapper
=
gen_neutral_srcmap_func
(
test_code
)
errflag
=
len
(
errata
)
try
:
cst
=
parser
(
test_code
,
parser_name
)
...
...
tests/test_error.py
View file @
93a3868b
...
...
@@ -74,11 +74,11 @@ class TestErrorSupport:
self
.
mini_suite
(
s
,
linebreaks
(
s
),
1
)
def
test_boundary_cases
(
self
):
err
=
Error
(
'Error-Test'
,
0
,
ERROR
)
err
=
Error
(
'Error-Test'
,
1
,
ERROR
)
source_mapping
=
gen_neutral_srcmap_func
(
' '
)
adjust_error_locations
([
err
],
source_mapping
)
err
=
Error
(
'Error-Test'
,
1
,
ERROR
)
err
=
Error
(
'Error-Test'
,
2
,
ERROR
)
try
:
adjust_error_locations
([
err
],
source_mapping
)
assert
False
,
"Error-location outside text. ValueError was expected but not raised"
...
...
tests/test_preprocess.py
View file @
93a3868b
...
...
@@ -130,7 +130,8 @@ def preprocess_comments(src: str, src_name: str) -> Tuple[str, SourceMapFunc]:
positions
.
append
(
pos
)
offsets
.
append
(
offsets
[
-
1
])
return
'
\n
'
.
join
(
lines
),
\
partial
(
source_map
,
srcmap
=
SourceMap
(
'DUMMY'
,
positions
,
offsets
,
[
'DUMMY'
]
*
len
(
positions
),
{
'DUMMY'
:
[]}))
partial
(
source_map
,
srcmap
=
SourceMap
(
src_name
,
positions
,
offsets
,
[
src_name
]
*
len
(
positions
),
{
src_name
:
[
-
1
,
len
(
src
)]}))
class
TestTokenParsing
:
...
...
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