Commit de019592 authored by eckhart's avatar eckhart

Merge branch 'development' of gitlab.lrz.de:badw-it/DHParser into development

parents 022e8763 a6830768
......@@ -301,6 +301,8 @@ class Parser:
node = error.node
node.result += (nd,)
else:
# 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(None, text[:gap]), error.node, nd))
elif error.first_throw:
raise ParserError(error.node, error.rest, first_throw=False)
......
......@@ -354,11 +354,11 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
self._content = str(self._result)
self._result = self._content # self._result might be more efficient as a string!?
return self._content
@content.setter
def content(self, content: str):
self.result = content
#
#
# @content.setter
# def content(self, content: str):
# self.result = content
@property
......
......@@ -318,33 +318,35 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
parser = parser_factory()
transform = transformer_factory()
is_lookahead = set() # type: Dict[str] # Dictionary of parser names
with_lookahead = set() # type: Set[Parser]
visited = set() # type: Set[Parser]
is_lookahead = set() # type: Set[str] # Dictionary of parser names
with_lookahead = set() # type: Set[Optional[Parser]]
lookahead_flag = False # type: bool
def find_lookahead(p: Parser):
"""Raises a StopIterationError if parser `p` is or contains
a Lookahead-parser."""
nonlocal is_lookahead, with_lookahead, visited
if p in visited:
raise StopIteration
visited.add(p)
if isinstance(p, Lookahead):
is_lookahead.add(p.tag_name)
with_lookahead.add(p)
nonlocal is_lookahead, with_lookahead, lookahead_flag
if p in with_lookahead:
lookahead_flag = True
else:
if isinstance(p, Lookahead):
is_lookahead.add(p.tag_name)
with_lookahead.add(p)
lookahead_flag = True
else:
if any(child for child in (getattr(p, 'parsers', [])
or [getattr(p, 'parser', None)]) if child in with_lookahead):
with_lookahead.add(p)
def has_lookahead(parser_name: str):
"""Returns `True`, if given parser is or contains a Lookahead-parser."""
nonlocal is_lookahead, with_lookahead, visited, parser
nonlocal is_lookahead, with_lookahead, lookahead_flag, parser
p = parser[parser_name]
num_lookaheads = len(is_lookahead)
if p in with_lookahead:
return True
try:
p.apply(find_lookahead)
except StopIteration:
pass
if len(is_lookahead) > num_lookaheads:
lookahead_flag = False
p.apply(find_lookahead)
if lookahead_flag:
with_lookahead.add(p)
return True
return False
......
......@@ -22,9 +22,9 @@ several of the the other DHParser-Modules or that are just very generic
so that they are best defined in a toolkit-module.
"""
# import codecs
import codecs
import hashlib
# import io
import io
import multiprocessing
import parser
import threading
......@@ -41,7 +41,7 @@ except ImportError:
import DHParser.foreign_typing as typing
sys.modules['typing'] = typing # make it possible to import from typing
from typing import Any, Iterable, Sequence, Set, Union, Dict, Hashable # , cast
from typing import Any, Iterable, Sequence, Set, Union, Dict, Hashable, cast
try:
import cython
......@@ -449,12 +449,13 @@ def sane_parser_name(name) -> bool:
#######################################################################
# try:
# if sys.stdout.encoding.upper() != "UTF-8":
# # make sure that `print()` does not raise an error on
# # non-ASCII characters:
# sys.stdout = cast(io.TextIOWrapper, codecs.getwriter("utf-8")(cast(
# io.BytesIO, cast(io.TextIOWrapper, sys.stdout).detach())))
# except AttributeError:
# # somebody has already taken care of this !?
# pass
try:
if sys.stdout.encoding.upper() != "UTF-8": # and platform.system() == "Windows":
# make sure that `print()` does not raise an error on
# non-ASCII characters:
# sys.stdout = cast(io.TextIOWrapper, codecs.getwriter("utf-8")(cast(
# io.BytesIO, cast(io.TextIOWrapper, sys.stdout).detach())))
sys.stdout = io.TextIOWrapper(sys.stdout.detach(), sys.stdout.encoding, 'replace')
except AttributeError:
# somebody has already taken care of this !?
pass
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