summaryrefslogtreecommitdiff
path: root/spec/parser.bnf
blob: caa24f32c8169d63385b3dd9d17e4cc9f6504d89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
unit          : blank* ( datum blank? | EOF ) ;


blank         : 9...13 | comment ;

datum         : one_datum ( join_char? one_datum )* ;

join_char     : '.' | ':' ;


comment       : ';' ( skip_unit | skip_line ) ;

skip_unit     : '~' unit ;

skip_line     : ( ~LF )* LF? ;


one_datum     : bare_string | clad_datum ;

bare_string   : ( '.' | '+' | '-' | DIGIT ) ( bare_str_elt | '.' )*
              | bare_str_elt+
              ;

clad_datum    : '\' bare_esc_str
              | '|' pipe_str_elt* '|'
              | '"' quot_str_elt* '"'
              | '#' hash_expr
              | '(' list ')'
              | '[' list ']'
              | '{' list '}'
              | quote_expr
              ;


bare_str_elt  : bare_char | '\' bare_esc ;


bare_esc_str  : bare_esc bare_str_elt* ;

pipe_str_elt  : ~( '|' | '\' ) | '\' pipe_esc ;

quot_str_elt  : ~( '"' | '\' ) | '\' quot_esc ;

hash_expr     : rune clad_datum?
              | '%' label ( '%' | '=' datum )
              | clad_datum
              ;

list          : unit* ( '.' unit )? blank* ;

quote_expr    : ( "'" | "`" | "," ) datum ;


bare_char     : ALPHA | DIGIT | bare_punct ;

bare_punct    : '!' | '$' | '%' | '&' | '*' | '+' | '-' | '/'
              | '<' | '=' | '>' | '?' | '@' | '^' | '_' | '~'
              ;

bare_esc      : 33...126 ;


pipe_esc      : string_esc | '|' ;

quot_esc      : string_esc | '"' ;

string_esc    : '\' | 'a' | 'b' | 'e' | 'f' | 'n' | 'r' | 't' | 'v'
              | 'x' HEXDIG{2}
              | 'u' '{' HEXDIG+ '}'
              ;


rune          : ALPHA ( ALPHA | DIGIT ){0,5} ;

label         : HEXDIG{1,12} ;