From 94b188039aec3fb16befe2557b433d26ae68c574 Mon Sep 17 00:00:00 2001 From: mhoffm Date: Fri, 11 Jun 2021 23:57:34 +0200 Subject: [PATCH] add ellipsis token --- grammar.js | 6 +- src/grammar.json | 15 ++- src/node-types.json | 16 ++- src/parser.c | 200 ++++++++++++++++---------------- test/corpus/for_expressions.txt | 82 +++++++++++++ test/corpus/function_calls.txt | 5 +- 6 files changed, 210 insertions(+), 114 deletions(-) diff --git a/grammar.js b/grammar.js index fbffc00..550246b 100644 --- a/grammar.js +++ b/grammar.js @@ -136,7 +136,7 @@ module.exports = grammar({ $.expression, '=>', $.expression, - optional('...'), + optional($.ellipsis), optional($.for_cond), '}', ), @@ -164,9 +164,11 @@ module.exports = grammar({ function_arguments: $ => seq( $.expression, repeat(seq(',', $.expression)), - optional(choice(',', '...')) + optional(choice(',', $.ellipsis)) ), + ellipsis: $ => token('...'), + // http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890 comment: $ => token(choice( seq('#', /.*/), diff --git a/src/grammar.json b/src/grammar.json index 4f04c52..3df4900 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -601,8 +601,8 @@ "type": "CHOICE", "members": [ { - "type": "STRING", - "value": "..." + "type": "SYMBOL", + "name": "ellipsis" }, { "type": "BLANK" @@ -757,8 +757,8 @@ "value": "," }, { - "type": "STRING", - "value": "..." + "type": "SYMBOL", + "name": "ellipsis" } ] }, @@ -769,6 +769,13 @@ } ] }, + "ellipsis": { + "type": "TOKEN", + "content": { + "type": "STRING", + "value": "..." + } + }, "comment": { "type": "TOKEN", "content": { diff --git a/src/node-types.json b/src/node-types.json index 6af1dfc..f24472d 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -259,6 +259,10 @@ "multiple": true, "required": true, "types": [ + { + "type": "ellipsis", + "named": true + }, { "type": "expression", "named": true @@ -324,6 +328,10 @@ "multiple": true, "required": true, "types": [ + { + "type": "ellipsis", + "named": true + }, { "type": "expression", "named": true @@ -526,10 +534,6 @@ "type": ".", "named": false }, - { - "type": "...", - "named": false - }, { "type": ":", "named": false @@ -554,6 +558,10 @@ "type": "comment", "named": true }, + { + "type": "ellipsis", + "named": true + }, { "type": "false", "named": false diff --git a/src/parser.c b/src/parser.c index 8e54f2e..c424c33 100644 --- a/src/parser.c +++ b/src/parser.c @@ -36,10 +36,10 @@ enum { anon_sym_DOT = 17, anon_sym_STAR = 18, anon_sym_EQ_GT = 19, - anon_sym_DOT_DOT_DOT = 20, - anon_sym_for = 21, - anon_sym_in = 22, - anon_sym_if = 23, + anon_sym_for = 20, + anon_sym_in = 21, + anon_sym_if = 22, + sym_ellipsis = 23, sym_comment = 24, sym_config_file = 25, sym_body = 26, @@ -96,10 +96,10 @@ static const char * const ts_symbol_names[] = { [anon_sym_DOT] = ".", [anon_sym_STAR] = "*", [anon_sym_EQ_GT] = "=>", - [anon_sym_DOT_DOT_DOT] = "...", [anon_sym_for] = "for", [anon_sym_in] = "in", [anon_sym_if] = "if", + [sym_ellipsis] = "ellipsis", [sym_comment] = "comment", [sym_config_file] = "config_file", [sym_body] = "body", @@ -156,10 +156,10 @@ static const TSSymbol ts_symbol_map[] = { [anon_sym_DOT] = anon_sym_DOT, [anon_sym_STAR] = anon_sym_STAR, [anon_sym_EQ_GT] = anon_sym_EQ_GT, - [anon_sym_DOT_DOT_DOT] = anon_sym_DOT_DOT_DOT, [anon_sym_for] = anon_sym_for, [anon_sym_in] = anon_sym_in, [anon_sym_if] = anon_sym_if, + [sym_ellipsis] = sym_ellipsis, [sym_comment] = sym_comment, [sym_config_file] = sym_config_file, [sym_body] = sym_body, @@ -276,10 +276,6 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { .visible = true, .named = false, }, - [anon_sym_DOT_DOT_DOT] = { - .visible = true, - .named = false, - }, [anon_sym_for] = { .visible = true, .named = false, @@ -292,6 +288,10 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { .visible = true, .named = false, }, + [sym_ellipsis] = { + .visible = true, + .named = true, + }, [sym_comment] = { .visible = true, .named = true, @@ -2092,7 +2092,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead != 0) ADVANCE(6); END_STATE(); case 7: - if (lookahead == '.') ADVANCE(72); + if (lookahead == '.') ADVANCE(76); END_STATE(); case 8: if (lookahead == '>') ADVANCE(71); @@ -2108,8 +2108,8 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'e') ADVANCE(60); END_STATE(); case 12: - if (lookahead == 'f') ADVANCE(76); - if (lookahead == 'n') ADVANCE(75); + if (lookahead == 'f') ADVANCE(75); + if (lookahead == 'n') ADVANCE(74); END_STATE(); case 13: if (lookahead == 'l') ADVANCE(18); @@ -2121,7 +2121,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'l') ADVANCE(14); END_STATE(); case 16: - if (lookahead == 'r') ADVANCE(73); + if (lookahead == 'r') ADVANCE(72); END_STATE(); case 17: if (lookahead == 'r') ADVANCE(19); @@ -2248,7 +2248,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { END_STATE(); case 40: ACCEPT_TOKEN(sym_identifier); - if (lookahead == 'r') ADVANCE(74); + if (lookahead == 'r') ADVANCE(73); if (sym_identifier_character_set_3(lookahead)) ADVANCE(45); END_STATE(); case 41: @@ -2398,21 +2398,21 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { ACCEPT_TOKEN(anon_sym_EQ_GT); END_STATE(); case 72: - ACCEPT_TOKEN(anon_sym_DOT_DOT_DOT); + ACCEPT_TOKEN(anon_sym_for); END_STATE(); case 73: - ACCEPT_TOKEN(anon_sym_for); - END_STATE(); - case 74: ACCEPT_TOKEN(anon_sym_for); if (sym_identifier_character_set_3(lookahead)) ADVANCE(45); END_STATE(); - case 75: + case 74: ACCEPT_TOKEN(anon_sym_in); END_STATE(); - case 76: + case 75: ACCEPT_TOKEN(anon_sym_if); END_STATE(); + case 76: + ACCEPT_TOKEN(sym_ellipsis); + END_STATE(); case 77: ACCEPT_TOKEN(sym_comment); END_STATE(); @@ -2620,10 +2620,10 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [anon_sym_DOT] = ACTIONS(1), [anon_sym_STAR] = ACTIONS(1), [anon_sym_EQ_GT] = ACTIONS(1), - [anon_sym_DOT_DOT_DOT] = ACTIONS(1), [anon_sym_for] = ACTIONS(1), [anon_sym_in] = ACTIONS(1), [anon_sym_if] = ACTIONS(1), + [sym_ellipsis] = ACTIONS(1), [sym_comment] = ACTIONS(3), }, [1] = { @@ -3762,7 +3762,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1560] = 6, ACTIONS(3), 1, sym_comment, @@ -3785,7 +3785,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1589] = 6, ACTIONS(3), 1, sym_comment, @@ -3808,7 +3808,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1618] = 6, ACTIONS(3), 1, sym_comment, @@ -3831,7 +3831,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1647] = 3, ACTIONS(3), 1, sym_comment, @@ -3850,7 +3850,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1669] = 5, ACTIONS(3), 1, sym_comment, @@ -3871,7 +3871,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1695] = 5, ACTIONS(3), 1, sym_comment, @@ -3892,7 +3892,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1721] = 5, ACTIONS(3), 1, sym_comment, @@ -3913,7 +3913,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1747] = 3, ACTIONS(3), 1, sym_comment, @@ -3930,7 +3930,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1767] = 3, ACTIONS(3), 1, sym_comment, @@ -3947,7 +3947,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1787] = 3, ACTIONS(3), 1, sym_comment, @@ -3964,7 +3964,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1807] = 3, ACTIONS(3), 1, sym_comment, @@ -3981,7 +3981,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1827] = 3, ACTIONS(3), 1, sym_comment, @@ -3998,7 +3998,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1847] = 3, ACTIONS(3), 1, sym_comment, @@ -4015,7 +4015,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1867] = 3, ACTIONS(3), 1, sym_comment, @@ -4032,7 +4032,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1887] = 3, ACTIONS(3), 1, sym_comment, @@ -4049,7 +4049,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1907] = 3, ACTIONS(3), 1, sym_comment, @@ -4066,7 +4066,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1927] = 3, ACTIONS(3), 1, sym_comment, @@ -4083,7 +4083,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1947] = 3, ACTIONS(3), 1, sym_comment, @@ -4100,7 +4100,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1967] = 3, ACTIONS(3), 1, sym_comment, @@ -4117,7 +4117,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [1987] = 3, ACTIONS(3), 1, sym_comment, @@ -4134,7 +4134,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2007] = 3, ACTIONS(3), 1, sym_comment, @@ -4151,7 +4151,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2027] = 3, ACTIONS(3), 1, sym_comment, @@ -4168,7 +4168,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2047] = 3, ACTIONS(3), 1, sym_comment, @@ -4185,7 +4185,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2067] = 3, ACTIONS(3), 1, sym_comment, @@ -4202,7 +4202,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2087] = 4, ACTIONS(3), 1, sym_comment, @@ -4220,7 +4220,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2109] = 3, ACTIONS(3), 1, sym_comment, @@ -4237,7 +4237,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2129] = 3, ACTIONS(3), 1, sym_comment, @@ -4254,7 +4254,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2149] = 3, ACTIONS(3), 1, sym_comment, @@ -4271,7 +4271,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2169] = 3, ACTIONS(3), 1, sym_comment, @@ -4288,7 +4288,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2189] = 3, ACTIONS(3), 1, sym_comment, @@ -4305,7 +4305,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2209] = 3, ACTIONS(3), 1, sym_comment, @@ -4322,7 +4322,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, anon_sym_COLON, anon_sym_EQ_GT, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2229] = 6, ACTIONS(3), 1, sym_comment, @@ -4340,8 +4340,8 @@ static const uint16_t ts_small_parse_table[] = { ACTIONS(63), 4, anon_sym_RBRACE, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2254] = 5, ACTIONS(3), 1, sym_comment, @@ -4356,8 +4356,8 @@ static const uint16_t ts_small_parse_table[] = { ACTIONS(91), 4, anon_sym_RBRACE, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2275] = 5, ACTIONS(3), 1, sym_comment, @@ -4372,8 +4372,8 @@ static const uint16_t ts_small_parse_table[] = { ACTIONS(71), 4, anon_sym_RBRACE, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2296] = 3, ACTIONS(3), 1, sym_comment, @@ -4416,8 +4416,8 @@ static const uint16_t ts_small_parse_table[] = { ACTIONS(81), 4, anon_sym_RBRACE, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2351] = 4, ACTIONS(3), 1, sym_comment, @@ -4430,8 +4430,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2369] = 4, ACTIONS(3), 1, sym_comment, @@ -4444,8 +4444,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2387] = 4, ACTIONS(3), 1, sym_comment, @@ -4458,8 +4458,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2405] = 4, ACTIONS(3), 1, sym_comment, @@ -4471,8 +4471,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2422] = 3, ACTIONS(3), 1, sym_comment, @@ -4482,8 +4482,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2436] = 3, ACTIONS(3), 1, sym_comment, @@ -4493,8 +4493,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2450] = 3, ACTIONS(3), 1, sym_comment, @@ -4504,8 +4504,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2464] = 3, ACTIONS(3), 1, sym_comment, @@ -4515,8 +4515,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2478] = 3, ACTIONS(3), 1, sym_comment, @@ -4526,8 +4526,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2492] = 3, ACTIONS(3), 1, sym_comment, @@ -4537,8 +4537,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2506] = 3, ACTIONS(3), 1, sym_comment, @@ -4548,8 +4548,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2520] = 5, ACTIONS(3), 1, sym_comment, @@ -4572,8 +4572,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2552] = 3, ACTIONS(3), 1, sym_comment, @@ -4583,8 +4583,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2566] = 4, ACTIONS(3), 1, sym_comment, @@ -4606,8 +4606,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2596] = 3, ACTIONS(3), 1, sym_comment, @@ -4617,8 +4617,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2610] = 6, ACTIONS(3), 1, sym_comment, @@ -4642,8 +4642,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2644] = 3, ACTIONS(3), 1, sym_comment, @@ -4653,8 +4653,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2658] = 3, ACTIONS(3), 1, sym_comment, @@ -4664,8 +4664,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2672] = 3, ACTIONS(3), 1, sym_comment, @@ -4675,8 +4675,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2686] = 3, ACTIONS(3), 1, sym_comment, @@ -4686,8 +4686,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2700] = 4, ACTIONS(3), 1, sym_comment, @@ -4709,8 +4709,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2730] = 3, ACTIONS(3), 1, sym_comment, @@ -4720,8 +4720,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2744] = 3, ACTIONS(3), 1, sym_comment, @@ -4731,8 +4731,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2758] = 3, ACTIONS(3), 1, sym_comment, @@ -4742,8 +4742,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2772] = 3, ACTIONS(3), 1, sym_comment, @@ -4753,8 +4753,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2786] = 5, ACTIONS(3), 1, sym_comment, @@ -4777,8 +4777,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2818] = 3, ACTIONS(3), 1, sym_comment, @@ -4788,8 +4788,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2832] = 3, ACTIONS(3), 1, sym_comment, @@ -4799,8 +4799,8 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACE, anon_sym_LBRACK, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, anon_sym_if, + sym_ellipsis, [2846] = 5, ACTIONS(3), 1, sym_comment, @@ -4834,7 +4834,7 @@ static const uint16_t ts_small_parse_table[] = { ACTIONS(289), 3, anon_sym_RPAREN, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2893] = 5, ACTIONS(3), 1, sym_comment, @@ -4855,7 +4855,7 @@ static const uint16_t ts_small_parse_table[] = { ACTIONS(302), 1, anon_sym_COMMA, ACTIONS(304), 1, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, STATE(102), 1, aux_sym_tuple_repeat1, [2926] = 2, @@ -4865,16 +4865,16 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RPAREN, anon_sym_COMMA, anon_sym_RBRACK, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, [2936] = 5, ACTIONS(3), 1, sym_comment, ACTIONS(306), 1, anon_sym_RBRACE, ACTIONS(308), 1, - anon_sym_DOT_DOT_DOT, - ACTIONS(310), 1, anon_sym_if, + ACTIONS(310), 1, + sym_ellipsis, STATE(157), 1, sym_for_cond, [2952] = 5, @@ -4885,18 +4885,18 @@ static const uint16_t ts_small_parse_table[] = { ACTIONS(314), 1, anon_sym_COMMA, ACTIONS(316), 1, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, STATE(104), 1, aux_sym_tuple_repeat1, [2968] = 5, ACTIONS(3), 1, sym_comment, - ACTIONS(310), 1, + ACTIONS(308), 1, anon_sym_if, ACTIONS(318), 1, anon_sym_RBRACE, ACTIONS(320), 1, - anon_sym_DOT_DOT_DOT, + sym_ellipsis, STATE(134), 1, sym_for_cond, [2984] = 2, @@ -4909,7 +4909,7 @@ static const uint16_t ts_small_parse_table[] = { [2993] = 4, ACTIONS(3), 1, sym_comment, - ACTIONS(310), 1, + ACTIONS(308), 1, anon_sym_if, ACTIONS(324), 1, anon_sym_RBRACK, @@ -4952,7 +4952,7 @@ static const uint16_t ts_small_parse_table[] = { [3054] = 4, ACTIONS(3), 1, sym_comment, - ACTIONS(310), 1, + ACTIONS(308), 1, anon_sym_if, ACTIONS(338), 1, anon_sym_RBRACK, @@ -4961,7 +4961,7 @@ static const uint16_t ts_small_parse_table[] = { [3067] = 4, ACTIONS(3), 1, sym_comment, - ACTIONS(310), 1, + ACTIONS(308), 1, anon_sym_if, ACTIONS(340), 1, anon_sym_RBRACE, @@ -5004,7 +5004,7 @@ static const uint16_t ts_small_parse_table[] = { [3128] = 4, ACTIONS(3), 1, sym_comment, - ACTIONS(310), 1, + ACTIONS(308), 1, anon_sym_if, ACTIONS(350), 1, anon_sym_RBRACE, @@ -5567,8 +5567,8 @@ static const TSParseActionEntry ts_parse_actions[] = { [302] = {.entry = {.count = 1, .reusable = true}}, SHIFT(12), [304] = {.entry = {.count = 1, .reusable = true}}, SHIFT(150), [306] = {.entry = {.count = 1, .reusable = true}}, SHIFT(83), - [308] = {.entry = {.count = 1, .reusable = true}}, SHIFT(121), - [310] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), + [308] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), + [310] = {.entry = {.count = 1, .reusable = true}}, SHIFT(121), [312] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_function_arguments, 1), [314] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10), [316] = {.entry = {.count = 1, .reusable = true}}, SHIFT(139), diff --git a/test/corpus/for_expressions.txt b/test/corpus/for_expressions.txt index 163de0e..7d5f7a1 100644 --- a/test/corpus/for_expressions.txt +++ b/test/corpus/for_expressions.txt @@ -24,3 +24,85 @@ foo = [for v in ["a", "b"]: v] (expression (expr_term (literal_value (string_lit))))))))) (expression (expr_term (variable_expr (identifier))))))))))) +================== +for tuple expression with index +================== + +foo = [for i, v in ["a", "b"]: i] + +--- + +(config_file + (body + (attribute + (identifier) + (expression + (expr_term + (for_expr + (for_tuple_expr + (for_intro + (identifier) + (identifier) + (expression + (expr_term + (collection_value + (tuple + (expression (expr_term (literal_value (string_lit)))) + (expression (expr_term (literal_value (string_lit))))))))) + (expression (expr_term (variable_expr (identifier))))))))))) + +================== +for object expression +================== + +foo = {for i, v in ["a", "b"]: v => i} + +--- + +(config_file + (body + (attribute + (identifier) + (expression + (expr_term + (for_expr + (for_object_expr + (for_intro + (identifier) + (identifier) + (expression + (expr_term + (collection_value + (tuple + (expression (expr_term (literal_value (string_lit)))) + (expression (expr_term (literal_value (string_lit))))))))) + (expression (expr_term (variable_expr (identifier)))) + (expression (expr_term (variable_expr (identifier))))))))))) + +================== +for object expression 2 +================== + +foo = {for i, v in ["a", "b"]: v => i...} + +--- + +(config_file + (body + (attribute + (identifier) + (expression + (expr_term + (for_expr + (for_object_expr + (for_intro + (identifier) + (identifier) + (expression + (expr_term + (collection_value + (tuple + (expression (expr_term (literal_value (string_lit)))) + (expression (expr_term (literal_value (string_lit))))))))) + (expression (expr_term (variable_expr (identifier)))) + (expression (expr_term (variable_expr (identifier)))) (ellipsis)))))))) diff --git a/test/corpus/function_calls.txt b/test/corpus/function_calls.txt index 989dfba..f6303f5 100644 --- a/test/corpus/function_calls.txt +++ b/test/corpus/function_calls.txt @@ -54,10 +54,7 @@ foo = bar(x...) (function_call (identifier) (function_arguments - (expression - (expr_term - (variable_expr - (identifier))))))))))) + (expression (expr_term (variable_expr (identifier)))) (ellipsis)))))))) ================== multiline function call