diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index 45da0fea..24db131c 100644 --- a/lib/lrama/parser.rb +++ b/lib/lrama/parser.rb @@ -733,90 +733,90 @@ def raise_parse_error(error_message, location) racc_action_table = [ 98, 51, 99, 163, 88, 79, 51, 51, 179, 163, - 79, 79, 51, 162, 179, 156, 79, 165, 157, 3, - 8, 203, 180, 165, 186, 187, 188, 96, 180, 186, - 187, 188, 41, 48, 51, 161, 50, 47, 51, 70, - 50, 54, 89, 82, 51, 166, 50, 54, 100, 82, - 181, 166, 216, 54, 57, 217, 181, 23, 25, 26, + 79, 79, 51, 162, 179, 156, 79, 165, 157, 51, + 3, 50, 180, 165, 70, 51, 8, 50, 180, 79, + 75, 51, 6, 50, 7, 161, 82, 47, 51, 51, + 50, 50, 89, 82, 82, 166, 41, 51, 100, 50, + 181, 166, 82, 51, 48, 50, 181, 23, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, - 37, 38, 47, 6, 51, 7, 50, 93, 79, 75, - 51, 51, 50, 50, 58, 82, 82, 51, 51, 50, - 50, 79, 23, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 9, 51, 59, - 50, 14, 15, 16, 17, 18, 19, 60, 61, 20, + 37, 38, 47, 51, 51, 50, 50, 93, 79, 196, + 51, 51, 50, 50, 79, 196, 51, 51, 50, 50, + 79, 196, 23, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 9, 51, 54, + 50, 14, 15, 16, 17, 18, 19, 54, 54, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 51, 51, 50, 50, 79, 196, 51, 51, 50, 50, 79, 196, 51, 51, 50, 50, 79, 196, 51, 51, 50, 50, - 79, 196, 51, 51, 50, 50, 79, 196, 51, 51, - 50, 50, 79, 196, 51, 51, 50, 50, 79, 79, - 51, 51, 50, 50, 79, 79, 51, 51, 50, 50, - 79, 79, 51, 51, 206, 206, 79, 79, 51, 51, - 206, 50, 79, 79, 220, 227, 62, 217, 217, 51, - 51, 50, 50, 51, 63, 50, 186, 187, 188, 64, + 79, 79, 51, 51, 50, 50, 79, 79, 51, 51, + 50, 50, 79, 79, 51, 51, 50, 206, 79, 79, + 51, 51, 206, 206, 79, 79, 51, 51, 50, 50, + 79, 186, 187, 188, 96, 186, 187, 188, 96, 216, + 220, 227, 217, 217, 217, 51, 51, 50, 50, 186, + 187, 188, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 90, 94, 96, 101, 101, 101, 103, 109, 113, 114, 117, 117, 117, 117, 120, 47, 124, 125, 127, 129, 130, 131, 132, 133, 136, 140, 141, 142, 143, 146, 147, 148, 150, 160, 168, 170, 171, 172, 173, 174, 175, 176, 177, 146, 183, 191, 192, - 160, 160, 96, 210, 211, 177, 214, 215, 210, 225, + 160, 160, 203, 210, 211, 177, 214, 215, 210, 225, 226, 96, 96, 210 ] racc_action_check = [ 49, 145, 49, 145, 39, 145, 159, 182, 159, 182, - 159, 182, 200, 144, 200, 139, 200, 145, 139, 1, - 3, 179, 159, 182, 164, 164, 164, 164, 200, 179, - 179, 179, 7, 14, 33, 144, 33, 9, 35, 33, - 35, 16, 39, 35, 36, 145, 36, 17, 49, 36, - 159, 182, 207, 18, 19, 207, 200, 9, 9, 9, + 159, 182, 200, 144, 200, 139, 200, 145, 139, 33, + 1, 33, 159, 182, 33, 34, 3, 34, 200, 34, + 34, 35, 2, 35, 2, 144, 35, 9, 36, 37, + 36, 37, 39, 36, 37, 145, 7, 38, 49, 38, + 159, 182, 38, 15, 14, 15, 200, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 42, 2, 34, 2, 34, 42, 34, 34, - 37, 38, 37, 38, 20, 37, 38, 74, 15, 74, - 15, 74, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 4, 69, 23, - 69, 4, 4, 4, 4, 4, 4, 25, 26, 4, + 9, 9, 42, 69, 172, 69, 172, 42, 172, 172, + 173, 70, 173, 70, 173, 173, 174, 81, 174, 81, + 174, 174, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 4, 82, 16, + 82, 4, 4, 4, 4, 4, 4, 17, 18, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 172, 70, - 172, 70, 172, 172, 173, 81, 173, 81, 173, 173, - 174, 82, 174, 82, 174, 174, 193, 109, 193, 109, - 193, 193, 197, 111, 197, 111, 197, 197, 198, 117, - 198, 117, 198, 198, 75, 114, 75, 114, 75, 114, - 116, 137, 116, 137, 116, 137, 166, 181, 166, 181, - 166, 181, 183, 203, 183, 203, 183, 203, 215, 217, - 215, 217, 215, 217, 213, 222, 27, 213, 222, 119, - 134, 119, 134, 138, 28, 138, 208, 208, 208, 29, + 4, 4, 4, 4, 4, 4, 4, 4, 193, 109, + 193, 109, 193, 193, 197, 111, 197, 111, 197, 197, + 198, 117, 198, 117, 198, 198, 74, 75, 74, 75, + 74, 75, 114, 116, 114, 116, 114, 116, 137, 166, + 137, 166, 137, 166, 181, 183, 181, 183, 181, 183, + 203, 215, 203, 215, 203, 215, 217, 119, 217, 119, + 217, 164, 164, 164, 164, 178, 178, 178, 178, 207, + 213, 222, 207, 213, 222, 134, 138, 134, 138, 208, + 208, 208, 19, 20, 23, 25, 26, 27, 28, 29, 30, 31, 32, 40, 45, 46, 53, 55, 56, 57, 68, 72, 73, 80, 85, 86, 87, 88, 89, 95, 96, 102, 104, 105, 106, 107, 108, 112, 120, 121, 122, 123, 124, 125, 126, 128, 141, 149, 151, 152, 153, 154, 155, 156, 157, 158, 161, 163, 167, 169, - 175, 177, 178, 185, 189, 199, 204, 206, 216, 219, + 175, 177, 179, 185, 189, 199, 204, 206, 216, 219, 221, 225, 226, 228 ] racc_action_pointer = [ - nil, 19, 63, 20, 98, nil, nil, 25, nil, 33, - nil, nil, nil, nil, 27, 85, 22, 28, 34, 49, - 65, nil, nil, 90, nil, 98, 99, 187, 209, 214, - 215, 216, 217, 31, 71, 35, 41, 77, 78, -1, + nil, 20, 22, 26, 98, nil, nil, 39, nil, 33, + nil, nil, nil, nil, 48, 50, 90, 98, 99, 207, + 194, nil, nil, 195, nil, 196, 197, 198, 213, 214, + 215, 216, 217, 16, 22, 28, 35, 36, 44, -1, 221, nil, 68, nil, nil, 201, 174, nil, nil, -5, nil, nil, nil, 207, nil, 208, 209, 210, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, 222, 105, - 136, nil, 225, 224, 84, 171, nil, nil, nil, nil, - 225, 142, 148, nil, nil, 226, 227, 228, 197, 234, + nil, nil, nil, nil, nil, nil, nil, nil, 222, 70, + 78, nil, 225, 224, 153, 154, nil, nil, nil, nil, + 225, 84, 105, nil, nil, 226, 227, 228, 197, 234, nil, nil, nil, nil, nil, 197, 235, nil, nil, nil, - nil, nil, 239, nil, 240, 241, 242, 243, 244, 154, - nil, 160, 240, nil, 172, nil, 177, 166, nil, 206, + nil, nil, 239, nil, 240, 241, 242, 243, 244, 136, + nil, 142, 240, nil, 159, nil, 160, 148, nil, 184, 243, 207, 239, 249, 206, 201, 252, nil, 253, nil, - nil, nil, nil, nil, 207, nil, nil, 178, 210, -26, + nil, nil, nil, nil, 202, nil, nil, 165, 203, -26, nil, 210, nil, nil, -10, -2, nil, nil, nil, 237, nil, 238, 239, 240, 241, 242, 221, 259, 220, 3, - nil, 220, nil, 227, -24, nil, 183, 248, nil, 249, - nil, nil, 135, 141, 147, 224, nil, 225, 221, -19, - nil, 184, 4, 189, nil, 265, nil, nil, nil, 272, - nil, nil, nil, 153, nil, nil, nil, 159, 165, 230, - 9, nil, nil, 190, 274, nil, 237, 11, 168, nil, - nil, nil, nil, 163, nil, 195, 270, 196, nil, 259, - nil, 260, 164, nil, nil, 230, 231, nil, 275, nil, + nil, 220, nil, 227, 143, nil, 166, 248, nil, 249, + nil, nil, 71, 77, 83, 224, nil, 225, 147, 232, + nil, 171, 4, 172, nil, 265, nil, nil, nil, 272, + nil, nil, nil, 135, nil, nil, nil, 141, 147, 230, + 9, nil, nil, 177, 274, nil, 237, 158, 161, nil, + nil, nil, nil, 159, nil, 178, 270, 183, nil, 259, + nil, 260, 160, nil, nil, 230, 231, nil, 275, nil, nil ] racc_action_default = [ @@ -846,12 +846,12 @@ def raise_parse_error(error_message, location) -111 ] racc_goto_table = [ - 76, 74, 69, 52, 209, 95, 110, 118, 119, 145, - 158, 1, 185, 2, 4, 212, 43, 42, 207, 212, - 212, 72, 91, 84, 84, 84, 84, 202, 80, 85, - 86, 87, 53, 55, 56, 223, 5, 40, 213, 111, - 115, 76, 116, 138, 199, 118, 182, 230, 110, 92, - 222, 193, 197, 198, 122, 10, 218, 72, 72, 11, + 76, 74, 69, 52, 209, 95, 110, 118, 185, 145, + 158, 207, 1, 2, 119, 212, 4, 43, 42, 212, + 212, 72, 202, 84, 84, 84, 84, 80, 85, 86, + 87, 213, 53, 55, 56, 223, 193, 197, 198, 111, + 115, 76, 116, 222, 199, 118, 182, 230, 110, 138, + 92, 91, 218, 5, 40, 122, 10, 72, 72, 11, 12, 13, 49, 97, 118, 128, 169, 104, 151, 84, 84, 110, 105, 152, 106, 153, 107, 154, 134, 108, 76, 137, 115, 155, 68, 73, 112, 135, 139, 121, @@ -867,12 +867,12 @@ def raise_parse_error(error_message, location) nil, 208, nil, 224, 228, 229 ] racc_goto_check = [ - 42, 48, 33, 35, 60, 43, 34, 55, 54, 59, - 39, 1, 44, 2, 3, 64, 56, 4, 45, 64, - 64, 35, 5, 35, 35, 35, 35, 44, 32, 32, - 32, 32, 15, 15, 15, 60, 6, 7, 45, 33, - 42, 42, 48, 54, 39, 55, 59, 60, 34, 56, - 45, 21, 21, 21, 8, 9, 44, 35, 35, 10, + 42, 48, 33, 35, 60, 43, 34, 55, 44, 59, + 39, 45, 1, 2, 54, 64, 3, 56, 4, 64, + 64, 35, 44, 35, 35, 35, 35, 32, 32, 32, + 32, 45, 15, 15, 15, 60, 21, 21, 21, 33, + 42, 42, 48, 45, 39, 55, 59, 60, 34, 54, + 56, 5, 44, 6, 7, 8, 9, 35, 35, 10, 11, 12, 13, 14, 55, 16, 17, 18, 19, 35, 35, 34, 22, 23, 24, 25, 26, 27, 33, 28, 42, 48, 42, 29, 30, 31, 36, 37, 38, 40, @@ -888,12 +888,12 @@ def raise_parse_error(error_message, location) nil, 42, nil, 42, 43, 43 ] racc_goto_pointer = [ - nil, 11, 13, 12, 8, -20, 34, 31, -36, 51, + nil, 12, 13, 14, 9, 9, 51, 48, -35, 52, 55, 56, 57, 47, 14, 16, -38, -84, 9, -61, - nil, -121, 13, -57, 14, -56, 15, -55, 17, -50, - 51, 51, -7, -31, -63, -12, 14, -25, -32, -131, - 0, -87, -34, -41, -152, -165, -89, -122, -33, nil, - -8, -54, 41, -31, -74, -74, 7, nil, -26, -115, + nil, -136, 13, -57, 14, -56, 15, -55, 17, -50, + 51, 51, -8, -31, -63, -12, 14, -25, -32, -131, + 0, -87, -34, -41, -156, -172, -89, -122, -33, nil, + -8, -54, 41, -31, -68, -74, 8, nil, -26, -115, -181, -65, -110, 9, -178 ] racc_goto_default = [ diff --git a/parser.y b/parser.y index 878e7a59..f82c4fb7 100644 --- a/parser.y +++ b/parser.y @@ -276,7 +276,7 @@ rule builder.symbols << token result = builder } - | rule_rhs IDENTIFIER parameterizing_suffix + | rule_rhs symbol parameterizing_suffix { builder = val[0] builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]]) diff --git a/spec/fixtures/parameterizing_rules/user_defined_with_nest.y b/spec/fixtures/parameterizing_rules/user_defined_with_nest.y index 10ca701f..8e3b26f3 100644 --- a/spec/fixtures/parameterizing_rules/user_defined_with_nest.y +++ b/spec/fixtures/parameterizing_rules/user_defined_with_nest.y @@ -37,10 +37,15 @@ static int yyerror(YYLTYPE *loc, const char *str); | nested_multi_option(Y) X ; +%rule with_word_seps(X): /* empty */ + | X ' '+ + ; + %% program : option(number) | multi_option(number, string) + | with_word_seps(string) ; %% diff --git a/spec/lrama/parser_spec.rb b/spec/lrama/parser_spec.rb index a32f6b42..a0df4d5e 100644 --- a/spec/lrama/parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -1632,14 +1632,16 @@ it "expands parameterizing rules" do expect(grammar.nterms.sort_by(&:number)).to match_symbols([ - Sym.new(id: T::Ident.new(s_value: "$accept"), alias_name: nil, number: 5, tag: nil, term: false, token_id: 0, nullable: false), - Sym.new(id: T::Ident.new(s_value: "option_number"), alias_name: nil, number: 6, tag: nil, term: false, token_id: 1, nullable: true), - Sym.new(id: T::Ident.new(s_value: "nested_option_number"), alias_name: nil, number: 7, tag: nil, term: false, token_id: 2, nullable: true), - Sym.new(id: T::Ident.new(s_value: "nested_nested_option_number"), alias_name: nil, number: 8, tag: nil, term: false, token_id: 3, nullable: true), - Sym.new(id: T::Ident.new(s_value: "program"), alias_name: nil, number: 9, tag: nil, term: false, token_id: 4, nullable: true), - Sym.new(id: T::Ident.new(s_value: "multi_option_number_string"), alias_name: nil, number: 10, tag: nil, term: false, token_id: 5, nullable: true), - Sym.new(id: T::Ident.new(s_value: "nested_multi_option_number"), alias_name: nil, number: 11, tag: nil, term: false, token_id: 6, nullable: true), - Sym.new(id: T::Ident.new(s_value: "nested_multi_option_string"), alias_name: nil, number: 12, tag: nil, term: false, token_id: 7, nullable: true) + Sym.new(id: T::Ident.new(s_value: "$accept"), alias_name: nil, number: 6, tag: nil, term: false, token_id: 0, nullable: false), + Sym.new(id: T::Ident.new(s_value: "option_number"), alias_name: nil, number: 7, tag: nil, term: false, token_id: 1, nullable: true), + Sym.new(id: T::Ident.new(s_value: "nested_option_number"), alias_name: nil, number: 8, tag: nil, term: false, token_id: 2, nullable: true), + Sym.new(id: T::Ident.new(s_value: "nested_nested_option_number"), alias_name: nil, number: 9, tag: nil, term: false, token_id: 3, nullable: true), + Sym.new(id: T::Ident.new(s_value: "program"), alias_name: nil, number: 10, tag: nil, term: false, token_id: 4, nullable: true), + Sym.new(id: T::Ident.new(s_value: "multi_option_number_string"), alias_name: nil, number: 11, tag: nil, term: false, token_id: 5, nullable: true), + Sym.new(id: T::Ident.new(s_value: "nested_multi_option_number"), alias_name: nil, number: 12, tag: nil, term: false, token_id: 6, nullable: true), + Sym.new(id: T::Ident.new(s_value: "nested_multi_option_string"), alias_name: nil, number: 13, tag: nil, term: false, token_id: 7, nullable: true), + Sym.new(id: T::Ident.new(s_value: "with_word_seps_string"), alias_name: nil, number: 14, tag: nil, term: false, token_id: 8, nullable: true), + Sym.new(id: T::Ident.new(s_value: "nonempty_list_' '"), alias_name: nil, number: 15, tag: nil, term: false, token_id: 9, nullable: false) ]) expect(grammar.rules).to eq([ @@ -1653,7 +1655,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"), - lineno: 42, + lineno: 46, ), Rule.new( id: 1, @@ -1662,7 +1664,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 42, + lineno: 46, ), Rule.new( id: 2, @@ -1671,7 +1673,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 42, + lineno: 46, ), Rule.new( id: 3, @@ -1680,7 +1682,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 42, + lineno: 46, ), Rule.new( id: 4, @@ -1691,7 +1693,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), - lineno: 42, + lineno: 46, ), Rule.new( id: 5, @@ -1702,7 +1704,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 42, + lineno: 46, ), Rule.new( id: 6, @@ -1713,7 +1715,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 42, + lineno: 46, ), Rule.new( id: 7, @@ -1724,7 +1726,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 42, + lineno: 46, ), Rule.new( id: 8, @@ -1733,7 +1735,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 43, + lineno: 47, ), Rule.new( id: 9, @@ -1742,7 +1744,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 43, + lineno: 47, ), Rule.new( id: 10, @@ -1753,7 +1755,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), - lineno: 43, + lineno: 47, ), Rule.new( id: 11, @@ -1764,7 +1766,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 43, + lineno: 47, ), Rule.new( id: 12, @@ -1773,7 +1775,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 43, + lineno: 47, ), Rule.new( id: 13, @@ -1784,7 +1786,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("string"), - lineno: 43, + lineno: 47, ), Rule.new( id: 14, @@ -1796,7 +1798,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), - lineno: 43, + lineno: 47, ), Rule.new( id: 15, @@ -1807,7 +1809,62 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 43, + lineno: 47, + ), + Rule.new( + id: 16, + lhs: grammar.find_symbol_by_s_value!("with_word_seps_string"), + rhs: [], + token_code: nil, + nullable: true, + precedence_sym: nil, + lineno: 48, + ), + Rule.new( + id: 17, + lhs: grammar.find_symbol_by_s_value!("nonempty_list_' '"), + rhs: [ + grammar.find_symbol_by_s_value!("' '") + ], + token_code: nil, + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("' '"), + lineno: 48, + ), + Rule.new( + id: 18, + lhs: grammar.find_symbol_by_s_value!("nonempty_list_' '"), + rhs: [ + grammar.find_symbol_by_s_value!("nonempty_list_' '"), + grammar.find_symbol_by_s_value!("' '") + ], + token_code: nil, + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("' '"), + lineno: 48, + ), + Rule.new( + id: 19, + lhs: grammar.find_symbol_by_s_value!("with_word_seps_string"), + rhs: [ + grammar.find_symbol_by_s_value!("string"), + grammar.find_symbol_by_s_value!("nonempty_list_' '") + ], + token_code: nil, + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("string"), + lineno: 48, + ), + Rule.new( + id: 20, + lhs: grammar.find_symbol_by_s_value!("program"), + rhs: [ + grammar.find_symbol_by_s_value!("with_word_seps_string") + ], + token_code: nil, + nullable: true, + precedence_sym: nil, + lineno: 48, ), ]) end