EBNF.ebnf 2.08 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
17
18
19
20
            | [flowmarker] literal
            | [flowmarker] regexp
            | [flowmarker] group
            | [flowmarker] oneormore
            | repetition
            | option

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

group      =  "(" expression §")"
26
oneormore  =  "{" expression "}+"
Eckhart Arnold's avatar
Eckhart Arnold committed
27
repetition =  "{" expression §"}"
28
option     =  "[" expression §"]"
Eckhart Arnold's avatar
Eckhart Arnold committed
29
30
31

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