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
0e90dfe0
Commit
0e90dfe0
authored
Jul 01, 2017
by
Eckhart Arnold
Browse files
- test for whitespace handling added
parent
60800f1c
Changes
3
Hide whitespace changes
Inline
Side-by-side
DHParser/dsl.py
View file @
0e90dfe0
...
@@ -257,6 +257,7 @@ def parser_factory(ebnf_src: str, branding="DSL") -> Grammar:
...
@@ -257,6 +257,7 @@ def parser_factory(ebnf_src: str, branding="DSL") -> Grammar:
"""
"""
grammar_src
=
compileDSL
(
ebnf_src
,
nil_scanner
,
get_ebnf_grammar
(),
grammar_src
=
compileDSL
(
ebnf_src
,
nil_scanner
,
get_ebnf_grammar
(),
get_ebnf_transformer
(),
get_ebnf_compiler
(
branding
))
get_ebnf_transformer
(),
get_ebnf_compiler
(
branding
))
print
(
grammar_src
)
return
compile_python_object
(
DHPARSER_IMPORTS
+
grammar_src
,
'get_(?:\w+_)?grammar$'
)
return
compile_python_object
(
DHPARSER_IMPORTS
+
grammar_src
,
'get_(?:\w+_)?grammar$'
)
...
...
DHParser/parsers.py
View file @
0e90dfe0
...
@@ -707,6 +707,15 @@ class RE(Parser):
...
@@ -707,6 +707,15 @@ class RE(Parser):
class
Token
(
RE
):
class
Token
(
RE
):
"""Class Token parses simple strings. Any regular regular
expression commands will be interpreted as simple sequence of
characters.
Other than that class Token is essentially a renamed version of
class RE. Because tokens often have a particular semantic different
from other REs, parsing them with a separate parser class allows to
distinguish them by their parser type.
"""
assert
TOKEN_PTYPE
==
":Token"
assert
TOKEN_PTYPE
==
":Token"
def
__init__
(
self
,
token
:
str
,
wL
=
None
,
wR
=
None
,
name
:
str
=
''
)
->
None
:
def
__init__
(
self
,
token
:
str
,
wL
=
None
,
wR
=
None
,
name
:
str
=
''
)
->
None
:
...
...
test/test_parsers.py
View file @
0e90dfe0
...
@@ -274,6 +274,32 @@ class TestPopRetrieve:
...
@@ -274,6 +274,32 @@ class TestPopRetrieve:
syntax_tree
.
log
(
"test_PopRetrieve_multi_line.cst"
)
syntax_tree
.
log
(
"test_PopRetrieve_multi_line.cst"
)
class
TestWhitespaceHandling
:
minilang
=
"""@testing = True
doc = A B
A = "A"
B = "B"
Rdoc = ar br
ar = /A/
br = /B/
"""
def
setup
(
self
):
self
.
gr
=
parser_factory
(
self
.
minilang
)()
def
test_token_whitespace
(
self
):
st
=
self
.
gr
(
"AB"
,
'doc'
)
assert
not
st
.
error_flag
st
=
self
.
gr
(
"A B"
,
'doc'
)
assert
not
st
.
error_flag
def
test_regexp_whitespace
(
self
):
st
=
self
.
gr
(
"AB"
,
'Rdoc'
)
assert
not
st
.
error_flag
st
=
self
.
gr
(
"A B"
,
'Rdoc'
)
assert
st
.
error_flag
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
from
DHParser.testing
import
runner
from
DHParser.testing
import
runner
runner
(
""
,
globals
())
runner
(
""
,
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