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
eda151f2
Commit
eda151f2
authored
Jul 06, 2021
by
di68kap
Browse files
Documentation erweitert
parent
958459c3
Changes
4
Hide whitespace changes
Inline
Side-by-side
documentation_src/Overview.rst
View file @
eda151f2
...
...
@@ -17,7 +17,7 @@ to analyse the parsing process and it offers facilities for unit-testing grammar
support for fail-tolerant parsing so that the parser does not stop at the first syntax error
it encounters. Finally, there is some support for writing language servers for DSLs
in Python that adhere to editor-independent the
`languag server-protocol <https://microsoft.github.io/language-server-protocol/>
_
`.
`languag server-protocol <https://microsoft.github.io/language-server-protocol/>`
_
.
Adhoc-Parsers
...
...
examples/EBNF/FixedEBNF.ebnf
View file @
eda151f2
...
...
@@ -36,7 +36,8 @@ syntax = ~ { definition | directive } EOF
definition = symbol §DEF~ [ OR~ ] expression ENDL~ & FOLLOW_UP # [OR~] to support v. Rossum's syntax
directive = "@" §symbol "=" component { "," component } & FOLLOW_UP
component = (regexp | literals | procedure | symbol !DEF)
# component = (regexp | literals | procedure | symbol !DEF)
component = (procedure | expression)
literals = { literal }+ # string chaining, only allowed in directives!
procedure = SYM_REGEX "()" # procedure name, only allowed in directives!
...
...
examples/EBNF/tst_FixedEBNF_grammar.py
0 → 100644
View file @
eda151f2
#!/usr/bin/env python3
"""tst_EBNF_grammar.py - runs the unit tests for the EBNF-grammar
"""
import
os
import
sys
LOGGING
=
''
scriptpath
=
os
.
path
.
dirname
(
__file__
)
dhparserdir
=
os
.
path
.
abspath
(
os
.
path
.
join
(
scriptpath
,
'../..'
))
if
scriptpath
not
in
sys
.
path
:
sys
.
path
.
append
(
scriptpath
)
if
dhparserdir
not
in
sys
.
path
:
sys
.
path
.
append
(
dhparserdir
)
try
:
from
DHParser.configuration
import
get_config_value
,
set_config_value
from
DHParser
import
dsl
import
DHParser.log
from
DHParser
import
testing
from
DHParser.toolkit
import
is_filename
except
ModuleNotFoundError
:
print
(
'Could not import DHParser. Please adjust sys.path in file '
'"%s" manually'
%
__file__
)
sys
.
exit
(
1
)
def
recompile_grammar
(
grammar_src
,
force
):
grammar_tests_dir
=
os
.
path
.
join
(
scriptpath
,
'test_grammar'
)
testing
.
create_test_templates
(
grammar_src
,
grammar_tests_dir
)
DHParser
.
log
.
start_logging
(
'LOGS'
)
# recompiles Grammar only if it has changed
saved_syntax_variant
=
get_config_value
(
'syntax_variant'
)
set_config_value
(
'syntax_variant'
,
'heuristic'
)
if
not
dsl
.
recompile_grammar
(
grammar_src
,
force
=
force
,
notify
=
lambda
:
print
(
'recompiling '
+
grammar_src
)):
print
(
'
\n
Errors while recompiling "%s":'
%
grammar_src
+
'
\n
--------------------------------------
\n\n
'
)
if
is_filename
(
grammar_src
):
err_name
=
grammar_src
.
replace
(
'.'
,
'_'
)
+
'_ERRORS.txt'
else
:
err_name
=
'EBNF_ebnf_ERRORS.txt'
with
open
(
err_name
,
encoding
=
'utf-8'
)
as
f
:
print
(
f
.
read
())
sys
.
exit
(
1
)
set_config_value
(
'syntax_variant'
,
saved_syntax_variant
)
def
run_grammar_tests
(
glob_pattern
,
get_grammar
,
get_transformer
):
DHParser
.
log
.
start_logging
(
LOGGING
)
error_report
=
testing
.
grammar_suite
(
os
.
path
.
join
(
scriptpath
,
'test_grammar'
),
get_grammar
,
get_transformer
,
fn_patterns
=
[
glob_pattern
],
report
=
'REPORT'
,
verbose
=
True
)
return
error_report
if
__name__
==
'__main__'
:
argv
=
sys
.
argv
[:]
if
len
(
argv
)
>
1
and
sys
.
argv
[
1
]
==
"--debug"
:
LOGGING
=
True
del
argv
[
1
]
if
(
len
(
argv
)
>=
2
and
(
argv
[
1
].
endswith
(
'.ebnf'
)
or
os
.
path
.
splitext
(
argv
[
1
])[
1
].
lower
()
in
testing
.
TEST_READERS
.
keys
())):
# if called with a single filename that is either an EBNF file or a known
# test file type then use the given argument
arg
=
argv
[
1
]
else
:
# otherwise run all tests in the test directory
arg
=
'*_test_*.ini'
if
arg
.
endswith
(
'.ebnf'
):
recompile_grammar
(
arg
,
force
=
True
)
else
:
recompile_grammar
(
os
.
path
.
join
(
scriptpath
,
'EBNF.ebnf'
),
force
=
False
)
sys
.
path
.
append
(
'.'
)
from
EBNFParser
import
get_grammar
,
get_transformer
error_report
=
run_grammar_tests
(
arg
,
get_grammar
,
get_transformer
)
if
error_report
:
print
(
'
\n
'
)
print
(
error_report
)
sys
.
exit
(
1
)
print
(
'ready.
\n
'
)
experimental/JSON/tests_grammar/02_test_simple_elements.ini
0 → 100644
View file @
eda151f2
[match:string]
[ast:string]
[fail:string]
[match:number]
M1:
"-3.2E-32"
M2:
"42"
[ast:number]
M1:
(number
"-3.2E-32")
[fail:number]
F1:
"π"
[match:_bool]
[ast:_bool]
[fail:_bool]
[match:true]
[ast:true]
[fail:true]
[match:false]
[ast:false]
[fail:false]
[match:null]
[ast:null]
[fail:null]
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