tangled
alpha
login
or
join now
nove.dev
/
tree-sitter-confindent
1
fork
atom
tree-sitter implementation for the confindent configuration language
1
fork
atom
overview
issues
pulls
pipelines
Fix errors
nove.dev
4 months ago
9501dfa6
a50422f7
+203
-46
4 changed files
expand all
collapse all
unified
split
grammar.js
src
grammar.json
node-types.json
parser.c
+3
-5
grammar.js
···
12
12
13
13
rules: {
14
14
// TODO: add external scanner for proper child support (dedents...)
15
15
-
source_file: $ => repeat($._definition),
15
15
+
source_file: $ => repeat($.definition),
16
16
17
17
-
definition: $ => seq($.key, $.value),
17
17
+
definition: $ => seq($.key, optional($.value)),
18
18
19
19
key: $ => /[^ \t]+/,
20
20
21
21
-
value: $ => optional($._simple_value),
22
22
-
23
23
-
_simple_value: $ => /[^\n]+/,
21
21
+
value: $ => /[^\n]+/,
24
22
}
25
23
});
+34
-2
src/grammar.json
···
3
3
"name": "confindent",
4
4
"rules": {
5
5
"source_file": {
6
6
-
"type": "STRING",
7
7
-
"value": "hello"
6
6
+
"type": "REPEAT",
7
7
+
"content": {
8
8
+
"type": "SYMBOL",
9
9
+
"name": "definition"
10
10
+
}
11
11
+
},
12
12
+
"definition": {
13
13
+
"type": "SEQ",
14
14
+
"members": [
15
15
+
{
16
16
+
"type": "SYMBOL",
17
17
+
"name": "key"
18
18
+
},
19
19
+
{
20
20
+
"type": "CHOICE",
21
21
+
"members": [
22
22
+
{
23
23
+
"type": "SYMBOL",
24
24
+
"name": "value"
25
25
+
},
26
26
+
{
27
27
+
"type": "BLANK"
28
28
+
}
29
29
+
]
30
30
+
}
31
31
+
]
32
32
+
},
33
33
+
"key": {
34
34
+
"type": "PATTERN",
35
35
+
"value": "[^ \\t]+"
36
36
+
},
37
37
+
"value": {
38
38
+
"type": "PATTERN",
39
39
+
"value": "[^\\n]+"
8
40
}
9
41
},
10
42
"extras": [
+36
-3
src/node-types.json
···
1
1
[
2
2
{
3
3
+
"type": "definition",
4
4
+
"named": true,
5
5
+
"fields": {},
6
6
+
"children": {
7
7
+
"multiple": true,
8
8
+
"required": true,
9
9
+
"types": [
10
10
+
{
11
11
+
"type": "key",
12
12
+
"named": true
13
13
+
},
14
14
+
{
15
15
+
"type": "value",
16
16
+
"named": true
17
17
+
}
18
18
+
]
19
19
+
}
20
20
+
},
21
21
+
{
3
22
"type": "source_file",
4
23
"named": true,
5
24
"root": true,
6
6
-
"fields": {}
25
25
+
"fields": {},
26
26
+
"children": {
27
27
+
"multiple": true,
28
28
+
"required": false,
29
29
+
"types": [
30
30
+
{
31
31
+
"type": "definition",
32
32
+
"named": true
33
33
+
}
34
34
+
]
35
35
+
}
36
36
+
},
37
37
+
{
38
38
+
"type": "key",
39
39
+
"named": true
7
40
},
8
41
{
9
9
-
"type": "hello",
10
10
-
"named": false
42
42
+
"type": "value",
43
43
+
"named": true
11
44
}
12
45
]
+130
-36
src/parser.c
···
7
7
#endif
8
8
9
9
#define LANGUAGE_VERSION 15
10
10
-
#define STATE_COUNT 4
11
11
-
#define LARGE_STATE_COUNT 2
12
12
-
#define SYMBOL_COUNT 3
10
10
+
#define STATE_COUNT 7
11
11
+
#define LARGE_STATE_COUNT 4
12
12
+
#define SYMBOL_COUNT 6
13
13
#define ALIAS_COUNT 0
14
14
-
#define TOKEN_COUNT 2
14
14
+
#define TOKEN_COUNT 3
15
15
#define EXTERNAL_TOKEN_COUNT 0
16
16
#define FIELD_COUNT 0
17
17
-
#define MAX_ALIAS_SEQUENCE_LENGTH 1
17
17
+
#define MAX_ALIAS_SEQUENCE_LENGTH 2
18
18
#define MAX_RESERVED_WORD_SET_SIZE 0
19
19
#define PRODUCTION_ID_COUNT 1
20
20
#define SUPERTYPE_COUNT 0
21
21
22
22
enum ts_symbol_identifiers {
23
23
-
anon_sym_hello = 1,
24
24
-
sym_source_file = 2,
23
23
+
sym_key = 1,
24
24
+
sym_value = 2,
25
25
+
sym_source_file = 3,
26
26
+
sym_definition = 4,
27
27
+
aux_sym_source_file_repeat1 = 5,
25
28
};
26
29
27
30
static const char * const ts_symbol_names[] = {
28
31
[ts_builtin_sym_end] = "end",
29
29
-
[anon_sym_hello] = "hello",
32
32
+
[sym_key] = "key",
33
33
+
[sym_value] = "value",
30
34
[sym_source_file] = "source_file",
35
35
+
[sym_definition] = "definition",
36
36
+
[aux_sym_source_file_repeat1] = "source_file_repeat1",
31
37
};
32
38
33
39
static const TSSymbol ts_symbol_map[] = {
34
40
[ts_builtin_sym_end] = ts_builtin_sym_end,
35
35
-
[anon_sym_hello] = anon_sym_hello,
41
41
+
[sym_key] = sym_key,
42
42
+
[sym_value] = sym_value,
36
43
[sym_source_file] = sym_source_file,
44
44
+
[sym_definition] = sym_definition,
45
45
+
[aux_sym_source_file_repeat1] = aux_sym_source_file_repeat1,
37
46
};
38
47
39
48
static const TSSymbolMetadata ts_symbol_metadata[] = {
···
41
50
.visible = false,
42
51
.named = true,
43
52
},
44
44
-
[anon_sym_hello] = {
53
53
+
[sym_key] = {
54
54
+
.visible = true,
55
55
+
.named = true,
56
56
+
},
57
57
+
[sym_value] = {
45
58
.visible = true,
46
46
-
.named = false,
59
59
+
.named = true,
47
60
},
48
61
[sym_source_file] = {
49
62
.visible = true,
50
63
.named = true,
51
64
},
65
65
+
[sym_definition] = {
66
66
+
.visible = true,
67
67
+
.named = true,
68
68
+
},
69
69
+
[aux_sym_source_file_repeat1] = {
70
70
+
.visible = false,
71
71
+
.named = false,
72
72
+
},
52
73
};
53
74
54
75
static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = {
···
64
85
[1] = 1,
65
86
[2] = 2,
66
87
[3] = 3,
88
88
+
[4] = 4,
89
89
+
[5] = 5,
90
90
+
[6] = 6,
67
91
};
68
92
69
93
static bool ts_lex(TSLexer *lexer, TSStateId state) {
···
71
95
eof = lexer->eof(lexer);
72
96
switch (state) {
73
97
case 0:
74
74
-
if (eof) ADVANCE(5);
75
75
-
if (lookahead == 'h') ADVANCE(1);
76
76
-
if (('\t' <= lookahead && lookahead <= '\r') ||
77
77
-
lookahead == ' ') SKIP(0);
98
98
+
if (eof) ADVANCE(2);
99
99
+
if (lookahead == '\n') ADVANCE(3);
100
100
+
if (lookahead == '\t' ||
101
101
+
lookahead == ' ') ADVANCE(7);
102
102
+
if ((0x0b <= lookahead && lookahead <= '\r')) ADVANCE(3);
103
103
+
if (lookahead != 0) ADVANCE(4);
78
104
END_STATE();
79
105
case 1:
80
80
-
if (lookahead == 'e') ADVANCE(3);
106
106
+
if (eof) ADVANCE(2);
107
107
+
if (lookahead == '\t' ||
108
108
+
lookahead == ' ') SKIP(1);
109
109
+
if (('\n' <= lookahead && lookahead <= '\r')) ADVANCE(5);
110
110
+
if (lookahead != 0) ADVANCE(6);
81
111
END_STATE();
82
112
case 2:
83
83
-
if (lookahead == 'l') ADVANCE(4);
113
113
+
ACCEPT_TOKEN(ts_builtin_sym_end);
84
114
END_STATE();
85
115
case 3:
86
86
-
if (lookahead == 'l') ADVANCE(2);
116
116
+
ACCEPT_TOKEN(sym_key);
117
117
+
if (lookahead == '\n') ADVANCE(3);
118
118
+
if (lookahead == '\t' ||
119
119
+
lookahead == ' ') ADVANCE(7);
120
120
+
if ((0x0b <= lookahead && lookahead <= '\r')) ADVANCE(3);
121
121
+
if (lookahead != 0) ADVANCE(4);
87
122
END_STATE();
88
123
case 4:
89
89
-
if (lookahead == 'o') ADVANCE(6);
124
124
+
ACCEPT_TOKEN(sym_key);
125
125
+
if (lookahead == '\n') ADVANCE(6);
126
126
+
if (lookahead == '\t' ||
127
127
+
lookahead == ' ') ADVANCE(8);
128
128
+
if (lookahead != 0) ADVANCE(4);
90
129
END_STATE();
91
130
case 5:
92
92
-
ACCEPT_TOKEN(ts_builtin_sym_end);
131
131
+
ACCEPT_TOKEN(sym_key);
132
132
+
if (('\n' <= lookahead && lookahead <= '\r')) ADVANCE(5);
133
133
+
if (lookahead != 0 &&
134
134
+
(lookahead < '\t' || '\r' < lookahead) &&
135
135
+
lookahead != ' ') ADVANCE(6);
93
136
END_STATE();
94
137
case 6:
95
95
-
ACCEPT_TOKEN(anon_sym_hello);
138
138
+
ACCEPT_TOKEN(sym_key);
139
139
+
if (lookahead != 0 &&
140
140
+
lookahead != '\t' &&
141
141
+
lookahead != ' ') ADVANCE(6);
142
142
+
END_STATE();
143
143
+
case 7:
144
144
+
ACCEPT_TOKEN(sym_value);
145
145
+
if (lookahead == '\n') ADVANCE(3);
146
146
+
if (lookahead == '\t' ||
147
147
+
lookahead == ' ') ADVANCE(7);
148
148
+
if ((0x0b <= lookahead && lookahead <= '\r')) ADVANCE(3);
149
149
+
if (lookahead != 0) ADVANCE(4);
150
150
+
END_STATE();
151
151
+
case 8:
152
152
+
ACCEPT_TOKEN(sym_value);
153
153
+
if (lookahead != 0 &&
154
154
+
lookahead != '\n') ADVANCE(8);
96
155
END_STATE();
97
156
default:
98
157
return false;
···
101
160
102
161
static const TSLexerMode ts_lex_modes[STATE_COUNT] = {
103
162
[0] = {.lex_state = 0},
104
104
-
[1] = {.lex_state = 0},
105
105
-
[2] = {.lex_state = 0},
106
106
-
[3] = {.lex_state = 0},
163
163
+
[1] = {.lex_state = 1},
164
164
+
[2] = {.lex_state = 1},
165
165
+
[3] = {.lex_state = 1},
166
166
+
[4] = {.lex_state = 0},
167
167
+
[5] = {.lex_state = 1},
168
168
+
[6] = {.lex_state = 0},
107
169
};
108
170
109
171
static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
110
172
[STATE(0)] = {
111
173
[ts_builtin_sym_end] = ACTIONS(1),
112
112
-
[anon_sym_hello] = ACTIONS(1),
174
174
+
[sym_key] = ACTIONS(1),
175
175
+
[sym_value] = ACTIONS(1),
113
176
},
114
177
[STATE(1)] = {
115
115
-
[sym_source_file] = STATE(3),
116
116
-
[anon_sym_hello] = ACTIONS(3),
178
178
+
[sym_source_file] = STATE(6),
179
179
+
[sym_definition] = STATE(2),
180
180
+
[aux_sym_source_file_repeat1] = STATE(2),
181
181
+
[ts_builtin_sym_end] = ACTIONS(3),
182
182
+
[sym_key] = ACTIONS(5),
183
183
+
},
184
184
+
[STATE(2)] = {
185
185
+
[sym_definition] = STATE(3),
186
186
+
[aux_sym_source_file_repeat1] = STATE(3),
187
187
+
[ts_builtin_sym_end] = ACTIONS(7),
188
188
+
[sym_key] = ACTIONS(5),
189
189
+
},
190
190
+
[STATE(3)] = {
191
191
+
[sym_definition] = STATE(3),
192
192
+
[aux_sym_source_file_repeat1] = STATE(3),
193
193
+
[ts_builtin_sym_end] = ACTIONS(9),
194
194
+
[sym_key] = ACTIONS(11),
117
195
},
118
196
};
119
197
120
198
static const uint16_t ts_small_parse_table[] = {
121
121
-
[0] = 1,
122
122
-
ACTIONS(5), 1,
199
199
+
[0] = 3,
200
200
+
ACTIONS(14), 1,
201
201
+
ts_builtin_sym_end,
202
202
+
ACTIONS(16), 1,
203
203
+
sym_key,
204
204
+
ACTIONS(18), 1,
205
205
+
sym_value,
206
206
+
[10] = 1,
207
207
+
ACTIONS(20), 2,
123
208
ts_builtin_sym_end,
124
124
-
[4] = 1,
125
125
-
ACTIONS(7), 1,
209
209
+
sym_key,
210
210
+
[15] = 1,
211
211
+
ACTIONS(22), 1,
126
212
ts_builtin_sym_end,
127
213
};
128
214
129
215
static const uint32_t ts_small_parse_table_map[] = {
130
130
-
[SMALL_STATE(2)] = 0,
131
131
-
[SMALL_STATE(3)] = 4,
216
216
+
[SMALL_STATE(4)] = 0,
217
217
+
[SMALL_STATE(5)] = 10,
218
218
+
[SMALL_STATE(6)] = 15,
132
219
};
133
220
134
221
static const TSParseActionEntry ts_parse_actions[] = {
135
222
[0] = {.entry = {.count = 0, .reusable = false}},
136
223
[1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(),
137
137
-
[3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2),
138
138
-
[5] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1, 0, 0),
139
139
-
[7] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(),
224
224
+
[3] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 0, 0, 0),
225
225
+
[5] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4),
226
226
+
[7] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1, 0, 0),
227
227
+
[9] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0),
228
228
+
[11] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(4),
229
229
+
[14] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_definition, 1, 0, 0),
230
230
+
[16] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_definition, 1, 0, 0),
231
231
+
[18] = {.entry = {.count = 1, .reusable = false}}, SHIFT(5),
232
232
+
[20] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_definition, 2, 0, 0),
233
233
+
[22] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(),
140
234
};
141
235
142
236
#ifdef __cplusplus