Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
badw-it
DHParser
Commits
091a584b
Commit
091a584b
authored
Apr 26, 2017
by
Eckhart Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- thrown out test_bed: bad (i.e. unneccesary) idea
parent
7595cd9c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
21 additions
and
12 deletions
+21
-12
DHParser/dsl.py
DHParser/dsl.py
+8
-8
DHParser/parsers.py
DHParser/parsers.py
+3
-0
DHParser/syntaxtree.py
DHParser/syntaxtree.py
+4
-3
OLDSTUFF/DHParser-Testbed/Testbed.ebnf
OLDSTUFF/DHParser-Testbed/Testbed.ebnf
+0
-0
OLDSTUFF/DHParser-Testbed/example.tb
OLDSTUFF/DHParser-Testbed/example.tb
+0
-0
OLDSTUFF/DHParser-Testbed/readme.md
OLDSTUFF/DHParser-Testbed/readme.md
+0
-0
test/test_syntaxtree.py
test/test_syntaxtree.py
+6
-1
No files found.
DHParser/dsl.py
View file @
091a584b
...
...
@@ -124,16 +124,16 @@ if __name__ == "__main__":
'''
def
get_
grammar_instance
(
grammar
):
def
grammar_instance
(
grammar
_representation
):
"""Returns a grammar object and the source code of the grammar, from
the given `grammar`-data which can be either a file name, ebnf-code,
python-code, a GrammarBase-derived grammar class or an instance of
such a class (i.e. a grammar object already).
"""
if
isinstance
(
grammar
,
str
):
if
isinstance
(
grammar
_representation
,
str
):
# read grammar
grammar_src
=
load_if_file
(
grammar
)
if
is_python_code
(
grammar
):
grammar_src
=
load_if_file
(
grammar
_representation
)
if
is_python_code
(
grammar
_representation
):
parser_py
,
errors
,
AST
=
grammar_src
,
''
,
None
else
:
parser_py
,
errors
,
AST
=
full_compilation
(
grammar_src
,
None
,
...
...
@@ -144,11 +144,11 @@ def get_grammar_instance(grammar):
else
:
# assume that dsl_grammar is a ParserHQ-object or Grammar class
grammar_src
=
''
if
isinstance
(
grammar
,
GrammarBase
):
parser_root
=
grammar
if
isinstance
(
grammar
_representation
,
GrammarBase
):
parser_root
=
grammar
_representation
else
:
# assume `grammar` is a grammar class and get the root object
parser_root
=
grammar
()
parser_root
=
grammar
_representation
()
return
parser_root
,
grammar_src
...
...
@@ -162,7 +162,7 @@ def compileDSL(text_or_file, scanner, dsl_grammar, ast_transformation, compiler)
"""
assert
isinstance
(
text_or_file
,
str
)
assert
isinstance
(
compiler
,
CompilerBase
)
parser_root
,
grammar_src
=
get_
grammar_instance
(
dsl_grammar
)
parser_root
,
grammar_src
=
grammar_instance
(
dsl_grammar
)
src
=
load_if_file
(
text_or_file
)
result
,
errors
,
AST
=
full_compilation
(
src
,
scanner
,
parser_root
,
ast_transformation
,
compiler
)
...
...
DHParser/parsers.py
View file @
091a584b
...
...
@@ -332,6 +332,9 @@ class GrammarBase:
Args:
document (str): The source text to be parsed.
start_parser (str): The name of the parser with which to
start. This is useful for testing particular parsers
(i.e. particular parts of the EBNF-Grammar.)
Returns:
Node: The root node ot the parse tree.
"""
...
...
DHParser/syntaxtree.py
View file @
091a584b
...
...
@@ -20,8 +20,6 @@ permissions and limitations under the License.
import
itertools
import
os
from
functools
import
partial
try
:
import
regex
as
re
except
ImportError
:
...
...
@@ -165,9 +163,12 @@ class Node:
return
""
.
join
(
str
(
child
)
for
child
in
self
.
result
)
return
str
(
self
.
result
)
def
__eq__
(
self
,
other
):
return
str
(
self
.
parser
)
==
str
(
other
.
parser
)
and
self
.
result
==
other
.
result
@
property
def
tag_name
(
self
):
return
s
elf
.
parser
.
name
or
self
.
parser
.
__class__
.
__name__
return
s
tr
(
self
.
parser
)
# ONLY FOR DEBUGGING: return self.parser.name + ':' + self.parser.__class__.__name__
@
property
...
...
examples
/DHParser-Testbed/Testbed.ebnf
→
OLDSTUFF
/DHParser-Testbed/Testbed.ebnf
View file @
091a584b
File moved
examples
/DHParser-Testbed/example.tb
→
OLDSTUFF
/DHParser-Testbed/example.tb
View file @
091a584b
File moved
examples
/DHParser-Testbed/readme.md
→
OLDSTUFF
/DHParser-Testbed/readme.md
View file @
091a584b
File moved
test/test_syntaxtree.py
View file @
091a584b
...
...
@@ -85,6 +85,11 @@ class TestNode:
assert
len
(
found
)
==
2
assert
found
[
0
].
result
==
'x'
and
found
[
1
].
result
==
'y'
def
test_equality
(
self
):
assert
self
.
unique_tree
==
self
.
unique_tree
assert
self
.
recurr_tree
!=
self
.
unique_tree
assert
mock_syntax_tree
(
'(a (b c))'
)
!=
mock_syntax_tree
(
'(a (b d))'
)
class
TestErrorHandling
:
def
test_error_flag_propagation
(
self
):
...
...
@@ -101,4 +106,4 @@ class TestErrorHandling:
if
__name__
==
"__main__"
:
from
run
import
runner
runner
(
""
,
globals
())
runner
(
"
TestNode
"
,
globals
())
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