diff --git a/grammar.js b/grammar.js index 1a1891a..8ca1a61 100644 --- a/grammar.js +++ b/grammar.js @@ -1,3 +1,7 @@ +function commaSeparated(elem) { + return seq(elem, repeat(seq(",", elem)), optional(",")) +} + module.exports = grammar({ name: "blueprint", @@ -32,6 +36,8 @@ module.exports = grammar({ $.identifier, $.integer_literal, $._string_literal, + // Composites + $.list_expression, ), // The Blueprint scanner makes use of Go's lexer, so copy their rule @@ -72,6 +78,12 @@ module.exports = grammar({ ), )), + list_expression: ($) => seq( + "[", + optional(commaSeparated($._expr)), + "]", + ), + // }}} } }); diff --git a/src/grammar.json b/src/grammar.json index bfe10e3..1d143a0 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -82,6 +82,10 @@ { "type": "SYMBOL", "name": "_string_literal" + }, + { + "type": "SYMBOL", + "name": "list_expression" } ] }, @@ -211,6 +215,64 @@ } ] } + }, + "list_expression": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "[" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "_expr" + }, + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "," + }, + { + "type": "SYMBOL", + "name": "_expr" + } + ] + } + }, + { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "," + }, + { + "type": "BLANK" + } + ] + } + ] + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "STRING", + "value": "]" + } + ] } }, "extras": [ diff --git a/src/node-types.json b/src/node-types.json index 9f0e7f2..6ce1da6 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -43,6 +43,10 @@ "type": "interpreted_string_literal", "named": true }, + { + "type": "list_expression", + "named": true + }, { "type": "raw_string_literal", "named": true @@ -76,6 +80,37 @@ ] } }, + { + "type": "list_expression", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "identifier", + "named": true + }, + { + "type": "integer_literal", + "named": true + }, + { + "type": "interpreted_string_literal", + "named": true + }, + { + "type": "list_expression", + "named": true + }, + { + "type": "raw_string_literal", + "named": true + } + ] + } + }, { "type": "source_file", "named": true, @@ -103,6 +138,10 @@ "type": "+=", "named": false }, + { + "type": ",", + "named": false + }, { "type": "-", "named": false @@ -111,6 +150,14 @@ "type": "=", "named": false }, + { + "type": "[", + "named": false + }, + { + "type": "]", + "named": false + }, { "type": "escape_sequence", "named": true diff --git a/src/parser.c b/src/parser.c index 17aeed4..2b757c6 100644 --- a/src/parser.c +++ b/src/parser.c @@ -6,14 +6,14 @@ #endif #define LANGUAGE_VERSION 14 -#define STATE_COUNT 23 +#define STATE_COUNT 35 #define LARGE_STATE_COUNT 2 -#define SYMBOL_COUNT 23 +#define SYMBOL_COUNT 28 #define ALIAS_COUNT 0 -#define TOKEN_COUNT 13 +#define TOKEN_COUNT 16 #define EXTERNAL_TOKEN_COUNT 0 #define FIELD_COUNT 3 -#define MAX_ALIAS_SEQUENCE_LENGTH 3 +#define MAX_ALIAS_SEQUENCE_LENGTH 5 #define PRODUCTION_ID_COUNT 2 enum ts_symbol_identifiers { @@ -29,16 +29,21 @@ enum ts_symbol_identifiers { aux_sym_interpreted_string_literal_token1 = 10, anon_sym_DQUOTE2 = 11, sym_escape_sequence = 12, - sym_source_file = 13, - sym__definition = 14, - sym_comment = 15, - sym_assignment = 16, - sym__expr = 17, - sym_integer_literal = 18, - sym__string_literal = 19, - sym_interpreted_string_literal = 20, - aux_sym_source_file_repeat1 = 21, - aux_sym_interpreted_string_literal_repeat1 = 22, + anon_sym_LBRACK = 13, + anon_sym_COMMA = 14, + anon_sym_RBRACK = 15, + sym_source_file = 16, + sym__definition = 17, + sym_comment = 18, + sym_assignment = 19, + sym__expr = 20, + sym_integer_literal = 21, + sym__string_literal = 22, + sym_interpreted_string_literal = 23, + sym_list_expression = 24, + aux_sym_source_file_repeat1 = 25, + aux_sym_interpreted_string_literal_repeat1 = 26, + aux_sym_list_expression_repeat1 = 27, }; static const char * const ts_symbol_names[] = { @@ -55,6 +60,9 @@ static const char * const ts_symbol_names[] = { [aux_sym_interpreted_string_literal_token1] = "interpreted_string_literal_token1", [anon_sym_DQUOTE2] = "\"", [sym_escape_sequence] = "escape_sequence", + [anon_sym_LBRACK] = "[", + [anon_sym_COMMA] = ",", + [anon_sym_RBRACK] = "]", [sym_source_file] = "source_file", [sym__definition] = "_definition", [sym_comment] = "comment", @@ -63,8 +71,10 @@ static const char * const ts_symbol_names[] = { [sym_integer_literal] = "integer_literal", [sym__string_literal] = "_string_literal", [sym_interpreted_string_literal] = "interpreted_string_literal", + [sym_list_expression] = "list_expression", [aux_sym_source_file_repeat1] = "source_file_repeat1", [aux_sym_interpreted_string_literal_repeat1] = "interpreted_string_literal_repeat1", + [aux_sym_list_expression_repeat1] = "list_expression_repeat1", }; static const TSSymbol ts_symbol_map[] = { @@ -81,6 +91,9 @@ static const TSSymbol ts_symbol_map[] = { [aux_sym_interpreted_string_literal_token1] = aux_sym_interpreted_string_literal_token1, [anon_sym_DQUOTE2] = anon_sym_DQUOTE, [sym_escape_sequence] = sym_escape_sequence, + [anon_sym_LBRACK] = anon_sym_LBRACK, + [anon_sym_COMMA] = anon_sym_COMMA, + [anon_sym_RBRACK] = anon_sym_RBRACK, [sym_source_file] = sym_source_file, [sym__definition] = sym__definition, [sym_comment] = sym_comment, @@ -89,8 +102,10 @@ static const TSSymbol ts_symbol_map[] = { [sym_integer_literal] = sym_integer_literal, [sym__string_literal] = sym__string_literal, [sym_interpreted_string_literal] = sym_interpreted_string_literal, + [sym_list_expression] = sym_list_expression, [aux_sym_source_file_repeat1] = aux_sym_source_file_repeat1, [aux_sym_interpreted_string_literal_repeat1] = aux_sym_interpreted_string_literal_repeat1, + [aux_sym_list_expression_repeat1] = aux_sym_list_expression_repeat1, }; static const TSSymbolMetadata ts_symbol_metadata[] = { @@ -146,6 +161,18 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { .visible = true, .named = true, }, + [anon_sym_LBRACK] = { + .visible = true, + .named = false, + }, + [anon_sym_COMMA] = { + .visible = true, + .named = false, + }, + [anon_sym_RBRACK] = { + .visible = true, + .named = false, + }, [sym_source_file] = { .visible = true, .named = true, @@ -178,6 +205,10 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { .visible = true, .named = true, }, + [sym_list_expression] = { + .visible = true, + .named = true, + }, [aux_sym_source_file_repeat1] = { .visible = false, .named = false, @@ -186,6 +217,10 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { .visible = false, .named = false, }, + [aux_sym_list_expression_repeat1] = { + .visible = false, + .named = false, + }, }; enum ts_field_identifiers { @@ -244,6 +279,18 @@ static const TSStateId ts_primary_state_ids[STATE_COUNT] = { [20] = 20, [21] = 21, [22] = 22, + [23] = 23, + [24] = 24, + [25] = 25, + [26] = 26, + [27] = 27, + [28] = 28, + [29] = 29, + [30] = 30, + [31] = 31, + [32] = 32, + [33] = 33, + [34] = 34, }; static inline bool sym_identifier_character_set_1(int32_t c) { @@ -2075,9 +2122,12 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '"') ADVANCE(32); if (lookahead == '#') ADVANCE(18); if (lookahead == '+') ADVANCE(4); + if (lookahead == ',') ADVANCE(37); if (lookahead == '-') ADVANCE(26); if (lookahead == '=') ADVANCE(23); + if (lookahead == '[') ADVANCE(36); if (lookahead == '\\') ADVANCE(5); + if (lookahead == ']') ADVANCE(38); if (lookahead == '`') ADVANCE(15); if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(16) @@ -2106,6 +2156,8 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '"') ADVANCE(29); if (lookahead == '#') ADVANCE(18); if (lookahead == '-') ADVANCE(26); + if (lookahead == '[') ADVANCE(36); + if (lookahead == ']') ADVANCE(38); if (lookahead == '`') ADVANCE(15); if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(3) @@ -2175,8 +2227,11 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '"') ADVANCE(29); if (lookahead == '#') ADVANCE(18); if (lookahead == '+') ADVANCE(4); + if (lookahead == ',') ADVANCE(37); if (lookahead == '-') ADVANCE(26); if (lookahead == '=') ADVANCE(23); + if (lookahead == '[') ADVANCE(36); + if (lookahead == ']') ADVANCE(38); if (lookahead == '`') ADVANCE(15); if (('\t' <= lookahead && lookahead <= '\r') || lookahead == ' ') SKIP(16) @@ -2270,6 +2325,15 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { ACCEPT_TOKEN(sym_escape_sequence); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(34); END_STATE(); + case 36: + ACCEPT_TOKEN(anon_sym_LBRACK); + END_STATE(); + case 37: + ACCEPT_TOKEN(anon_sym_COMMA); + END_STATE(); + case 38: + ACCEPT_TOKEN(anon_sym_RBRACK); + END_STATE(); default: return false; } @@ -2279,12 +2343,12 @@ static const TSLexMode ts_lex_modes[STATE_COUNT] = { [0] = {.lex_state = 0}, [1] = {.lex_state = 0}, [2] = {.lex_state = 3}, - [3] = {.lex_state = 0}, - [4] = {.lex_state = 0}, - [5] = {.lex_state = 1}, - [6] = {.lex_state = 1}, - [7] = {.lex_state = 1}, - [8] = {.lex_state = 1}, + [3] = {.lex_state = 3}, + [4] = {.lex_state = 3}, + [5] = {.lex_state = 3}, + [6] = {.lex_state = 3}, + [7] = {.lex_state = 0}, + [8] = {.lex_state = 0}, [9] = {.lex_state = 0}, [10] = {.lex_state = 0}, [11] = {.lex_state = 0}, @@ -2292,13 +2356,25 @@ static const TSLexMode ts_lex_modes[STATE_COUNT] = { [13] = {.lex_state = 0}, [14] = {.lex_state = 0}, [15] = {.lex_state = 0}, - [16] = {.lex_state = 0}, + [16] = {.lex_state = 1}, [17] = {.lex_state = 0}, [18] = {.lex_state = 0}, - [19] = {.lex_state = 21}, + [19] = {.lex_state = 1}, [20] = {.lex_state = 0}, - [21] = {.lex_state = 0}, - [22] = {(TSStateId)(-1)}, + [21] = {.lex_state = 1}, + [22] = {.lex_state = 0}, + [23] = {.lex_state = 1}, + [24] = {.lex_state = 0}, + [25] = {.lex_state = 0}, + [26] = {.lex_state = 0}, + [27] = {.lex_state = 0}, + [28] = {.lex_state = 0}, + [29] = {.lex_state = 0}, + [30] = {.lex_state = 0}, + [31] = {.lex_state = 21}, + [32] = {.lex_state = 0}, + [33] = {.lex_state = 0}, + [34] = {(TSStateId)(-1)}, }; static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { @@ -2315,13 +2391,16 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [anon_sym_DQUOTE] = ACTIONS(1), [anon_sym_DQUOTE2] = ACTIONS(1), [sym_escape_sequence] = ACTIONS(1), + [anon_sym_LBRACK] = ACTIONS(1), + [anon_sym_COMMA] = ACTIONS(1), + [anon_sym_RBRACK] = ACTIONS(1), }, [1] = { - [sym_source_file] = STATE(20), - [sym__definition] = STATE(9), + [sym_source_file] = STATE(33), + [sym__definition] = STATE(27), [sym_comment] = STATE(1), - [sym_assignment] = STATE(10), - [aux_sym_source_file_repeat1] = STATE(3), + [sym_assignment] = STATE(26), + [aux_sym_source_file_repeat1] = STATE(8), [ts_builtin_sym_end] = ACTIONS(5), [anon_sym_POUND] = ACTIONS(3), [sym_identifier] = ACTIONS(7), @@ -2329,7 +2408,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { }; static const uint16_t ts_small_parse_table[] = { - [0] = 10, + [0] = 12, ACTIONS(3), 1, anon_sym_POUND, ACTIONS(9), 1, @@ -2342,260 +2421,486 @@ static const uint16_t ts_small_parse_table[] = { sym_raw_string_literal, ACTIONS(17), 1, anon_sym_DQUOTE, + ACTIONS(19), 1, + anon_sym_LBRACK, + ACTIONS(21), 1, + anon_sym_RBRACK, STATE(2), 1, sym_comment, - STATE(13), 1, - sym_interpreted_string_literal, STATE(15), 1, + sym_interpreted_string_literal, + STATE(29), 1, sym__expr, - STATE(11), 2, + STATE(12), 3, sym_integer_literal, sym__string_literal, - [32] = 7, + sym_list_expression, + [39] = 12, + ACTIONS(3), 1, + anon_sym_POUND, + ACTIONS(9), 1, + sym_identifier, + ACTIONS(11), 1, + anon_sym_DASH, + ACTIONS(13), 1, + aux_sym_integer_literal_token1, + ACTIONS(15), 1, + sym_raw_string_literal, + ACTIONS(17), 1, + anon_sym_DQUOTE, + ACTIONS(19), 1, + anon_sym_LBRACK, + ACTIONS(23), 1, + anon_sym_RBRACK, + STATE(3), 1, + sym_comment, + STATE(15), 1, + sym_interpreted_string_literal, + STATE(29), 1, + sym__expr, + STATE(12), 3, + sym_integer_literal, + sym__string_literal, + sym_list_expression, + [78] = 12, + ACTIONS(3), 1, + anon_sym_POUND, + ACTIONS(9), 1, + sym_identifier, + ACTIONS(11), 1, + anon_sym_DASH, + ACTIONS(13), 1, + aux_sym_integer_literal_token1, + ACTIONS(15), 1, + sym_raw_string_literal, + ACTIONS(17), 1, + anon_sym_DQUOTE, + ACTIONS(19), 1, + anon_sym_LBRACK, + ACTIONS(25), 1, + anon_sym_RBRACK, + STATE(4), 1, + sym_comment, + STATE(15), 1, + sym_interpreted_string_literal, + STATE(22), 1, + sym__expr, + STATE(12), 3, + sym_integer_literal, + sym__string_literal, + sym_list_expression, + [117] = 11, + ACTIONS(3), 1, + anon_sym_POUND, + ACTIONS(9), 1, + sym_identifier, + ACTIONS(11), 1, + anon_sym_DASH, + ACTIONS(13), 1, + aux_sym_integer_literal_token1, + ACTIONS(15), 1, + sym_raw_string_literal, + ACTIONS(17), 1, + anon_sym_DQUOTE, + ACTIONS(19), 1, + anon_sym_LBRACK, + STATE(5), 1, + sym_comment, + STATE(15), 1, + sym_interpreted_string_literal, + STATE(28), 1, + sym__expr, + STATE(12), 3, + sym_integer_literal, + sym__string_literal, + sym_list_expression, + [153] = 11, + ACTIONS(3), 1, + anon_sym_POUND, + ACTIONS(9), 1, + sym_identifier, + ACTIONS(11), 1, + anon_sym_DASH, + ACTIONS(13), 1, + aux_sym_integer_literal_token1, + ACTIONS(15), 1, + sym_raw_string_literal, + ACTIONS(17), 1, + anon_sym_DQUOTE, + ACTIONS(19), 1, + anon_sym_LBRACK, + STATE(6), 1, + sym_comment, + STATE(15), 1, + sym_interpreted_string_literal, + STATE(29), 1, + sym__expr, + STATE(12), 3, + sym_integer_literal, + sym__string_literal, + sym_list_expression, + [189] = 6, + ACTIONS(3), 1, + anon_sym_POUND, + ACTIONS(27), 1, + ts_builtin_sym_end, + ACTIONS(29), 1, + sym_identifier, + STATE(26), 1, + sym_assignment, + STATE(27), 1, + sym__definition, + STATE(7), 2, + sym_comment, + aux_sym_source_file_repeat1, + [209] = 7, ACTIONS(3), 1, anon_sym_POUND, ACTIONS(7), 1, sym_identifier, - ACTIONS(19), 1, - ts_builtin_sym_end, - STATE(3), 1, - sym_comment, - STATE(4), 1, - aux_sym_source_file_repeat1, - STATE(9), 1, - sym__definition, - STATE(10), 1, - sym_assignment, - [54] = 6, - ACTIONS(3), 1, - anon_sym_POUND, - ACTIONS(21), 1, - ts_builtin_sym_end, - ACTIONS(23), 1, - sym_identifier, - STATE(9), 1, - sym__definition, - STATE(10), 1, - sym_assignment, - STATE(4), 2, - sym_comment, - aux_sym_source_file_repeat1, - [74] = 6, - ACTIONS(26), 1, - anon_sym_POUND, - ACTIONS(28), 1, - aux_sym_interpreted_string_literal_token1, - ACTIONS(30), 1, - anon_sym_DQUOTE2, ACTIONS(32), 1, - sym_escape_sequence, - STATE(5), 1, - sym_comment, - STATE(6), 1, - aux_sym_interpreted_string_literal_repeat1, - [93] = 6, - ACTIONS(26), 1, - anon_sym_POUND, - ACTIONS(28), 1, - aux_sym_interpreted_string_literal_token1, - ACTIONS(32), 1, - sym_escape_sequence, - ACTIONS(34), 1, - anon_sym_DQUOTE2, - STATE(6), 1, - sym_comment, + ts_builtin_sym_end, STATE(7), 1, - aux_sym_interpreted_string_literal_repeat1, - [112] = 5, - ACTIONS(26), 1, - anon_sym_POUND, - ACTIONS(36), 1, - aux_sym_interpreted_string_literal_token1, - ACTIONS(39), 1, - anon_sym_DQUOTE2, - ACTIONS(41), 1, - sym_escape_sequence, - STATE(7), 2, - sym_comment, - aux_sym_interpreted_string_literal_repeat1, - [129] = 4, - ACTIONS(26), 1, - anon_sym_POUND, - ACTIONS(44), 1, - aux_sym_interpreted_string_literal_token1, + aux_sym_source_file_repeat1, STATE(8), 1, sym_comment, - ACTIONS(46), 2, - anon_sym_DQUOTE2, - sym_escape_sequence, - [143] = 3, + STATE(26), 1, + sym_assignment, + STATE(27), 1, + sym__definition, + [231] = 3, ACTIONS(3), 1, anon_sym_POUND, STATE(9), 1, sym_comment, - ACTIONS(48), 2, + ACTIONS(34), 4, ts_builtin_sym_end, sym_identifier, - [154] = 3, + anon_sym_COMMA, + anon_sym_RBRACK, + [244] = 3, ACTIONS(3), 1, anon_sym_POUND, STATE(10), 1, sym_comment, - ACTIONS(50), 2, + ACTIONS(36), 4, ts_builtin_sym_end, sym_identifier, - [165] = 3, + anon_sym_COMMA, + anon_sym_RBRACK, + [257] = 3, ACTIONS(3), 1, anon_sym_POUND, STATE(11), 1, sym_comment, - ACTIONS(52), 2, + ACTIONS(38), 4, ts_builtin_sym_end, sym_identifier, - [176] = 3, + anon_sym_COMMA, + anon_sym_RBRACK, + [270] = 3, ACTIONS(3), 1, anon_sym_POUND, STATE(12), 1, sym_comment, - ACTIONS(54), 2, + ACTIONS(40), 4, ts_builtin_sym_end, sym_identifier, - [187] = 3, + anon_sym_COMMA, + anon_sym_RBRACK, + [283] = 3, ACTIONS(3), 1, anon_sym_POUND, STATE(13), 1, sym_comment, - ACTIONS(56), 2, + ACTIONS(42), 4, ts_builtin_sym_end, sym_identifier, - [198] = 3, + anon_sym_COMMA, + anon_sym_RBRACK, + [296] = 3, ACTIONS(3), 1, anon_sym_POUND, STATE(14), 1, sym_comment, - ACTIONS(58), 2, - anon_sym_EQ, - anon_sym_PLUS_EQ, - [209] = 3, + ACTIONS(44), 4, + ts_builtin_sym_end, + sym_identifier, + anon_sym_COMMA, + anon_sym_RBRACK, + [309] = 3, ACTIONS(3), 1, anon_sym_POUND, STATE(15), 1, sym_comment, - ACTIONS(60), 2, + ACTIONS(46), 4, ts_builtin_sym_end, sym_identifier, - [220] = 3, - ACTIONS(3), 1, + anon_sym_COMMA, + anon_sym_RBRACK, + [322] = 6, + ACTIONS(48), 1, anon_sym_POUND, + ACTIONS(50), 1, + aux_sym_interpreted_string_literal_token1, + ACTIONS(52), 1, + anon_sym_DQUOTE2, + ACTIONS(54), 1, + sym_escape_sequence, STATE(16), 1, sym_comment, - ACTIONS(62), 2, - ts_builtin_sym_end, - sym_identifier, - [231] = 3, + STATE(21), 1, + aux_sym_interpreted_string_literal_repeat1, + [341] = 3, ACTIONS(3), 1, anon_sym_POUND, STATE(17), 1, sym_comment, - ACTIONS(64), 2, + ACTIONS(56), 4, ts_builtin_sym_end, sym_identifier, - [242] = 3, + anon_sym_COMMA, + anon_sym_RBRACK, + [354] = 3, ACTIONS(3), 1, anon_sym_POUND, STATE(18), 1, sym_comment, - ACTIONS(66), 2, + ACTIONS(58), 4, ts_builtin_sym_end, sym_identifier, - [253] = 3, - ACTIONS(26), 1, + anon_sym_COMMA, + anon_sym_RBRACK, + [367] = 5, + ACTIONS(48), 1, anon_sym_POUND, - ACTIONS(68), 1, - aux_sym_comment_token1, - STATE(19), 1, + ACTIONS(60), 1, + aux_sym_interpreted_string_literal_token1, + ACTIONS(63), 1, + anon_sym_DQUOTE2, + ACTIONS(65), 1, + sym_escape_sequence, + STATE(19), 2, sym_comment, - [263] = 3, + aux_sym_interpreted_string_literal_repeat1, + [384] = 3, ACTIONS(3), 1, anon_sym_POUND, - ACTIONS(70), 1, - ts_builtin_sym_end, STATE(20), 1, sym_comment, - [273] = 3, + ACTIONS(68), 4, + ts_builtin_sym_end, + sym_identifier, + anon_sym_COMMA, + anon_sym_RBRACK, + [397] = 6, + ACTIONS(48), 1, + anon_sym_POUND, + ACTIONS(50), 1, + aux_sym_interpreted_string_literal_token1, + ACTIONS(54), 1, + sym_escape_sequence, + ACTIONS(70), 1, + anon_sym_DQUOTE2, + STATE(19), 1, + aux_sym_interpreted_string_literal_repeat1, + STATE(21), 1, + sym_comment, + [416] = 5, ACTIONS(3), 1, anon_sym_POUND, ACTIONS(72), 1, - aux_sym_integer_literal_token1, - STATE(21), 1, - sym_comment, - [283] = 1, + anon_sym_COMMA, ACTIONS(74), 1, + anon_sym_RBRACK, + STATE(22), 1, + sym_comment, + STATE(24), 1, + aux_sym_list_expression_repeat1, + [432] = 4, + ACTIONS(48), 1, + anon_sym_POUND, + ACTIONS(76), 1, + aux_sym_interpreted_string_literal_token1, + STATE(23), 1, + sym_comment, + ACTIONS(78), 2, + anon_sym_DQUOTE2, + sym_escape_sequence, + [446] = 5, + ACTIONS(3), 1, + anon_sym_POUND, + ACTIONS(23), 1, + anon_sym_RBRACK, + ACTIONS(80), 1, + anon_sym_COMMA, + STATE(24), 1, + sym_comment, + STATE(25), 1, + aux_sym_list_expression_repeat1, + [462] = 4, + ACTIONS(3), 1, + anon_sym_POUND, + ACTIONS(82), 1, + anon_sym_COMMA, + ACTIONS(85), 1, + anon_sym_RBRACK, + STATE(25), 2, + sym_comment, + aux_sym_list_expression_repeat1, + [476] = 3, + ACTIONS(3), 1, + anon_sym_POUND, + STATE(26), 1, + sym_comment, + ACTIONS(87), 2, + ts_builtin_sym_end, + sym_identifier, + [487] = 3, + ACTIONS(3), 1, + anon_sym_POUND, + STATE(27), 1, + sym_comment, + ACTIONS(89), 2, + ts_builtin_sym_end, + sym_identifier, + [498] = 3, + ACTIONS(3), 1, + anon_sym_POUND, + STATE(28), 1, + sym_comment, + ACTIONS(91), 2, + ts_builtin_sym_end, + sym_identifier, + [509] = 3, + ACTIONS(3), 1, + anon_sym_POUND, + STATE(29), 1, + sym_comment, + ACTIONS(85), 2, + anon_sym_COMMA, + anon_sym_RBRACK, + [520] = 3, + ACTIONS(3), 1, + anon_sym_POUND, + STATE(30), 1, + sym_comment, + ACTIONS(93), 2, + anon_sym_EQ, + anon_sym_PLUS_EQ, + [531] = 3, + ACTIONS(48), 1, + anon_sym_POUND, + ACTIONS(95), 1, + aux_sym_comment_token1, + STATE(31), 1, + sym_comment, + [541] = 3, + ACTIONS(3), 1, + anon_sym_POUND, + ACTIONS(97), 1, + aux_sym_integer_literal_token1, + STATE(32), 1, + sym_comment, + [551] = 3, + ACTIONS(3), 1, + anon_sym_POUND, + ACTIONS(99), 1, + ts_builtin_sym_end, + STATE(33), 1, + sym_comment, + [561] = 1, + ACTIONS(101), 1, ts_builtin_sym_end, }; static const uint32_t ts_small_parse_table_map[] = { [SMALL_STATE(2)] = 0, - [SMALL_STATE(3)] = 32, - [SMALL_STATE(4)] = 54, - [SMALL_STATE(5)] = 74, - [SMALL_STATE(6)] = 93, - [SMALL_STATE(7)] = 112, - [SMALL_STATE(8)] = 129, - [SMALL_STATE(9)] = 143, - [SMALL_STATE(10)] = 154, - [SMALL_STATE(11)] = 165, - [SMALL_STATE(12)] = 176, - [SMALL_STATE(13)] = 187, - [SMALL_STATE(14)] = 198, - [SMALL_STATE(15)] = 209, - [SMALL_STATE(16)] = 220, - [SMALL_STATE(17)] = 231, - [SMALL_STATE(18)] = 242, - [SMALL_STATE(19)] = 253, - [SMALL_STATE(20)] = 263, - [SMALL_STATE(21)] = 273, - [SMALL_STATE(22)] = 283, + [SMALL_STATE(3)] = 39, + [SMALL_STATE(4)] = 78, + [SMALL_STATE(5)] = 117, + [SMALL_STATE(6)] = 153, + [SMALL_STATE(7)] = 189, + [SMALL_STATE(8)] = 209, + [SMALL_STATE(9)] = 231, + [SMALL_STATE(10)] = 244, + [SMALL_STATE(11)] = 257, + [SMALL_STATE(12)] = 270, + [SMALL_STATE(13)] = 283, + [SMALL_STATE(14)] = 296, + [SMALL_STATE(15)] = 309, + [SMALL_STATE(16)] = 322, + [SMALL_STATE(17)] = 341, + [SMALL_STATE(18)] = 354, + [SMALL_STATE(19)] = 367, + [SMALL_STATE(20)] = 384, + [SMALL_STATE(21)] = 397, + [SMALL_STATE(22)] = 416, + [SMALL_STATE(23)] = 432, + [SMALL_STATE(24)] = 446, + [SMALL_STATE(25)] = 462, + [SMALL_STATE(26)] = 476, + [SMALL_STATE(27)] = 487, + [SMALL_STATE(28)] = 498, + [SMALL_STATE(29)] = 509, + [SMALL_STATE(30)] = 520, + [SMALL_STATE(31)] = 531, + [SMALL_STATE(32)] = 541, + [SMALL_STATE(33)] = 551, + [SMALL_STATE(34)] = 561, }; static const TSParseActionEntry ts_parse_actions[] = { [0] = {.entry = {.count = 0, .reusable = false}}, [1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(), - [3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(19), + [3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(31), [5] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 0), - [7] = {.entry = {.count = 1, .reusable = true}}, SHIFT(14), - [9] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11), - [11] = {.entry = {.count = 1, .reusable = true}}, SHIFT(21), - [13] = {.entry = {.count = 1, .reusable = true}}, SHIFT(12), - [15] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), - [17] = {.entry = {.count = 1, .reusable = true}}, SHIFT(5), - [19] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1), - [21] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2), - [23] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2), SHIFT_REPEAT(14), - [26] = {.entry = {.count = 1, .reusable = false}}, SHIFT(19), - [28] = {.entry = {.count = 1, .reusable = false}}, SHIFT(8), - [30] = {.entry = {.count = 1, .reusable = true}}, SHIFT(17), - [32] = {.entry = {.count = 1, .reusable = true}}, SHIFT(8), - [34] = {.entry = {.count = 1, .reusable = true}}, SHIFT(18), - [36] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_interpreted_string_literal_repeat1, 2), SHIFT_REPEAT(8), - [39] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_interpreted_string_literal_repeat1, 2), - [41] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_interpreted_string_literal_repeat1, 2), SHIFT_REPEAT(8), - [44] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_interpreted_string_literal_repeat1, 1), - [46] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_interpreted_string_literal_repeat1, 1), - [48] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 1), - [50] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__definition, 1), - [52] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__expr, 1), - [54] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_integer_literal, 1), - [56] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__string_literal, 1), - [58] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2), - [60] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_assignment, 3, .production_id = 1), - [62] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_integer_literal, 2), - [64] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_interpreted_string_literal, 2), - [66] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_interpreted_string_literal, 3), - [68] = {.entry = {.count = 1, .reusable = false}}, SHIFT(22), - [70] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), - [72] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), - [74] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_comment, 2), + [7] = {.entry = {.count = 1, .reusable = true}}, SHIFT(30), + [9] = {.entry = {.count = 1, .reusable = true}}, SHIFT(12), + [11] = {.entry = {.count = 1, .reusable = true}}, SHIFT(32), + [13] = {.entry = {.count = 1, .reusable = true}}, SHIFT(14), + [15] = {.entry = {.count = 1, .reusable = true}}, SHIFT(15), + [17] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), + [19] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), + [21] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11), + [23] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), + [25] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10), + [27] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2), + [29] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 2), SHIFT_REPEAT(30), + [32] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1), + [34] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_interpreted_string_literal, 3), + [36] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_list_expression, 2), + [38] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_list_expression, 5), + [40] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__expr, 1), + [42] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_list_expression, 4), + [44] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_integer_literal, 1), + [46] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__string_literal, 1), + [48] = {.entry = {.count = 1, .reusable = false}}, SHIFT(31), + [50] = {.entry = {.count = 1, .reusable = false}}, SHIFT(23), + [52] = {.entry = {.count = 1, .reusable = true}}, SHIFT(20), + [54] = {.entry = {.count = 1, .reusable = true}}, SHIFT(23), + [56] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_list_expression, 3), + [58] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_integer_literal, 2), + [60] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_interpreted_string_literal_repeat1, 2), SHIFT_REPEAT(23), + [63] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_interpreted_string_literal_repeat1, 2), + [65] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_interpreted_string_literal_repeat1, 2), SHIFT_REPEAT(23), + [68] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_interpreted_string_literal, 2), + [70] = {.entry = {.count = 1, .reusable = true}}, SHIFT(9), + [72] = {.entry = {.count = 1, .reusable = true}}, SHIFT(3), + [74] = {.entry = {.count = 1, .reusable = true}}, SHIFT(17), + [76] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_interpreted_string_literal_repeat1, 1), + [78] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_interpreted_string_literal_repeat1, 1), + [80] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2), + [82] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_list_expression_repeat1, 2), SHIFT_REPEAT(6), + [85] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_list_expression_repeat1, 2), + [87] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__definition, 1), + [89] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_source_file_repeat1, 1), + [91] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_assignment, 3, .production_id = 1), + [93] = {.entry = {.count = 1, .reusable = true}}, SHIFT(5), + [95] = {.entry = {.count = 1, .reusable = false}}, SHIFT(34), + [97] = {.entry = {.count = 1, .reusable = true}}, SHIFT(18), + [99] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), + [101] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_comment, 2), }; #ifdef __cplusplus diff --git a/test/corpus/expressions.txt b/test/corpus/expressions.txt index d78b1dc..a3270a7 100644 --- a/test/corpus/expressions.txt +++ b/test/corpus/expressions.txt @@ -71,3 +71,118 @@ foo = `Hello\nWorld!` (assignment (identifier) (raw_string_literal))) + +================================================================================ +List (empty) +================================================================================ + +foo = [] + +-------------------------------------------------------------------------------- + +(source_file + (assignment + (identifier) + (list_expression))) + +================================================================================ +List (singleton) +================================================================================ + +foo = [42] + +-------------------------------------------------------------------------------- + +(source_file + (assignment + (identifier) + (list_expression + (integer_literal)))) + +================================================================================ +List (singleton multiline) +================================================================================ + +foo = [ + 42 +] + +-------------------------------------------------------------------------------- + +(source_file + (assignment + (identifier) + (list_expression + (integer_literal)))) + +================================================================================ +List (singleton trailing comma) +================================================================================ + +foo = [ + 42, +] + +-------------------------------------------------------------------------------- + +(source_file + (assignment + (identifier) + (list_expression + (integer_literal)))) + +================================================================================ +List (mixed values) +================================================================================ + +foo = [ + 42, + "foobar", +] + +-------------------------------------------------------------------------------- + +(source_file + (assignment + (identifier) + (list_expression + (integer_literal) + (interpreted_string_literal)))) + +================================================================================ +List (list of list) +================================================================================ + +foo = [ + [42], + ["foobar"], + [], +] + +-------------------------------------------------------------------------------- + +(source_file + (assignment + (identifier) + (list_expression + (list_expression + (integer_literal)) + (list_expression + (interpreted_string_literal)) + (list_expression)))) + +================================================================================ +List (rogue comma) +================================================================================ + +foo = [ + , +] + +-------------------------------------------------------------------------------- + +(source_file + (assignment + (identifier) + (list_expression + (ERROR))))