Fix expansion of repeat rules into recursive rules

Previously, the way repeat rules were expanded, the auxiliary
rule always needed to be reduced, even if the repeating content
was empty. This caused problems in parse states where some items
contained the repeat rule and some did not. To make those cases
work, the repeat rule had to explicitly be marked as optional.
With this change, that is no longer necessary.
This commit is contained in:
Max Brunsfeld 2014-09-07 08:50:42 -07:00
parent 43ecac2a1d
commit ed11ef557a
10 changed files with 48641 additions and 39051 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
#include "tree_sitter/parser.h"
#define STATE_COUNT 60
#define STATE_COUNT 69
#define SYMBOL_COUNT 19
enum {
@ -378,51 +378,60 @@ static TSStateId ts_lex_states[STATE_COUNT] = {
[12] = 32,
[13] = 1,
[14] = 30,
[15] = 32,
[16] = 30,
[17] = 33,
[18] = 34,
[19] = 30,
[20] = 1,
[21] = 33,
[15] = 30,
[16] = 32,
[17] = 30,
[18] = 33,
[19] = 34,
[20] = 30,
[21] = 1,
[22] = 33,
[23] = 26,
[24] = 28,
[25] = 30,
[26] = 33,
[27] = 32,
[28] = 33,
[23] = 33,
[24] = 26,
[25] = 28,
[26] = 30,
[27] = 33,
[28] = 32,
[29] = 33,
[30] = 34,
[30] = 33,
[31] = 33,
[32] = 1,
[32] = 34,
[33] = 33,
[34] = 36,
[35] = 37,
[36] = 33,
[37] = 34,
[38] = 1,
[34] = 1,
[35] = 33,
[36] = 36,
[37] = 37,
[38] = 33,
[39] = 33,
[40] = 36,
[41] = 36,
[40] = 34,
[41] = 1,
[42] = 33,
[43] = 36,
[44] = 33,
[45] = 36,
[46] = 30,
[47] = 36,
[48] = 30,
[49] = 32,
[50] = 24,
[51] = 33,
[52] = 34,
[53] = 24,
[54] = 1,
[55] = 33,
[56] = 36,
[44] = 36,
[45] = 33,
[46] = 36,
[47] = 33,
[48] = 33,
[49] = 36,
[50] = 30,
[51] = 30,
[52] = 36,
[53] = 30,
[54] = 30,
[55] = 32,
[56] = 24,
[57] = 24,
[58] = 36,
[59] = 24,
[58] = 33,
[59] = 34,
[60] = 24,
[61] = 1,
[62] = 33,
[63] = 36,
[64] = 24,
[65] = 24,
[66] = 36,
[67] = 24,
[68] = 24,
};
#pragma GCC diagnostic push
@ -448,9 +457,9 @@ static const TSParseAction ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] = {
[ts_builtin_sym_end] = REDUCE(ts_sym_value, 1),
},
[3] = {
[ts_builtin_sym_error] = SHIFT(51),
[ts_sym_string] = SHIFT(52),
[ts_aux_sym_4] = SHIFT(53),
[ts_builtin_sym_error] = SHIFT(58),
[ts_sym_string] = SHIFT(59),
[ts_aux_sym_4] = SHIFT(60),
},
[4] = {
[ts_sym_value] = SHIFT(5),
@ -467,18 +476,18 @@ static const TSParseAction ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] = {
[ts_aux_sym_6] = SHIFT(9),
},
[5] = {
[ts_aux_sym_array_repeat0] = SHIFT(49),
[ts_aux_sym_array_repeat0] = SHIFT(55),
[ts_aux_sym_3] = SHIFT(13),
[ts_aux_sym_6] = REDUCE(ts_aux_sym_array_repeat0, 0),
[ts_aux_sym_6] = SHIFT(56),
},
[6] = {
[ts_aux_sym_3] = REDUCE(ts_sym_value, 1),
[ts_aux_sym_6] = REDUCE(ts_sym_value, 1),
},
[7] = {
[ts_builtin_sym_error] = SHIFT(17),
[ts_sym_string] = SHIFT(18),
[ts_aux_sym_4] = SHIFT(19),
[ts_builtin_sym_error] = SHIFT(18),
[ts_sym_string] = SHIFT(19),
[ts_aux_sym_4] = SHIFT(20),
},
[8] = {
[ts_sym_value] = SHIFT(10),
@ -500,20 +509,20 @@ static const TSParseAction ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] = {
[10] = {
[ts_aux_sym_array_repeat0] = SHIFT(12),
[ts_aux_sym_3] = SHIFT(13),
[ts_aux_sym_6] = REDUCE(ts_aux_sym_array_repeat0, 0),
[ts_aux_sym_6] = SHIFT(14),
},
[11] = {
[ts_aux_sym_3] = REDUCE(ts_sym_array, 2),
[ts_aux_sym_6] = REDUCE(ts_sym_array, 2),
},
[12] = {
[ts_aux_sym_6] = SHIFT(16),
[ts_aux_sym_6] = SHIFT(17),
},
[13] = {
[ts_sym_value] = SHIFT(14),
[ts_sym_value] = SHIFT(15),
[ts_sym_object] = SHIFT(6),
[ts_sym_array] = SHIFT(6),
[ts_builtin_sym_error] = SHIFT(14),
[ts_builtin_sym_error] = SHIFT(15),
[ts_sym_string] = SHIFT(6),
[ts_sym_number] = SHIFT(6),
[ts_sym_null] = SHIFT(6),
@ -523,60 +532,64 @@ static const TSParseAction ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] = {
[ts_aux_sym_5] = SHIFT(8),
},
[14] = {
[ts_aux_sym_array_repeat0] = SHIFT(15),
[ts_aux_sym_3] = SHIFT(13),
[ts_aux_sym_6] = REDUCE(ts_aux_sym_array_repeat0, 0),
[ts_aux_sym_3] = REDUCE(ts_sym_array, 3),
[ts_aux_sym_6] = REDUCE(ts_sym_array, 3),
},
[15] = {
[ts_aux_sym_6] = REDUCE(ts_aux_sym_array_repeat0, 3),
[ts_aux_sym_array_repeat0] = SHIFT(16),
[ts_aux_sym_3] = SHIFT(13),
[ts_aux_sym_6] = REDUCE(ts_aux_sym_array_repeat0, 2),
},
[16] = {
[ts_aux_sym_6] = REDUCE(ts_aux_sym_array_repeat0, 3),
},
[17] = {
[ts_aux_sym_3] = REDUCE(ts_sym_array, 4),
[ts_aux_sym_6] = REDUCE(ts_sym_array, 4),
},
[17] = {
[ts_aux_sym_object_repeat0] = SHIFT(47),
[ts_aux_sym_3] = SHIFT(35),
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 0),
},
[18] = {
[ts_aux_sym_2] = SHIFT(20),
[ts_aux_sym_object_repeat0] = SHIFT(52),
[ts_aux_sym_3] = SHIFT(37),
[ts_aux_sym_4] = SHIFT(53),
},
[19] = {
[ts_aux_sym_2] = SHIFT(21),
},
[20] = {
[ts_aux_sym_3] = REDUCE(ts_sym_object, 2),
[ts_aux_sym_6] = REDUCE(ts_sym_object, 2),
},
[20] = {
[ts_sym_value] = SHIFT(21),
[ts_sym_object] = SHIFT(22),
[ts_sym_array] = SHIFT(22),
[ts_sym_string] = SHIFT(22),
[ts_sym_number] = SHIFT(22),
[ts_sym_null] = SHIFT(22),
[ts_sym_true] = SHIFT(22),
[ts_sym_false] = SHIFT(22),
[ts_aux_sym_1] = SHIFT(23),
[ts_aux_sym_5] = SHIFT(24),
},
[21] = {
[ts_aux_sym_object_repeat0] = SHIFT(45),
[ts_aux_sym_3] = SHIFT(35),
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 0),
[ts_sym_value] = SHIFT(22),
[ts_sym_object] = SHIFT(23),
[ts_sym_array] = SHIFT(23),
[ts_sym_string] = SHIFT(23),
[ts_sym_number] = SHIFT(23),
[ts_sym_null] = SHIFT(23),
[ts_sym_true] = SHIFT(23),
[ts_sym_false] = SHIFT(23),
[ts_aux_sym_1] = SHIFT(24),
[ts_aux_sym_5] = SHIFT(25),
},
[22] = {
[ts_aux_sym_object_repeat0] = SHIFT(49),
[ts_aux_sym_3] = SHIFT(37),
[ts_aux_sym_4] = SHIFT(50),
},
[23] = {
[ts_aux_sym_3] = REDUCE(ts_sym_value, 1),
[ts_aux_sym_4] = REDUCE(ts_sym_value, 1),
},
[23] = {
[ts_builtin_sym_error] = SHIFT(29),
[ts_sym_string] = SHIFT(30),
[ts_aux_sym_4] = SHIFT(31),
},
[24] = {
[ts_sym_value] = SHIFT(25),
[ts_builtin_sym_error] = SHIFT(31),
[ts_sym_string] = SHIFT(32),
[ts_aux_sym_4] = SHIFT(33),
},
[25] = {
[ts_sym_value] = SHIFT(26),
[ts_sym_object] = SHIFT(6),
[ts_sym_array] = SHIFT(6),
[ts_builtin_sym_error] = SHIFT(25),
[ts_builtin_sym_error] = SHIFT(26),
[ts_sym_string] = SHIFT(6),
[ts_sym_number] = SHIFT(6),
[ts_sym_null] = SHIFT(6),
@ -584,160 +597,189 @@ static const TSParseAction ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] = {
[ts_sym_false] = SHIFT(6),
[ts_aux_sym_1] = SHIFT(7),
[ts_aux_sym_5] = SHIFT(8),
[ts_aux_sym_6] = SHIFT(26),
},
[25] = {
[ts_aux_sym_array_repeat0] = SHIFT(27),
[ts_aux_sym_3] = SHIFT(13),
[ts_aux_sym_6] = REDUCE(ts_aux_sym_array_repeat0, 0),
[ts_aux_sym_6] = SHIFT(27),
},
[26] = {
[ts_aux_sym_array_repeat0] = SHIFT(28),
[ts_aux_sym_3] = SHIFT(13),
[ts_aux_sym_6] = SHIFT(29),
},
[27] = {
[ts_aux_sym_3] = REDUCE(ts_sym_array, 2),
[ts_aux_sym_4] = REDUCE(ts_sym_array, 2),
},
[27] = {
[ts_aux_sym_6] = SHIFT(28),
},
[28] = {
[ts_aux_sym_6] = SHIFT(30),
},
[29] = {
[ts_aux_sym_3] = REDUCE(ts_sym_array, 3),
[ts_aux_sym_4] = REDUCE(ts_sym_array, 3),
},
[30] = {
[ts_aux_sym_3] = REDUCE(ts_sym_array, 4),
[ts_aux_sym_4] = REDUCE(ts_sym_array, 4),
},
[29] = {
[ts_aux_sym_object_repeat0] = SHIFT(43),
[ts_aux_sym_3] = SHIFT(35),
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 0),
},
[30] = {
[ts_aux_sym_2] = SHIFT(32),
},
[31] = {
[ts_aux_sym_object_repeat0] = SHIFT(46),
[ts_aux_sym_3] = SHIFT(37),
[ts_aux_sym_4] = SHIFT(47),
},
[32] = {
[ts_aux_sym_2] = SHIFT(34),
},
[33] = {
[ts_aux_sym_3] = REDUCE(ts_sym_object, 2),
[ts_aux_sym_4] = REDUCE(ts_sym_object, 2),
},
[32] = {
[ts_sym_value] = SHIFT(33),
[ts_sym_object] = SHIFT(22),
[ts_sym_array] = SHIFT(22),
[ts_sym_string] = SHIFT(22),
[ts_sym_number] = SHIFT(22),
[ts_sym_null] = SHIFT(22),
[ts_sym_true] = SHIFT(22),
[ts_sym_false] = SHIFT(22),
[ts_aux_sym_1] = SHIFT(23),
[ts_aux_sym_5] = SHIFT(24),
},
[33] = {
[ts_aux_sym_object_repeat0] = SHIFT(34),
[ts_aux_sym_3] = SHIFT(35),
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 0),
},
[34] = {
[ts_aux_sym_4] = SHIFT(42),
[ts_sym_value] = SHIFT(35),
[ts_sym_object] = SHIFT(23),
[ts_sym_array] = SHIFT(23),
[ts_sym_string] = SHIFT(23),
[ts_sym_number] = SHIFT(23),
[ts_sym_null] = SHIFT(23),
[ts_sym_true] = SHIFT(23),
[ts_sym_false] = SHIFT(23),
[ts_aux_sym_1] = SHIFT(24),
[ts_aux_sym_5] = SHIFT(25),
},
[35] = {
[ts_builtin_sym_error] = SHIFT(36),
[ts_sym_string] = SHIFT(37),
[ts_aux_sym_object_repeat0] = SHIFT(36),
[ts_aux_sym_3] = SHIFT(37),
[ts_aux_sym_4] = SHIFT(38),
},
[36] = {
[ts_aux_sym_object_repeat0] = SHIFT(41),
[ts_aux_sym_3] = SHIFT(35),
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 0),
[ts_aux_sym_4] = SHIFT(45),
},
[37] = {
[ts_aux_sym_2] = SHIFT(38),
[ts_builtin_sym_error] = SHIFT(39),
[ts_sym_string] = SHIFT(40),
},
[38] = {
[ts_sym_value] = SHIFT(39),
[ts_sym_object] = SHIFT(22),
[ts_sym_array] = SHIFT(22),
[ts_sym_string] = SHIFT(22),
[ts_sym_number] = SHIFT(22),
[ts_sym_null] = SHIFT(22),
[ts_sym_true] = SHIFT(22),
[ts_sym_false] = SHIFT(22),
[ts_aux_sym_1] = SHIFT(23),
[ts_aux_sym_5] = SHIFT(24),
[ts_aux_sym_3] = REDUCE(ts_sym_object, 5),
[ts_aux_sym_4] = REDUCE(ts_sym_object, 5),
},
[39] = {
[ts_aux_sym_object_repeat0] = SHIFT(40),
[ts_aux_sym_3] = SHIFT(35),
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 0),
[ts_aux_sym_object_repeat0] = SHIFT(44),
[ts_aux_sym_3] = SHIFT(37),
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 2),
},
[40] = {
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 5),
[ts_aux_sym_2] = SHIFT(41),
},
[41] = {
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 3),
[ts_sym_value] = SHIFT(42),
[ts_sym_object] = SHIFT(23),
[ts_sym_array] = SHIFT(23),
[ts_sym_string] = SHIFT(23),
[ts_sym_number] = SHIFT(23),
[ts_sym_null] = SHIFT(23),
[ts_sym_true] = SHIFT(23),
[ts_sym_false] = SHIFT(23),
[ts_aux_sym_1] = SHIFT(24),
[ts_aux_sym_5] = SHIFT(25),
},
[42] = {
[ts_aux_sym_object_repeat0] = SHIFT(43),
[ts_aux_sym_3] = SHIFT(37),
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 4),
},
[43] = {
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 5),
},
[44] = {
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 3),
},
[45] = {
[ts_aux_sym_3] = REDUCE(ts_sym_object, 6),
[ts_aux_sym_4] = REDUCE(ts_sym_object, 6),
},
[43] = {
[ts_aux_sym_4] = SHIFT(44),
},
[44] = {
[ts_aux_sym_3] = REDUCE(ts_sym_object, 4),
[ts_aux_sym_4] = REDUCE(ts_sym_object, 4),
},
[45] = {
[ts_aux_sym_4] = SHIFT(46),
},
[46] = {
[ts_aux_sym_3] = REDUCE(ts_sym_object, 6),
[ts_aux_sym_6] = REDUCE(ts_sym_object, 6),
[ts_aux_sym_4] = SHIFT(48),
},
[47] = {
[ts_aux_sym_4] = SHIFT(48),
[ts_aux_sym_3] = REDUCE(ts_sym_object, 3),
[ts_aux_sym_4] = REDUCE(ts_sym_object, 3),
},
[48] = {
[ts_aux_sym_3] = REDUCE(ts_sym_object, 4),
[ts_aux_sym_6] = REDUCE(ts_sym_object, 4),
[ts_aux_sym_4] = REDUCE(ts_sym_object, 4),
},
[49] = {
[ts_aux_sym_6] = SHIFT(50),
[ts_aux_sym_4] = SHIFT(51),
},
[50] = {
[ts_builtin_sym_end] = REDUCE(ts_sym_array, 4),
[ts_aux_sym_3] = REDUCE(ts_sym_object, 5),
[ts_aux_sym_6] = REDUCE(ts_sym_object, 5),
},
[51] = {
[ts_aux_sym_object_repeat0] = SHIFT(58),
[ts_aux_sym_3] = SHIFT(35),
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 0),
[ts_aux_sym_3] = REDUCE(ts_sym_object, 6),
[ts_aux_sym_6] = REDUCE(ts_sym_object, 6),
},
[52] = {
[ts_aux_sym_2] = SHIFT(54),
[ts_aux_sym_4] = SHIFT(54),
},
[53] = {
[ts_builtin_sym_end] = REDUCE(ts_sym_object, 2),
[ts_aux_sym_3] = REDUCE(ts_sym_object, 3),
[ts_aux_sym_6] = REDUCE(ts_sym_object, 3),
},
[54] = {
[ts_sym_value] = SHIFT(55),
[ts_sym_object] = SHIFT(22),
[ts_sym_array] = SHIFT(22),
[ts_sym_string] = SHIFT(22),
[ts_sym_number] = SHIFT(22),
[ts_sym_null] = SHIFT(22),
[ts_sym_true] = SHIFT(22),
[ts_sym_false] = SHIFT(22),
[ts_aux_sym_1] = SHIFT(23),
[ts_aux_sym_5] = SHIFT(24),
[ts_aux_sym_3] = REDUCE(ts_sym_object, 4),
[ts_aux_sym_6] = REDUCE(ts_sym_object, 4),
},
[55] = {
[ts_aux_sym_object_repeat0] = SHIFT(56),
[ts_aux_sym_3] = SHIFT(35),
[ts_aux_sym_4] = REDUCE(ts_aux_sym_object_repeat0, 0),
[ts_aux_sym_6] = SHIFT(57),
},
[56] = {
[ts_aux_sym_4] = SHIFT(57),
[ts_builtin_sym_end] = REDUCE(ts_sym_array, 3),
},
[57] = {
[ts_builtin_sym_end] = REDUCE(ts_sym_object, 6),
[ts_builtin_sym_end] = REDUCE(ts_sym_array, 4),
},
[58] = {
[ts_aux_sym_4] = SHIFT(59),
[ts_aux_sym_object_repeat0] = SHIFT(66),
[ts_aux_sym_3] = SHIFT(37),
[ts_aux_sym_4] = SHIFT(67),
},
[59] = {
[ts_aux_sym_2] = SHIFT(61),
},
[60] = {
[ts_builtin_sym_end] = REDUCE(ts_sym_object, 2),
},
[61] = {
[ts_sym_value] = SHIFT(62),
[ts_sym_object] = SHIFT(23),
[ts_sym_array] = SHIFT(23),
[ts_sym_string] = SHIFT(23),
[ts_sym_number] = SHIFT(23),
[ts_sym_null] = SHIFT(23),
[ts_sym_true] = SHIFT(23),
[ts_sym_false] = SHIFT(23),
[ts_aux_sym_1] = SHIFT(24),
[ts_aux_sym_5] = SHIFT(25),
},
[62] = {
[ts_aux_sym_object_repeat0] = SHIFT(63),
[ts_aux_sym_3] = SHIFT(37),
[ts_aux_sym_4] = SHIFT(64),
},
[63] = {
[ts_aux_sym_4] = SHIFT(65),
},
[64] = {
[ts_builtin_sym_end] = REDUCE(ts_sym_object, 5),
},
[65] = {
[ts_builtin_sym_end] = REDUCE(ts_sym_object, 6),
},
[66] = {
[ts_aux_sym_4] = SHIFT(68),
},
[67] = {
[ts_builtin_sym_end] = REDUCE(ts_sym_object, 3),
},
[68] = {
[ts_builtin_sym_end] = REDUCE(ts_sym_object, 4),
},
};