From 540da2d374933ce08d092f9b6915f94e08fa6bc0 Mon Sep 17 00:00:00 2001 From: yui-knk Date: Wed, 31 Jan 2024 23:34:53 +0900 Subject: [PATCH] Add %after-shift-error-token --- lib/lrama/grammar.rb | 2 +- lib/lrama/lexer.rb | 1 + lib/lrama/output.rb | 11 + lib/lrama/parser.rb | 915 ++++++++++++------------ parser.y | 4 + spec/fixtures/integration/after_shift.y | 7 + spec/lrama/integration_spec.rb | 11 +- template/bison/yacc.c | 1 + 8 files changed, 495 insertions(+), 457 deletions(-) diff --git a/lib/lrama/grammar.rb b/lib/lrama/grammar.rb index e8a11d32..b1126ff8 100644 --- a/lib/lrama/grammar.rb +++ b/lib/lrama/grammar.rb @@ -22,7 +22,7 @@ class Grammar attr_accessor :union, :expect, :printers, :error_tokens, :lex_param, :parse_param, :initial_action, - :after_shift, :before_reduce, :after_reduce, :after_pop_stack, + :after_shift, :before_reduce, :after_reduce, :after_shift_error_token, :after_pop_stack, :symbols, :types, :rules, :rule_builders, :sym_to_rules, :no_stdlib diff --git a/lib/lrama/lexer.rb b/lib/lrama/lexer.rb index c976c298..9e369734 100644 --- a/lib/lrama/lexer.rb +++ b/lib/lrama/lexer.rb @@ -28,6 +28,7 @@ class Lexer %error-token %before-reduce %after-reduce + %after-shift-error-token %after-shift %after-pop-stack %empty diff --git a/lib/lrama/output.rb b/lib/lrama/output.rb index 2c0a367d..c5fac7ad 100644 --- a/lib/lrama/output.rb +++ b/lib/lrama/output.rb @@ -195,6 +195,17 @@ def after_reduce_function(comment = "") STR end + def after_shift_error_token_function(comment = "") + return "" unless @grammar.after_shift_error_token + + <<-STR + #{comment} +#line #{@grammar.after_shift_error_token.line} "#{@grammar_file_path}" + {#{@grammar.after_shift_error_token.s_value}(#{parse_param_name});} +#line [@oline@] [@ofile@] + STR + end + def after_pop_stack_function(len, comment = "") return "" unless @grammar.after_pop_stack diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index 958a1373..148457f1 100644 --- a/lib/lrama/parser.rb +++ b/lib/lrama/parser.rb @@ -658,7 +658,7 @@ def token_to_str(t) module Lrama class Parser < Racc::Parser -module_eval(<<'...end parser.y/module_eval...', 'parser.y', 517) +module_eval(<<'...end parser.y/module_eval...', 'parser.y', 521) include Lrama::Report::Duration @@ -732,315 +732,316 @@ def raise_parse_error(error_message, location) ##### State transition tables begin ### racc_action_table = [ - 94, 49, 95, 154, 153, 76, 49, 49, 154, 197, - 76, 76, 49, 6, 197, 7, 76, 156, 208, 49, - 3, 48, 156, 198, 152, 172, 173, 174, 198, 49, - 49, 48, 48, 8, 67, 45, 49, 49, 48, 48, - 76, 72, 79, 157, 39, 49, 96, 48, 157, 199, - 79, 49, 46, 48, 199, 22, 24, 25, 26, 27, - 28, 29, 30, 31, 32, 33, 34, 35, 36, 45, - 49, 49, 48, 48, 89, 79, 79, 49, 49, 48, - 48, 76, 182, 49, 49, 48, 48, 76, 182, 22, - 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, - 34, 35, 36, 9, 49, 52, 48, 13, 14, 15, - 16, 17, 18, 52, 52, 19, 20, 21, 22, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 36, 37, 49, 49, 48, 48, 76, 182, 49, - 49, 48, 48, 76, 182, 49, 49, 48, 48, 76, - 182, 49, 49, 48, 48, 76, 182, 49, 49, 48, - 48, 76, 76, 49, 49, 48, 48, 76, 76, 49, - 49, 48, 48, 76, 76, 49, 49, 188, 48, 76, - 76, 49, 49, 188, 48, 76, 76, 49, 49, 188, - 48, 76, 172, 173, 174, 92, 150, 201, 151, 202, - 172, 173, 174, 217, 219, 202, 202, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, 85, 86, 90, - 92, 97, 97, 97, 99, 105, 109, 110, 113, 113, - 113, 113, 116, 119, 120, 122, 124, 125, 126, 127, - 128, 131, 135, 136, 137, 140, 141, 142, 144, 159, - 161, 162, 163, 164, 165, 166, 167, 140, 169, 177, - 178, 187, 192, 193, 195, 200, 187, 92, 192, 214, - 216, 92, 221, 92 ] + 96, 50, 97, 156, 155, 78, 50, 50, 156, 199, + 78, 78, 50, 50, 199, 49, 78, 158, 69, 6, + 3, 7, 158, 200, 210, 154, 8, 50, 200, 49, + 40, 174, 175, 176, 47, 50, 46, 49, 53, 78, + 74, 50, 53, 49, 159, 53, 81, 98, 56, 159, + 201, 174, 175, 176, 94, 201, 22, 24, 25, 26, + 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, + 37, 46, 50, 50, 49, 49, 91, 81, 81, 50, + 50, 49, 49, 50, 81, 49, 57, 78, 184, 58, + 59, 22, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 9, 50, 60, 49, + 13, 14, 15, 16, 17, 18, 61, 62, 19, 20, + 21, 22, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 50, 50, 49, + 49, 78, 184, 50, 50, 49, 49, 78, 184, 50, + 50, 49, 49, 78, 184, 50, 50, 49, 49, 78, + 184, 50, 50, 49, 49, 78, 184, 50, 50, 49, + 49, 78, 78, 50, 50, 49, 49, 78, 78, 50, + 50, 49, 49, 78, 78, 50, 50, 190, 49, 78, + 78, 50, 50, 190, 49, 78, 78, 50, 50, 190, + 49, 78, 50, 50, 49, 49, 152, 203, 153, 204, + 174, 175, 176, 219, 221, 204, 204, 63, 64, 65, + 66, 87, 88, 92, 94, 99, 99, 99, 101, 107, + 111, 112, 115, 115, 115, 115, 118, 121, 122, 124, + 126, 127, 128, 129, 130, 133, 137, 138, 139, 142, + 143, 144, 146, 161, 163, 164, 165, 166, 167, 168, + 169, 142, 171, 179, 180, 189, 194, 195, 197, 202, + 189, 94, 194, 216, 218, 94, 223, 94 ] racc_action_check = [ - 47, 139, 47, 139, 138, 139, 168, 186, 168, 186, - 168, 186, 205, 2, 205, 2, 205, 139, 197, 14, - 1, 14, 168, 186, 138, 197, 197, 197, 205, 31, - 66, 31, 66, 3, 31, 9, 32, 33, 32, 33, - 32, 32, 33, 139, 7, 34, 47, 34, 168, 186, - 34, 67, 13, 67, 205, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 40, - 35, 36, 35, 36, 40, 35, 36, 163, 78, 163, - 78, 163, 163, 164, 79, 164, 79, 164, 164, 40, - 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, - 40, 40, 40, 4, 105, 15, 105, 4, 4, 4, - 4, 4, 4, 16, 17, 4, 4, 4, 4, 4, + 48, 141, 48, 141, 140, 141, 170, 188, 170, 188, + 170, 188, 207, 32, 207, 32, 207, 141, 32, 2, + 1, 2, 170, 188, 199, 140, 3, 14, 207, 14, + 7, 199, 199, 199, 13, 33, 9, 33, 15, 33, + 33, 34, 16, 34, 141, 17, 34, 48, 18, 170, + 188, 157, 157, 157, 157, 207, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 41, 35, 36, 35, 36, 41, 35, 36, 37, + 68, 37, 68, 165, 37, 165, 19, 165, 165, 22, + 24, 41, 41, 41, 41, 41, 41, 41, 41, 41, + 41, 41, 41, 41, 41, 41, 4, 69, 25, 69, + 4, 4, 4, 4, 4, 4, 26, 27, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 165, 107, 165, 107, 165, 165, 179, - 113, 179, 113, 179, 179, 183, 115, 183, 115, 183, - 183, 184, 129, 184, 129, 184, 184, 71, 72, 71, - 72, 71, 72, 110, 112, 110, 112, 110, 112, 132, - 157, 132, 157, 132, 157, 169, 199, 169, 199, 169, - 199, 200, 202, 200, 202, 200, 202, 208, 133, 208, - 133, 208, 155, 155, 155, 155, 134, 189, 134, 189, - 190, 190, 190, 211, 215, 211, 215, 18, 19, 22, - 24, 25, 26, 27, 28, 29, 30, 37, 38, 43, - 44, 51, 53, 54, 55, 65, 69, 70, 77, 82, - 83, 84, 85, 91, 92, 98, 100, 101, 102, 103, - 104, 108, 116, 117, 118, 119, 120, 121, 123, 143, - 145, 146, 147, 148, 149, 150, 151, 152, 154, 158, - 160, 166, 171, 175, 185, 188, 195, 196, 201, 204, - 209, 214, 220, 221 ] + 4, 4, 4, 4, 4, 4, 4, 166, 80, 166, + 80, 166, 166, 167, 81, 167, 81, 167, 167, 181, + 107, 181, 107, 181, 181, 185, 109, 185, 109, 185, + 185, 186, 115, 186, 115, 186, 186, 73, 74, 73, + 74, 73, 74, 112, 114, 112, 114, 112, 114, 134, + 159, 134, 159, 134, 159, 171, 201, 171, 201, 171, + 201, 202, 204, 202, 204, 202, 204, 210, 117, 210, + 117, 210, 131, 135, 131, 135, 136, 191, 136, 191, + 192, 192, 192, 213, 217, 213, 217, 28, 29, 30, + 31, 38, 39, 44, 45, 52, 54, 55, 56, 67, + 71, 72, 79, 84, 85, 86, 87, 93, 94, 100, + 102, 103, 104, 105, 106, 110, 118, 119, 120, 121, + 122, 123, 125, 145, 147, 148, 149, 150, 151, 152, + 153, 154, 156, 160, 162, 168, 173, 177, 187, 190, + 197, 198, 203, 206, 211, 216, 222, 223 ] racc_action_pointer = [ - nil, 20, 3, 33, 94, nil, nil, 37, nil, 31, - nil, nil, nil, 46, 16, 86, 94, 95, 202, 189, - nil, nil, 190, nil, 191, 192, 193, 208, 209, 210, - 211, 26, 33, 34, 42, 67, 68, 212, 216, nil, - 65, nil, nil, 196, 171, nil, nil, -5, nil, nil, - nil, 202, nil, 203, 204, 205, nil, nil, nil, nil, - nil, nil, nil, nil, nil, 217, 27, 48, nil, 220, - 219, 154, 155, nil, nil, nil, nil, 220, 75, 81, - nil, nil, 221, 222, 223, 193, nil, nil, nil, nil, - nil, 192, 229, nil, nil, nil, nil, nil, 233, nil, - 234, 235, 236, 237, 238, 101, nil, 131, 234, nil, - 160, nil, 161, 137, nil, 143, 237, 232, 242, 201, - 196, 245, nil, 246, nil, nil, nil, nil, nil, 149, - nil, nil, 166, 185, 156, nil, nil, nil, -19, -2, - nil, nil, nil, 229, nil, 230, 231, 232, 233, 234, - 214, 251, 213, nil, 219, 146, nil, 167, 239, nil, - 240, nil, nil, 74, 80, 130, 217, nil, 3, 172, - nil, 254, nil, nil, nil, 261, nil, nil, nil, 136, - nil, nil, nil, 142, 148, 221, 4, nil, 226, 157, - 154, nil, nil, nil, nil, 222, 218, -21, nil, 173, - 178, 260, 179, nil, 249, 9, nil, nil, 184, 268, - nil, 163, nil, nil, 222, 164, nil, nil, nil, nil, - 252, 224, nil ] + nil, 20, 9, 26, 97, nil, nil, 23, nil, 32, + nil, nil, nil, 28, 24, 19, 23, 26, 43, 67, + nil, nil, 70, nil, 71, 89, 97, 112, 212, 213, + 214, 215, 10, 32, 38, 69, 70, 76, 216, 220, + nil, 67, nil, nil, 200, 174, nil, nil, -5, nil, + nil, nil, 206, nil, 207, 208, 209, nil, nil, nil, + nil, nil, nil, nil, nil, nil, nil, 221, 77, 104, + nil, 224, 223, 164, 165, nil, nil, nil, nil, 224, + 135, 141, nil, nil, 225, 226, 227, 196, nil, nil, + nil, nil, nil, 195, 233, nil, nil, nil, nil, nil, + 237, nil, 238, 239, 240, 241, 242, 147, nil, 153, + 238, nil, 170, nil, 171, 159, nil, 195, 241, 236, + 246, 204, 199, 249, nil, 250, nil, nil, nil, nil, + nil, 199, nil, nil, 176, 200, 165, nil, nil, nil, + -19, -2, nil, nil, nil, 233, nil, 234, 235, 236, + 237, 238, 217, 255, 216, nil, 222, 4, nil, 177, + 243, nil, 244, nil, nil, 80, 134, 140, 220, nil, + 3, 182, nil, 258, nil, nil, nil, 265, nil, nil, + nil, 146, nil, nil, nil, 152, 158, 224, 4, nil, + 229, 166, 163, nil, nil, nil, nil, 225, 221, -16, + nil, 183, 188, 264, 189, nil, 253, 9, nil, nil, + 194, 272, nil, 172, nil, nil, 225, 173, nil, nil, + nil, nil, 256, 227, nil ] racc_action_default = [ - -2, -135, -8, -135, -135, -3, -4, -135, 223, -135, - -9, -10, -11, -135, -135, -135, -135, -135, -135, -135, - -23, -24, -135, -28, -135, -135, -135, -135, -135, -135, - -135, -135, -135, -135, -135, -135, -135, -135, -135, -7, - -120, -93, -95, -135, -117, -119, -12, -124, -91, -92, - -123, -14, -82, -15, -16, -135, -20, -25, -29, -32, - -35, -38, -39, -40, -41, -42, -48, -135, -51, -68, - -43, -72, -135, -75, -77, -78, -132, -44, -85, -135, - -88, -90, -45, -46, -47, -135, -5, -1, -94, -121, - -96, -135, -135, -13, -125, -126, -127, -79, -135, -17, - -135, -135, -135, -135, -135, -135, -52, -49, -70, -69, - -135, -76, -73, -135, -89, -86, -135, -135, -135, -101, - -135, -135, -83, -135, -21, -26, -30, -33, -36, -50, - -53, -71, -74, -87, -135, -55, -6, -122, -97, -98, - -102, -118, -80, -135, -18, -135, -135, -135, -135, -135, - -135, -135, -101, -100, -91, -117, -106, -135, -135, -84, - -135, -22, -27, -135, -135, -135, -59, -56, -99, -135, - -103, -133, -110, -111, -112, -135, -109, -81, -19, -31, - -128, -130, -131, -34, -37, -54, -57, -60, -91, -135, - -113, -104, -134, -107, -129, -59, -117, -91, -64, -135, - -135, -133, -135, -115, -135, -58, -61, -62, -135, -135, - -67, -135, -105, -114, -117, -135, -65, -116, -108, -63, - -135, -117, -66 ] + -2, -136, -8, -136, -136, -3, -4, -136, 225, -136, + -9, -10, -11, -136, -136, -136, -136, -136, -136, -136, + -23, -24, -136, -28, -136, -136, -136, -136, -136, -136, + -136, -136, -136, -136, -136, -136, -136, -136, -136, -136, + -7, -121, -94, -96, -136, -118, -120, -12, -125, -92, + -93, -124, -14, -83, -15, -16, -136, -20, -25, -29, + -32, -35, -38, -39, -40, -41, -42, -43, -49, -136, + -52, -69, -44, -73, -136, -76, -78, -79, -133, -45, + -86, -136, -89, -91, -46, -47, -48, -136, -5, -1, + -95, -122, -97, -136, -136, -13, -126, -127, -128, -80, + -136, -17, -136, -136, -136, -136, -136, -136, -53, -50, + -71, -70, -136, -77, -74, -136, -90, -87, -136, -136, + -136, -102, -136, -136, -84, -136, -21, -26, -30, -33, + -36, -51, -54, -72, -75, -88, -136, -56, -6, -123, + -98, -99, -103, -119, -81, -136, -18, -136, -136, -136, + -136, -136, -136, -136, -102, -101, -92, -118, -107, -136, + -136, -85, -136, -22, -27, -136, -136, -136, -60, -57, + -100, -136, -104, -134, -111, -112, -113, -136, -110, -82, + -19, -31, -129, -131, -132, -34, -37, -55, -58, -61, + -92, -136, -114, -105, -135, -108, -130, -60, -118, -92, + -65, -136, -136, -134, -136, -116, -136, -59, -62, -63, + -136, -136, -68, -136, -106, -115, -118, -136, -66, -117, + -109, -64, -136, -118, -67 ] racc_goto_table = [ - 91, 50, 71, 66, 114, 73, 106, 189, 171, 41, - 77, 82, 83, 84, 115, 1, 139, 2, 69, 4, - 81, 81, 81, 81, 194, 191, 40, 186, 194, 194, - 51, 53, 54, 179, 183, 184, 87, 5, 211, 107, - 88, 114, 112, 203, 111, 73, 215, 106, 133, 168, - 207, 38, 117, 69, 69, 212, 205, 10, 11, 114, - 12, 47, 93, 123, 160, 81, 81, 100, 145, 106, - 101, 146, 102, 147, 103, 148, 104, 129, 149, 65, - 132, 70, 108, 73, 130, 111, 134, 185, 209, 220, - 121, 158, 69, 98, 69, 143, 138, 175, 204, 118, - 81, nil, 81, nil, nil, 111, nil, nil, nil, nil, - nil, 170, 155, nil, nil, nil, 69, nil, nil, nil, - 81, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 176, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, 155, 190, nil, nil, nil, nil, nil, nil, nil, - nil, nil, 206, nil, nil, nil, nil, nil, nil, 196, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 218, nil, 210, 190, nil, 213, nil, 222, 196, nil, - nil, 190 ] + 93, 51, 73, 68, 116, 75, 108, 173, 193, 1, + 188, 196, 2, 191, 117, 196, 196, 141, 4, 71, + 41, 83, 83, 83, 83, 42, 79, 84, 85, 86, + 52, 54, 55, 181, 185, 186, 89, 5, 214, 207, + 109, 116, 205, 114, 213, 113, 75, 108, 135, 209, + 170, 39, 217, 119, 10, 71, 71, 90, 11, 116, + 12, 48, 95, 125, 162, 102, 147, 83, 83, 108, + 103, 148, 104, 149, 105, 150, 106, 151, 131, 67, + 72, 134, 110, 132, 75, 136, 113, 187, 211, 222, + 123, 160, 100, 145, 71, 140, 71, 177, 206, 120, + nil, nil, 83, nil, 83, nil, 113, nil, nil, nil, + nil, nil, 172, 157, nil, nil, nil, nil, 71, nil, + nil, nil, 83, nil, nil, nil, nil, nil, nil, nil, + nil, 178, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, 157, 192, nil, nil, nil, nil, nil, nil, + nil, nil, nil, 208, nil, nil, nil, nil, nil, nil, + 198, nil, nil, nil, nil, nil, nil, nil, nil, nil, + nil, 220, nil, 212, 192, nil, 215, nil, 224, 198, + nil, nil, 192 ] racc_goto_check = [ - 41, 34, 46, 32, 53, 40, 33, 43, 42, 54, - 31, 31, 31, 31, 52, 1, 58, 2, 34, 3, - 34, 34, 34, 34, 63, 59, 4, 39, 63, 63, - 14, 14, 14, 20, 20, 20, 5, 6, 43, 32, - 54, 53, 46, 42, 40, 40, 43, 33, 52, 58, - 42, 7, 8, 34, 34, 59, 39, 9, 10, 53, - 11, 12, 13, 15, 16, 34, 34, 17, 18, 33, - 21, 22, 23, 24, 25, 26, 27, 32, 28, 29, - 46, 30, 35, 40, 36, 40, 37, 38, 44, 45, - 48, 49, 34, 50, 34, 51, 57, 60, 61, 62, - 34, nil, 34, nil, nil, 40, nil, nil, nil, nil, - nil, 41, 40, nil, nil, nil, 34, nil, nil, nil, - 34, nil, nil, nil, nil, nil, nil, nil, nil, nil, + 41, 34, 46, 32, 53, 40, 33, 42, 59, 1, + 39, 63, 2, 43, 52, 63, 63, 58, 3, 34, + 4, 34, 34, 34, 34, 54, 31, 31, 31, 31, + 14, 14, 14, 20, 20, 20, 5, 6, 59, 39, + 32, 53, 42, 46, 43, 40, 40, 33, 52, 42, + 58, 7, 43, 8, 9, 34, 34, 54, 10, 53, + 11, 12, 13, 15, 16, 17, 18, 34, 34, 33, + 21, 22, 23, 24, 25, 26, 27, 28, 32, 29, + 30, 46, 35, 36, 40, 37, 40, 38, 44, 45, + 48, 49, 50, 51, 34, 57, 34, 60, 61, 62, + nil, nil, 34, nil, 34, nil, 40, nil, nil, nil, + nil, nil, 41, 40, nil, nil, nil, nil, 34, nil, + nil, nil, 34, nil, nil, nil, nil, nil, nil, nil, + nil, 40, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, 40, 40, nil, nil, nil, nil, nil, nil, + nil, nil, nil, 41, nil, nil, nil, nil, nil, nil, 40, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, 40, 40, nil, nil, nil, nil, nil, nil, nil, - nil, nil, 41, nil, nil, nil, nil, nil, nil, 40, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 41, nil, 40, 40, nil, 40, nil, 41, 40, nil, - nil, 40 ] + nil, 41, nil, 40, 40, nil, 40, nil, 41, 40, + nil, nil, 40 ] racc_goto_pointer = [ - nil, 15, 17, 17, 17, -4, 35, 45, -34, 53, - 54, 56, 47, 15, 15, -36, -80, 11, -56, nil, - -130, 13, -54, 14, -53, 15, -52, 16, -50, 48, - 49, -23, -28, -60, -13, 13, -24, -30, -79, -139, - -27, -44, -147, -162, -110, -127, -30, nil, -7, -51, - 41, -27, -65, -74, 0, nil, nil, -23, -103, -146, - -59, -95, 10, -155 ] + nil, 9, 12, 16, 11, -5, 35, 45, -35, 50, + 54, 56, 47, 14, 15, -38, -82, 8, -60, nil, + -132, 12, -56, 13, -55, 14, -54, 15, -53, 47, + 47, -8, -29, -62, -13, 11, -27, -33, -81, -158, + -28, -45, -150, -158, -112, -129, -31, nil, -9, -53, + 39, -31, -67, -76, 16, nil, nil, -26, -104, -165, + -61, -97, 8, -170 ] racc_goto_default = [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 43, nil, nil, nil, nil, nil, nil, nil, nil, 23, + 44, nil, nil, nil, nil, nil, nil, nil, nil, 23, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, 68, 74, nil, nil, nil, nil, nil, - 181, nil, nil, nil, nil, nil, nil, 75, nil, nil, - nil, nil, 78, 80, nil, 42, 44, nil, nil, nil, - nil, nil, nil, 180 ] + nil, nil, nil, 70, 76, nil, nil, nil, nil, nil, + 183, nil, nil, nil, nil, nil, nil, 77, nil, nil, + nil, nil, 80, 82, nil, 43, 45, nil, nil, nil, + nil, nil, nil, 182 ] racc_reduce_table = [ 0, 0, :racc_error, - 5, 53, :_reduce_none, - 0, 54, :_reduce_none, - 2, 54, :_reduce_none, - 0, 59, :_reduce_4, - 0, 60, :_reduce_5, - 5, 58, :_reduce_6, - 2, 58, :_reduce_none, - 0, 55, :_reduce_8, + 5, 54, :_reduce_none, + 0, 55, :_reduce_none, 2, 55, :_reduce_none, - 1, 61, :_reduce_none, - 1, 61, :_reduce_none, - 2, 61, :_reduce_12, - 3, 61, :_reduce_none, - 2, 61, :_reduce_none, - 2, 61, :_reduce_15, - 2, 61, :_reduce_16, - 0, 67, :_reduce_17, - 0, 68, :_reduce_18, - 7, 61, :_reduce_19, - 0, 69, :_reduce_20, - 0, 70, :_reduce_21, - 6, 61, :_reduce_22, - 1, 61, :_reduce_23, - 1, 61, :_reduce_none, - 0, 73, :_reduce_25, - 0, 74, :_reduce_26, - 6, 62, :_reduce_27, + 0, 60, :_reduce_4, + 0, 61, :_reduce_5, + 5, 59, :_reduce_6, + 2, 59, :_reduce_none, + 0, 56, :_reduce_8, + 2, 56, :_reduce_none, 1, 62, :_reduce_none, - 0, 75, :_reduce_29, - 0, 76, :_reduce_30, - 7, 62, :_reduce_none, - 0, 77, :_reduce_32, - 0, 78, :_reduce_33, - 7, 62, :_reduce_34, - 0, 79, :_reduce_35, - 0, 80, :_reduce_36, - 7, 62, :_reduce_37, - 2, 62, :_reduce_38, - 2, 62, :_reduce_39, - 2, 62, :_reduce_40, - 2, 62, :_reduce_41, - 2, 71, :_reduce_none, - 2, 71, :_reduce_43, - 2, 71, :_reduce_44, - 2, 71, :_reduce_45, - 2, 71, :_reduce_46, - 2, 71, :_reduce_47, - 1, 81, :_reduce_48, - 2, 81, :_reduce_49, - 3, 81, :_reduce_50, - 1, 84, :_reduce_51, - 2, 84, :_reduce_52, - 3, 85, :_reduce_53, - 7, 63, :_reduce_54, - 1, 89, :_reduce_55, - 3, 89, :_reduce_56, - 1, 90, :_reduce_57, - 3, 90, :_reduce_58, - 0, 91, :_reduce_59, - 1, 91, :_reduce_60, - 3, 91, :_reduce_61, - 3, 91, :_reduce_62, - 5, 91, :_reduce_63, - 0, 96, :_reduce_64, + 1, 62, :_reduce_none, + 2, 62, :_reduce_12, + 3, 62, :_reduce_none, + 2, 62, :_reduce_none, + 2, 62, :_reduce_15, + 2, 62, :_reduce_16, + 0, 68, :_reduce_17, + 0, 69, :_reduce_18, + 7, 62, :_reduce_19, + 0, 70, :_reduce_20, + 0, 71, :_reduce_21, + 6, 62, :_reduce_22, + 1, 62, :_reduce_23, + 1, 62, :_reduce_none, + 0, 74, :_reduce_25, + 0, 75, :_reduce_26, + 6, 63, :_reduce_27, + 1, 63, :_reduce_none, + 0, 76, :_reduce_29, + 0, 77, :_reduce_30, + 7, 63, :_reduce_none, + 0, 78, :_reduce_32, + 0, 79, :_reduce_33, + 7, 63, :_reduce_34, + 0, 80, :_reduce_35, + 0, 81, :_reduce_36, + 7, 63, :_reduce_37, + 2, 63, :_reduce_38, + 2, 63, :_reduce_39, + 2, 63, :_reduce_40, + 2, 63, :_reduce_41, + 2, 63, :_reduce_42, + 2, 72, :_reduce_none, + 2, 72, :_reduce_44, + 2, 72, :_reduce_45, + 2, 72, :_reduce_46, + 2, 72, :_reduce_47, + 2, 72, :_reduce_48, + 1, 82, :_reduce_49, + 2, 82, :_reduce_50, + 3, 82, :_reduce_51, + 1, 85, :_reduce_52, + 2, 85, :_reduce_53, + 3, 86, :_reduce_54, + 7, 64, :_reduce_55, + 1, 90, :_reduce_56, + 3, 90, :_reduce_57, + 1, 91, :_reduce_58, + 3, 91, :_reduce_59, + 0, 92, :_reduce_60, + 1, 92, :_reduce_61, + 3, 92, :_reduce_62, + 3, 92, :_reduce_63, + 5, 92, :_reduce_64, 0, 97, :_reduce_65, - 7, 91, :_reduce_66, - 3, 91, :_reduce_67, - 0, 87, :_reduce_none, - 1, 87, :_reduce_none, + 0, 98, :_reduce_66, + 7, 92, :_reduce_67, + 3, 92, :_reduce_68, 0, 88, :_reduce_none, 1, 88, :_reduce_none, - 1, 82, :_reduce_72, - 2, 82, :_reduce_73, - 3, 82, :_reduce_74, - 1, 98, :_reduce_75, - 2, 98, :_reduce_76, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 0, 100, :_reduce_79, + 0, 89, :_reduce_none, + 1, 89, :_reduce_none, + 1, 83, :_reduce_73, + 2, 83, :_reduce_74, + 3, 83, :_reduce_75, + 1, 99, :_reduce_76, + 2, 99, :_reduce_77, + 1, 93, :_reduce_none, + 1, 93, :_reduce_none, 0, 101, :_reduce_80, - 6, 66, :_reduce_81, - 0, 102, :_reduce_82, + 0, 102, :_reduce_81, + 6, 67, :_reduce_82, 0, 103, :_reduce_83, - 5, 66, :_reduce_84, - 1, 83, :_reduce_85, - 2, 83, :_reduce_86, - 3, 83, :_reduce_87, - 1, 104, :_reduce_88, - 2, 104, :_reduce_89, - 1, 105, :_reduce_none, - 1, 86, :_reduce_91, - 1, 86, :_reduce_92, - 1, 56, :_reduce_none, - 2, 56, :_reduce_none, + 0, 104, :_reduce_84, + 5, 67, :_reduce_85, + 1, 84, :_reduce_86, + 2, 84, :_reduce_87, + 3, 84, :_reduce_88, + 1, 105, :_reduce_89, + 2, 105, :_reduce_90, 1, 106, :_reduce_none, - 2, 106, :_reduce_none, - 4, 107, :_reduce_97, - 1, 109, :_reduce_98, - 3, 109, :_reduce_99, - 2, 109, :_reduce_none, - 0, 110, :_reduce_101, - 1, 110, :_reduce_102, - 3, 110, :_reduce_103, - 4, 110, :_reduce_104, - 6, 110, :_reduce_105, - 0, 112, :_reduce_106, + 1, 87, :_reduce_92, + 1, 87, :_reduce_93, + 1, 57, :_reduce_none, + 2, 57, :_reduce_none, + 1, 107, :_reduce_none, + 2, 107, :_reduce_none, + 4, 108, :_reduce_98, + 1, 110, :_reduce_99, + 3, 110, :_reduce_100, + 2, 110, :_reduce_none, + 0, 111, :_reduce_102, + 1, 111, :_reduce_103, + 3, 111, :_reduce_104, + 4, 111, :_reduce_105, + 6, 111, :_reduce_106, 0, 113, :_reduce_107, - 7, 110, :_reduce_108, - 3, 110, :_reduce_109, - 1, 94, :_reduce_110, - 1, 94, :_reduce_111, - 1, 94, :_reduce_112, + 0, 114, :_reduce_108, + 7, 111, :_reduce_109, + 3, 111, :_reduce_110, + 1, 95, :_reduce_111, + 1, 95, :_reduce_112, 1, 95, :_reduce_113, - 3, 95, :_reduce_114, - 2, 95, :_reduce_115, - 4, 95, :_reduce_116, - 0, 93, :_reduce_none, - 3, 93, :_reduce_118, - 1, 108, :_reduce_none, - 0, 57, :_reduce_none, - 0, 114, :_reduce_121, - 3, 57, :_reduce_122, - 1, 64, :_reduce_none, - 0, 65, :_reduce_none, + 1, 96, :_reduce_114, + 3, 96, :_reduce_115, + 2, 96, :_reduce_116, + 4, 96, :_reduce_117, + 0, 94, :_reduce_none, + 3, 94, :_reduce_119, + 1, 109, :_reduce_none, + 0, 58, :_reduce_none, + 0, 115, :_reduce_122, + 3, 58, :_reduce_123, 1, 65, :_reduce_none, - 1, 65, :_reduce_none, - 1, 65, :_reduce_none, - 1, 72, :_reduce_128, - 2, 72, :_reduce_129, - 1, 115, :_reduce_none, - 1, 115, :_reduce_none, - 1, 99, :_reduce_132, - 0, 111, :_reduce_none, - 1, 111, :_reduce_none ] - -racc_reduce_n = 135 - -racc_shift_n = 223 + 0, 66, :_reduce_none, + 1, 66, :_reduce_none, + 1, 66, :_reduce_none, + 1, 66, :_reduce_none, + 1, 73, :_reduce_129, + 2, 73, :_reduce_130, + 1, 116, :_reduce_none, + 1, 116, :_reduce_none, + 1, 100, :_reduce_133, + 0, 112, :_reduce_none, + 1, 112, :_reduce_none ] + +racc_reduce_n = 136 + +racc_shift_n = 225 racc_token_table = { false => 0, @@ -1074,29 +1075,30 @@ def raise_parse_error(error_message, location) "%after-shift" => 28, "%before-reduce" => 29, "%after-reduce" => 30, - "%after-pop-stack" => 31, - "%token" => 32, - "%type" => 33, - "%left" => 34, - "%right" => 35, - "%precedence" => 36, - "%nonassoc" => 37, - "%rule" => 38, - "(" => 39, - ")" => 40, - ":" => 41, - "," => 42, - "|" => 43, - "%empty" => 44, - "%prec" => 45, - "?" => 46, - "+" => 47, - "*" => 48, - "[" => 49, - "]" => 50, - "{...}" => 51 } - -racc_nt_base = 52 + "%after-shift-error-token" => 31, + "%after-pop-stack" => 32, + "%token" => 33, + "%type" => 34, + "%left" => 35, + "%right" => 36, + "%precedence" => 37, + "%nonassoc" => 38, + "%rule" => 39, + "(" => 40, + ")" => 41, + ":" => 42, + "," => 43, + "|" => 44, + "%empty" => 45, + "%prec" => 46, + "?" => 47, + "+" => 48, + "*" => 49, + "[" => 50, + "]" => 51, + "{...}" => 52 } + +racc_nt_base = 53 racc_use_result_var = true @@ -1149,6 +1151,7 @@ def raise_parse_error(error_message, location) "\"%after-shift\"", "\"%before-reduce\"", "\"%after-reduce\"", + "\"%after-shift-error-token\"", "\"%after-pop-stack\"", "\"%token\"", "\"%type\"", @@ -1505,16 +1508,24 @@ def _reduce_40(val, _values, result) module_eval(<<'.,.,', 'parser.y', 145) def _reduce_41(val, _values, result) + @grammar.after_shift_error_token = val[1] + + result + end +.,., + +module_eval(<<'.,.,', 'parser.y', 149) + def _reduce_42(val, _values, result) @grammar.after_pop_stack = val[1] result end .,., -# reduce 42 omitted +# reduce 43 omitted -module_eval(<<'.,.,', 'parser.y', 151) - def _reduce_43(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 155) + def _reduce_44(val, _values, result) val[1].each {|hash| hash[:tokens].each {|id| @grammar.add_type(id: id, tag: hash[:tag]) @@ -1525,8 +1536,8 @@ def _reduce_43(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 159) - def _reduce_44(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 163) + def _reduce_45(val, _values, result) val[1].each {|hash| hash[:tokens].each {|id| sym = @grammar.add_term(id: id) @@ -1539,8 +1550,8 @@ def _reduce_44(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 169) - def _reduce_45(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 173) + def _reduce_46(val, _values, result) val[1].each {|hash| hash[:tokens].each {|id| sym = @grammar.add_term(id: id) @@ -1553,8 +1564,8 @@ def _reduce_45(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 179) - def _reduce_46(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 183) + def _reduce_47(val, _values, result) val[1].each {|hash| hash[:tokens].each {|id| sym = @grammar.add_term(id: id) @@ -1567,8 +1578,8 @@ def _reduce_46(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 189) - def _reduce_47(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 193) + def _reduce_48(val, _values, result) val[1].each {|hash| hash[:tokens].each {|id| sym = @grammar.add_term(id: id) @@ -1581,8 +1592,8 @@ def _reduce_47(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 200) - def _reduce_48(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 204) + def _reduce_49(val, _values, result) val[0].each {|token_declaration| @grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: nil, replace: true) } @@ -1591,8 +1602,8 @@ def _reduce_48(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 206) - def _reduce_49(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 210) + def _reduce_50(val, _values, result) val[1].each {|token_declaration| @grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: val[0], replace: true) } @@ -1601,8 +1612,8 @@ def _reduce_49(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 212) - def _reduce_50(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 216) + def _reduce_51(val, _values, result) val[2].each {|token_declaration| @grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: val[1], replace: true) } @@ -1611,29 +1622,29 @@ def _reduce_50(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 217) - def _reduce_51(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 221) + def _reduce_52(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 218) - def _reduce_52(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 222) + def _reduce_53(val, _values, result) result = val[0].append(val[1]) result end .,., -module_eval(<<'.,.,', 'parser.y', 220) - def _reduce_53(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 224) + def _reduce_54(val, _values, result) result = val result end .,., -module_eval(<<'.,.,', 'parser.y', 224) - def _reduce_54(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 228) + def _reduce_55(val, _values, result) rule = Grammar::ParameterizingRule::Rule.new(val[1].s_value, val[3], val[6]) @grammar.add_parameterizing_rule(rule) @@ -1641,22 +1652,22 @@ def _reduce_54(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 228) - def _reduce_55(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 232) + def _reduce_56(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 229) - def _reduce_56(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 233) + def _reduce_57(val, _values, result) result = val[0].append(val[2]) result end .,., -module_eval(<<'.,.,', 'parser.y', 233) - def _reduce_57(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 237) + def _reduce_58(val, _values, result) builder = val[0] result = [builder] @@ -1664,8 +1675,8 @@ def _reduce_57(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 238) - def _reduce_58(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 242) + def _reduce_59(val, _values, result) builder = val[2] result = val[0].append(builder) @@ -1673,8 +1684,8 @@ def _reduce_58(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 244) - def _reduce_59(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 248) + def _reduce_60(val, _values, result) reset_precs result = Grammar::ParameterizingRule::Rhs.new @@ -1682,8 +1693,8 @@ def _reduce_59(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 249) - def _reduce_60(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 253) + def _reduce_61(val, _values, result) reset_precs result = Grammar::ParameterizingRule::Rhs.new @@ -1691,8 +1702,8 @@ def _reduce_60(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 254) - def _reduce_61(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 258) + def _reduce_62(val, _values, result) token = val[1] token.alias_name = val[2] builder = val[0] @@ -1703,8 +1714,8 @@ def _reduce_61(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 262) - def _reduce_62(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 266) + def _reduce_63(val, _values, result) builder = val[0] builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]]) result = builder @@ -1713,8 +1724,8 @@ def _reduce_62(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 268) - def _reduce_63(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 272) + def _reduce_64(val, _values, result) builder = val[0] builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3]) result = builder @@ -1723,8 +1734,8 @@ def _reduce_63(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 274) - def _reduce_64(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 278) + def _reduce_65(val, _values, result) if @prec_seen on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec @code_after_prec = true @@ -1735,16 +1746,16 @@ def _reduce_64(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 282) - def _reduce_65(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 286) + def _reduce_66(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 286) - def _reduce_66(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 290) + def _reduce_67(val, _values, result) user_code = val[3] user_code.alias_name = val[6] builder = val[0] @@ -1755,8 +1766,8 @@ def _reduce_66(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 294) - def _reduce_67(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 298) + def _reduce_68(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) @prec_seen = true builder = val[0] @@ -1767,67 +1778,59 @@ def _reduce_67(val, _values, result) end .,., -# reduce 68 omitted - # reduce 69 omitted # reduce 70 omitted # reduce 71 omitted -module_eval(<<'.,.,', 'parser.y', 309) - def _reduce_72(val, _values, result) +# reduce 72 omitted + +module_eval(<<'.,.,', 'parser.y', 313) + def _reduce_73(val, _values, result) result = [{tag: nil, tokens: val[0]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 313) - def _reduce_73(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 317) + def _reduce_74(val, _values, result) result = [{tag: val[0], tokens: val[1]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 317) - def _reduce_74(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 321) + def _reduce_75(val, _values, result) result = val[0].append({tag: val[1], tokens: val[2]}) result end .,., -module_eval(<<'.,.,', 'parser.y', 320) - def _reduce_75(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 324) + def _reduce_76(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 321) - def _reduce_76(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 325) + def _reduce_77(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 77 omitted - # reduce 78 omitted -module_eval(<<'.,.,', 'parser.y', 328) - def _reduce_79(val, _values, result) - begin_c_declaration("}") - - result - end -.,., +# reduce 79 omitted module_eval(<<'.,.,', 'parser.y', 332) def _reduce_80(val, _values, result) - end_c_declaration + begin_c_declaration("}") result end @@ -1835,7 +1838,7 @@ def _reduce_80(val, _values, result) module_eval(<<'.,.,', 'parser.y', 336) def _reduce_81(val, _values, result) - result = val[0].append(val[3]) + end_c_declaration result end @@ -1843,7 +1846,7 @@ def _reduce_81(val, _values, result) module_eval(<<'.,.,', 'parser.y', 340) def _reduce_82(val, _values, result) - begin_c_declaration("}") + result = val[0].append(val[3]) result end @@ -1851,7 +1854,7 @@ def _reduce_82(val, _values, result) module_eval(<<'.,.,', 'parser.y', 344) def _reduce_83(val, _values, result) - end_c_declaration + begin_c_declaration("}") result end @@ -1859,15 +1862,15 @@ def _reduce_83(val, _values, result) module_eval(<<'.,.,', 'parser.y', 348) def _reduce_84(val, _values, result) - result = [val[2]] + end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 353) +module_eval(<<'.,.,', 'parser.y', 352) def _reduce_85(val, _values, result) - result = [{tag: nil, tokens: val[0]}] + result = [val[2]] result end @@ -1875,7 +1878,7 @@ def _reduce_85(val, _values, result) module_eval(<<'.,.,', 'parser.y', 357) def _reduce_86(val, _values, result) - result = [{tag: val[0], tokens: val[1]}] + result = [{tag: nil, tokens: val[0]}] result end @@ -1883,52 +1886,60 @@ def _reduce_86(val, _values, result) module_eval(<<'.,.,', 'parser.y', 361) def _reduce_87(val, _values, result) - result = val[0].append({tag: val[1], tokens: val[2]}) + result = [{tag: val[0], tokens: val[1]}] result end .,., -module_eval(<<'.,.,', 'parser.y', 364) +module_eval(<<'.,.,', 'parser.y', 365) def _reduce_88(val, _values, result) - result = [val[0]] + result = val[0].append({tag: val[1], tokens: val[2]}) + result end .,., -module_eval(<<'.,.,', 'parser.y', 365) +module_eval(<<'.,.,', 'parser.y', 368) def _reduce_89(val, _values, result) + result = [val[0]] + result + end +.,., + +module_eval(<<'.,.,', 'parser.y', 369) + def _reduce_90(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 90 omitted +# reduce 91 omitted -module_eval(<<'.,.,', 'parser.y', 369) - def _reduce_91(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 373) + def _reduce_92(val, _values, result) on_action_error("ident after %prec", val[0]) if @prec_seen result end .,., -module_eval(<<'.,.,', 'parser.y', 370) - def _reduce_92(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 374) + def _reduce_93(val, _values, result) on_action_error("char after %prec", val[0]) if @prec_seen result end .,., -# reduce 93 omitted - # reduce 94 omitted # reduce 95 omitted # reduce 96 omitted -module_eval(<<'.,.,', 'parser.y', 380) - def _reduce_97(val, _values, result) +# reduce 97 omitted + +module_eval(<<'.,.,', 'parser.y', 384) + def _reduce_98(val, _values, result) lhs = val[0] lhs.alias_name = val[1] val[3].each do |builder| @@ -1941,8 +1952,8 @@ def _reduce_97(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 391) - def _reduce_98(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 395) + def _reduce_99(val, _values, result) builder = val[0] if !builder.line builder.line = @lexer.line - 1 @@ -1953,8 +1964,8 @@ def _reduce_98(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 399) - def _reduce_99(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 403) + def _reduce_100(val, _values, result) builder = val[2] if !builder.line builder.line = @lexer.line - 1 @@ -1965,10 +1976,10 @@ def _reduce_99(val, _values, result) end .,., -# reduce 100 omitted +# reduce 101 omitted -module_eval(<<'.,.,', 'parser.y', 409) - def _reduce_101(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 413) + def _reduce_102(val, _values, result) reset_precs result = Grammar::RuleBuilder.new(@rule_counter, @midrule_action_counter) @@ -1976,8 +1987,8 @@ def _reduce_101(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 414) - def _reduce_102(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 418) + def _reduce_103(val, _values, result) reset_precs result = Grammar::RuleBuilder.new(@rule_counter, @midrule_action_counter) @@ -1985,8 +1996,8 @@ def _reduce_102(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 419) - def _reduce_103(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 423) + def _reduce_104(val, _values, result) token = val[1] token.alias_name = val[2] builder = val[0] @@ -1997,8 +2008,8 @@ def _reduce_103(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 427) - def _reduce_104(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 431) + def _reduce_105(val, _values, result) token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]], lhs_tag: val[3]) builder = val[0] builder.add_rhs(token) @@ -2009,8 +2020,8 @@ def _reduce_104(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 435) - def _reduce_105(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 439) + def _reduce_106(val, _values, result) token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[5]) builder = val[0] builder.add_rhs(token) @@ -2021,8 +2032,8 @@ def _reduce_105(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 443) - def _reduce_106(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 447) + def _reduce_107(val, _values, result) if @prec_seen on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec @code_after_prec = true @@ -2033,16 +2044,16 @@ def _reduce_106(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 451) - def _reduce_107(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 455) + def _reduce_108(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 455) - def _reduce_108(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 459) + def _reduce_109(val, _values, result) user_code = val[3] user_code.alias_name = val[6] builder = val[0] @@ -2053,8 +2064,8 @@ def _reduce_108(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 463) - def _reduce_109(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 467) + def _reduce_110(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) @prec_seen = true builder = val[0] @@ -2065,70 +2076,70 @@ def _reduce_109(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 470) - def _reduce_110(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 474) + def _reduce_111(val, _values, result) result = "option" result end .,., -module_eval(<<'.,.,', 'parser.y', 471) - def _reduce_111(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 475) + def _reduce_112(val, _values, result) result = "nonempty_list" result end .,., -module_eval(<<'.,.,', 'parser.y', 472) - def _reduce_112(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 476) + def _reduce_113(val, _values, result) result = "list" result end .,., -module_eval(<<'.,.,', 'parser.y', 474) - def _reduce_113(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 478) + def _reduce_114(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 475) - def _reduce_114(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 479) + def _reduce_115(val, _values, result) result = val[0].append(val[2]) result end .,., -module_eval(<<'.,.,', 'parser.y', 476) - def _reduce_115(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 480) + def _reduce_116(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] result end .,., -module_eval(<<'.,.,', 'parser.y', 477) - def _reduce_116(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 481) + def _reduce_117(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] result end .,., -# reduce 117 omitted +# reduce 118 omitted -module_eval(<<'.,.,', 'parser.y', 480) - def _reduce_118(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 484) + def _reduce_119(val, _values, result) result = val[1].s_value result end .,., -# reduce 119 omitted - # reduce 120 omitted -module_eval(<<'.,.,', 'parser.y', 487) - def _reduce_121(val, _values, result) +# reduce 121 omitted + +module_eval(<<'.,.,', 'parser.y', 491) + def _reduce_122(val, _values, result) begin_c_declaration('\Z') @grammar.epilogue_first_lineno = @lexer.line + 1 @@ -2136,8 +2147,8 @@ def _reduce_121(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 492) - def _reduce_122(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 496) + def _reduce_123(val, _values, result) end_c_declaration @grammar.epilogue = val[2].s_value @@ -2145,8 +2156,6 @@ def _reduce_122(val, _values, result) end .,., -# reduce 123 omitted - # reduce 124 omitted # reduce 125 omitted @@ -2155,35 +2164,37 @@ def _reduce_122(val, _values, result) # reduce 127 omitted -module_eval(<<'.,.,', 'parser.y', 503) - def _reduce_128(val, _values, result) +# reduce 128 omitted + +module_eval(<<'.,.,', 'parser.y', 507) + def _reduce_129(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 504) - def _reduce_129(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 508) + def _reduce_130(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 130 omitted - # reduce 131 omitted -module_eval(<<'.,.,', 'parser.y', 509) - def _reduce_132(val, _values, result) +# reduce 132 omitted + +module_eval(<<'.,.,', 'parser.y', 513) + def _reduce_133(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) result end .,., -# reduce 133 omitted - # reduce 134 omitted +# reduce 135 omitted + def _reduce_none(val, _values, result) val[0] end diff --git a/parser.y b/parser.y index 8ebe7563..1aedc75e 100644 --- a/parser.y +++ b/parser.y @@ -141,6 +141,10 @@ rule { @grammar.after_reduce = val[1] } + | "%after-shift-error-token" IDENTIFIER + { + @grammar.after_shift_error_token = val[1] + } | "%after-pop-stack" IDENTIFIER { @grammar.after_pop_stack = val[1] diff --git a/spec/fixtures/integration/after_shift.y b/spec/fixtures/integration/after_shift.y index 57e0054a..56ba9055 100644 --- a/spec/fixtures/integration/after_shift.y +++ b/spec/fixtures/integration/after_shift.y @@ -24,6 +24,12 @@ after_reduce(int len) printf("after-reduce: %d, %d\n", __LINE__, len); } +static void +after_shift_error_token(void) +{ + printf("after-shift-error-token: %d\n", __LINE__); +} + static void after_pop_stack(int len) { @@ -39,6 +45,7 @@ after_pop_stack(int len) %after-shift after_shift %before-reduce before_reduce %after-reduce after_reduce +%after-shift-error-token after_shift_error_token %after-pop-stack after_pop_stack %token NUM diff --git a/spec/lrama/integration_spec.rb b/spec/lrama/integration_spec.rb index d9129a7e..31f60150 100644 --- a/spec/lrama/integration_spec.rb +++ b/spec/lrama/integration_spec.rb @@ -181,16 +181,19 @@ def generate_object(grammar_file_path, c_path, obj_path, command_args: []) before-reduce: 18, 1 after-reduce: 24, 1 after-shift: 12 - after-pop-stack: 30, 1 - after-pop-stack: 30, 1 + after-pop-stack: 36, 1 + after-pop-stack: 36, 1 + after-shift-error-token: 30 before-reduce: 18, 1 error (-1) after-reduce: 24, 1 - after-pop-stack: 30, 1 + after-pop-stack: 36, 1 + after-shift-error-token: 30 before-reduce: 18, 1 error (-1) after-reduce: 24, 1 - after-pop-stack: 30, 1 + after-pop-stack: 36, 1 + after-shift-error-token: 30 before-reduce: 18, 1 error (-1) after-reduce: 24, 1 diff --git a/template/bison/yacc.c b/template/bison/yacc.c index 9774caf2..6145a950 100644 --- a/template/bison/yacc.c +++ b/template/bison/yacc.c @@ -1988,6 +1988,7 @@ YYLTYPE yylloc = yyloc_default; /* Shift the error token. */ YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp<%= output.user_args %>); +<%= output.after_shift_error_token_function("/* %after-shift-error-token code. */") %> yystate = yyn; goto yynewstate;