tree-sitter implementation for the confindent configuration language

Fix errors

+203 -46
+3 -5
grammar.js
··· 12 12 13 13 rules: { 14 14 // TODO: add external scanner for proper child support (dedents...) 15 - source_file: $ => repeat($._definition), 15 + source_file: $ => repeat($.definition), 16 16 17 - definition: $ => seq($.key, $.value), 17 + definition: $ => seq($.key, optional($.value)), 18 18 19 19 key: $ => /[^ \t]+/, 20 20 21 - value: $ => optional($._simple_value), 22 - 23 - _simple_value: $ => /[^\n]+/, 21 + value: $ => /[^\n]+/, 24 22 } 25 23 });
+34 -2
src/grammar.json
··· 3 3 "name": "confindent", 4 4 "rules": { 5 5 "source_file": { 6 - "type": "STRING", 7 - "value": "hello" 6 + "type": "REPEAT", 7 + "content": { 8 + "type": "SYMBOL", 9 + "name": "definition" 10 + } 11 + }, 12 + "definition": { 13 + "type": "SEQ", 14 + "members": [ 15 + { 16 + "type": "SYMBOL", 17 + "name": "key" 18 + }, 19 + { 20 + "type": "CHOICE", 21 + "members": [ 22 + { 23 + "type": "SYMBOL", 24 + "name": "value" 25 + }, 26 + { 27 + "type": "BLANK" 28 + } 29 + ] 30 + } 31 + ] 32 + }, 33 + "key": { 34 + "type": "PATTERN", 35 + "value": "[^ \\t]+" 36 + }, 37 + "value": { 38 + "type": "PATTERN", 39 + "value": "[^\\n]+" 8 40 } 9 41 }, 10 42 "extras": [
+36 -3
src/node-types.json
··· 1 1 [ 2 2 { 3 + "type": "definition", 4 + "named": true, 5 + "fields": {}, 6 + "children": { 7 + "multiple": true, 8 + "required": true, 9 + "types": [ 10 + { 11 + "type": "key", 12 + "named": true 13 + }, 14 + { 15 + "type": "value", 16 + "named": true 17 + } 18 + ] 19 + } 20 + }, 21 + { 3 22 "type": "source_file", 4 23 "named": true, 5 24 "root": true, 6 - "fields": {} 25 + "fields": {}, 26 + "children": { 27 + "multiple": true, 28 + "required": false, 29 + "types": [ 30 + { 31 + "type": "definition", 32 + "named": true 33 + } 34 + ] 35 + } 36 + }, 37 + { 38 + "type": "key", 39 + "named": true 7 40 }, 8 41 { 9 - "type": "hello", 10 - "named": false 42 + "type": "value", 43 + "named": true 11 44 } 12 45 ]
+130 -36
src/parser.c
··· 7 7 #endif 8 8 9 9 #define LANGUAGE_VERSION 15 10 - #define STATE_COUNT 4 11 - #define LARGE_STATE_COUNT 2 12 - #define SYMBOL_COUNT 3 10 + #define STATE_COUNT 7 11 + #define LARGE_STATE_COUNT 4 12 + #define SYMBOL_COUNT 6 13 13 #define ALIAS_COUNT 0 14 - #define TOKEN_COUNT 2 14 + #define TOKEN_COUNT 3 15 15 #define EXTERNAL_TOKEN_COUNT 0 16 16 #define FIELD_COUNT 0 17 - #define MAX_ALIAS_SEQUENCE_LENGTH 1 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 - anon_sym_hello = 1, 24 - sym_source_file = 2, 23 + sym_key = 1, 24 + sym_value = 2, 25 + sym_source_file = 3, 26 + sym_definition = 4, 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 - [anon_sym_hello] = "hello", 32 + [sym_key] = "key", 33 + [sym_value] = "value", 30 34 [sym_source_file] = "source_file", 35 + [sym_definition] = "definition", 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 - [anon_sym_hello] = anon_sym_hello, 41 + [sym_key] = sym_key, 42 + [sym_value] = sym_value, 36 43 [sym_source_file] = sym_source_file, 44 + [sym_definition] = sym_definition, 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 - [anon_sym_hello] = { 53 + [sym_key] = { 54 + .visible = true, 55 + .named = true, 56 + }, 57 + [sym_value] = { 45 58 .visible = true, 46 - .named = false, 59 + .named = true, 47 60 }, 48 61 [sym_source_file] = { 49 62 .visible = true, 50 63 .named = true, 51 64 }, 65 + [sym_definition] = { 66 + .visible = true, 67 + .named = true, 68 + }, 69 + [aux_sym_source_file_repeat1] = { 70 + .visible = false, 71 + .named = false, 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 + [4] = 4, 89 + [5] = 5, 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 - if (eof) ADVANCE(5); 75 - if (lookahead == 'h') ADVANCE(1); 76 - if (('\t' <= lookahead && lookahead <= '\r') || 77 - lookahead == ' ') SKIP(0); 98 + if (eof) ADVANCE(2); 99 + if (lookahead == '\n') ADVANCE(3); 100 + if (lookahead == '\t' || 101 + lookahead == ' ') ADVANCE(7); 102 + if ((0x0b <= lookahead && lookahead <= '\r')) ADVANCE(3); 103 + if (lookahead != 0) ADVANCE(4); 78 104 END_STATE(); 79 105 case 1: 80 - if (lookahead == 'e') ADVANCE(3); 106 + if (eof) ADVANCE(2); 107 + if (lookahead == '\t' || 108 + lookahead == ' ') SKIP(1); 109 + if (('\n' <= lookahead && lookahead <= '\r')) ADVANCE(5); 110 + if (lookahead != 0) ADVANCE(6); 81 111 END_STATE(); 82 112 case 2: 83 - if (lookahead == 'l') ADVANCE(4); 113 + ACCEPT_TOKEN(ts_builtin_sym_end); 84 114 END_STATE(); 85 115 case 3: 86 - if (lookahead == 'l') ADVANCE(2); 116 + ACCEPT_TOKEN(sym_key); 117 + if (lookahead == '\n') ADVANCE(3); 118 + if (lookahead == '\t' || 119 + lookahead == ' ') ADVANCE(7); 120 + if ((0x0b <= lookahead && lookahead <= '\r')) ADVANCE(3); 121 + if (lookahead != 0) ADVANCE(4); 87 122 END_STATE(); 88 123 case 4: 89 - if (lookahead == 'o') ADVANCE(6); 124 + ACCEPT_TOKEN(sym_key); 125 + if (lookahead == '\n') ADVANCE(6); 126 + if (lookahead == '\t' || 127 + lookahead == ' ') ADVANCE(8); 128 + if (lookahead != 0) ADVANCE(4); 90 129 END_STATE(); 91 130 case 5: 92 - ACCEPT_TOKEN(ts_builtin_sym_end); 131 + ACCEPT_TOKEN(sym_key); 132 + if (('\n' <= lookahead && lookahead <= '\r')) ADVANCE(5); 133 + if (lookahead != 0 && 134 + (lookahead < '\t' || '\r' < lookahead) && 135 + lookahead != ' ') ADVANCE(6); 93 136 END_STATE(); 94 137 case 6: 95 - ACCEPT_TOKEN(anon_sym_hello); 138 + ACCEPT_TOKEN(sym_key); 139 + if (lookahead != 0 && 140 + lookahead != '\t' && 141 + lookahead != ' ') ADVANCE(6); 142 + END_STATE(); 143 + case 7: 144 + ACCEPT_TOKEN(sym_value); 145 + if (lookahead == '\n') ADVANCE(3); 146 + if (lookahead == '\t' || 147 + lookahead == ' ') ADVANCE(7); 148 + if ((0x0b <= lookahead && lookahead <= '\r')) ADVANCE(3); 149 + if (lookahead != 0) ADVANCE(4); 150 + END_STATE(); 151 + case 8: 152 + ACCEPT_TOKEN(sym_value); 153 + if (lookahead != 0 && 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 - [1] = {.lex_state = 0}, 105 - [2] = {.lex_state = 0}, 106 - [3] = {.lex_state = 0}, 163 + [1] = {.lex_state = 1}, 164 + [2] = {.lex_state = 1}, 165 + [3] = {.lex_state = 1}, 166 + [4] = {.lex_state = 0}, 167 + [5] = {.lex_state = 1}, 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 - [anon_sym_hello] = ACTIONS(1), 174 + [sym_key] = ACTIONS(1), 175 + [sym_value] = ACTIONS(1), 113 176 }, 114 177 [STATE(1)] = { 115 - [sym_source_file] = STATE(3), 116 - [anon_sym_hello] = ACTIONS(3), 178 + [sym_source_file] = STATE(6), 179 + [sym_definition] = STATE(2), 180 + [aux_sym_source_file_repeat1] = STATE(2), 181 + [ts_builtin_sym_end] = ACTIONS(3), 182 + [sym_key] = ACTIONS(5), 183 + }, 184 + [STATE(2)] = { 185 + [sym_definition] = STATE(3), 186 + [aux_sym_source_file_repeat1] = STATE(3), 187 + [ts_builtin_sym_end] = ACTIONS(7), 188 + [sym_key] = ACTIONS(5), 189 + }, 190 + [STATE(3)] = { 191 + [sym_definition] = STATE(3), 192 + [aux_sym_source_file_repeat1] = STATE(3), 193 + [ts_builtin_sym_end] = ACTIONS(9), 194 + [sym_key] = ACTIONS(11), 117 195 }, 118 196 }; 119 197 120 198 static const uint16_t ts_small_parse_table[] = { 121 - [0] = 1, 122 - ACTIONS(5), 1, 199 + [0] = 3, 200 + ACTIONS(14), 1, 201 + ts_builtin_sym_end, 202 + ACTIONS(16), 1, 203 + sym_key, 204 + ACTIONS(18), 1, 205 + sym_value, 206 + [10] = 1, 207 + ACTIONS(20), 2, 123 208 ts_builtin_sym_end, 124 - [4] = 1, 125 - ACTIONS(7), 1, 209 + sym_key, 210 + [15] = 1, 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 - [SMALL_STATE(2)] = 0, 131 - [SMALL_STATE(3)] = 4, 216 + [SMALL_STATE(4)] = 0, 217 + [SMALL_STATE(5)] = 10, 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 - [3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2), 138 - [5] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1, 0, 0), 139 - [7] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), 224 + [3] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 0, 0, 0), 225 + [5] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), 226 + [7] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1, 0, 0), 227 + [9] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), 228 + [11] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2, 0, 0), SHIFT_REPEAT(4), 229 + [14] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_definition, 1, 0, 0), 230 + [16] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_definition, 1, 0, 0), 231 + [18] = {.entry = {.count = 1, .reusable = false}}, SHIFT(5), 232 + [20] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_definition, 2, 0, 0), 233 + [22] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), 140 234 }; 141 235 142 236 #ifdef __cplusplus