Commit 93a3868b authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

bugfixes

parent 19cfca77
......@@ -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))
......
......@@ -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 > len(err.orig_doc):
err.length = len(err.orig_doc) - err.orig_pos # err.length should not exceed text length
if err.orig_pos + err.length > lbreaks[-1]:
err.length = lbreaks[-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)
......
......@@ -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)
......
......@@ -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"
......
......@@ -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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment