Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
34b83dae
Commit
34b83dae
authored
Feb 20, 2019
by
eckhart
Browse files
- examples/EBNF/grammar_tests: grammar tests completed
parent
228c20d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/EBNF/example_2.dsl
View file @
34b83dae
# EBNF-Grammar in EBNF
# An alternative EBNF-Grammar
# Please note: This does not work with the current ebnf.py
# TODO: Transform ASTs stemming from this grammar to ASTs
# that DHParser.ebnf.EBNFCompiler can compile.
@ comment = /#.*(?:\n|$)/ # comments start with '#' and eat all chars up to and including '\n'
@ whitespace = /\s*/ # whitespace includes linefeed
@ literalws = right # trailing whitespace of literals will be ignored tacitly
#: top-level
syntax = [~//] { definition | directive } §EOF
definition = symbol §"=" expression
directive = "@" §symbol "=" (regexp | literal | symbol) { "," (regexp | literal | symbol) }
#: components
expression = term { "|" term }
term = { ["§"] factor }+ # "§" means all following factors mandatory
factor = [flowmarker] [retrieveop] symbol !"=" # negative lookahead to be sure it's not a definition
| [flowmarker] literal
| [flowmarker] plaintext
| [flowmarker] regexp
| [flowmarker] whitespace
| [flowmarker] oneormore
| [flowmarker] group
| [flowmarker] unordered
| repetition
| option
factor = [flowmarker] [retrieveop] symbol [suffix] !"="
| [flowmarker] ( literal
| plaintext
| regexp
| whitespace
| group
| unordered ) [suffix]
#: flow-operators
flowmarker = "!" | "&" # '!' negative lookahead, '&' positive lookahead
| "-!" | "-&" # '-' negative lookbehind, '-&' positive lookbehind
retrieveop = "::" | ":" # '::' pop, ':' retrieve
#: groups
group = "(" §expression ")"
unordered = "<" §expression ">" # elements of expression in arbitrary order
oneormore = "{" expression "}+"
repetition = "{" §expression "}"
option = "[" §expression "]"
unordered = "{" §expression "}" # elements of expression in arbitrary order
#: suffixes
oneormore = "+"
repetition = "*"
option = "?"
#: leaf-elements
symbol = /(?!\d)\w+/~ # e.g. expression, factor, parameter_list
literal = /"(?:
[^"]|\\")*?"/~
# e.g. "(", '+', 'while'
| /'(?:
[^']|\\')*?'/~
# whitespace following literals will be ignored tacitly.
plaintext = /`(?:
[^"]|\\")*?`/~
# like literal but does not eat whitespace
regexp = /\/(?:\\(\/)|[^\/])*?\//~
# e.g. /\w+/, ~/#.*(?:\n|$)/~
literal = /"(?:
(?<!\\)\\"|[^"])*?"/~
# e.g. "(", '+', 'while'
| /'(?:
(?<!\\)\\'|[^'])*?'/~
# whitespace following literals will be ignored tacitly.
plaintext = /`(?:
(?<!\\)\\`|[^"])*?`/~
# like literal but does not eat whitespace
regexp = /\/(?:
(?<!\\)
\\(
?:
\/)|[^\/])*?\//~ # e.g. /\w+/, ~/#.*(?:\n|$)/~
whitespace = /~/~ # insignificant whitespace
EOF = !/./
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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