Commit 08ea3533 authored by di68kap's avatar di68kap
Browse files

- DHParser/ ParserError bugfix

parent 4bff4c28
......@@ -307,7 +307,7 @@ class Parser:
# apply reentry-rule or catch error at root-parser
if i < 0:
i = 1
nd = Node(ZOMBIE_TAG, rest[:i])
nd = Node(ZOMBIE_TAG, rest[:i]).with_pos(location)
rest = rest[i:]
assert error.node.children or (not error.node.result)
if error.first_throw:
......@@ -316,15 +316,19 @@ class Parser:
# TODO: ggf. Fehlermeldung, die sagt, wo es weitergeht anfügen
# dürfte allerdings erst an den nächsten(!) Knoten angehängt werden (wie?)
node = Node(self.tag_name, (Node(ZOMBIE_TAG, text[:gap]), error.node, nd))
node = Node(self.tag_name,
(Node(ZOMBIE_TAG, text[:gap]).with_pos(location),
error.node, nd))
elif error.first_throw:
raise ParserError(error.node,, first_throw=False)
result = (Node(ZOMBIE_TAG, text[:gap]), error.node) if gap else error.node # type: ResultType
result = (Node(ZOMBIE_TAG, text[:gap]).with_pos(location), error.node) if gap \
else error.node # type: ResultType
if grammar.tree__.errors[-1].code == Error.MANDATORY_CONTINUATION_AT_EOF: # EXPERIMENTAL!!
node = error.node
raise ParserError(Node(self.tag_name, result), text, first_throw=False)
raise ParserError(Node(self.tag_name, result).with_pos(location),
text, first_throw=False)
if grammar.left_recursion_handling__:
......@@ -27,15 +27,21 @@ sys.path.extend(['../', './'])
from DHParser.toolkit import compile_python_object, get_config_value, set_config_value
from DHParser.log import logging, is_logging, log_ST, log_parsing_history
from DHParser.error import Error, is_error
from DHParser.parse import Parser, Grammar, Forward, TKN, ZeroOrMore, RE, \
from DHParser.parse import ParserError, Parser, Grammar, Forward, TKN, ZeroOrMore, RE, \
RegExp, Lookbehind, NegativeLookahead, OneOrMore, Series, Alternative, AllOf, SomeOf, \
UnknownParserError, MetaParser, GrammarError, EMPTY_NODE
from DHParser import compile_source
from DHParser.ebnf import get_ebnf_grammar, get_ebnf_transformer, get_ebnf_compiler, DHPARSER_IMPORTS
from DHParser.dsl import grammar_provider, CompilationError
from DHParser.syntaxtree import Node
from DHParser.stringview import StringView
class TestParserError:
def test_parser_error_str(self):
pe = ParserError(Node('TAG', 'test').with_pos(0), StringView('Beispiel'), True)
assert str(pe).find('Beispiel') >= 0 and str(pe).find('TAG') >= 0
class TestParserClass:
def test_apply(self):
minilang ="""
Supports Markdown
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