EBNF.ebnf 2.21 KB
Newer Older
Eckhart Arnold's avatar
Eckhart Arnold committed
1
2
# EBNF-Grammar in EBNF

3
@ comment    =  /#.*(?:\n|$)/                    # comments start with '#' and eat all chars up to and including '\n'
Eckhart Arnold's avatar
Eckhart Arnold committed
4
5
6
7
@ whitespace =  /\s*/                            # whitespace includes linefeed
@ literalws  =  right                            # trailing whitespace of literals will be ignored tacitly

syntax     =  [~//] { definition | directive } §EOF
8
9
definition =  symbol §"=" expression
directive  =  "@" §symbol "=" ( regexp | literal | list_ )
Eckhart Arnold's avatar
Eckhart Arnold committed
10
11

expression =  term { "|" term }
12
term       =  { ["§"] factor }+                       # "§" means all following factors mandatory
13
factor     =  [flowmarker] [retrieveop] symbol !"="   # negative lookahead to be sure it's not a definition
Eckhart Arnold's avatar
Eckhart Arnold committed
14
15
16
            | [flowmarker] literal
            | [flowmarker] regexp
            | [flowmarker] oneormore
eckhart's avatar
eckhart committed
17
            | [flowmarker] group
18
            | [flowmarker] unordered
Eckhart Arnold's avatar
Eckhart Arnold committed
19
20
21
            | repetition
            | option

22
flowmarker =  "!"  | "&"                         # '!' negative lookahead, '&' positive lookahead
23
            | "-!" | "-&"                        # '-' negative lookbehind, '-&' positive lookbehind
Eckhart Arnold's avatar
Eckhart Arnold committed
24
25
retrieveop =  "::" | ":"                         # '::' pop, ':' retrieve

26
group      =  "(" §expression ")"
27
unordered  =  "<" §expression ">"                # elements of expression in arbitrary order
28
oneormore  =  "{" expression "}+"
29
30
repetition =  "{" §expression "}"
option     =  "[" §expression "]"
Eckhart Arnold's avatar
Eckhart Arnold committed
31
32
33

symbol     =  /(?!\d)\w+/~                       # e.g. expression, factor, parameter_list
literal    =  /"(?:[^"]|\\")*?"/~                # e.g. "(", '+', 'while'
34
            | /'(?:[^']|\\')*?'/~                # whitespace following literals will be ignored tacitly.
35
regexp     =  /~?\/(?:\\\/|[^\/])*?\/~?/~        # e.g. /\w+/, ~/#.*(?:\n|$)/~
Eckhart Arnold's avatar
Eckhart Arnold committed
36
37
                                                 # '~' is a whitespace-marker, if present leading or trailing
                                                 # whitespace of a regular expression will be ignored tacitly.
38
list_      =  /\w+/~ { "," /\w+/~ }              # comma separated list of symbols, e.g. BEGIN_LIST, END_LIST,
39
                                                 # BEGIN_QUOTE, END_QUOTE ; see CommonMark/markdown.py for an exmaple
Eckhart Arnold's avatar
Eckhart Arnold committed
40
EOF =  !/./