-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYiniParser.g4
85 lines (62 loc) · 2.11 KB
/
YiniParser.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
/*
YINI grammar in ANTLR 4.
Apache License, Version 2.0, January 2004,
http://www.apache.org/licenses/
Copyright 2024 Gothenburg, Marko K. S. (Sweden via
Finland).
*/
/*
This grammar aims to follow, as closely as possible, the YINI specification v1.0.0 Alpha 3.
Feedback, bug reports and improvements are welcomed here https://github.com/YINI-lang/YINI-spec
http://yini-lang.org
*/
parser grammar YiniParser;
options {
tokenVocab = YiniLexer;
caseInsensitive = false;
}
//comment: BLOCK_COMMENT | LINE_COMMENT; NL: LINE_COMMENT+ | NL+;
yini: SHEBANG? COMMENT* NL* section+ NL* EOF;
section:
SECTION_HEAD section_members
| SECTION_HEAD section
| terminal_line;
terminal_line: TERMINAL_TOKEN (NL+ | COMMENT? NL*);
section_members: member+;
member:
member_explicit_string
| member_explicit_real_number
| member_explicit_integer_number
| member_explicit_boolean
| member_explicit_array
//| IDENT EQ NL+ // Empty value is treated as NULL.
| (IDENT | KEY) EQ value? NL+ // Empty value is treated as NULL.
//| IDENT COLON elements? NL+
| member_colon_list;
//| STRING COLON value? NL+; // ???
member_colon_list: (IDENT | KEY) COLON elements? NL+;
member_explicit_string: DOLLAR IDENT EQ string_literal? NL+;
member_explicit_real_number: SS IDENT EQ number_literal? NL+;
member_explicit_integer_number: SS IDENT EQ number_literal? NL+;
member_explicit_boolean: PC IDENT EQ boolean_literal? NL+;
member_explicit_array:
AT IDENT EQ list_in_brackets? NL+
| AT IDENT COLON elements? NL+; // ? reactor to colon list
key: IDENT;
//key: (IDENT | STRING);
//key: (IDENT | RAW_STRING);
value:
list_in_brackets
| string_literal
| number_literal
| boolean_literal
| NULL; // NOTE: In specs NULL should be case-insensitive.
list: elements | list_in_brackets;
list_in_brackets: OB NL* elements NL* CB | EMPTY_LIST;
elements: element COMMA? | element COMMA elements;
element: NL* value NL* | NL* list_in_brackets NL*;
number_literal: NUMBER;
string_literal: STRING string_concat*;
string_concat: NL* PLUS NL* STRING;
// NOTE: In specs boolean literals should be case-insensitive.
boolean_literal: BOOLEAN_FALSE | BOOLEAN_TRUE;