In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

Commit d65ff898 authored by Eckhart Arnold's avatar Eckhart Arnold

- better cython support

parent bc4584d6
......@@ -143,6 +143,8 @@ def reentry_point(rest: StringView, rules: ResumeList) -> int:
# return Node(None, rest[:i]), rest[i:]
# TODO: Refactor guarded_call into an ordinary method of Parser. That should
# make things much simpler and potentially more efficient (no extra closure needed)
def add_parser_guard(parser_func):
"""
Add a wrapper function to a parser functions (i.e. Parser.__call__ method)
......@@ -2093,7 +2095,7 @@ class Forward(Parser):
@property
def repr(self) -> str:
"""Returns the parser's name if it has a name or repr(self) if not."""
return self.parser.name if self.parser.name else repr(self)
return self.parser.name if self.parser.name else self.__repr__()
def set(self, parser: Parser):
"""
......
......@@ -112,10 +112,11 @@ class StringView: # collections.abc.Sized
self._text = text # type: str
self._begin, self._end = real_indices(begin, end, len(text))
self._len = max(self._end - self._begin, 0) # type: int
if (self._begin == 0 and self._len == len(self._text)):
self._fullstring = self._text # type: str
else:
self._fullstring = ''
self._fullstring = '' # type: str
# if (self._begin == 0 and self._len == len(self._text)):
# self._fullstring = self._text # type: str
# else:
# self._fullstring = ''
def __bool__(self) -> bool:
return self._end > self._begin # and bool(self.text)
......
......@@ -85,7 +85,7 @@ class ParserBase:
@property
def repr(self) -> str:
"""Returns the parser's name if it has a name and repr()"""
return self.name if self.name else repr(self)
return self.name if self.name else self.__repr__()
def reset(self):
"""Resets any parser variables. (Should be overridden.)"""
......@@ -207,7 +207,7 @@ def flatten_xml(xml: str) -> str:
RX_AMP = re.compile(r'&(?!\w+;)')
class Node(collections.abc.Sized):
class Node: # (collections.abc.Sized): Base class omitted for cython-compatibility
"""
Represents a node in the concrete or abstract syntax tree.
......
......@@ -165,8 +165,8 @@ def transformation_factory(t1=None, t2=None, t3=None, t4=None, t5=None):
# raise TypeError("Generic Type %s not permitted\n in transformation_factory "
# "decorator. Use the equivalent non-generic type instead!"
# % str(t))
if isinstance(t, str): # ensure compatibility with python versions
t = eval(t) # with alternative type handling.
if isinstance(t, str): # ensure compatibility with python versions
t = eval(t.replace('unicode', 'str')) # with alternative type handling.
if isgenerictype(t):
raise TypeError("Generic Type %s not permitted\n in transformation_factory "
"decorator. Use the equivalent non-generic type instead!"
......
......@@ -240,7 +240,7 @@ def selftest() -> bool:
print("\nSTAGE I: Trying to compile EBNF-Grammar:\n")
builtin_ebnf_parser = get_ebnf_grammar()
docstring = str(builtin_ebnf_parser.__doc__) # type: str
ebnf_src = docstring[docstring.find('#'):]
ebnf_src = docstring[docstring.find('@'):]
ebnf_transformer = get_ebnf_transformer()
ebnf_compiler = get_ebnf_compiler('EBNF')
result, errors, _ = compile_source(
......
......@@ -21,10 +21,9 @@ limitations under the License.
import sys
import DHParser.log
sys.path.extend(['../../', '../'])
import DHParser.log
import DHParser.dsl
from DHParser import testing
from DHParser import toolkit
......
File mode changed from 100644 to 100755
......@@ -15,7 +15,8 @@ setup(
name='DHParser',
version=__version__,
packages=['DHParser'],
ext_modules=cythonize('DHParser/stringview.py'),
ext_modules=cythonize(['DHParser/stringview.py', 'DHParser/syntaxtree.py',
'DHParser/parse.py', 'DHParser/transform.py']),
url='https://gitlab.lrz.de/badw-it/DHParser',
license='[Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0)',
author='Eckhart Arnold',
......
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