Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
ece3854d
Commit
ece3854d
authored
Jan 31, 2019
by
eckhart
Browse files
Merge branch 'development' of gitlab.lrz.de:badw-it/DHParser into development
parents
e70e5649
93f72763
Changes
6
Hide whitespace changes
Inline
Side-by-side
DHParser/parse.py
View file @
ece3854d
...
...
@@ -334,10 +334,10 @@ class Parser:
# otherwise also cache None-results
self
.
visited
[
location
]
=
(
None
,
rest
)
else
:
assert
node
.
_pos
<
0
or
node
==
EMPTY_NODE
#
assert node._pos < 0 or node == EMPTY_NODE
node
.
_pos
=
location
assert
node
.
_pos
>=
0
or
node
==
EMPTY_NODE
,
\
str
(
"%i < %i"
%
(
grammar
.
document_length__
,
location
))
#
assert node._pos >= 0 or node == EMPTY_NODE, \
#
str("%i < %i" % (grammar.document_length__, location))
if
(
grammar
.
last_rb__loc__
<
location
and
(
grammar
.
memoization__
or
location
in
grammar
.
recursion_locations__
)):
# - variable manipulating parsers will not be entered into the cache,
...
...
@@ -389,13 +389,12 @@ class Parser:
@
property
def
grammar
(
self
)
->
'Grammar'
:
try
:
grammar
=
self
.
_grammar
if
self
.
_grammar
!=
GRAMMAR_PLACEHOLDER
:
return
self
.
_grammar
else
:
raise
AssertionError
(
'Grammar has not yet been set!'
)
except
AttributeError
:
raise
A
ssertion
Error
(
'Parser placeholder does not have a grammar!'
)
except
(
AttributeError
,
NameError
)
:
raise
A
ttribute
Error
(
'Parser placeholder does not have a grammar!'
)
@
grammar
.
setter
def
grammar
(
self
,
grammar
:
'Grammar'
):
...
...
@@ -408,6 +407,8 @@ class Parser:
"to a different Grammar object!"
)
except
AttributeError
:
pass
# ignore setting of grammar attribute for placeholder parser
except
NameError
:
# Cython: No access to GRAMMA_PLACEHOLDER, yet :-(
self
.
_grammar
=
grammar
# def _grammar_assigned_notifier(self):
# """A function that notifies the parser object that it has been
...
...
DHParser/syntaxtree.py
View file @
ece3854d
...
...
@@ -190,7 +190,8 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
duplicate
.
_pos
=
self
.
_pos
duplicate
.
_len
=
self
.
_len
if
self
.
attr_active
():
duplicate
.
_xml_attr
=
copy
.
deepcopy
(
self
.
_xml_attr
)
duplicate
.
attr
.
update
(
copy
.
deepcopy
(
self
.
_xml_attr
))
# duplicate._xml_attr = copy.deepcopy(self._xml_attr) # this is not cython compatible
return
duplicate
def
__str__
(
self
):
...
...
@@ -748,7 +749,8 @@ class RootNode(Node):
duplicate
.
_pos
=
self
.
_pos
duplicate
.
_len
=
self
.
_len
if
self
.
attr_active
():
duplicate
.
_xml_attr
=
copy
.
deepcopy
(
self
.
_xml_attr
)
duplicate
.
attr
.
update
(
copy
.
deepcopy
(
self
.
_xml_attr
))
# duplicate._xml_attr = copy.deepcopy(self._xml_attr) # this is blocked by cython
duplicate
.
all_errors
=
copy
.
deepcopy
(
self
.
all_errors
)
duplicate
.
error_flag
=
self
.
error_flag
duplicate
.
inline_tags
=
self
.
inline_tags
...
...
DHParser/testing.py
View file @
ece3854d
...
...
@@ -515,6 +515,7 @@ def grammar_suite(directory, parser_factory, transformer_factory,
if
any
(
fnmatch
.
fnmatch
(
filename
,
pattern
)
for
pattern
in
fn_patterns
):
parameters
=
filename
,
parser_factory
,
transformer_factory
,
report
,
verbose
errata_futures
.
append
((
filename
,
pool
.
submit
(
grammar_unit
,
*
parameters
)))
# grammar_unit(*parameters)
for
filename
,
err_future
in
errata_futures
:
try
:
errata
=
err_future
.
result
()
...
...
examples/BibTeX/tst_BibTeX_grammar.py
View file @
ece3854d
...
...
@@ -23,27 +23,27 @@ import sys
sys
.
path
.
extend
([
'../../'
,
'../'
])
import
DHParser.log
import
DHParser.dsl
from
DHParser
import
testing
from
DHParser
import
toolkit
if
not
DHParser
.
dsl
.
recompile_grammar
(
'BibTeX.ebnf'
,
force
=
False
):
# recompiles Grammar only if it has changed
print
(
'
\n
Errors while recompiling "BibTeX.ebnf":
\n
--------------------------------------
\n\n
'
)
with
open
(
'BibTeX_ebnf_ERRORS.txt'
)
as
f
:
print
(
f
.
read
())
sys
.
exit
(
1
)
sys
.
path
.
append
(
'./'
)
# must be appended after module creation, because otherwise an ImportError is raised under Windows
from
BibTeXCompiler
import
get_grammar
,
get_transformer
with
DHParser
.
log
.
logging
(
True
):
error_report
=
testing
.
grammar_suite
(
'grammar_tests'
,
get_grammar
,
get_transformer
,
report
=
True
,
verbose
=
True
)
if
error_report
:
print
(
'
\n
'
)
print
(
error_report
)
sys
.
exit
(
1
)
else
:
print
(
'
\n
SUCCESS! All tests passed :-)'
)
if
__name__
==
"__main__"
:
if
not
DHParser
.
dsl
.
recompile_grammar
(
'BibTeX.ebnf'
,
force
=
False
):
# recompiles Grammar only if it has changed
print
(
'
\n
Errors while recompiling "BibTeX.ebnf":
\n
--------------------------------------
\n\n
'
)
with
open
(
'BibTeX_ebnf_ERRORS.txt'
)
as
f
:
print
(
f
.
read
())
sys
.
exit
(
1
)
sys
.
path
.
append
(
'./'
)
# must be appended after module creation, because otherwise an ImportError is raised under Windows
from
BibTeXCompiler
import
get_grammar
,
get_transformer
with
DHParser
.
log
.
logging
(
True
):
error_report
=
testing
.
grammar_suite
(
'grammar_tests'
,
get_grammar
,
get_transformer
,
report
=
True
,
verbose
=
True
)
if
error_report
:
print
(
'
\n
'
)
print
(
error_report
)
sys
.
exit
(
1
)
else
:
print
(
'
\n
SUCCESS! All tests passed :-)'
)
setup.py
View file @
ece3854d
...
...
@@ -26,7 +26,7 @@ setup(
'DHParser/compile.py'
,
'DHParser/ebnf.py'
,
],
nthreads
=
4
,
annotate
=
False
),
nthreads
=
0
,
annotate
=
False
),
url
=
'https://gitlab.lrz.de/badw-it/DHParser'
,
license
=
'[Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0)'
,
author
=
'Eckhart Arnold'
,
...
...
test/run.py
View file @
ece3854d
...
...
@@ -41,7 +41,7 @@ if __name__ == "__main__":
interpreters
=
[
'python.exe '
]
cwd
=
os
.
getcwd
()
os
.
chdir
(
scriptdir
+
'
/
..'
)
os
.
chdir
(
os
.
path
.
join
(
scriptdir
,
'..'
)
)
timestamp
=
time
.
time
()
...
...
@@ -65,9 +65,10 @@ if __name__ == "__main__":
# command = interpreter + os.path.join('test', filename)
# results.append(pool.submit(run_unittests, command))
os
.
system
(
' '
.
join
([
interpreter
,
'-c'
,
"""'import sys;"""
"""sys.path.extend(["DHParser"]);"""
"""import testing; testing.run_path("%s")'"""
%
scriptdir
,
'''"import sys; '''
'''sys.path.extend(['DHParser']);'''
'''import testing; testing.run_path('%s')"'''
%
scriptdir
.
replace
(
'
\\
'
,
'
\\\\
'
),
os
.
path
.
join
(
os
.
getcwd
(),
'test'
)]))
concurrent
.
futures
.
wait
(
results
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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