Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
d65ff898
Commit
d65ff898
authored
Jan 21, 2019
by
Eckhart Arnold
Browse files
- better cython support
parent
bc4584d6
Changes
8
Hide whitespace changes
Inline
Side-by-side
DHParser/parse.py
View file @
d65ff898
...
...
@@ -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
):
"""
...
...
DHParser/stringview.py
View file @
d65ff898
...
...
@@ -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)
...
...
DHParser/syntaxtree.py
View file @
d65ff898
...
...
@@ -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.
...
...
DHParser/transform.py
View file @
d65ff898
...
...
@@ -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!"
...
...
dhparser.py
View file @
d65ff898
...
...
@@ -240,7 +240,7 @@ def selftest() -> bool:
print
(
"
\n
STAGE 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
(
...
...
examples/BibTeX/tst_BibTeX_grammar.py
View file @
d65ff898
...
...
@@ -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
...
...
examples/check_examples.py
100644 → 100755
View file @
d65ff898
File mode changed from 100644 to 100755
setup.py
View file @
d65ff898
...
...
@@ -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'
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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