-
Notifications
You must be signed in to change notification settings - Fork 4
/
YamlParser.g4
106 lines (83 loc) · 1.76 KB
/
YamlParser.g4
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
parser grammar YamlParser;
options { tokenVocab = YamlLexer; }
// The Yaml Language Reference: http://www.yaml.org/spec/1.2/spec.html
/*
* my parser rules
*/
file
: NEWLINE*
(
(DOCUMENTSTART NEWLINE?)? document (DOCUMENTEND NEWLINE)? (NEWLINE* (DOCUMENTSTART NEWLINE) document (DOCUMENTEND NEWLINE?)?)*
)
NEWLINE* EOF
;
document
: list | mappinglist | flowlist | flowmappinglist | value
;
list
: (NEWLINE* listitem NEWLINE?)+
;
listitem
: MINUS ANCHOR? (
value |
NEWLINE+ INDENT list DEDENT |
NEWLINE+ INDENT mappinglist DEDENT |
flowlist
)
| MINUS ALIAS
| MINUS NEWLINE //null value
;
mappinglist
: (NEWLINE* mapping NEWLINE?)+
;
key
: STRING_MY
;
value
: value_scalar | NEWLINE INDENT value_scalar NEWLINE DEDENT | multiline_string | string_literal | string_folded | string_double_quoted
;
value_scalar
: number | STRING_MY
;
multiline_string
: value_scalar? NEWLINE INDENT ( value_scalar (NEWLINE value_scalar)* | multiline_string)+ NEWLINE? DEDENT
;
string_literal
: LITERIAL_STR_IND (NEWLINE_STR_LITERAL+ STRING_MY)*
;
string_folded
: FOLD_STR_IND (NEWLINE_STR_LITERAL+ STRING_MY)*
;
string_double_quoted
: DOUBLE_QUOTE STRING_MY (NEWLINE_STR_QUOTE+ STRING_MY)* DOUBLE_QUOTE
;
mapping
: key COLON NEWLINE+ INDENT mappinglist DEDENT
| key COLON NEWLINE+ INDENT list DEDENT
| key COLON flowmappinglist
| key COLON value?
;
/*
* flow rules
*/
flowlist
: OPEN_BRACK value (COMMA value)* CLOSE_BRACK
;
flowmappinglist
: OPEN_BRACE mapping (COMMA mapping)* CLOSE_BRACE
;
/*
* parser rules
*/
number
: integer
| FLOAT_NUMBER
| IMAG_NUMBER
;
/// integer ::= decimalinteger | octinteger | hexinteger | bininteger
integer
: DECIMAL_INTEGER
| OCT_INTEGER
| HEX_INTEGER
| BIN_INTEGER
;