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
db0a8568
Commit
db0a8568
authored
Jul 01, 2017
by
Eckhart Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfixes
parent
0e90dfe0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
8 deletions
+14
-8
DHParser/dsl.py
DHParser/dsl.py
+3
-3
DHParser/ebnf.py
DHParser/ebnf.py
+2
-1
DHParser/parsers.py
DHParser/parsers.py
+3
-1
DHParser/syntaxtree.py
DHParser/syntaxtree.py
+4
-2
examples/LaTeX/grammar_tests/test_paragraph.ini
examples/LaTeX/grammar_tests/test_paragraph.ini
+2
-1
No files found.
DHParser/dsl.py
View file @
db0a8568
...
...
@@ -82,8 +82,9 @@ from DHParser.parsers import Grammar, Compiler, nil_scanner, \\
last_value, counterpart, accumulate, ScannerFunc
from DHParser.syntaxtree import Node, traverse, remove_enclosing_delimiters,
\\
remove_children_if, reduce_single_child, replace_by_single_child, remove_whitespace,
\\
no_transformation, remove_expendables, remove_tokens, flatten, is_whitespace, is_expendable,
\\
collapse, map_content, WHITESPACE_PTYPE, TOKEN_PTYPE, TransformationFunc
no_transformation, remove_expendables, remove_empty, remove_tokens, flatten, is_whitespace,
\\
is_empty, is_expendable, collapse, map_content, WHITESPACE_PTYPE, TOKEN_PTYPE,
\\
TransformationFunc
'''
...
...
@@ -257,7 +258,6 @@ def parser_factory(ebnf_src: str, branding="DSL") -> Grammar:
"""
grammar_src
=
compileDSL
(
ebnf_src
,
nil_scanner
,
get_ebnf_grammar
(),
get_ebnf_transformer
(),
get_ebnf_compiler
(
branding
))
print
(
grammar_src
)
return
compile_python_object
(
DHPARSER_IMPORTS
+
grammar_src
,
'get_(?:\w+_)?grammar$'
)
...
...
DHParser/ebnf.py
View file @
db0a8568
...
...
@@ -356,9 +356,10 @@ class EBNFCompiler(Compiler):
transtable
=
[
tt_name
+
' = {'
,
' # AST Transformations for the '
+
self
.
grammar_name
+
'-grammar'
]
transtable
.
append
(
' "+": remove_empty,'
)
for
name
in
self
.
rules
:
transtable
.
append
(
' "'
+
name
+
'": no_transformation,'
)
transtable
+=
[
' "*":
no_transformation
'
,
'}'
,
''
,
tf_name
+
transtable
+=
[
' "*":
replace_by_single_child
'
,
'}'
,
''
,
tf_name
+
' = partial(traverse, processing_table=%s)'
%
tt_name
,
''
]
transtable
+=
[
TRANSFORMER_FACTORY
.
format
(
NAME
=
self
.
grammar_name
)]
return
'
\n
'
.
join
(
transtable
)
...
...
DHParser/parsers.py
View file @
db0a8568
...
...
@@ -390,7 +390,9 @@ class Grammar:
particular instance of Grammar.
"""
if
parser
.
name
:
assert
parser
.
name
not
in
self
.
__dict__
,
\
# prevent overwriting instance variables or parsers of a different class
assert
parser
.
name
not
in
self
.
__dict__
or
\
isinstance
(
self
.
__dict__
[
parser
.
name
],
parser
.
__class__
),
\
(
'Cannot add parser "%s" because a field with the same name '
'already exists in grammar object!'
%
parser
.
name
)
setattr
(
self
,
parser
.
name
,
parser
)
...
...
DHParser/syntaxtree.py
View file @
db0a8568
...
...
@@ -58,6 +58,7 @@ __all__ = ['WHITESPACE_PTYPE',
'is_token'
,
'remove_children_if'
,
'remove_whitespace'
,
'remove_empty'
,
'remove_expendables'
,
'remove_tokens'
,
'flatten'
,
...
...
@@ -755,8 +756,8 @@ def remove_children_if(node, condition):
remove_whitespace
=
remove_children_if
(
is_whitespace
)
# partial(remove_children_if, condition=is_whitespace)
remove_empty
=
remove_children_if
(
is_empty
)
remove_expendables
=
remove_children_if
(
is_expendable
)
# partial(remove_children_if, condition=is_expendable)
# remove_scanner_tokens = remove_children_if(is_scanner_token) # partial(remove_children_if, condition=is_scanner_token)
@
transformation_factory
...
...
@@ -777,7 +778,8 @@ def remove_enclosing_delimiters(node):
node
.
result
=
node
.
result
[
1
:
-
1
]
def
map_content
(
node
,
func
:
Callable
[[
Node
],
ResultType
]):
@
transformation_factory
def
map_content
(
node
,
func
:
Callable
):
# Callable[[Node], ResultType]
"""Replaces the content of the node. ``func`` takes the node
as an argument an returns the mapped result.
"""
...
...
examples/LaTeX/grammar_tests/test_paragraph.ini
View file @
db0a8568
...
...
@@ -15,4 +15,5 @@
Im
allgemeinen
werden
die
Bewohner
Göttingens
eingeteilt
in
Studenten,
Professoren,
Philister
und
Vieh
; welche vier Stände doch nichts weniger
als
streng
geschieden
sind.
Der
Viehstand
ist
der
bedeutendste.
\ No newline at end of file
als
streng
geschieden
sind.
Der
Viehstand
ist
der
bedeutendste.
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