From 127baa741708bfa0ec62562ad155ce762a0f59fd Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Sun, 5 Nov 2023 22:09:26 +0900 Subject: [PATCH 1/5] Add option(...) rules --- lib/lrama/lexer.rb | 7 +- lib/lrama/lexer/token/parameterizing.rb | 2 +- lib/lrama/parser.rb | 534 ++++++++++---------- parser.y | 5 + spec/fixtures/parameterizing_rules/option.y | 6 +- spec/lrama/parser_spec.rb | 44 +- 6 files changed, 333 insertions(+), 265 deletions(-) diff --git a/lib/lrama/lexer.rb b/lib/lrama/lexer.rb index c87efd58..bb0546b4 100644 --- a/lib/lrama/lexer.rb +++ b/lib/lrama/lexer.rb @@ -8,7 +8,7 @@ class Lexer attr_accessor :status attr_accessor :end_symbol - SYMBOLS = %w(%{ %} %% { } \[ \] : \| ;) + SYMBOLS = %w(%{ %} %% { } \[ \] \\( \\) : \| ;) PERCENT_TOKENS = %w( %union %token @@ -29,6 +29,9 @@ class Lexer %empty %code ) + PARAMETERIZING_TOKENS = %w( + option + ) def initialize(text) @scanner = StringScanner.new(text) @@ -89,6 +92,8 @@ def lex_token return [@scanner.matched, @scanner.matched] when @scanner.scan(/#{PERCENT_TOKENS.join('|')}/) return [@scanner.matched, @scanner.matched] + when @scanner.scan(/#{PARAMETERIZING_TOKENS.join('|')}/) + return [@scanner.matched, @scanner.matched] when @scanner.scan(/[\?\+\*]/) return [@scanner.matched, @scanner.matched] when @scanner.scan(/<\w+>/) diff --git a/lib/lrama/lexer/token/parameterizing.rb b/lib/lrama/lexer/token/parameterizing.rb index b5ce6fbd..7c3db311 100644 --- a/lib/lrama/lexer/token/parameterizing.rb +++ b/lib/lrama/lexer/token/parameterizing.rb @@ -3,7 +3,7 @@ class Lexer class Token class Parameterizing < Token def option? - self.s_value == "?" + %w(option ?).include?(self.s_value) end def nonempty_list? diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index 64932b76..dc1527f4 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', 386) +module_eval(<<'...end parser.y/module_eval...', 'parser.y', 391) include Lrama::Report::Duration @@ -731,251 +731,258 @@ def carrets(first_column, last_column) ##### State transition tables begin ### racc_action_table = [ - 84, 137, 85, 3, 6, 43, 7, 42, 39, 67, - 43, 8, 42, 136, 67, 43, 43, 42, 42, 33, - 58, 140, 43, 43, 42, 42, 140, 21, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 86, 141, 142, - 143, 144, 39, 141, 142, 143, 144, 79, 43, 43, - 42, 42, 67, 63, 70, 43, 43, 42, 42, 40, - 70, 21, 23, 24, 25, 26, 27, 28, 29, 30, - 31, 9, 45, 47, 14, 12, 13, 15, 16, 17, - 18, 47, 47, 19, 20, 21, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 43, 43, 42, 42, 50, - 70, 70, 43, 43, 42, 42, 67, 162, 43, 43, - 42, 42, 67, 162, 43, 43, 42, 42, 67, 162, - 43, 43, 42, 42, 67, 162, 43, 43, 42, 42, - 67, 162, 43, 43, 42, 42, 67, 162, 43, 43, + 84, 138, 85, 126, 127, 43, 43, 42, 42, 67, + 43, 58, 42, 137, 67, 43, 3, 42, 43, 67, + 42, 141, 67, 63, 8, 43, 141, 42, 126, 127, + 70, 141, 43, 43, 42, 42, 39, 70, 70, 33, + 86, 142, 143, 144, 145, 40, 142, 143, 144, 145, + 169, 142, 143, 144, 145, 21, 23, 24, 25, 26, + 27, 28, 29, 30, 31, 39, 43, 6, 42, 7, + 79, 70, 43, 43, 42, 42, 67, 165, 43, 43, + 42, 42, 67, 165, 21, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 9, 126, 127, 14, 12, 13, + 15, 16, 17, 18, 45, 47, 19, 20, 21, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 43, 43, + 42, 42, 67, 165, 43, 43, 42, 42, 67, 165, + 43, 43, 42, 42, 67, 165, 43, 43, 42, 42, + 67, 165, 43, 43, 42, 42, 67, 67, 43, 43, 42, 42, 67, 67, 43, 43, 42, 42, 67, 67, - 43, 43, 42, 42, 67, 67, 43, 43, 42, 42, - 43, 43, 42, 42, 51, 52, 53, 54, 55, 76, - 80, 82, 87, 87, 87, 89, 95, 99, 100, 108, - 109, 111, 113, 114, 115, 116, 117, 120, 122, 123, - 126, 127, 128, 130, 146, 148, 149, 150, 151, 152, - 126, 82, 157, 158, 165, 168, 82 ] + 43, 43, 42, 42, 43, 43, 42, 42, 43, 43, + 42, 42, 43, 43, 42, 42, 47, 47, 50, 51, + 52, 53, 54, 55, 76, 80, 82, 87, 87, 87, + 89, 95, 99, 100, 108, 109, 111, 113, 114, 115, + 116, 117, 120, 122, 123, 128, 129, 131, 146, 148, + 150, 151, 152, 153, 154, 82, 160, 161, 168, 172, + 82 ] racc_action_check = [ - 41, 124, 41, 1, 2, 125, 2, 125, 9, 125, - 153, 3, 153, 124, 153, 26, 13, 26, 13, 7, - 26, 125, 57, 58, 57, 58, 153, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 41, 125, 125, - 125, 125, 34, 153, 153, 153, 153, 34, 27, 28, - 27, 28, 27, 27, 28, 29, 68, 29, 68, 12, - 29, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 4, 14, 15, 4, 4, 4, 4, 4, 4, - 4, 16, 17, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 30, 31, 30, 31, 18, - 30, 31, 150, 69, 150, 69, 150, 150, 151, 70, - 151, 70, 151, 151, 152, 73, 152, 73, 152, 152, - 159, 74, 159, 74, 159, 159, 163, 75, 163, 75, - 163, 163, 164, 95, 164, 95, 164, 164, 62, 63, - 62, 63, 62, 63, 100, 102, 100, 102, 100, 102, - 121, 141, 121, 141, 121, 141, 97, 103, 97, 103, - 105, 118, 105, 118, 19, 21, 23, 24, 25, 32, - 37, 38, 46, 48, 49, 50, 56, 60, 61, 81, - 82, 88, 90, 91, 92, 93, 94, 98, 106, 107, - 108, 109, 110, 112, 129, 131, 132, 133, 134, 135, - 136, 138, 145, 147, 155, 167, 168 ] + 41, 124, 41, 108, 108, 125, 26, 125, 26, 125, + 155, 26, 155, 124, 155, 159, 1, 159, 27, 159, + 27, 125, 27, 27, 3, 28, 155, 28, 137, 137, + 28, 159, 29, 30, 29, 30, 9, 29, 30, 7, + 41, 125, 125, 125, 125, 12, 155, 155, 155, 155, + 159, 159, 159, 159, 159, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 34, 31, 2, 31, 2, + 34, 31, 152, 13, 152, 13, 152, 152, 153, 57, + 153, 57, 153, 153, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 4, 146, 146, 4, 4, 4, + 4, 4, 4, 4, 14, 15, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 154, 58, + 154, 58, 154, 154, 162, 68, 162, 68, 162, 162, + 166, 69, 166, 69, 166, 166, 167, 70, 167, 70, + 167, 167, 62, 63, 62, 63, 62, 63, 100, 102, + 100, 102, 100, 102, 121, 142, 121, 142, 121, 142, + 73, 74, 73, 74, 75, 95, 75, 95, 97, 103, + 97, 103, 105, 118, 105, 118, 16, 17, 18, 19, + 21, 23, 24, 25, 32, 37, 38, 46, 48, 49, + 50, 56, 60, 61, 81, 82, 88, 90, 91, 92, + 93, 94, 98, 106, 107, 109, 110, 112, 127, 130, + 132, 133, 134, 135, 136, 139, 147, 149, 157, 171, + 172 ] racc_action_pointer = [ - nil, 3, -6, 11, 62, nil, nil, 12, nil, 4, - nil, nil, 53, 13, 65, 54, 62, 63, 94, 145, - nil, 146, nil, 147, 148, 149, 12, 45, 46, 52, - 92, 93, 167, nil, 38, nil, nil, 148, 131, nil, - nil, -5, nil, nil, nil, nil, 153, nil, 154, 155, - 156, nil, nil, nil, nil, nil, 168, 19, 20, nil, - 171, 170, 135, 136, nil, nil, nil, nil, 53, 100, - 106, nil, nil, 112, 118, 124, nil, nil, nil, nil, - nil, 146, 175, nil, nil, nil, nil, nil, 179, nil, - 180, 181, 182, 183, 184, 130, nil, 153, 180, nil, - 141, nil, 142, 154, nil, 157, 177, 187, 155, 150, - 190, nil, 191, nil, nil, nil, nil, nil, 158, nil, - nil, 147, nil, nil, -21, 2, nil, nil, nil, 174, - nil, 175, 176, 177, 178, 179, 165, nil, 161, nil, - nil, 148, nil, nil, nil, 182, nil, 183, nil, nil, - 99, 105, 111, 7, nil, 202, nil, nil, nil, 117, - nil, nil, nil, 123, 129, nil, nil, 185, 166, nil ] + nil, 16, 57, 24, 85, nil, nil, 32, nil, 32, + nil, nil, 39, 70, 97, 86, 157, 158, 173, 160, + nil, 161, nil, 162, 163, 164, 3, 15, 22, 29, + 30, 63, 182, nil, 61, nil, nil, 163, 143, nil, + nil, -5, nil, nil, nil, nil, 168, nil, 169, 170, + 171, nil, nil, nil, nil, nil, 183, 76, 116, nil, + 186, 185, 139, 140, nil, nil, nil, nil, 122, 128, + 134, nil, nil, 157, 158, 161, nil, nil, nil, nil, + nil, 161, 190, nil, nil, nil, nil, nil, 194, nil, + 195, 196, 197, 198, 199, 162, nil, 165, 195, nil, + 145, nil, 146, 166, nil, 169, 192, 202, -32, 161, + 204, nil, 205, nil, nil, nil, nil, nil, 170, nil, + nil, 151, nil, nil, -21, 2, nil, 171, nil, nil, + 189, nil, 190, 191, 192, 193, 194, -7, nil, 172, + nil, nil, 152, nil, nil, nil, 60, 196, nil, 197, + nil, nil, 69, 75, 115, 7, nil, 216, nil, 12, + nil, nil, 121, nil, nil, nil, 127, 133, nil, nil, + nil, 199, 177, nil ] racc_action_default = [ - -2, -109, -8, -109, -109, -3, -4, -109, 170, -109, - -9, -10, -109, -109, -109, -109, -109, -109, -109, -109, - -23, -109, -27, -109, -109, -109, -109, -109, -109, -109, - -109, -109, -109, -7, -96, -74, -76, -109, -93, -95, - -11, -100, -72, -73, -99, -13, -14, -63, -15, -16, - -109, -20, -24, -28, -31, -34, -37, -43, -109, -46, - -49, -38, -53, -109, -56, -58, -59, -108, -39, -66, - -109, -69, -71, -40, -41, -42, -5, -1, -75, -97, - -77, -109, -109, -12, -101, -102, -103, -60, -109, -17, - -109, -109, -109, -109, -109, -109, -47, -44, -51, -50, - -109, -57, -54, -68, -70, -67, -109, -109, -82, -109, - -109, -64, -109, -21, -25, -29, -32, -35, -45, -48, - -52, -55, -6, -98, -78, -79, -83, -94, -61, -109, - -18, -109, -109, -109, -109, -109, -82, -81, -93, -85, - -86, -109, -90, -91, -92, -109, -65, -109, -22, -26, - -109, -109, -109, -80, -84, -109, -89, -62, -19, -30, - -104, -106, -107, -33, -36, -87, -105, -109, -93, -88 ] + -2, -110, -8, -110, -110, -3, -4, -110, 174, -110, + -9, -10, -110, -110, -110, -110, -110, -110, -110, -110, + -23, -110, -27, -110, -110, -110, -110, -110, -110, -110, + -110, -110, -110, -7, -97, -74, -76, -110, -94, -96, + -11, -101, -72, -73, -100, -13, -14, -63, -15, -16, + -110, -20, -24, -28, -31, -34, -37, -43, -110, -46, + -49, -38, -53, -110, -56, -58, -59, -109, -39, -66, + -110, -69, -71, -40, -41, -42, -5, -1, -75, -98, + -77, -110, -110, -12, -102, -103, -104, -60, -110, -17, + -110, -110, -110, -110, -110, -110, -47, -44, -51, -50, + -110, -57, -54, -68, -70, -67, -110, -110, -82, -110, + -110, -64, -110, -21, -25, -29, -32, -35, -45, -48, + -52, -55, -6, -99, -78, -79, -83, -110, -95, -61, + -110, -18, -110, -110, -110, -110, -110, -82, -81, -94, + -85, -87, -110, -91, -92, -93, -82, -110, -65, -110, + -22, -26, -110, -110, -110, -80, -84, -110, -90, -110, + -62, -19, -30, -105, -107, -108, -33, -36, -88, -86, + -106, -110, -94, -89 ] racc_goto_table = [ - 81, 64, 44, 57, 62, 96, 125, 104, 35, 166, - 46, 48, 49, 166, 166, 60, 1, 72, 72, 72, - 72, 103, 2, 105, 4, 34, 103, 103, 103, 68, - 73, 74, 75, 78, 153, 97, 101, 64, 77, 5, - 102, 104, 32, 104, 106, 96, 60, 60, 159, 163, - 164, 10, 11, 41, 83, 112, 147, 72, 72, 72, - 90, 131, 72, 72, 72, 91, 96, 132, 92, 133, - 93, 134, 118, 94, 64, 135, 101, 121, 56, 61, - 98, 119, 110, 145, 60, 88, 60, 129, 124, 155, - 167, 107, 72, nil, 72, 101, nil, nil, nil, 138, - 154, nil, nil, nil, nil, nil, nil, 60, nil, nil, - nil, nil, nil, nil, nil, 156, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, 138, nil, nil, - 169 ] + 81, 64, 44, 57, 62, 96, 35, 104, 170, 1, + 125, 2, 170, 170, 4, 60, 34, 72, 72, 72, + 72, 103, 77, 105, 5, 32, 103, 103, 103, 106, + 10, 78, 46, 48, 49, 97, 101, 64, 11, 155, + 102, 104, 41, 104, 83, 96, 60, 60, 159, 68, + 73, 74, 75, 162, 166, 167, 112, 72, 72, 72, + 149, 90, 72, 72, 72, 132, 96, 91, 133, 92, + 134, 93, 118, 135, 64, 94, 101, 121, 136, 56, + 61, 98, 119, 110, 60, 147, 60, 88, 130, 124, + 157, 171, 72, 107, 72, 101, nil, nil, nil, 139, + nil, 156, nil, nil, nil, nil, nil, 60, nil, nil, + nil, nil, nil, nil, nil, nil, 158, nil, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, 139, + nil, nil, nil, 139, 173 ] racc_goto_check = [ - 48, 37, 33, 31, 36, 32, 50, 44, 45, 55, - 13, 13, 13, 55, 55, 33, 1, 33, 33, 33, - 33, 43, 2, 43, 3, 4, 43, 43, 43, 30, - 30, 30, 30, 45, 50, 31, 37, 37, 5, 6, - 36, 44, 7, 44, 8, 32, 33, 33, 19, 19, - 19, 9, 10, 11, 12, 14, 15, 33, 33, 33, - 16, 17, 33, 33, 33, 20, 32, 21, 22, 23, - 24, 25, 31, 26, 37, 27, 37, 36, 28, 29, - 34, 35, 39, 40, 33, 41, 33, 42, 49, 52, - 53, 54, 33, nil, 33, 37, nil, nil, nil, 37, - 48, nil, nil, nil, nil, nil, nil, 33, nil, nil, - nil, nil, nil, nil, nil, 37, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, 37, nil, nil, - 48 ] + 48, 37, 33, 31, 36, 32, 45, 44, 55, 1, + 50, 2, 55, 55, 3, 33, 4, 33, 33, 33, + 33, 43, 5, 43, 6, 7, 43, 43, 43, 8, + 9, 45, 13, 13, 13, 31, 37, 37, 10, 50, + 36, 44, 11, 44, 12, 32, 33, 33, 50, 30, + 30, 30, 30, 19, 19, 19, 14, 33, 33, 33, + 15, 16, 33, 33, 33, 17, 32, 20, 21, 22, + 23, 24, 31, 25, 37, 26, 37, 36, 27, 28, + 29, 34, 35, 39, 33, 40, 33, 41, 42, 49, + 52, 53, 33, 54, 33, 37, nil, nil, nil, 37, + nil, 48, nil, nil, nil, nil, nil, 33, nil, nil, + nil, nil, nil, nil, nil, nil, 37, nil, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, 37, + nil, nil, nil, 37, 48 ] racc_goto_pointer = [ - nil, 16, 22, 22, 16, 4, 37, 36, -32, 47, - 48, 40, 13, -5, -34, -74, 9, -52, nil, -102, - 13, -47, 15, -46, 16, -45, 18, -42, 52, 52, - 1, -23, -52, -11, 20, -17, -23, -26, nil, -5, - -45, 38, -24, -47, -62, -1, nil, nil, -38, -20, - -102, nil, -51, -75, 12, -150 ] + nil, 9, 11, 12, 7, -12, 22, 19, -47, 26, + 34, 29, 3, 17, -33, -71, 10, -48, nil, -99, + 15, -46, 16, -45, 17, -43, 20, -39, 53, 53, + 21, -23, -52, -11, 21, -16, -23, -26, nil, -4, + -44, 40, -23, -47, -62, -3, nil, nil, -38, -19, + -98, nil, -51, -77, 14, -154 ] racc_goto_default = [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 37, nil, nil, nil, nil, nil, nil, nil, 22, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, 59, 65, nil, nil, nil, 161, 66, nil, + nil, nil, 59, 65, nil, nil, nil, 164, 66, nil, nil, nil, nil, 69, 71, nil, 36, 38, nil, nil, - nil, 139, nil, nil, nil, 160 ] + nil, 140, nil, nil, nil, 163 ] racc_reduce_table = [ 0, 0, :racc_error, - 5, 44, :_reduce_none, - 0, 45, :_reduce_none, - 2, 45, :_reduce_none, - 0, 50, :_reduce_4, - 0, 51, :_reduce_5, - 5, 49, :_reduce_6, - 2, 49, :_reduce_none, - 0, 46, :_reduce_8, - 2, 46, :_reduce_none, - 1, 52, :_reduce_none, - 2, 52, :_reduce_11, - 3, 52, :_reduce_none, - 2, 52, :_reduce_none, - 2, 52, :_reduce_none, - 2, 52, :_reduce_15, - 2, 52, :_reduce_16, - 0, 57, :_reduce_17, - 0, 58, :_reduce_18, - 7, 52, :_reduce_19, - 0, 59, :_reduce_20, - 0, 60, :_reduce_21, - 6, 52, :_reduce_22, - 1, 52, :_reduce_none, - 0, 63, :_reduce_24, - 0, 64, :_reduce_25, - 6, 53, :_reduce_26, - 1, 53, :_reduce_none, - 0, 65, :_reduce_28, - 0, 66, :_reduce_29, - 7, 53, :_reduce_none, - 0, 67, :_reduce_31, - 0, 68, :_reduce_32, - 7, 53, :_reduce_33, - 0, 69, :_reduce_34, - 0, 70, :_reduce_35, - 7, 53, :_reduce_36, - 2, 61, :_reduce_none, - 2, 61, :_reduce_38, - 2, 61, :_reduce_39, - 2, 61, :_reduce_40, - 2, 61, :_reduce_41, - 2, 61, :_reduce_42, - 1, 71, :_reduce_43, - 2, 71, :_reduce_44, - 3, 71, :_reduce_45, - 1, 74, :_reduce_46, - 2, 74, :_reduce_47, - 3, 75, :_reduce_48, - 0, 77, :_reduce_none, - 1, 77, :_reduce_none, - 0, 78, :_reduce_none, - 1, 78, :_reduce_none, - 1, 72, :_reduce_53, - 2, 72, :_reduce_54, - 3, 72, :_reduce_55, - 1, 79, :_reduce_56, - 2, 79, :_reduce_57, - 1, 80, :_reduce_none, - 1, 80, :_reduce_none, - 0, 82, :_reduce_60, - 0, 83, :_reduce_61, - 6, 56, :_reduce_62, - 0, 84, :_reduce_63, - 0, 85, :_reduce_64, - 5, 56, :_reduce_65, - 1, 73, :_reduce_66, - 2, 73, :_reduce_67, - 2, 73, :_reduce_68, - 1, 86, :_reduce_69, - 2, 86, :_reduce_70, - 1, 87, :_reduce_none, - 1, 76, :_reduce_72, - 1, 76, :_reduce_73, - 1, 47, :_reduce_none, - 2, 47, :_reduce_none, - 1, 88, :_reduce_none, - 2, 88, :_reduce_none, - 4, 89, :_reduce_78, - 1, 92, :_reduce_79, - 3, 92, :_reduce_80, - 2, 92, :_reduce_none, - 0, 93, :_reduce_82, - 1, 93, :_reduce_83, - 3, 93, :_reduce_84, - 2, 93, :_reduce_85, - 0, 95, :_reduce_86, - 0, 96, :_reduce_87, - 7, 93, :_reduce_88, - 3, 93, :_reduce_89, - 1, 94, :_reduce_none, - 1, 94, :_reduce_none, - 1, 94, :_reduce_none, - 0, 91, :_reduce_none, - 3, 91, :_reduce_94, - 1, 90, :_reduce_none, + 5, 47, :_reduce_none, 0, 48, :_reduce_none, - 0, 97, :_reduce_97, - 3, 48, :_reduce_98, - 1, 54, :_reduce_none, - 0, 55, :_reduce_none, - 1, 55, :_reduce_none, + 2, 48, :_reduce_none, + 0, 53, :_reduce_4, + 0, 54, :_reduce_5, + 5, 52, :_reduce_6, + 2, 52, :_reduce_none, + 0, 49, :_reduce_8, + 2, 49, :_reduce_none, 1, 55, :_reduce_none, + 2, 55, :_reduce_11, + 3, 55, :_reduce_none, + 2, 55, :_reduce_none, + 2, 55, :_reduce_none, + 2, 55, :_reduce_15, + 2, 55, :_reduce_16, + 0, 60, :_reduce_17, + 0, 61, :_reduce_18, + 7, 55, :_reduce_19, + 0, 62, :_reduce_20, + 0, 63, :_reduce_21, + 6, 55, :_reduce_22, 1, 55, :_reduce_none, - 1, 62, :_reduce_104, - 2, 62, :_reduce_105, - 1, 98, :_reduce_none, - 1, 98, :_reduce_none, - 1, 81, :_reduce_108 ] - -racc_reduce_n = 109 - -racc_shift_n = 170 + 0, 66, :_reduce_24, + 0, 67, :_reduce_25, + 6, 56, :_reduce_26, + 1, 56, :_reduce_none, + 0, 68, :_reduce_28, + 0, 69, :_reduce_29, + 7, 56, :_reduce_none, + 0, 70, :_reduce_31, + 0, 71, :_reduce_32, + 7, 56, :_reduce_33, + 0, 72, :_reduce_34, + 0, 73, :_reduce_35, + 7, 56, :_reduce_36, + 2, 64, :_reduce_none, + 2, 64, :_reduce_38, + 2, 64, :_reduce_39, + 2, 64, :_reduce_40, + 2, 64, :_reduce_41, + 2, 64, :_reduce_42, + 1, 74, :_reduce_43, + 2, 74, :_reduce_44, + 3, 74, :_reduce_45, + 1, 77, :_reduce_46, + 2, 77, :_reduce_47, + 3, 78, :_reduce_48, + 0, 80, :_reduce_none, + 1, 80, :_reduce_none, + 0, 81, :_reduce_none, + 1, 81, :_reduce_none, + 1, 75, :_reduce_53, + 2, 75, :_reduce_54, + 3, 75, :_reduce_55, + 1, 82, :_reduce_56, + 2, 82, :_reduce_57, + 1, 83, :_reduce_none, + 1, 83, :_reduce_none, + 0, 85, :_reduce_60, + 0, 86, :_reduce_61, + 6, 59, :_reduce_62, + 0, 87, :_reduce_63, + 0, 88, :_reduce_64, + 5, 59, :_reduce_65, + 1, 76, :_reduce_66, + 2, 76, :_reduce_67, + 2, 76, :_reduce_68, + 1, 89, :_reduce_69, + 2, 89, :_reduce_70, + 1, 90, :_reduce_none, + 1, 79, :_reduce_72, + 1, 79, :_reduce_73, + 1, 50, :_reduce_none, + 2, 50, :_reduce_none, + 1, 91, :_reduce_none, + 2, 91, :_reduce_none, + 4, 92, :_reduce_78, + 1, 95, :_reduce_79, + 3, 95, :_reduce_80, + 2, 95, :_reduce_none, + 0, 96, :_reduce_82, + 1, 96, :_reduce_83, + 3, 96, :_reduce_84, + 2, 96, :_reduce_85, + 4, 96, :_reduce_86, + 0, 98, :_reduce_87, + 0, 99, :_reduce_88, + 7, 96, :_reduce_89, + 3, 96, :_reduce_90, + 1, 97, :_reduce_none, + 1, 97, :_reduce_none, + 1, 97, :_reduce_none, + 0, 94, :_reduce_none, + 3, 94, :_reduce_95, + 1, 93, :_reduce_none, + 0, 51, :_reduce_none, + 0, 100, :_reduce_98, + 3, 51, :_reduce_99, + 1, 57, :_reduce_none, + 0, 58, :_reduce_none, + 1, 58, :_reduce_none, + 1, 58, :_reduce_none, + 1, 58, :_reduce_none, + 1, 65, :_reduce_105, + 2, 65, :_reduce_106, + 1, 101, :_reduce_none, + 1, 101, :_reduce_none, + 1, 84, :_reduce_109 ] + +racc_reduce_n = 110 + +racc_shift_n = 174 racc_token_table = { false => 0, @@ -1014,15 +1021,18 @@ def carrets(first_column, last_column) ":" => 33, "|" => 34, "%empty" => 35, - "%prec" => 36, - "?" => 37, - "+" => 38, - "*" => 39, - "[" => 40, - "]" => 41, - "{...}" => 42 } - -racc_nt_base = 43 + "option" => 36, + "(" => 37, + ")" => 38, + "%prec" => 39, + "?" => 40, + "+" => 41, + "*" => 42, + "[" => 43, + "]" => 44, + "{...}" => 45 } + +racc_nt_base = 46 racc_use_result_var = true @@ -1080,6 +1090,9 @@ def carrets(first_column, last_column) "\":\"", "\"|\"", "\"%empty\"", + "\"option\"", + "\"(\"", + "\")\"", "\"%prec\"", "\"?\"", "\"+\"", @@ -1731,6 +1744,15 @@ def _reduce_85(val, _values, result) module_eval(<<'.,.,', 'parser.y', 324) def _reduce_86(val, _values, result) + token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0]) + result = val[2].append(token) + + result + end +.,., + +module_eval(<<'.,.,', 'parser.y', 329) + def _reduce_87(val, _values, result) if @prec_seen raise "Multiple User_code after %prec" if @code_after_prec @code_after_prec = true @@ -1741,16 +1763,16 @@ def _reduce_86(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 332) - def _reduce_87(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 337) + def _reduce_88(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 336) - def _reduce_88(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 341) + def _reduce_89(val, _values, result) token = val[3] token.alias_name = val[6] result = val[0].append(token) @@ -1759,8 +1781,8 @@ def _reduce_88(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 342) - def _reduce_89(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 347) + def _reduce_90(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) result = val[0].append(sym) @prec_seen = true @@ -1769,27 +1791,27 @@ def _reduce_89(val, _values, result) end .,., -# reduce 90 omitted - # reduce 91 omitted # reduce 92 omitted # reduce 93 omitted -module_eval(<<'.,.,', 'parser.y', 352) - def _reduce_94(val, _values, result) +# reduce 94 omitted + +module_eval(<<'.,.,', 'parser.y', 357) + def _reduce_95(val, _values, result) result = val[1].s_value result end .,., -# reduce 95 omitted - # reduce 96 omitted -module_eval(<<'.,.,', 'parser.y', 359) - def _reduce_97(val, _values, result) +# reduce 97 omitted + +module_eval(<<'.,.,', 'parser.y', 364) + def _reduce_98(val, _values, result) begin_c_declaration('\Z') @grammar.epilogue_first_lineno = @lexer.line + 1 @@ -1797,8 +1819,8 @@ def _reduce_97(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 364) - def _reduce_98(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 369) + def _reduce_99(val, _values, result) end_c_declaration @grammar.epilogue = val[2].s_value @@ -1806,8 +1828,6 @@ def _reduce_98(val, _values, result) end .,., -# reduce 99 omitted - # reduce 100 omitted # reduce 101 omitted @@ -1816,26 +1836,28 @@ def _reduce_98(val, _values, result) # reduce 103 omitted -module_eval(<<'.,.,', 'parser.y', 375) - def _reduce_104(val, _values, result) +# reduce 104 omitted + +module_eval(<<'.,.,', 'parser.y', 380) + def _reduce_105(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 376) - def _reduce_105(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 381) + def _reduce_106(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 106 omitted - # reduce 107 omitted -module_eval(<<'.,.,', 'parser.y', 381) - def _reduce_108(val, _values, result) +# reduce 108 omitted + +module_eval(<<'.,.,', 'parser.y', 386) + def _reduce_109(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) result end diff --git a/parser.y b/parser.y index 0361e0e2..944286d9 100644 --- a/parser.y +++ b/parser.y @@ -320,6 +320,11 @@ rule token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1]) result = val[0].append(token) } + | "option" "(" rhs ")" + { + token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0]) + result = val[2].append(token) + } | rhs "{" { if @prec_seen diff --git a/spec/fixtures/parameterizing_rules/option.y b/spec/fixtures/parameterizing_rules/option.y index 7c152c46..05c3cd07 100644 --- a/spec/fixtures/parameterizing_rules/option.y +++ b/spec/fixtures/parameterizing_rules/option.y @@ -14,10 +14,14 @@ static int yyerror(YYLTYPE *loc, const char *str); } %token number +%token number_alias %% -program : number? +program : option(number) + ; + +alias : number_alias? ; %% diff --git a/spec/lrama/parser_spec.rb b/spec/lrama/parser_spec.rb index f3bb3c74..1235dad9 100644 --- a/spec/lrama/parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -559,8 +559,9 @@ grammar = Lrama::Parser.new(y, path).parse expect(grammar.nterms.sort_by(&:number)).to eq([ - 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: "program"), alias_name: nil, number: 6, tag: nil, term: false, token_id: 1, nullable: false), + Sym.new(id: T::Ident.new(s_value: "$accept"), alias_name: nil, number: 7, tag: nil, term: false, token_id: 0, nullable: false), + Sym.new(id: T::Ident.new(s_value: "program"), alias_name: nil, number: 8, tag: nil, term: false, token_id: 1, nullable: false), + Sym.new(id: T::Ident.new(s_value: "alias"), alias_name: nil, number: 9, tag: nil, term: false, token_id: 2, nullable: false), ]) expect(grammar.rules).to eq([ @@ -574,7 +575,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"), - lineno: 20, + lineno: 21, ), Rule.new( id: 1, @@ -585,7 +586,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("option_number"), - lineno: 20, + lineno: 21, ), Rule.new( id: 2, @@ -594,7 +595,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 20, + lineno: 21, ), Rule.new( id: 3, @@ -605,7 +606,38 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), - lineno: 20, + lineno: 21, + ), + Rule.new( + id: 4, + lhs: grammar.find_symbol_by_s_value!("alias"), + rhs: [ + grammar.find_symbol_by_s_value!("option_number_alias"), + ], + code: nil, + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("option_number_alias"), + lineno: 24, + ), + Rule.new( + id: 5, + lhs: grammar.find_symbol_by_s_value!("option_number_alias"), + rhs: [], + code: nil, + nullable: true, + precedence_sym: nil, + lineno: 24, + ), + Rule.new( + id: 6, + lhs: grammar.find_symbol_by_s_value!("option_number_alias"), + rhs: [ + grammar.find_symbol_by_s_value!("number_alias"), + ], + code: nil, + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("number_alias"), + lineno: 24, ), ]) end From a621b9d1dcba4c8591a07a1aff0b04cebfd2b83a Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Sun, 5 Nov 2023 22:27:05 +0900 Subject: [PATCH 2/5] Add nonempty_list(...) rules --- lib/lrama/lexer.rb | 1 + lib/lrama/lexer/token/parameterizing.rb | 2 +- lib/lrama/parser.rb | 522 +++++++++--------- parser.y | 5 + .../parameterizing_rules/nonempty_list.y | 6 +- spec/lrama/parser_spec.rb | 47 +- 6 files changed, 321 insertions(+), 262 deletions(-) diff --git a/lib/lrama/lexer.rb b/lib/lrama/lexer.rb index bb0546b4..eea86d9f 100644 --- a/lib/lrama/lexer.rb +++ b/lib/lrama/lexer.rb @@ -31,6 +31,7 @@ class Lexer ) PARAMETERIZING_TOKENS = %w( option + nonempty_list ) def initialize(text) diff --git a/lib/lrama/lexer/token/parameterizing.rb b/lib/lrama/lexer/token/parameterizing.rb index 7c3db311..1218af7a 100644 --- a/lib/lrama/lexer/token/parameterizing.rb +++ b/lib/lrama/lexer/token/parameterizing.rb @@ -7,7 +7,7 @@ def option? end def nonempty_list? - self.s_value == "+" + %w(nonempty_list +).include?(self.s_value) end def list? diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index dc1527f4..bcb8024e 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', 391) +module_eval(<<'...end parser.y/module_eval...', 'parser.y', 396) include Lrama::Report::Duration @@ -731,258 +731,261 @@ def carrets(first_column, last_column) ##### State transition tables begin ### racc_action_table = [ - 84, 138, 85, 126, 127, 43, 43, 42, 42, 67, - 43, 58, 42, 137, 67, 43, 3, 42, 43, 67, - 42, 141, 67, 63, 8, 43, 141, 42, 126, 127, - 70, 141, 43, 43, 42, 42, 39, 70, 70, 33, - 86, 142, 143, 144, 145, 40, 142, 143, 144, 145, - 169, 142, 143, 144, 145, 21, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 39, 43, 6, 42, 7, - 79, 70, 43, 43, 42, 42, 67, 165, 43, 43, - 42, 42, 67, 165, 21, 23, 24, 25, 26, 27, - 28, 29, 30, 31, 9, 126, 127, 14, 12, 13, - 15, 16, 17, 18, 45, 47, 19, 20, 21, 23, - 24, 25, 26, 27, 28, 29, 30, 31, 43, 43, - 42, 42, 67, 165, 43, 43, 42, 42, 67, 165, - 43, 43, 42, 42, 67, 165, 43, 43, 42, 42, - 67, 165, 43, 43, 42, 42, 67, 67, 43, 43, - 42, 42, 67, 67, 43, 43, 42, 42, 67, 67, - 43, 43, 42, 42, 43, 43, 42, 42, 43, 43, - 42, 42, 43, 43, 42, 42, 47, 47, 50, 51, - 52, 53, 54, 55, 76, 80, 82, 87, 87, 87, - 89, 95, 99, 100, 108, 109, 111, 113, 114, 115, - 116, 117, 120, 122, 123, 128, 129, 131, 146, 148, - 150, 151, 152, 153, 154, 82, 160, 161, 168, 172, - 82 ] + 84, 139, 85, 3, 8, 43, 43, 42, 42, 67, + 43, 58, 42, 138, 67, 33, 43, 43, 42, 42, + 67, 142, 70, 43, 40, 42, 142, 67, 6, 43, + 7, 42, 142, 67, 63, 43, 43, 42, 42, 142, + 70, 86, 143, 144, 145, 146, 39, 143, 144, 145, + 146, 172, 45, 143, 144, 145, 146, 47, 173, 39, + 143, 144, 145, 146, 79, 21, 23, 24, 25, 26, + 27, 28, 29, 30, 31, 43, 47, 42, 21, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 9, 47, + 50, 14, 12, 13, 15, 16, 17, 18, 51, 52, + 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 43, 43, 42, 42, 53, 70, 70, 43, + 43, 42, 42, 67, 168, 43, 43, 42, 42, 67, + 168, 43, 43, 42, 42, 67, 168, 43, 43, 42, + 42, 67, 168, 43, 43, 42, 42, 67, 168, 43, + 43, 42, 42, 67, 168, 43, 43, 42, 42, 67, + 67, 43, 43, 42, 42, 67, 67, 126, 127, 54, + 43, 128, 42, 55, 67, 126, 127, 76, 43, 128, + 42, 80, 67, 126, 127, 126, 127, 128, 43, 128, + 42, 43, 43, 42, 42, 43, 43, 42, 42, 43, + 82, 42, 87, 87, 87, 89, 95, 99, 100, 108, + 109, 111, 113, 114, 115, 116, 117, 120, 122, 123, + 129, 130, 132, 147, 148, 150, 152, 153, 154, 155, + 156, 82, 163, 164, 171, 176, 82 ] racc_action_check = [ - 41, 124, 41, 108, 108, 125, 26, 125, 26, 125, - 155, 26, 155, 124, 155, 159, 1, 159, 27, 159, - 27, 125, 27, 27, 3, 28, 155, 28, 137, 137, - 28, 159, 29, 30, 29, 30, 9, 29, 30, 7, - 41, 125, 125, 125, 125, 12, 155, 155, 155, 155, - 159, 159, 159, 159, 159, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 34, 31, 2, 31, 2, - 34, 31, 152, 13, 152, 13, 152, 152, 153, 57, - 153, 57, 153, 153, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 4, 146, 146, 4, 4, 4, - 4, 4, 4, 4, 14, 15, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 154, 58, - 154, 58, 154, 154, 162, 68, 162, 68, 162, 162, - 166, 69, 166, 69, 166, 166, 167, 70, 167, 70, - 167, 167, 62, 63, 62, 63, 62, 63, 100, 102, - 100, 102, 100, 102, 121, 142, 121, 142, 121, 142, - 73, 74, 73, 74, 75, 95, 75, 95, 97, 103, - 97, 103, 105, 118, 105, 118, 16, 17, 18, 19, - 21, 23, 24, 25, 32, 37, 38, 46, 48, 49, - 50, 56, 60, 61, 81, 82, 88, 90, 91, 92, - 93, 94, 98, 106, 107, 109, 110, 112, 127, 130, - 132, 133, 134, 135, 136, 139, 147, 149, 157, 171, - 172 ] + 41, 124, 41, 1, 3, 125, 26, 125, 26, 125, + 157, 26, 157, 124, 157, 7, 161, 28, 161, 28, + 161, 125, 28, 162, 12, 162, 157, 162, 2, 27, + 2, 27, 161, 27, 27, 29, 13, 29, 13, 162, + 29, 41, 125, 125, 125, 125, 9, 157, 157, 157, + 157, 161, 14, 161, 161, 161, 161, 15, 162, 34, + 162, 162, 162, 162, 34, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 57, 16, 57, 34, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 4, 17, + 18, 4, 4, 4, 4, 4, 4, 4, 19, 21, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 30, 31, 30, 31, 23, 30, 31, 154, + 58, 154, 58, 154, 154, 155, 68, 155, 68, 155, + 155, 156, 69, 156, 69, 156, 156, 165, 70, 165, + 70, 165, 165, 169, 73, 169, 73, 169, 169, 170, + 74, 170, 74, 170, 170, 62, 63, 62, 63, 62, + 63, 100, 102, 100, 102, 100, 102, 108, 108, 24, + 121, 108, 121, 25, 121, 138, 138, 32, 143, 138, + 143, 37, 143, 147, 147, 148, 148, 147, 75, 148, + 75, 95, 97, 95, 97, 103, 105, 103, 105, 118, + 38, 118, 46, 48, 49, 50, 56, 60, 61, 81, + 82, 88, 90, 91, 92, 93, 94, 98, 106, 107, + 109, 110, 112, 127, 128, 131, 133, 134, 135, 136, + 137, 140, 149, 151, 159, 175, 176 ] racc_action_pointer = [ - nil, 16, 57, 24, 85, nil, nil, 32, nil, 32, - nil, nil, 39, 70, 97, 86, 157, 158, 173, 160, - nil, 161, nil, 162, 163, 164, 3, 15, 22, 29, - 30, 63, 182, nil, 61, nil, nil, 163, 143, nil, - nil, -5, nil, nil, nil, nil, 168, nil, 169, 170, - 171, nil, nil, nil, nil, nil, 183, 76, 116, nil, - 186, 185, 139, 140, nil, nil, nil, nil, 122, 128, - 134, nil, nil, 157, 158, 161, nil, nil, nil, nil, - nil, 161, 190, nil, nil, nil, nil, nil, 194, nil, - 195, 196, 197, 198, 199, 162, nil, 165, 195, nil, - 145, nil, 146, 166, nil, 169, 192, 202, -32, 161, - 204, nil, 205, nil, nil, nil, nil, nil, 170, nil, - nil, 151, nil, nil, -21, 2, nil, 171, nil, nil, - 189, nil, 190, 191, 192, 193, 194, -7, nil, 172, - nil, nil, 152, nil, nil, nil, 60, 196, nil, 197, - nil, nil, 69, 75, 115, 7, nil, 216, nil, 12, - nil, nil, 121, nil, nil, nil, 127, 133, nil, nil, - nil, 199, 177, nil ] + nil, 3, 18, 4, 79, nil, nil, 8, nil, 42, + nil, nil, 18, 33, 45, 38, 57, 70, 85, 79, + nil, 80, nil, 97, 150, 154, 3, 26, 14, 32, + 109, 110, 175, nil, 55, nil, nil, 159, 156, nil, + nil, -5, nil, nil, nil, nil, 183, nil, 184, 185, + 186, nil, nil, nil, nil, nil, 198, 72, 117, nil, + 201, 200, 152, 153, nil, nil, nil, nil, 123, 129, + 135, nil, nil, 141, 147, 185, nil, nil, nil, nil, + nil, 176, 205, nil, nil, nil, nil, nil, 209, nil, + 210, 211, 212, 213, 214, 188, nil, 189, 210, nil, + 158, nil, 159, 192, nil, 193, 207, 217, 132, 175, + 219, nil, 220, nil, nil, nil, nil, nil, 196, nil, + nil, 167, nil, nil, -21, 2, nil, 186, 187, nil, + nil, 205, nil, 206, 207, 208, 209, 210, 140, nil, + 187, nil, nil, 175, nil, nil, nil, 148, 150, 212, + nil, 213, nil, nil, 116, 122, 128, 7, nil, 232, + nil, 13, 20, nil, nil, 134, nil, nil, nil, 140, + 146, nil, nil, nil, nil, 215, 192, nil ] racc_action_default = [ - -2, -110, -8, -110, -110, -3, -4, -110, 174, -110, - -9, -10, -110, -110, -110, -110, -110, -110, -110, -110, - -23, -110, -27, -110, -110, -110, -110, -110, -110, -110, - -110, -110, -110, -7, -97, -74, -76, -110, -94, -96, - -11, -101, -72, -73, -100, -13, -14, -63, -15, -16, - -110, -20, -24, -28, -31, -34, -37, -43, -110, -46, - -49, -38, -53, -110, -56, -58, -59, -109, -39, -66, - -110, -69, -71, -40, -41, -42, -5, -1, -75, -98, - -77, -110, -110, -12, -102, -103, -104, -60, -110, -17, - -110, -110, -110, -110, -110, -110, -47, -44, -51, -50, - -110, -57, -54, -68, -70, -67, -110, -110, -82, -110, - -110, -64, -110, -21, -25, -29, -32, -35, -45, -48, - -52, -55, -6, -99, -78, -79, -83, -110, -95, -61, - -110, -18, -110, -110, -110, -110, -110, -82, -81, -94, - -85, -87, -110, -91, -92, -93, -82, -110, -65, -110, - -22, -26, -110, -110, -110, -80, -84, -110, -90, -110, - -62, -19, -30, -105, -107, -108, -33, -36, -88, -86, - -106, -110, -94, -89 ] + -2, -111, -8, -111, -111, -3, -4, -111, 178, -111, + -9, -10, -111, -111, -111, -111, -111, -111, -111, -111, + -23, -111, -27, -111, -111, -111, -111, -111, -111, -111, + -111, -111, -111, -7, -98, -74, -76, -111, -95, -97, + -11, -102, -72, -73, -101, -13, -14, -63, -15, -16, + -111, -20, -24, -28, -31, -34, -37, -43, -111, -46, + -49, -38, -53, -111, -56, -58, -59, -110, -39, -66, + -111, -69, -71, -40, -41, -42, -5, -1, -75, -99, + -77, -111, -111, -12, -103, -104, -105, -60, -111, -17, + -111, -111, -111, -111, -111, -111, -47, -44, -51, -50, + -111, -57, -54, -68, -70, -67, -111, -111, -82, -111, + -111, -64, -111, -21, -25, -29, -32, -35, -45, -48, + -52, -55, -6, -100, -78, -79, -83, -111, -111, -96, + -61, -111, -18, -111, -111, -111, -111, -111, -82, -81, + -95, -85, -88, -111, -92, -93, -94, -82, -82, -111, + -65, -111, -22, -26, -111, -111, -111, -80, -84, -111, + -91, -111, -111, -62, -19, -30, -106, -108, -109, -33, + -36, -89, -86, -87, -107, -111, -95, -90 ] racc_goto_table = [ - 81, 64, 44, 57, 62, 96, 35, 104, 170, 1, - 125, 2, 170, 170, 4, 60, 34, 72, 72, 72, + 81, 64, 44, 57, 62, 96, 35, 104, 174, 125, + 1, 2, 174, 174, 4, 60, 34, 72, 72, 72, 72, 103, 77, 105, 5, 32, 103, 103, 103, 106, - 10, 78, 46, 48, 49, 97, 101, 64, 11, 155, - 102, 104, 41, 104, 83, 96, 60, 60, 159, 68, - 73, 74, 75, 162, 166, 167, 112, 72, 72, 72, - 149, 90, 72, 72, 72, 132, 96, 91, 133, 92, - 134, 93, 118, 135, 64, 94, 101, 121, 136, 56, - 61, 98, 119, 110, 60, 147, 60, 88, 130, 124, - 157, 171, 72, 107, 72, 101, nil, nil, nil, 139, - nil, 156, nil, nil, nil, nil, nil, 60, nil, nil, - nil, nil, nil, nil, nil, nil, 158, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, 139, - nil, nil, nil, 139, 173 ] + 10, 78, 46, 48, 49, 97, 101, 64, 11, 157, + 102, 104, 41, 104, 83, 96, 60, 60, 161, 162, + 68, 73, 74, 75, 165, 169, 170, 72, 72, 72, + 112, 151, 72, 72, 72, 90, 96, 133, 91, 134, + 92, 135, 118, 93, 64, 136, 101, 121, 94, 137, + 56, 61, 98, 119, 60, 110, 60, 149, 88, 131, + 124, 159, 72, 175, 72, 101, 107, nil, nil, 140, + nil, nil, 158, nil, nil, nil, nil, 60, nil, nil, + nil, nil, nil, nil, nil, nil, nil, 160, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, + nil, 140, nil, nil, nil, 140, 140, nil, 177 ] racc_goto_check = [ - 48, 37, 33, 31, 36, 32, 45, 44, 55, 1, - 50, 2, 55, 55, 3, 33, 4, 33, 33, 33, + 48, 37, 33, 31, 36, 32, 45, 44, 55, 50, + 1, 2, 55, 55, 3, 33, 4, 33, 33, 33, 33, 43, 5, 43, 6, 7, 43, 43, 43, 8, 9, 45, 13, 13, 13, 31, 37, 37, 10, 50, - 36, 44, 11, 44, 12, 32, 33, 33, 50, 30, - 30, 30, 30, 19, 19, 19, 14, 33, 33, 33, - 15, 16, 33, 33, 33, 17, 32, 20, 21, 22, - 23, 24, 31, 25, 37, 26, 37, 36, 27, 28, - 29, 34, 35, 39, 33, 40, 33, 41, 42, 49, - 52, 53, 33, 54, 33, 37, nil, nil, nil, 37, - nil, 48, nil, nil, nil, nil, nil, 33, nil, nil, - nil, nil, nil, nil, nil, nil, 37, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, 37, - nil, nil, nil, 37, 48 ] + 36, 44, 11, 44, 12, 32, 33, 33, 50, 50, + 30, 30, 30, 30, 19, 19, 19, 33, 33, 33, + 14, 15, 33, 33, 33, 16, 32, 17, 20, 21, + 22, 23, 31, 24, 37, 25, 37, 36, 26, 27, + 28, 29, 34, 35, 33, 39, 33, 40, 41, 42, + 49, 52, 33, 53, 33, 37, 54, nil, nil, 37, + nil, nil, 48, nil, nil, nil, nil, 33, nil, nil, + nil, nil, nil, nil, nil, nil, nil, 37, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, + nil, 37, nil, nil, nil, 37, 37, nil, 48 ] racc_goto_pointer = [ - nil, 9, 11, 12, 7, -12, 22, 19, -47, 26, - 34, 29, 3, 17, -33, -71, 10, -48, nil, -99, - 15, -46, 16, -45, 17, -43, 20, -39, 53, 53, - 21, -23, -52, -11, 21, -16, -23, -26, nil, -4, - -44, 40, -23, -47, -62, -3, nil, nil, -38, -19, - -98, nil, -51, -77, 14, -154 ] + nil, 10, 11, 12, 7, -12, 22, 19, -47, 26, + 34, 29, 3, 17, -29, -71, 14, -46, nil, -100, + 16, -45, 17, -44, 19, -41, 23, -38, 54, 54, + 22, -23, -52, -11, 22, -15, -23, -26, nil, -2, + -43, 41, -22, -47, -62, -3, nil, nil, -38, -18, + -99, nil, -51, -78, 17, -157 ] racc_goto_default = [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 37, nil, nil, nil, nil, nil, nil, nil, 22, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, 59, 65, nil, nil, nil, 164, 66, nil, + nil, nil, 59, 65, nil, nil, nil, 167, 66, nil, nil, nil, nil, 69, 71, nil, 36, 38, nil, nil, - nil, 140, nil, nil, nil, 163 ] + nil, 141, nil, nil, nil, 166 ] racc_reduce_table = [ 0, 0, :racc_error, - 5, 47, :_reduce_none, - 0, 48, :_reduce_none, - 2, 48, :_reduce_none, - 0, 53, :_reduce_4, - 0, 54, :_reduce_5, - 5, 52, :_reduce_6, - 2, 52, :_reduce_none, - 0, 49, :_reduce_8, + 5, 48, :_reduce_none, + 0, 49, :_reduce_none, 2, 49, :_reduce_none, - 1, 55, :_reduce_none, - 2, 55, :_reduce_11, - 3, 55, :_reduce_none, - 2, 55, :_reduce_none, - 2, 55, :_reduce_none, - 2, 55, :_reduce_15, - 2, 55, :_reduce_16, - 0, 60, :_reduce_17, - 0, 61, :_reduce_18, - 7, 55, :_reduce_19, - 0, 62, :_reduce_20, - 0, 63, :_reduce_21, - 6, 55, :_reduce_22, - 1, 55, :_reduce_none, - 0, 66, :_reduce_24, - 0, 67, :_reduce_25, - 6, 56, :_reduce_26, + 0, 54, :_reduce_4, + 0, 55, :_reduce_5, + 5, 53, :_reduce_6, + 2, 53, :_reduce_none, + 0, 50, :_reduce_8, + 2, 50, :_reduce_none, 1, 56, :_reduce_none, - 0, 68, :_reduce_28, - 0, 69, :_reduce_29, - 7, 56, :_reduce_none, - 0, 70, :_reduce_31, - 0, 71, :_reduce_32, - 7, 56, :_reduce_33, - 0, 72, :_reduce_34, - 0, 73, :_reduce_35, - 7, 56, :_reduce_36, - 2, 64, :_reduce_none, - 2, 64, :_reduce_38, - 2, 64, :_reduce_39, - 2, 64, :_reduce_40, - 2, 64, :_reduce_41, - 2, 64, :_reduce_42, - 1, 74, :_reduce_43, - 2, 74, :_reduce_44, - 3, 74, :_reduce_45, - 1, 77, :_reduce_46, - 2, 77, :_reduce_47, - 3, 78, :_reduce_48, - 0, 80, :_reduce_none, - 1, 80, :_reduce_none, + 2, 56, :_reduce_11, + 3, 56, :_reduce_none, + 2, 56, :_reduce_none, + 2, 56, :_reduce_none, + 2, 56, :_reduce_15, + 2, 56, :_reduce_16, + 0, 61, :_reduce_17, + 0, 62, :_reduce_18, + 7, 56, :_reduce_19, + 0, 63, :_reduce_20, + 0, 64, :_reduce_21, + 6, 56, :_reduce_22, + 1, 56, :_reduce_none, + 0, 67, :_reduce_24, + 0, 68, :_reduce_25, + 6, 57, :_reduce_26, + 1, 57, :_reduce_none, + 0, 69, :_reduce_28, + 0, 70, :_reduce_29, + 7, 57, :_reduce_none, + 0, 71, :_reduce_31, + 0, 72, :_reduce_32, + 7, 57, :_reduce_33, + 0, 73, :_reduce_34, + 0, 74, :_reduce_35, + 7, 57, :_reduce_36, + 2, 65, :_reduce_none, + 2, 65, :_reduce_38, + 2, 65, :_reduce_39, + 2, 65, :_reduce_40, + 2, 65, :_reduce_41, + 2, 65, :_reduce_42, + 1, 75, :_reduce_43, + 2, 75, :_reduce_44, + 3, 75, :_reduce_45, + 1, 78, :_reduce_46, + 2, 78, :_reduce_47, + 3, 79, :_reduce_48, 0, 81, :_reduce_none, 1, 81, :_reduce_none, - 1, 75, :_reduce_53, - 2, 75, :_reduce_54, - 3, 75, :_reduce_55, - 1, 82, :_reduce_56, - 2, 82, :_reduce_57, - 1, 83, :_reduce_none, - 1, 83, :_reduce_none, - 0, 85, :_reduce_60, - 0, 86, :_reduce_61, - 6, 59, :_reduce_62, - 0, 87, :_reduce_63, - 0, 88, :_reduce_64, - 5, 59, :_reduce_65, - 1, 76, :_reduce_66, - 2, 76, :_reduce_67, - 2, 76, :_reduce_68, - 1, 89, :_reduce_69, - 2, 89, :_reduce_70, - 1, 90, :_reduce_none, - 1, 79, :_reduce_72, - 1, 79, :_reduce_73, - 1, 50, :_reduce_none, - 2, 50, :_reduce_none, + 0, 82, :_reduce_none, + 1, 82, :_reduce_none, + 1, 76, :_reduce_53, + 2, 76, :_reduce_54, + 3, 76, :_reduce_55, + 1, 83, :_reduce_56, + 2, 83, :_reduce_57, + 1, 84, :_reduce_none, + 1, 84, :_reduce_none, + 0, 86, :_reduce_60, + 0, 87, :_reduce_61, + 6, 60, :_reduce_62, + 0, 88, :_reduce_63, + 0, 89, :_reduce_64, + 5, 60, :_reduce_65, + 1, 77, :_reduce_66, + 2, 77, :_reduce_67, + 2, 77, :_reduce_68, + 1, 90, :_reduce_69, + 2, 90, :_reduce_70, 1, 91, :_reduce_none, - 2, 91, :_reduce_none, - 4, 92, :_reduce_78, - 1, 95, :_reduce_79, - 3, 95, :_reduce_80, - 2, 95, :_reduce_none, - 0, 96, :_reduce_82, - 1, 96, :_reduce_83, - 3, 96, :_reduce_84, - 2, 96, :_reduce_85, - 4, 96, :_reduce_86, - 0, 98, :_reduce_87, + 1, 80, :_reduce_72, + 1, 80, :_reduce_73, + 1, 51, :_reduce_none, + 2, 51, :_reduce_none, + 1, 92, :_reduce_none, + 2, 92, :_reduce_none, + 4, 93, :_reduce_78, + 1, 96, :_reduce_79, + 3, 96, :_reduce_80, + 2, 96, :_reduce_none, + 0, 97, :_reduce_82, + 1, 97, :_reduce_83, + 3, 97, :_reduce_84, + 2, 97, :_reduce_85, + 4, 97, :_reduce_86, + 4, 97, :_reduce_87, 0, 99, :_reduce_88, - 7, 96, :_reduce_89, - 3, 96, :_reduce_90, - 1, 97, :_reduce_none, - 1, 97, :_reduce_none, - 1, 97, :_reduce_none, - 0, 94, :_reduce_none, - 3, 94, :_reduce_95, - 1, 93, :_reduce_none, - 0, 51, :_reduce_none, - 0, 100, :_reduce_98, - 3, 51, :_reduce_99, - 1, 57, :_reduce_none, - 0, 58, :_reduce_none, - 1, 58, :_reduce_none, + 0, 100, :_reduce_89, + 7, 97, :_reduce_90, + 3, 97, :_reduce_91, + 1, 98, :_reduce_none, + 1, 98, :_reduce_none, + 1, 98, :_reduce_none, + 0, 95, :_reduce_none, + 3, 95, :_reduce_96, + 1, 94, :_reduce_none, + 0, 52, :_reduce_none, + 0, 101, :_reduce_99, + 3, 52, :_reduce_100, 1, 58, :_reduce_none, - 1, 58, :_reduce_none, - 1, 65, :_reduce_105, - 2, 65, :_reduce_106, - 1, 101, :_reduce_none, - 1, 101, :_reduce_none, - 1, 84, :_reduce_109 ] + 0, 59, :_reduce_none, + 1, 59, :_reduce_none, + 1, 59, :_reduce_none, + 1, 59, :_reduce_none, + 1, 66, :_reduce_106, + 2, 66, :_reduce_107, + 1, 102, :_reduce_none, + 1, 102, :_reduce_none, + 1, 85, :_reduce_110 ] -racc_reduce_n = 110 +racc_reduce_n = 111 -racc_shift_n = 174 +racc_shift_n = 178 racc_token_table = { false => 0, @@ -1024,15 +1027,16 @@ def carrets(first_column, last_column) "option" => 36, "(" => 37, ")" => 38, - "%prec" => 39, - "?" => 40, - "+" => 41, - "*" => 42, - "[" => 43, - "]" => 44, - "{...}" => 45 } + "nonempty_list" => 39, + "%prec" => 40, + "?" => 41, + "+" => 42, + "*" => 43, + "[" => 44, + "]" => 45, + "{...}" => 46 } -racc_nt_base = 46 +racc_nt_base = 47 racc_use_result_var = true @@ -1093,6 +1097,7 @@ def carrets(first_column, last_column) "\"option\"", "\"(\"", "\")\"", + "\"nonempty_list\"", "\"%prec\"", "\"?\"", "\"+\"", @@ -1753,6 +1758,15 @@ def _reduce_86(val, _values, result) module_eval(<<'.,.,', 'parser.y', 329) def _reduce_87(val, _values, result) + token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0]) + result = val[2].append(token) + + result + end +.,., + +module_eval(<<'.,.,', 'parser.y', 334) + def _reduce_88(val, _values, result) if @prec_seen raise "Multiple User_code after %prec" if @code_after_prec @code_after_prec = true @@ -1763,16 +1777,16 @@ def _reduce_87(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 337) - def _reduce_88(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 342) + def _reduce_89(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 341) - def _reduce_89(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 346) + def _reduce_90(val, _values, result) token = val[3] token.alias_name = val[6] result = val[0].append(token) @@ -1781,8 +1795,8 @@ def _reduce_89(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 347) - def _reduce_90(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 352) + def _reduce_91(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) result = val[0].append(sym) @prec_seen = true @@ -1791,27 +1805,27 @@ def _reduce_90(val, _values, result) end .,., -# reduce 91 omitted - # reduce 92 omitted # reduce 93 omitted # reduce 94 omitted -module_eval(<<'.,.,', 'parser.y', 357) - def _reduce_95(val, _values, result) +# reduce 95 omitted + +module_eval(<<'.,.,', 'parser.y', 362) + def _reduce_96(val, _values, result) result = val[1].s_value result end .,., -# reduce 96 omitted - # reduce 97 omitted -module_eval(<<'.,.,', 'parser.y', 364) - def _reduce_98(val, _values, result) +# reduce 98 omitted + +module_eval(<<'.,.,', 'parser.y', 369) + def _reduce_99(val, _values, result) begin_c_declaration('\Z') @grammar.epilogue_first_lineno = @lexer.line + 1 @@ -1819,8 +1833,8 @@ def _reduce_98(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 369) - def _reduce_99(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 374) + def _reduce_100(val, _values, result) end_c_declaration @grammar.epilogue = val[2].s_value @@ -1828,8 +1842,6 @@ def _reduce_99(val, _values, result) end .,., -# reduce 100 omitted - # reduce 101 omitted # reduce 102 omitted @@ -1838,26 +1850,28 @@ def _reduce_99(val, _values, result) # reduce 104 omitted -module_eval(<<'.,.,', 'parser.y', 380) - def _reduce_105(val, _values, result) +# reduce 105 omitted + +module_eval(<<'.,.,', 'parser.y', 385) + def _reduce_106(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 381) - def _reduce_106(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 386) + def _reduce_107(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 107 omitted - # reduce 108 omitted -module_eval(<<'.,.,', 'parser.y', 386) - def _reduce_109(val, _values, result) +# reduce 109 omitted + +module_eval(<<'.,.,', 'parser.y', 391) + def _reduce_110(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) result end diff --git a/parser.y b/parser.y index 944286d9..d811ab21 100644 --- a/parser.y +++ b/parser.y @@ -325,6 +325,11 @@ rule token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0]) result = val[2].append(token) } + | "nonempty_list" "(" rhs ")" + { + token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0]) + result = val[2].append(token) + } | rhs "{" { if @prec_seen diff --git a/spec/fixtures/parameterizing_rules/nonempty_list.y b/spec/fixtures/parameterizing_rules/nonempty_list.y index b22ec184..71c7e01a 100644 --- a/spec/fixtures/parameterizing_rules/nonempty_list.y +++ b/spec/fixtures/parameterizing_rules/nonempty_list.y @@ -14,10 +14,14 @@ static int yyerror(YYLTYPE *loc, const char *str); } %token number +%token number_alias %% -program : number+ +program : nonempty_list(number) + ; + +alias : number_alias+ ; %% diff --git a/spec/lrama/parser_spec.rb b/spec/lrama/parser_spec.rb index 1235dad9..c9e287e8 100644 --- a/spec/lrama/parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -648,8 +648,9 @@ grammar = Lrama::Parser.new(y, path).parse expect(grammar.nterms.sort_by(&:number)).to eq([ - 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: "program"), alias_name: nil, number: 6, tag: nil, term: false, token_id: 1, nullable: false), + Sym.new(id: T::Ident.new(s_value: "$accept"), alias_name: nil, number: 7, tag: nil, term: false, token_id: 0, nullable: false), + Sym.new(id: T::Ident.new(s_value: "program"), alias_name: nil, number: 8, tag: nil, term: false, token_id: 1, nullable: false), + Sym.new(id: T::Ident.new(s_value: "alias"), alias_name: nil, number: 9, tag: nil, term: false, token_id: 2, nullable: false), ]) expect(grammar.rules).to eq([ @@ -663,7 +664,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"), - lineno: 20, + lineno: 21, ), Rule.new( id: 1, @@ -674,7 +675,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("nonempty_list_number"), - lineno: 20, + lineno: 21, ), Rule.new( id: 2, @@ -685,7 +686,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), - lineno: 20, + lineno: 21, ), Rule.new( id: 3, @@ -697,7 +698,41 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), - lineno: 20, + lineno: 21, + ), + Rule.new( + id: 4, + lhs: grammar.find_symbol_by_s_value!("alias"), + rhs: [ + grammar.find_symbol_by_s_value!("nonempty_list_number_alias"), + ], + code: nil, + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("nonempty_list_number_alias"), + lineno: 24, + ), + Rule.new( + id: 5, + lhs: grammar.find_symbol_by_s_value!("nonempty_list_number_alias"), + rhs: [ + grammar.find_symbol_by_s_value!("number_alias"), + ], + code: nil, + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("number_alias"), + lineno: 24, + ), + Rule.new( + id: 6, + lhs: grammar.find_symbol_by_s_value!("nonempty_list_number_alias"), + rhs: [ + grammar.find_symbol_by_s_value!("nonempty_list_number_alias"), + grammar.find_symbol_by_s_value!("number_alias"), + ], + code: nil, + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("number_alias"), + lineno: 24, ), ]) end From c384a82e796e12ad94e57d5ecd84cacfd7a5520a Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Sun, 5 Nov 2023 23:01:37 +0900 Subject: [PATCH 3/5] Add list(...) rules --- lib/lrama/lexer.rb | 11 +- lib/lrama/lexer/token/parameterizing.rb | 2 +- lib/lrama/parser.rb | 356 +++++++++++----------- parser.y | 17 +- spec/fixtures/parameterizing_rules/list.y | 6 +- spec/lrama/parser_spec.rb | 45 ++- 6 files changed, 247 insertions(+), 190 deletions(-) diff --git a/lib/lrama/lexer.rb b/lib/lrama/lexer.rb index eea86d9f..367e24c1 100644 --- a/lib/lrama/lexer.rb +++ b/lib/lrama/lexer.rb @@ -8,7 +8,7 @@ class Lexer attr_accessor :status attr_accessor :end_symbol - SYMBOLS = %w(%{ %} %% { } \[ \] \\( \\) : \| ;) + SYMBOLS = ['%{', '%}', '%%', '{', '}', '\[', '\]', '\(', '\)', ':', '\|', ';'] PERCENT_TOKENS = %w( %union %token @@ -29,10 +29,11 @@ class Lexer %empty %code ) - PARAMETERIZING_TOKENS = %w( - option - nonempty_list - ) + PARAMETERIZING_TOKENS = [ + 'option\(', + 'nonempty_list\(', + 'list\(' + ] def initialize(text) @scanner = StringScanner.new(text) diff --git a/lib/lrama/lexer/token/parameterizing.rb b/lib/lrama/lexer/token/parameterizing.rb index 1218af7a..9fb898cc 100644 --- a/lib/lrama/lexer/token/parameterizing.rb +++ b/lib/lrama/lexer/token/parameterizing.rb @@ -11,7 +11,7 @@ def nonempty_list? end def list? - self.s_value == "*" + %w(list *).include?(self.s_value) end end end diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index bcb8024e..7465e85f 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', 396) +module_eval(<<'...end parser.y/module_eval...', 'parser.y', 401) include Lrama::Report::Duration @@ -731,144 +731,148 @@ def carrets(first_column, last_column) ##### State transition tables begin ### racc_action_table = [ - 84, 139, 85, 3, 8, 43, 43, 42, 42, 67, - 43, 58, 42, 138, 67, 33, 43, 43, 42, 42, - 67, 142, 70, 43, 40, 42, 142, 67, 6, 43, - 7, 42, 142, 67, 63, 43, 43, 42, 42, 142, - 70, 86, 143, 144, 145, 146, 39, 143, 144, 145, - 146, 172, 45, 143, 144, 145, 146, 47, 173, 39, - 143, 144, 145, 146, 79, 21, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 43, 47, 42, 21, 23, - 24, 25, 26, 27, 28, 29, 30, 31, 9, 47, - 50, 14, 12, 13, 15, 16, 17, 18, 51, 52, - 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 43, 43, 42, 42, 53, 70, 70, 43, - 43, 42, 42, 67, 168, 43, 43, 42, 42, 67, - 168, 43, 43, 42, 42, 67, 168, 43, 43, 42, - 42, 67, 168, 43, 43, 42, 42, 67, 168, 43, - 43, 42, 42, 67, 168, 43, 43, 42, 42, 67, - 67, 43, 43, 42, 42, 67, 67, 126, 127, 54, - 43, 128, 42, 55, 67, 126, 127, 76, 43, 128, - 42, 80, 67, 126, 127, 126, 127, 128, 43, 128, - 42, 43, 43, 42, 42, 43, 43, 42, 42, 43, - 82, 42, 87, 87, 87, 89, 95, 99, 100, 108, - 109, 111, 113, 114, 115, 116, 117, 120, 122, 123, - 129, 130, 132, 147, 148, 150, 152, 153, 154, 155, - 156, 82, 163, 164, 171, 176, 82 ] + 84, 140, 85, 3, 8, 43, 43, 42, 42, 67, + 33, 58, 43, 139, 42, 43, 67, 42, 40, 67, + 43, 143, 42, 45, 67, 43, 47, 42, 143, 67, + 63, 43, 43, 42, 42, 67, 143, 70, 6, 47, + 7, 86, 144, 145, 146, 147, 163, 143, 47, 144, + 145, 146, 147, 43, 164, 42, 50, 144, 145, 146, + 147, 39, 43, 51, 42, 165, 67, 52, 144, 145, + 146, 147, 43, 43, 42, 42, 53, 70, 143, 54, + 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 39, 43, 43, 42, 42, 79, 70, 70, 55, 144, + 145, 146, 147, 43, 43, 42, 42, 67, 171, 21, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 9, + 76, 80, 14, 12, 13, 15, 16, 17, 18, 82, + 87, 19, 20, 21, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 43, 43, 42, 42, 67, 171, 43, + 43, 42, 42, 67, 171, 43, 43, 42, 42, 67, + 171, 43, 43, 42, 42, 67, 171, 43, 43, 42, + 42, 67, 171, 43, 43, 42, 42, 67, 67, 43, + 43, 42, 42, 67, 126, 127, 87, 128, 129, 43, + 43, 42, 42, 67, 126, 127, 87, 128, 129, 126, + 127, 89, 128, 129, 126, 127, 95, 128, 129, 126, + 127, 99, 128, 129, 43, 43, 42, 42, 67, 43, + 43, 42, 42, 43, 100, 42, 108, 109, 111, 113, + 114, 115, 116, 117, 120, 122, 123, 130, 131, 133, + 152, 154, 155, 156, 157, 158, 82, 166, 167, 174, + 177, 82 ] racc_action_check = [ 41, 124, 41, 1, 3, 125, 26, 125, 26, 125, - 157, 26, 157, 124, 157, 7, 161, 28, 161, 28, - 161, 125, 28, 162, 12, 162, 157, 162, 2, 27, - 2, 27, 161, 27, 27, 29, 13, 29, 13, 162, - 29, 41, 125, 125, 125, 125, 9, 157, 157, 157, - 157, 161, 14, 161, 161, 161, 161, 15, 162, 34, - 162, 162, 162, 162, 34, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 57, 16, 57, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 4, 17, - 18, 4, 4, 4, 4, 4, 4, 4, 19, 21, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 30, 31, 30, 31, 23, 30, 31, 154, - 58, 154, 58, 154, 154, 155, 68, 155, 68, 155, - 155, 156, 69, 156, 69, 156, 156, 165, 70, 165, - 70, 165, 165, 169, 73, 169, 73, 169, 169, 170, - 74, 170, 74, 170, 170, 62, 63, 62, 63, 62, - 63, 100, 102, 100, 102, 100, 102, 108, 108, 24, - 121, 108, 121, 25, 121, 138, 138, 32, 143, 138, - 143, 37, 143, 147, 147, 148, 148, 147, 75, 148, - 75, 95, 97, 95, 97, 103, 105, 103, 105, 118, - 38, 118, 46, 48, 49, 50, 56, 60, 61, 81, - 82, 88, 90, 91, 92, 93, 94, 98, 106, 107, - 109, 110, 112, 127, 128, 131, 133, 134, 135, 136, - 137, 140, 149, 151, 159, 175, 176 ] + 7, 26, 148, 124, 148, 62, 148, 62, 12, 62, + 149, 125, 149, 14, 149, 27, 15, 27, 148, 27, + 27, 150, 28, 150, 28, 150, 149, 28, 2, 16, + 2, 41, 125, 125, 125, 125, 148, 150, 17, 148, + 148, 148, 148, 13, 149, 13, 18, 149, 149, 149, + 149, 9, 159, 19, 159, 150, 159, 21, 150, 150, + 150, 150, 29, 57, 29, 57, 23, 29, 159, 24, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 34, 30, 31, 30, 31, 34, 30, 31, 25, 159, + 159, 159, 159, 156, 58, 156, 58, 156, 156, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 4, + 32, 37, 4, 4, 4, 4, 4, 4, 4, 38, + 46, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 157, 68, 157, 68, 157, 157, 158, + 69, 158, 69, 158, 158, 168, 70, 168, 70, 168, + 168, 172, 73, 172, 73, 172, 172, 173, 74, 173, + 74, 173, 173, 63, 100, 63, 100, 63, 100, 102, + 75, 102, 75, 102, 108, 108, 48, 108, 108, 121, + 95, 121, 95, 121, 127, 127, 49, 127, 127, 128, + 128, 50, 128, 128, 129, 129, 56, 129, 129, 139, + 139, 60, 139, 139, 144, 97, 144, 97, 144, 103, + 105, 103, 105, 118, 61, 118, 81, 82, 88, 90, + 91, 92, 93, 94, 98, 106, 107, 109, 110, 112, + 132, 134, 135, 136, 137, 138, 141, 151, 153, 161, + 176, 177 ] racc_action_pointer = [ - nil, 3, 18, 4, 79, nil, nil, 8, nil, 42, - nil, nil, 18, 33, 45, 38, 57, 70, 85, 79, - nil, 80, nil, 97, 150, 154, 3, 26, 14, 32, - 109, 110, 175, nil, 55, nil, nil, 159, 156, nil, - nil, -5, nil, nil, nil, nil, 183, nil, 184, 185, - 186, nil, nil, nil, nil, nil, 198, 72, 117, nil, - 201, 200, 152, 153, nil, nil, nil, nil, 123, 129, - 135, nil, nil, 141, 147, 185, nil, nil, nil, nil, - nil, 176, 205, nil, nil, nil, nil, nil, 209, nil, - 210, 211, 212, 213, 214, 188, nil, 189, 210, nil, - 158, nil, 159, 192, nil, 193, 207, 217, 132, 175, - 219, nil, 220, nil, nil, nil, nil, nil, 196, nil, - nil, 167, nil, nil, -21, 2, nil, 186, 187, nil, - nil, 205, nil, 206, 207, 208, 209, 210, 140, nil, - 187, nil, nil, 175, nil, nil, nil, 148, 150, 212, - nil, 213, nil, nil, 116, 122, 128, 7, nil, 232, - nil, 13, 20, nil, nil, 134, nil, nil, nil, 140, - 146, nil, nil, nil, nil, 215, 192, nil ] + nil, 3, 28, 4, 110, nil, nil, 3, nil, 57, + nil, nil, 12, 50, 16, 7, 20, 29, 51, 44, + nil, 48, nil, 57, 60, 79, 3, 22, 29, 69, + 88, 89, 118, nil, 86, nil, nil, 99, 85, nil, + nil, -5, nil, nil, nil, nil, 111, nil, 167, 177, + 182, nil, nil, nil, nil, nil, 198, 70, 101, nil, + 205, 216, 12, 170, nil, nil, nil, nil, 141, 147, + 153, nil, nil, 159, 165, 177, nil, nil, nil, nil, + nil, 193, 222, nil, nil, nil, nil, nil, 226, nil, + 227, 228, 229, 230, 231, 187, nil, 212, 227, nil, + 171, nil, 176, 216, nil, 217, 224, 234, 149, 192, + 236, nil, 237, nil, nil, nil, nil, nil, 220, nil, + nil, 186, nil, nil, -21, 2, nil, 159, 164, 169, + nil, nil, 220, nil, 221, 222, 223, 224, 225, 174, + nil, 202, nil, nil, 211, nil, nil, nil, 9, 17, + 28, 227, nil, 228, nil, nil, 100, 140, 146, 59, + nil, 247, nil, nil, nil, nil, nil, nil, 152, nil, + nil, nil, 158, 164, nil, nil, 230, 207, nil ] racc_action_default = [ - -2, -111, -8, -111, -111, -3, -4, -111, 178, -111, - -9, -10, -111, -111, -111, -111, -111, -111, -111, -111, - -23, -111, -27, -111, -111, -111, -111, -111, -111, -111, - -111, -111, -111, -7, -98, -74, -76, -111, -95, -97, - -11, -102, -72, -73, -101, -13, -14, -63, -15, -16, - -111, -20, -24, -28, -31, -34, -37, -43, -111, -46, - -49, -38, -53, -111, -56, -58, -59, -110, -39, -66, - -111, -69, -71, -40, -41, -42, -5, -1, -75, -99, - -77, -111, -111, -12, -103, -104, -105, -60, -111, -17, - -111, -111, -111, -111, -111, -111, -47, -44, -51, -50, - -111, -57, -54, -68, -70, -67, -111, -111, -82, -111, - -111, -64, -111, -21, -25, -29, -32, -35, -45, -48, - -52, -55, -6, -100, -78, -79, -83, -111, -111, -96, - -61, -111, -18, -111, -111, -111, -111, -111, -82, -81, - -95, -85, -88, -111, -92, -93, -94, -82, -82, -111, - -65, -111, -22, -26, -111, -111, -111, -80, -84, -111, - -91, -111, -111, -62, -19, -30, -106, -108, -109, -33, - -36, -89, -86, -87, -107, -111, -95, -90 ] + -2, -112, -8, -112, -112, -3, -4, -112, 179, -112, + -9, -10, -112, -112, -112, -112, -112, -112, -112, -112, + -23, -112, -27, -112, -112, -112, -112, -112, -112, -112, + -112, -112, -112, -7, -99, -74, -76, -112, -96, -98, + -11, -103, -72, -73, -102, -13, -14, -63, -15, -16, + -112, -20, -24, -28, -31, -34, -37, -43, -112, -46, + -49, -38, -53, -112, -56, -58, -59, -111, -39, -66, + -112, -69, -71, -40, -41, -42, -5, -1, -75, -100, + -77, -112, -112, -12, -104, -105, -106, -60, -112, -17, + -112, -112, -112, -112, -112, -112, -47, -44, -51, -50, + -112, -57, -54, -68, -70, -67, -112, -112, -82, -112, + -112, -64, -112, -21, -25, -29, -32, -35, -45, -48, + -52, -55, -6, -101, -78, -79, -83, -82, -82, -82, + -97, -61, -112, -18, -112, -112, -112, -112, -112, -82, + -81, -96, -85, -89, -112, -93, -94, -95, -112, -112, + -112, -112, -65, -112, -22, -26, -112, -112, -112, -80, + -84, -112, -92, -86, -87, -88, -62, -19, -30, -107, + -109, -110, -33, -36, -90, -108, -112, -96, -91 ] racc_goto_table = [ - 81, 64, 44, 57, 62, 96, 35, 104, 174, 125, - 1, 2, 174, 174, 4, 60, 34, 72, 72, 72, - 72, 103, 77, 105, 5, 32, 103, 103, 103, 106, - 10, 78, 46, 48, 49, 97, 101, 64, 11, 157, - 102, 104, 41, 104, 83, 96, 60, 60, 161, 162, - 68, 73, 74, 75, 165, 169, 170, 72, 72, 72, - 112, 151, 72, 72, 72, 90, 96, 133, 91, 134, - 92, 135, 118, 93, 64, 136, 101, 121, 94, 137, - 56, 61, 98, 119, 60, 110, 60, 149, 88, 131, - 124, 159, 72, 175, 72, 101, 107, nil, nil, 140, - nil, nil, 158, nil, nil, nil, nil, 60, nil, nil, - nil, nil, nil, nil, nil, nil, nil, 160, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, 140, nil, nil, nil, 140, 140, nil, 177 ] + 81, 64, 44, 57, 62, 96, 35, 104, 125, 175, + 46, 48, 49, 175, 175, 60, 1, 72, 72, 72, + 72, 68, 73, 74, 75, 2, 4, 148, 149, 150, + 34, 78, 168, 172, 173, 97, 101, 64, 77, 159, + 102, 104, 5, 104, 32, 96, 60, 60, 103, 106, + 105, 10, 11, 103, 103, 103, 41, 72, 72, 72, + 83, 112, 72, 72, 72, 153, 96, 90, 134, 91, + 135, 92, 118, 136, 64, 93, 101, 121, 137, 94, + 138, 56, 61, 98, 60, 119, 60, 110, 151, 88, + 132, 124, 72, 161, 72, 101, 176, 107, nil, 141, + nil, nil, nil, 160, nil, nil, nil, 60, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, 162, nil, + nil, nil, 141, 141, 141, nil, nil, nil, nil, nil, + nil, nil, nil, 141, nil, nil, nil, nil, nil, 178 ] racc_goto_check = [ - 48, 37, 33, 31, 36, 32, 45, 44, 55, 50, - 1, 2, 55, 55, 3, 33, 4, 33, 33, 33, - 33, 43, 5, 43, 6, 7, 43, 43, 43, 8, - 9, 45, 13, 13, 13, 31, 37, 37, 10, 50, - 36, 44, 11, 44, 12, 32, 33, 33, 50, 50, - 30, 30, 30, 30, 19, 19, 19, 33, 33, 33, - 14, 15, 33, 33, 33, 16, 32, 17, 20, 21, - 22, 23, 31, 24, 37, 25, 37, 36, 26, 27, - 28, 29, 34, 35, 33, 39, 33, 40, 41, 42, - 49, 52, 33, 53, 33, 37, 54, nil, nil, 37, - nil, nil, 48, nil, nil, nil, nil, 33, nil, nil, - nil, nil, nil, nil, nil, nil, nil, 37, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, 37, nil, nil, nil, 37, 37, nil, 48 ] + 48, 37, 33, 31, 36, 32, 45, 44, 50, 55, + 13, 13, 13, 55, 55, 33, 1, 33, 33, 33, + 33, 30, 30, 30, 30, 2, 3, 50, 50, 50, + 4, 45, 19, 19, 19, 31, 37, 37, 5, 50, + 36, 44, 6, 44, 7, 32, 33, 33, 43, 8, + 43, 9, 10, 43, 43, 43, 11, 33, 33, 33, + 12, 14, 33, 33, 33, 15, 32, 16, 17, 20, + 21, 22, 31, 23, 37, 24, 37, 36, 25, 26, + 27, 28, 29, 34, 33, 35, 33, 39, 40, 41, + 42, 49, 33, 52, 33, 37, 53, 54, nil, 37, + nil, nil, nil, 48, nil, nil, nil, 33, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, 37, nil, + nil, nil, 37, 37, 37, nil, nil, nil, nil, nil, + nil, nil, nil, 37, nil, nil, nil, nil, nil, 48 ] racc_goto_pointer = [ - nil, 10, 11, 12, 7, -12, 22, 19, -47, 26, - 34, 29, 3, 17, -29, -71, 14, -46, nil, -100, - 16, -45, 17, -44, 19, -41, 23, -38, 54, 54, - 22, -23, -52, -11, 22, -15, -23, -26, nil, -2, - -43, 41, -22, -47, -62, -3, nil, nil, -38, -18, - -99, nil, -51, -78, 17, -157 ] + nil, 16, 25, 24, 21, 4, 40, 38, -27, 47, + 48, 43, 19, -5, -28, -68, 16, -45, nil, -124, + 17, -44, 18, -42, 21, -38, 24, -37, 55, 55, + -7, -23, -52, -11, 23, -13, -23, -26, nil, 0, + -43, 42, -21, -20, -62, -3, nil, nil, -38, -17, + -100, nil, -50, -78, 18, -159 ] racc_goto_default = [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 37, nil, nil, nil, nil, nil, nil, nil, 22, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, 59, 65, nil, nil, nil, 167, 66, nil, + nil, nil, 59, 65, nil, nil, nil, 170, 66, nil, nil, nil, nil, 69, 71, nil, 36, 38, nil, nil, - nil, 141, nil, nil, nil, 166 ] + nil, 142, nil, nil, nil, 169 ] racc_reduce_table = [ 0, 0, :racc_error, @@ -957,35 +961,36 @@ def carrets(first_column, last_column) 1, 97, :_reduce_83, 3, 97, :_reduce_84, 2, 97, :_reduce_85, - 4, 97, :_reduce_86, - 4, 97, :_reduce_87, - 0, 99, :_reduce_88, - 0, 100, :_reduce_89, - 7, 97, :_reduce_90, - 3, 97, :_reduce_91, + 3, 97, :_reduce_86, + 3, 97, :_reduce_87, + 3, 97, :_reduce_88, + 0, 99, :_reduce_89, + 0, 100, :_reduce_90, + 7, 97, :_reduce_91, + 3, 97, :_reduce_92, 1, 98, :_reduce_none, 1, 98, :_reduce_none, 1, 98, :_reduce_none, 0, 95, :_reduce_none, - 3, 95, :_reduce_96, + 3, 95, :_reduce_97, 1, 94, :_reduce_none, 0, 52, :_reduce_none, - 0, 101, :_reduce_99, - 3, 52, :_reduce_100, + 0, 101, :_reduce_100, + 3, 52, :_reduce_101, 1, 58, :_reduce_none, 0, 59, :_reduce_none, 1, 59, :_reduce_none, 1, 59, :_reduce_none, 1, 59, :_reduce_none, - 1, 66, :_reduce_106, - 2, 66, :_reduce_107, + 1, 66, :_reduce_107, + 2, 66, :_reduce_108, 1, 102, :_reduce_none, 1, 102, :_reduce_none, - 1, 85, :_reduce_110 ] + 1, 85, :_reduce_111 ] -racc_reduce_n = 111 +racc_reduce_n = 112 -racc_shift_n = 178 +racc_shift_n = 179 racc_token_table = { false => 0, @@ -1024,10 +1029,10 @@ def carrets(first_column, last_column) ":" => 33, "|" => 34, "%empty" => 35, - "option" => 36, - "(" => 37, - ")" => 38, - "nonempty_list" => 39, + "option(" => 36, + ")" => 37, + "nonempty_list(" => 38, + "list(" => 39, "%prec" => 40, "?" => 41, "+" => 42, @@ -1094,10 +1099,10 @@ def carrets(first_column, last_column) "\":\"", "\"|\"", "\"%empty\"", - "\"option\"", - "\"(\"", + "\"option(\"", "\")\"", - "\"nonempty_list\"", + "\"nonempty_list(\"", + "\"list(\"", "\"%prec\"", "\"?\"", "\"+\"", @@ -1749,8 +1754,8 @@ def _reduce_85(val, _values, result) module_eval(<<'.,.,', 'parser.y', 324) def _reduce_86(val, _values, result) - token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0]) - result = val[2].append(token) + token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0].chop) + result = val[1].append(token) result end @@ -1758,8 +1763,8 @@ def _reduce_86(val, _values, result) module_eval(<<'.,.,', 'parser.y', 329) def _reduce_87(val, _values, result) - token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0]) - result = val[2].append(token) + token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0].chop) + result = val[1].append(token) result end @@ -1767,6 +1772,15 @@ def _reduce_87(val, _values, result) module_eval(<<'.,.,', 'parser.y', 334) def _reduce_88(val, _values, result) + token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0].chop) + result = val[1].append(token) + + result + end +.,., + +module_eval(<<'.,.,', 'parser.y', 339) + def _reduce_89(val, _values, result) if @prec_seen raise "Multiple User_code after %prec" if @code_after_prec @code_after_prec = true @@ -1777,16 +1791,16 @@ def _reduce_88(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 342) - def _reduce_89(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 347) + def _reduce_90(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 346) - def _reduce_90(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 351) + def _reduce_91(val, _values, result) token = val[3] token.alias_name = val[6] result = val[0].append(token) @@ -1795,8 +1809,8 @@ def _reduce_90(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 352) - def _reduce_91(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 357) + def _reduce_92(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) result = val[0].append(sym) @prec_seen = true @@ -1805,27 +1819,27 @@ def _reduce_91(val, _values, result) end .,., -# reduce 92 omitted - # reduce 93 omitted # reduce 94 omitted # reduce 95 omitted -module_eval(<<'.,.,', 'parser.y', 362) - def _reduce_96(val, _values, result) +# reduce 96 omitted + +module_eval(<<'.,.,', 'parser.y', 367) + def _reduce_97(val, _values, result) result = val[1].s_value result end .,., -# reduce 97 omitted - # reduce 98 omitted -module_eval(<<'.,.,', 'parser.y', 369) - def _reduce_99(val, _values, result) +# reduce 99 omitted + +module_eval(<<'.,.,', 'parser.y', 374) + def _reduce_100(val, _values, result) begin_c_declaration('\Z') @grammar.epilogue_first_lineno = @lexer.line + 1 @@ -1833,8 +1847,8 @@ def _reduce_99(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 374) - def _reduce_100(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 379) + def _reduce_101(val, _values, result) end_c_declaration @grammar.epilogue = val[2].s_value @@ -1842,8 +1856,6 @@ def _reduce_100(val, _values, result) end .,., -# reduce 101 omitted - # reduce 102 omitted # reduce 103 omitted @@ -1852,26 +1864,28 @@ def _reduce_100(val, _values, result) # reduce 105 omitted -module_eval(<<'.,.,', 'parser.y', 385) - def _reduce_106(val, _values, result) +# reduce 106 omitted + +module_eval(<<'.,.,', 'parser.y', 390) + def _reduce_107(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 386) - def _reduce_107(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 391) + def _reduce_108(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 108 omitted - # reduce 109 omitted -module_eval(<<'.,.,', 'parser.y', 391) - def _reduce_110(val, _values, result) +# reduce 110 omitted + +module_eval(<<'.,.,', 'parser.y', 396) + def _reduce_111(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) result end diff --git a/parser.y b/parser.y index d811ab21..cc4f4136 100644 --- a/parser.y +++ b/parser.y @@ -320,15 +320,20 @@ rule token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1]) result = val[0].append(token) } - | "option" "(" rhs ")" + | "option(" rhs ")" { - token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0]) - result = val[2].append(token) + token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0].chop) + result = val[1].append(token) } - | "nonempty_list" "(" rhs ")" + | "nonempty_list(" rhs ")" { - token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0]) - result = val[2].append(token) + token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0].chop) + result = val[1].append(token) + } + | "list(" rhs ")" + { + token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0].chop) + result = val[1].append(token) } | rhs "{" { diff --git a/spec/fixtures/parameterizing_rules/list.y b/spec/fixtures/parameterizing_rules/list.y index 141b403c..3e0efbfc 100644 --- a/spec/fixtures/parameterizing_rules/list.y +++ b/spec/fixtures/parameterizing_rules/list.y @@ -14,10 +14,14 @@ static int yyerror(YYLTYPE *loc, const char *str); } %token number +%token number_alias %% -program : number* +program : list(number) + ; + +alias : number_alias* ; %% diff --git a/spec/lrama/parser_spec.rb b/spec/lrama/parser_spec.rb index c9e287e8..c0a8f1d6 100644 --- a/spec/lrama/parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -743,8 +743,9 @@ grammar = Lrama::Parser.new(y, path).parse expect(grammar.nterms.sort_by(&:number)).to eq([ - 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: "program"), alias_name: nil, number: 6, tag: nil, term: false, token_id: 1, nullable: false), + Sym.new(id: T::Ident.new(s_value: "$accept"), alias_name: nil, number: 7, tag: nil, term: false, token_id: 0, nullable: false), + Sym.new(id: T::Ident.new(s_value: "program"), alias_name: nil, number: 8, tag: nil, term: false, token_id: 1, nullable: false), + Sym.new(id: T::Ident.new(s_value: "alias"), alias_name: nil, number: 9, tag: nil, term: false, token_id: 2, nullable: false), ]) expect(grammar.rules).to eq([ @@ -758,7 +759,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"), - lineno: 20, + lineno: 21, ), Rule.new( id: 1, @@ -769,7 +770,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("list_number"), - lineno: 20, + lineno: 21, ), Rule.new( id: 2, @@ -778,7 +779,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 20, + lineno: 21, ), Rule.new( id: 3, @@ -790,7 +791,39 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), - lineno: 20, + lineno: 21, + ), + Rule.new( + id: 4, + lhs: grammar.find_symbol_by_s_value!("alias"), + rhs: [ + grammar.find_symbol_by_s_value!("list_number_alias"), + ], + code: nil, + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("list_number_alias"), + lineno: 24, + ), + Rule.new( + id: 5, + lhs: grammar.find_symbol_by_s_value!("list_number_alias"), + rhs: [], + code: nil, + nullable: true, + precedence_sym: nil, + lineno: 24, + ), + Rule.new( + id: 6, + lhs: grammar.find_symbol_by_s_value!("list_number_alias"), + rhs: [ + grammar.find_symbol_by_s_value!("list_number_alias"), + grammar.find_symbol_by_s_value!("number_alias"), + ], + code: nil, + nullable: false, + precedence_sym: grammar.find_symbol_by_s_value!("number_alias"), + lineno: 24, ), ]) end From 02f8599d72bbc79dd21c1076d60fd02a7657af78 Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Sun, 5 Nov 2023 23:04:41 +0900 Subject: [PATCH 4/5] Extract parameterizing_prefix --- lib/lrama/parser.rb | 364 +++++++++++++++++++++----------------------- parser.y | 16 +- 2 files changed, 179 insertions(+), 201 deletions(-) diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index 7465e85f..e5c8b684 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', 401) +module_eval(<<'...end parser.y/module_eval...', 'parser.y', 395) include Lrama::Report::Duration @@ -731,148 +731,142 @@ def carrets(first_column, last_column) ##### State transition tables begin ### racc_action_table = [ - 84, 140, 85, 3, 8, 43, 43, 42, 42, 67, - 33, 58, 43, 139, 42, 43, 67, 42, 40, 67, - 43, 143, 42, 45, 67, 43, 47, 42, 143, 67, - 63, 43, 43, 42, 42, 67, 143, 70, 6, 47, - 7, 86, 144, 145, 146, 147, 163, 143, 47, 144, - 145, 146, 147, 43, 164, 42, 50, 144, 145, 146, - 147, 39, 43, 51, 42, 165, 67, 52, 144, 145, - 146, 147, 43, 43, 42, 42, 53, 70, 143, 54, - 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 39, 43, 43, 42, 42, 79, 70, 70, 55, 144, - 145, 146, 147, 43, 43, 42, 42, 67, 171, 21, - 23, 24, 25, 26, 27, 28, 29, 30, 31, 9, - 76, 80, 14, 12, 13, 15, 16, 17, 18, 82, - 87, 19, 20, 21, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 43, 43, 42, 42, 67, 171, 43, - 43, 42, 42, 67, 171, 43, 43, 42, 42, 67, - 171, 43, 43, 42, 42, 67, 171, 43, 43, 42, - 42, 67, 171, 43, 43, 42, 42, 67, 67, 43, - 43, 42, 42, 67, 126, 127, 87, 128, 129, 43, - 43, 42, 42, 67, 126, 127, 87, 128, 129, 126, - 127, 89, 128, 129, 126, 127, 95, 128, 129, 126, - 127, 99, 128, 129, 43, 43, 42, 42, 67, 43, - 43, 42, 42, 43, 100, 42, 108, 109, 111, 113, - 114, 115, 116, 117, 120, 122, 123, 130, 131, 133, - 152, 154, 155, 156, 157, 158, 82, 166, 167, 174, - 177, 82 ] + 84, 141, 85, 3, 43, 43, 42, 42, 67, 6, + 58, 7, 43, 140, 42, 43, 67, 42, 8, 67, + 144, 43, 43, 42, 42, 67, 63, 70, 144, 33, + 43, 144, 42, 40, 43, 70, 42, 39, 145, 70, + 45, 86, 146, 147, 148, 162, 145, 47, 47, 145, + 146, 147, 148, 146, 147, 148, 21, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 39, 43, 47, 42, + 126, 79, 70, 128, 129, 130, 126, 50, 51, 128, + 129, 130, 43, 52, 42, 21, 23, 24, 25, 26, + 27, 28, 29, 30, 31, 9, 53, 54, 14, 12, + 13, 15, 16, 17, 18, 55, 76, 19, 20, 21, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 126, + 80, 82, 128, 129, 130, 43, 43, 42, 42, 67, + 168, 43, 43, 42, 42, 67, 168, 43, 43, 42, + 42, 67, 168, 43, 43, 42, 42, 67, 168, 43, + 43, 42, 42, 67, 168, 43, 43, 42, 42, 67, + 168, 43, 43, 42, 42, 67, 67, 43, 43, 42, + 42, 67, 67, 43, 43, 42, 42, 67, 67, 43, + 43, 42, 42, 43, 43, 42, 42, 43, 43, 42, + 42, 43, 87, 42, 87, 87, 89, 95, 99, 100, + 108, 109, 111, 113, 114, 115, 116, 117, 120, 122, + 123, 131, 132, 134, 151, 153, 154, 155, 156, 157, + 82, 163, 164, 171, 174, 82 ] racc_action_check = [ - 41, 124, 41, 1, 3, 125, 26, 125, 26, 125, - 7, 26, 148, 124, 148, 62, 148, 62, 12, 62, - 149, 125, 149, 14, 149, 27, 15, 27, 148, 27, - 27, 150, 28, 150, 28, 150, 149, 28, 2, 16, - 2, 41, 125, 125, 125, 125, 148, 150, 17, 148, - 148, 148, 148, 13, 149, 13, 18, 149, 149, 149, - 149, 9, 159, 19, 159, 150, 159, 21, 150, 150, - 150, 150, 29, 57, 29, 57, 23, 29, 159, 24, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 34, 30, 31, 30, 31, 34, 30, 31, 25, 159, - 159, 159, 159, 156, 58, 156, 58, 156, 156, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 4, - 32, 37, 4, 4, 4, 4, 4, 4, 4, 38, - 46, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 157, 68, 157, 68, 157, 157, 158, - 69, 158, 69, 158, 158, 168, 70, 168, 70, 168, - 168, 172, 73, 172, 73, 172, 172, 173, 74, 173, - 74, 173, 173, 63, 100, 63, 100, 63, 100, 102, - 75, 102, 75, 102, 108, 108, 48, 108, 108, 121, - 95, 121, 95, 121, 127, 127, 49, 127, 127, 128, - 128, 50, 128, 128, 129, 129, 56, 129, 129, 139, - 139, 60, 139, 139, 144, 97, 144, 97, 144, 103, - 105, 103, 105, 118, 61, 118, 81, 82, 88, 90, - 91, 92, 93, 94, 98, 106, 107, 109, 110, 112, - 132, 134, 135, 136, 137, 138, 141, 151, 153, 161, - 176, 177 ] + 41, 124, 41, 1, 125, 26, 125, 26, 125, 2, + 26, 2, 149, 124, 149, 158, 149, 158, 3, 158, + 125, 27, 28, 27, 28, 27, 27, 28, 149, 7, + 29, 158, 29, 12, 30, 29, 30, 9, 125, 30, + 14, 41, 125, 125, 125, 149, 149, 15, 16, 158, + 149, 149, 149, 158, 158, 158, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 34, 31, 17, 31, + 108, 34, 31, 108, 108, 108, 127, 18, 19, 127, + 127, 127, 13, 21, 13, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34, 4, 23, 24, 4, 4, + 4, 4, 4, 4, 4, 25, 32, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 140, + 37, 38, 140, 140, 140, 155, 57, 155, 57, 155, + 155, 156, 58, 156, 58, 156, 156, 157, 68, 157, + 68, 157, 157, 165, 69, 165, 69, 165, 165, 169, + 70, 169, 70, 169, 169, 170, 73, 170, 73, 170, + 170, 62, 63, 62, 63, 62, 63, 100, 102, 100, + 102, 100, 102, 121, 145, 121, 145, 121, 145, 74, + 75, 74, 75, 95, 97, 95, 97, 103, 105, 103, + 105, 118, 46, 118, 48, 49, 50, 56, 60, 61, + 81, 82, 88, 90, 91, 92, 93, 94, 98, 106, + 107, 109, 110, 112, 133, 135, 136, 137, 138, 139, + 142, 150, 152, 160, 173, 174 ] racc_action_pointer = [ - nil, 3, 28, 4, 110, nil, nil, 3, nil, 57, - nil, nil, 12, 50, 16, 7, 20, 29, 51, 44, - nil, 48, nil, 57, 60, 79, 3, 22, 29, 69, - 88, 89, 118, nil, 86, nil, nil, 99, 85, nil, - nil, -5, nil, nil, nil, nil, 111, nil, 167, 177, - 182, nil, nil, nil, nil, nil, 198, 70, 101, nil, - 205, 216, 12, 170, nil, nil, nil, nil, 141, 147, - 153, nil, nil, 159, 165, 177, nil, nil, nil, nil, - nil, 193, 222, nil, nil, nil, nil, nil, 226, nil, - 227, 228, 229, 230, 231, 187, nil, 212, 227, nil, - 171, nil, 176, 216, nil, 217, 224, 234, 149, 192, - 236, nil, 237, nil, nil, nil, nil, nil, 220, nil, - nil, 186, nil, nil, -21, 2, nil, 159, 164, 169, - nil, nil, 220, nil, 221, 222, 223, 224, 225, 174, - nil, 202, nil, nil, 211, nil, nil, nil, 9, 17, - 28, 227, nil, 228, nil, nil, 100, 140, 146, 59, - nil, 247, nil, nil, nil, nil, nil, nil, 152, nil, - nil, nil, 158, 164, nil, nil, 230, 207, nil ] + nil, 3, -1, 18, 86, nil, nil, 22, nil, 33, + nil, nil, 27, 79, 33, 28, 29, 49, 72, 59, + nil, 64, nil, 77, 78, 86, 2, 18, 19, 27, + 31, 64, 104, nil, 62, nil, nil, 98, 77, nil, + nil, -5, nil, nil, nil, nil, 173, nil, 175, 176, + 177, nil, nil, nil, nil, nil, 189, 123, 129, nil, + 192, 191, 158, 159, nil, nil, nil, nil, 135, 141, + 147, nil, nil, 153, 176, 177, nil, nil, nil, nil, + nil, 167, 196, nil, nil, nil, nil, nil, 200, nil, + 201, 202, 203, 204, 205, 180, nil, 181, 201, nil, + 164, nil, 165, 184, nil, 185, 198, 208, 35, 166, + 210, nil, 211, nil, nil, nil, nil, nil, 188, nil, + nil, 170, nil, nil, -21, 1, nil, 41, nil, nil, + nil, nil, nil, 194, nil, 195, 196, 197, 198, 199, + 84, nil, 176, nil, nil, 171, nil, nil, nil, 9, + 201, nil, 202, nil, nil, 122, 128, 134, 12, nil, + 221, nil, nil, nil, nil, 140, nil, nil, nil, 146, + 152, nil, nil, 204, 181, nil ] racc_action_default = [ - -2, -112, -8, -112, -112, -3, -4, -112, 179, -112, - -9, -10, -112, -112, -112, -112, -112, -112, -112, -112, - -23, -112, -27, -112, -112, -112, -112, -112, -112, -112, - -112, -112, -112, -7, -99, -74, -76, -112, -96, -98, - -11, -103, -72, -73, -102, -13, -14, -63, -15, -16, - -112, -20, -24, -28, -31, -34, -37, -43, -112, -46, - -49, -38, -53, -112, -56, -58, -59, -111, -39, -66, - -112, -69, -71, -40, -41, -42, -5, -1, -75, -100, - -77, -112, -112, -12, -104, -105, -106, -60, -112, -17, - -112, -112, -112, -112, -112, -112, -47, -44, -51, -50, - -112, -57, -54, -68, -70, -67, -112, -112, -82, -112, - -112, -64, -112, -21, -25, -29, -32, -35, -45, -48, - -52, -55, -6, -101, -78, -79, -83, -82, -82, -82, - -97, -61, -112, -18, -112, -112, -112, -112, -112, -82, - -81, -96, -85, -89, -112, -93, -94, -95, -112, -112, - -112, -112, -65, -112, -22, -26, -112, -112, -112, -80, - -84, -112, -92, -86, -87, -88, -62, -19, -30, -107, - -109, -110, -33, -36, -90, -108, -112, -96, -91 ] + -2, -113, -8, -113, -113, -3, -4, -113, 176, -113, + -9, -10, -113, -113, -113, -113, -113, -113, -113, -113, + -23, -113, -27, -113, -113, -113, -113, -113, -113, -113, + -113, -113, -113, -7, -100, -74, -76, -113, -97, -99, + -11, -104, -72, -73, -103, -13, -14, -63, -15, -16, + -113, -20, -24, -28, -31, -34, -37, -43, -113, -46, + -49, -38, -53, -113, -56, -58, -59, -112, -39, -66, + -113, -69, -71, -40, -41, -42, -5, -1, -75, -101, + -77, -113, -113, -12, -105, -106, -107, -60, -113, -17, + -113, -113, -113, -113, -113, -113, -47, -44, -51, -50, + -113, -57, -54, -68, -70, -67, -113, -113, -82, -113, + -113, -64, -113, -21, -25, -29, -32, -35, -45, -48, + -52, -55, -6, -102, -78, -79, -83, -82, -91, -92, + -93, -98, -61, -113, -18, -113, -113, -113, -113, -113, + -82, -81, -97, -85, -87, -113, -94, -95, -96, -113, + -113, -65, -113, -22, -26, -113, -113, -113, -80, -84, + -113, -90, -86, -62, -19, -30, -108, -110, -111, -33, + -36, -88, -109, -113, -97, -89 ] racc_goto_table = [ - 81, 64, 44, 57, 62, 96, 35, 104, 125, 175, - 46, 48, 49, 175, 175, 60, 1, 72, 72, 72, - 72, 68, 73, 74, 75, 2, 4, 148, 149, 150, - 34, 78, 168, 172, 173, 97, 101, 64, 77, 159, - 102, 104, 5, 104, 32, 96, 60, 60, 103, 106, - 105, 10, 11, 103, 103, 103, 41, 72, 72, 72, - 83, 112, 72, 72, 72, 153, 96, 90, 134, 91, - 135, 92, 118, 136, 64, 93, 101, 121, 137, 94, - 138, 56, 61, 98, 60, 119, 60, 110, 151, 88, - 132, 124, 72, 161, 72, 101, 176, 107, nil, 141, - nil, nil, nil, 160, nil, nil, nil, 60, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, 162, nil, - nil, nil, 141, 141, 141, nil, nil, nil, nil, nil, - nil, nil, nil, 141, nil, nil, nil, nil, nil, 178 ] + 81, 64, 44, 57, 62, 96, 125, 104, 35, 172, + 46, 48, 49, 172, 172, 60, 1, 72, 72, 72, + 72, 103, 2, 105, 4, 149, 103, 103, 103, 68, + 73, 74, 75, 78, 34, 97, 101, 64, 158, 77, + 102, 104, 5, 104, 32, 96, 60, 60, 165, 169, + 170, 106, 10, 11, 41, 83, 112, 72, 72, 72, + 152, 90, 72, 72, 72, 135, 96, 91, 136, 92, + 137, 93, 118, 138, 64, 94, 101, 121, 139, 56, + 61, 98, 119, 110, 60, 150, 60, 88, 133, 124, + 160, 173, 72, 107, 72, 101, nil, nil, nil, 142, + nil, nil, nil, nil, 159, nil, nil, 60, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, 161, + nil, nil, nil, 142, nil, nil, nil, nil, nil, nil, + nil, nil, 142, nil, nil, nil, 175 ] racc_goto_check = [ - 48, 37, 33, 31, 36, 32, 45, 44, 50, 55, - 13, 13, 13, 55, 55, 33, 1, 33, 33, 33, - 33, 30, 30, 30, 30, 2, 3, 50, 50, 50, - 4, 45, 19, 19, 19, 31, 37, 37, 5, 50, - 36, 44, 6, 44, 7, 32, 33, 33, 43, 8, - 43, 9, 10, 43, 43, 43, 11, 33, 33, 33, - 12, 14, 33, 33, 33, 15, 32, 16, 17, 20, - 21, 22, 31, 23, 37, 24, 37, 36, 25, 26, - 27, 28, 29, 34, 33, 35, 33, 39, 40, 41, - 42, 49, 33, 52, 33, 37, 53, 54, nil, 37, - nil, nil, nil, 48, nil, nil, nil, 33, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, 37, nil, - nil, nil, 37, 37, 37, nil, nil, nil, nil, nil, - nil, nil, nil, 37, nil, nil, nil, nil, nil, 48 ] + 48, 37, 33, 31, 36, 32, 50, 44, 45, 56, + 13, 13, 13, 56, 56, 33, 1, 33, 33, 33, + 33, 43, 2, 43, 3, 50, 43, 43, 43, 30, + 30, 30, 30, 45, 4, 31, 37, 37, 50, 5, + 36, 44, 6, 44, 7, 32, 33, 33, 19, 19, + 19, 8, 9, 10, 11, 12, 14, 33, 33, 33, + 15, 16, 33, 33, 33, 17, 32, 20, 21, 22, + 23, 24, 31, 25, 37, 26, 37, 36, 27, 28, + 29, 34, 35, 39, 33, 40, 33, 41, 42, 49, + 53, 54, 33, 55, 33, 37, nil, nil, nil, 37, + nil, nil, nil, nil, 48, nil, nil, 33, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, 37, + nil, nil, nil, 37, nil, nil, nil, nil, nil, nil, + nil, nil, 37, nil, nil, nil, 48 ] racc_goto_pointer = [ - nil, 16, 25, 24, 21, 4, 40, 38, -27, 47, - 48, 43, 19, -5, -28, -68, 16, -45, nil, -124, - 17, -44, 18, -42, 21, -38, 24, -37, 55, 55, - -7, -23, -52, -11, 23, -13, -23, -26, nil, 0, - -43, 42, -21, -20, -62, -3, nil, nil, -38, -17, - -100, nil, -50, -78, 18, -159 ] + nil, 16, 22, 22, 25, 5, 40, 38, -25, 48, + 49, 41, 14, -5, -33, -74, 10, -48, nil, -107, + 15, -46, 16, -45, 17, -43, 20, -39, 53, 53, + 1, -23, -52, -11, 21, -16, -23, -26, nil, -4, + -47, 40, -23, -47, -62, -1, nil, nil, -38, -19, + -102, nil, nil, -54, -80, 14, -156 ] racc_goto_default = [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 37, nil, nil, nil, nil, nil, nil, nil, 22, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, 59, 65, nil, nil, nil, 170, 66, nil, + nil, nil, 59, 65, nil, nil, nil, 167, 66, nil, nil, nil, nil, 69, 71, nil, 36, 38, nil, nil, - nil, 142, nil, nil, nil, 169 ] + nil, 143, 127, nil, nil, nil, 166 ] racc_reduce_table = [ 0, 0, :racc_error, @@ -962,35 +956,36 @@ def carrets(first_column, last_column) 3, 97, :_reduce_84, 2, 97, :_reduce_85, 3, 97, :_reduce_86, - 3, 97, :_reduce_87, - 3, 97, :_reduce_88, - 0, 99, :_reduce_89, - 0, 100, :_reduce_90, - 7, 97, :_reduce_91, - 3, 97, :_reduce_92, + 0, 100, :_reduce_87, + 0, 101, :_reduce_88, + 7, 97, :_reduce_89, + 3, 97, :_reduce_90, + 1, 99, :_reduce_none, + 1, 99, :_reduce_none, + 1, 99, :_reduce_none, 1, 98, :_reduce_none, 1, 98, :_reduce_none, 1, 98, :_reduce_none, 0, 95, :_reduce_none, - 3, 95, :_reduce_97, + 3, 95, :_reduce_98, 1, 94, :_reduce_none, 0, 52, :_reduce_none, - 0, 101, :_reduce_100, - 3, 52, :_reduce_101, + 0, 102, :_reduce_101, + 3, 52, :_reduce_102, 1, 58, :_reduce_none, 0, 59, :_reduce_none, 1, 59, :_reduce_none, 1, 59, :_reduce_none, 1, 59, :_reduce_none, - 1, 66, :_reduce_107, - 2, 66, :_reduce_108, - 1, 102, :_reduce_none, - 1, 102, :_reduce_none, - 1, 85, :_reduce_111 ] + 1, 66, :_reduce_108, + 2, 66, :_reduce_109, + 1, 103, :_reduce_none, + 1, 103, :_reduce_none, + 1, 85, :_reduce_112 ] -racc_reduce_n = 112 +racc_reduce_n = 113 -racc_shift_n = 179 +racc_shift_n = 176 racc_token_table = { false => 0, @@ -1029,11 +1024,11 @@ def carrets(first_column, last_column) ":" => 33, "|" => 34, "%empty" => 35, - "option(" => 36, - ")" => 37, - "nonempty_list(" => 38, - "list(" => 39, - "%prec" => 40, + ")" => 36, + "%prec" => 37, + "option(" => 38, + "nonempty_list(" => 39, + "list(" => 40, "?" => 41, "+" => 42, "*" => 43, @@ -1099,11 +1094,11 @@ def carrets(first_column, last_column) "\":\"", "\"|\"", "\"%empty\"", - "\"option(\"", "\")\"", + "\"%prec\"", + "\"option(\"", "\"nonempty_list(\"", "\"list(\"", - "\"%prec\"", "\"?\"", "\"+\"", "\"*\"", @@ -1162,6 +1157,7 @@ def carrets(first_column, last_column) "rhs_list", "rhs", "parameterizing_suffix", + "parameterizing_prefix", "@19", "@20", "@21", @@ -1763,24 +1759,6 @@ def _reduce_86(val, _values, result) module_eval(<<'.,.,', 'parser.y', 329) def _reduce_87(val, _values, result) - token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0].chop) - result = val[1].append(token) - - result - end -.,., - -module_eval(<<'.,.,', 'parser.y', 334) - def _reduce_88(val, _values, result) - token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0].chop) - result = val[1].append(token) - - result - end -.,., - -module_eval(<<'.,.,', 'parser.y', 339) - def _reduce_89(val, _values, result) if @prec_seen raise "Multiple User_code after %prec" if @code_after_prec @code_after_prec = true @@ -1791,16 +1769,16 @@ def _reduce_89(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 347) - def _reduce_90(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 337) + def _reduce_88(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 351) - def _reduce_91(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 341) + def _reduce_89(val, _values, result) token = val[3] token.alias_name = val[6] result = val[0].append(token) @@ -1809,8 +1787,8 @@ def _reduce_91(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 357) - def _reduce_92(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 347) + def _reduce_90(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) result = val[0].append(sym) @prec_seen = true @@ -1819,6 +1797,10 @@ def _reduce_92(val, _values, result) end .,., +# reduce 91 omitted + +# reduce 92 omitted + # reduce 93 omitted # reduce 94 omitted @@ -1827,19 +1809,21 @@ def _reduce_92(val, _values, result) # reduce 96 omitted -module_eval(<<'.,.,', 'parser.y', 367) - def _reduce_97(val, _values, result) +# reduce 97 omitted + +module_eval(<<'.,.,', 'parser.y', 361) + def _reduce_98(val, _values, result) result = val[1].s_value result end .,., -# reduce 98 omitted - # reduce 99 omitted -module_eval(<<'.,.,', 'parser.y', 374) - def _reduce_100(val, _values, result) +# reduce 100 omitted + +module_eval(<<'.,.,', 'parser.y', 368) + def _reduce_101(val, _values, result) begin_c_declaration('\Z') @grammar.epilogue_first_lineno = @lexer.line + 1 @@ -1847,8 +1831,8 @@ def _reduce_100(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 379) - def _reduce_101(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 373) + def _reduce_102(val, _values, result) end_c_declaration @grammar.epilogue = val[2].s_value @@ -1856,8 +1840,6 @@ def _reduce_101(val, _values, result) end .,., -# reduce 102 omitted - # reduce 103 omitted # reduce 104 omitted @@ -1866,26 +1848,28 @@ def _reduce_101(val, _values, result) # reduce 106 omitted -module_eval(<<'.,.,', 'parser.y', 390) - def _reduce_107(val, _values, result) +# reduce 107 omitted + +module_eval(<<'.,.,', 'parser.y', 384) + def _reduce_108(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 391) - def _reduce_108(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 385) + def _reduce_109(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 109 omitted - # reduce 110 omitted -module_eval(<<'.,.,', 'parser.y', 396) - def _reduce_111(val, _values, result) +# reduce 111 omitted + +module_eval(<<'.,.,', 'parser.y', 390) + def _reduce_112(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) result end diff --git a/parser.y b/parser.y index cc4f4136..b98a31c2 100644 --- a/parser.y +++ b/parser.y @@ -320,17 +320,7 @@ rule token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1]) result = val[0].append(token) } - | "option(" rhs ")" - { - token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0].chop) - result = val[1].append(token) - } - | "nonempty_list(" rhs ")" - { - token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0].chop) - result = val[1].append(token) - } - | "list(" rhs ")" + | parameterizing_prefix rhs ")" { token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[0].chop) result = val[1].append(token) @@ -360,6 +350,10 @@ rule @prec_seen = true } + parameterizing_prefix: "option(" + | "nonempty_list(" + | "list(" + parameterizing_suffix: "?" | "+" | "*" From 206f2e944e6dfd63b11e2c9d65c0545bfc0e542e Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Sun, 5 Nov 2023 23:09:41 +0900 Subject: [PATCH 5/5] Remove unknown argument for Rules --- spec/lrama/parser_spec.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/spec/lrama/parser_spec.rb b/spec/lrama/parser_spec.rb index c0a8f1d6..104c9abf 100644 --- a/spec/lrama/parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -614,7 +614,6 @@ rhs: [ grammar.find_symbol_by_s_value!("option_number_alias"), ], - code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("option_number_alias"), lineno: 24, @@ -623,7 +622,6 @@ id: 5, lhs: grammar.find_symbol_by_s_value!("option_number_alias"), rhs: [], - code: nil, nullable: true, precedence_sym: nil, lineno: 24, @@ -634,7 +632,6 @@ rhs: [ grammar.find_symbol_by_s_value!("number_alias"), ], - code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number_alias"), lineno: 24, @@ -706,7 +703,6 @@ rhs: [ grammar.find_symbol_by_s_value!("nonempty_list_number_alias"), ], - code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("nonempty_list_number_alias"), lineno: 24, @@ -717,7 +713,6 @@ rhs: [ grammar.find_symbol_by_s_value!("number_alias"), ], - code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number_alias"), lineno: 24, @@ -729,7 +724,6 @@ grammar.find_symbol_by_s_value!("nonempty_list_number_alias"), grammar.find_symbol_by_s_value!("number_alias"), ], - code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number_alias"), lineno: 24, @@ -799,7 +793,6 @@ rhs: [ grammar.find_symbol_by_s_value!("list_number_alias"), ], - code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("list_number_alias"), lineno: 24, @@ -808,7 +801,6 @@ id: 5, lhs: grammar.find_symbol_by_s_value!("list_number_alias"), rhs: [], - code: nil, nullable: true, precedence_sym: nil, lineno: 24, @@ -820,7 +812,6 @@ grammar.find_symbol_by_s_value!("list_number_alias"), grammar.find_symbol_by_s_value!("number_alias"), ], - code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number_alias"), lineno: 24,