lrama 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9da05580a6b043f3aed0b59a8960a121b492fb12f206c305c158db5159a2ec0
4
- data.tar.gz: 2021675193cc9cda3e60b0b8102f5105502abd9d7dd539d37748554d80ce09bb
3
+ metadata.gz: b4f465954bd574e3af961a8f81fabc1f09623e33a2713d61ebf81e0f3c0157c6
4
+ data.tar.gz: 21003fa125c6b7104321ddd8e4ed9d987f084a6091e2aabde380db3e75412032
5
5
  SHA512:
6
- metadata.gz: 4bf20bb095d05dff1d433b1cbb28f6245e9abe162adbc26f19970344d9a1adcb582a43168c29709b765927ffebbc6272c6098561afeb9d536af778da42dfef81
7
- data.tar.gz: 916d2dd4cb22e88b8bc543a8bc26b7246eada1beb7065d5ece965ffe143bcb06689480733e0ba969e5ba90a20e65af9ff7a288b4c27391b74224044d8d1e5452
6
+ metadata.gz: c70043eda6fc7daa5bb810d0d387d0cdda7d9d141e7b279894975b0084435c0b12eaeaaad0b6a15c3d6cf2eb7e67d110db9b153586b3452a56dd36aa4a9e106c
7
+ data.tar.gz: 0a2ab263ce326971b685497d200e2ca118a07808302f310066b8365d9727fc384f04b1c09a1311cc4930d79af8f7f1dc50c327c298f512d5408c59b5c8aeae93
data/Gemfile CHANGED
@@ -17,7 +17,7 @@ gem "stackprof", platforms: [:ruby] # stackprof doesn't support Windows
17
17
  # Recent steep requires Ruby >= 3.0.0.
18
18
  # Then skip install on some CI jobs.
19
19
  if !ENV['GITHUB_ACTION'] || ENV['INSTALL_STEEP'] == 'true'
20
- gem "rbs", "3.9.5", require: false
20
+ gem "rbs", "3.10.0", require: false
21
21
  gem "rbs-inline", require: false
22
22
  gem "steep", "1.10.0", require: false
23
23
  end
data/NEWS.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # NEWS for Lrama
2
2
 
3
+ ## Lrama 0.8.0 (2026-03-01)
4
+
5
+ ### Support parser generation without %union directive (Bison compatibility)
6
+
7
+ When writing simple parsers or prototypes, defining `%union` can be cumbersome and unnecessary.
8
+ Lrama now supports generating parsers without the `%union` directive, defaulting `YYSTYPE` to `int`, the same behavior as Bison.
9
+
10
+ When `%union` is not defined:
11
+
12
+ - `YYSTYPE` defaults to `int`
13
+ - Semantic value references are generated without union member access
14
+ - The generated parser behaves identically to Bison-generated parsers
15
+
16
+ https://github.com/ruby/lrama/pull/765
17
+
18
+ ### Allow named references on parameterized rule calls inside %rule
19
+
20
+ Named references (e.g. `[opt]`) can now be used with parameterized rule calls inside a `%rule` body.
21
+ Previously, writing `f_opt_arg(value)[opt]` inside a `%rule` resulted in a parse error.
22
+
23
+ ```yacc
24
+ %rule example(X): f_opt_arg(X)[opt] { $$ = $opt; }
25
+ ;
26
+ ```
27
+
28
+ https://github.com/ruby/lrama/pull/778
29
+
30
+ ### Fix nested parameterized rule calls in subsequent argument positions
31
+
32
+ Nested parameterized rule calls (e.g. `f_opt(number)`) can now appear in any argument position, not only the first one.
33
+ Previously, using a nested call as the second or later argument caused a parse error.
34
+
35
+ ```yacc
36
+ %%
37
+ program: args_list(f_opt(number), opt_tail(string), number)
38
+ ;
39
+ ```
40
+
41
+ https://github.com/ruby/lrama/pull/779
42
+
3
43
  ## Lrama 0.7.1 (2025-12-24)
4
44
 
5
45
  ### Optimize IELR
data/README.md CHANGED
@@ -11,7 +11,8 @@ Lrama (pronounced in the same way as the noun “llama” in English) is LALR (1
11
11
  - [Usage](#usage)
12
12
  - [Documentation](#documentation)
13
13
  - [Versions and Branches](#versions-and-branches)
14
- - [v0\_7 (`master` branch)](#v0_7-master-branch)
14
+ - [v0\_8 (`master` branch)](#v0_8-master-branch)
15
+ - [v0\_7 (`lrama_0_7` branch)](#v0_7-lrama_0_7-branch)
15
16
  - [v0\_6 (`lrama_0_6` branch)](#v0_6-lrama_0_6-branch)
16
17
  - [v0\_5 (`lrama_0_5` branch)](#v0_5-lrama_0_5-branch)
17
18
  - [v0\_4 (`lrama_0_4` branch)](#v0_4-lrama_0_4-branch)
@@ -84,9 +85,13 @@ https://ruby.github.io/lrama/ provides a comprehensive guide to Lrama's features
84
85
 
85
86
  ## Versions and Branches
86
87
 
87
- ### v0_7 (`master` branch)
88
+ ### v0_8 (`master` branch)
88
89
 
89
- This branch is for Ruby 3.5. `lrama_0_7` branch is created from this branch, once Ruby 3.5 is released.
90
+ This branch is for Ruby 4.1. `lrama_0_8` branch is created from this branch, once Ruby 4.1 is released.
91
+
92
+ ### v0_7 (`lrama_0_7` branch)
93
+
94
+ This branch is for Ruby 4.0.
90
95
 
91
96
  ### v0_6 (`lrama_0_6` branch)
92
97
 
@@ -30,6 +30,7 @@ module Lrama
30
30
  def create_instantiate_rule(sym)
31
31
  Lrama::Lexer::Token::InstantiateRule.new(
32
32
  s_value: sym.s_value,
33
+ alias_name: sym.alias_name,
33
34
  location: sym.location,
34
35
  args: resolve_args(sym.args),
35
36
  lhs_tag: sym.lhs_tag
@@ -11,11 +11,13 @@ module Lrama
11
11
  #
12
12
  # @rbs!
13
13
  # @rule: Rule
14
+ # @grammar: Grammar
14
15
 
15
- # @rbs (type: ::Symbol, token_code: Lexer::Token::UserCode, rule: Rule) -> void
16
- def initialize(type:, token_code:, rule:)
16
+ # @rbs (type: ::Symbol, token_code: Lexer::Token::UserCode, rule: Rule, grammar: Grammar) -> void
17
+ def initialize(type:, token_code:, rule:, grammar:)
17
18
  super(type: type, token_code: token_code)
18
19
  @rule = rule
20
+ @grammar = grammar
19
21
  end
20
22
 
21
23
  private
@@ -53,9 +55,15 @@ module Lrama
53
55
  case
54
56
  when ref.type == :dollar && ref.name == "$" # $$
55
57
  tag = ref.ex_tag || lhs.tag
56
- raise_tag_not_found_error(ref) unless tag
57
- # @type var tag: Lexer::Token::Tag
58
- "(yyval.#{tag.member})"
58
+ if tag
59
+ # @type var tag: Lexer::Token::Tag
60
+ "(yyval.#{tag.member})"
61
+ elsif union_not_defined?
62
+ # When %union is not defined, YYSTYPE defaults to int
63
+ "(yyval)"
64
+ else
65
+ raise_tag_not_found_error(ref)
66
+ end
59
67
  when ref.type == :at && ref.name == "$" # @$
60
68
  "(yyloc)"
61
69
  when ref.type == :index && ref.name == "$" # $:$
@@ -63,9 +71,15 @@ module Lrama
63
71
  when ref.type == :dollar # $n
64
72
  i = -position_in_rhs + ref.index
65
73
  tag = ref.ex_tag || rhs[ref.index - 1].tag
66
- raise_tag_not_found_error(ref) unless tag
67
- # @type var tag: Lexer::Token::Tag
68
- "(yyvsp[#{i}].#{tag.member})"
74
+ if tag
75
+ # @type var tag: Lexer::Token::Tag
76
+ "(yyvsp[#{i}].#{tag.member})"
77
+ elsif union_not_defined?
78
+ # When %union is not defined, YYSTYPE defaults to int
79
+ "(yyvsp[#{i}])"
80
+ else
81
+ raise_tag_not_found_error(ref)
82
+ end
69
83
  when ref.type == :at # @n
70
84
  i = -position_in_rhs + ref.index
71
85
  "(yylsp[#{i}])"
@@ -99,6 +113,11 @@ module Lrama
99
113
  @rule.lhs
100
114
  end
101
115
 
116
+ # @rbs () -> bool
117
+ def union_not_defined?
118
+ @grammar.union.nil?
119
+ end
120
+
102
121
  # @rbs (Reference ref) -> bot
103
122
  def raise_tag_not_found_error(ref)
104
123
  raise "Tag is not specified for '$#{ref.value}' in '#{@rule.display_name}'"
@@ -104,11 +104,11 @@ module Lrama
104
104
  id == 0
105
105
  end
106
106
 
107
- # @rbs () -> String?
108
- def translated_code
107
+ # @rbs (Grammar grammar) -> String?
108
+ def translated_code(grammar)
109
109
  return nil unless token_code
110
110
 
111
- Code::RuleAction.new(type: :rule_action, token_code: token_code, rule: self).translated_code
111
+ Code::RuleAction.new(type: :rule_action, token_code: token_code, rule: self, grammar: grammar).translated_code
112
112
  end
113
113
 
114
114
  # @rbs () -> bool
data/lib/lrama/output.rb CHANGED
@@ -246,7 +246,7 @@ module Lrama
246
246
  <<-STR
247
247
  case #{rule.id + 1}: /* #{rule.as_comment} */
248
248
  #line #{code.line} "#{@grammar_file_path}"
249
- #{spaces}{#{rule.translated_code}}
249
+ #{spaces}{#{rule.translated_code(@grammar)}}
250
250
  #line [@oline@] [@ofile@]
251
251
  break;
252
252
 
data/lib/lrama/parser.rb CHANGED
@@ -655,7 +655,7 @@ end
655
655
  module Lrama
656
656
  class Parser < Racc::Parser
657
657
 
658
- module_eval(<<'...end parser.y/module_eval...', 'parser.y', 504)
658
+ module_eval(<<'...end parser.y/module_eval...', 'parser.y', 505)
659
659
 
660
660
  include Lrama::Tracer::Duration
661
661
 
@@ -765,16 +765,17 @@ racc_action_table = [
765
765
  52, 110, 105, 53, 53, 52, 52, 110, 105, 53,
766
766
  53, 52, 52, 110, 105, 53, 53, 52, 52, 110,
767
767
  105, 53, 53, 52, 52, 110, 110, 53, 53, 52,
768
- 209, 110, 110, 53, 53, 209, 52, 110, 110, 53,
769
- 53, 209, 52, 110, 193, 194, 195, 137, 216, 222,
770
- 229, 217, 217, 217, 53, 53, 52, 52, 193, 194,
771
- 195, 57, 57, 57, 57, 66, 67, 68, 69, 70,
772
- 72, 72, 72, 86, 89, 47, 57, 57, 113, 117,
773
- 117, 79, 123, 124, 131, 47, 133, 137, 139, 143,
774
- 149, 150, 151, 152, 133, 155, 156, 157, 110, 166,
775
- 149, 169, 172, 173, 72, 175, 176, 183, 189, 166,
776
- 196, 137, 200, 202, 137, 166, 211, 166, 137, 72,
777
- 176, 218, 176, 72, 72, 227, 137, 72 ]
768
+ 209, 110, 110, 53, 53, 209, 225, 110, 110, 53,
769
+ 53, 209, 209, 110, 110, 193, 194, 195, 137, 216,
770
+ 222, 232, 217, 217, 217, 235, 57, 53, 217, 52,
771
+ 53, 53, 52, 52, 193, 194, 195, 57, 57, 57,
772
+ 66, 67, 68, 69, 70, 72, 72, 72, 86, 89,
773
+ 47, 57, 57, 113, 117, 117, 79, 123, 124, 131,
774
+ 47, 133, 137, 139, 143, 149, 150, 151, 152, 133,
775
+ 155, 156, 157, 110, 166, 149, 169, 172, 173, 72,
776
+ 175, 176, 183, 189, 166, 196, 137, 200, 202, 137,
777
+ 166, 211, 166, 137, 72, 176, 218, 176, 72, 137,
778
+ 228, 137, 72, 231, 72 ]
778
779
 
779
780
  racc_action_check = [
780
781
  51, 97, 51, 97, 41, 75, 165, 75, 165, 75,
@@ -798,119 +799,120 @@ racc_action_check = [
798
799
  78, 65, 78, 65, 65, 106, 79, 106, 79, 106,
799
800
  106, 118, 180, 118, 180, 118, 180, 188, 196, 188,
800
801
  196, 188, 196, 202, 217, 202, 217, 202, 217, 218,
801
- 113, 218, 113, 218, 186, 186, 186, 186, 208, 213,
802
- 226, 208, 213, 226, 114, 123, 114, 123, 210, 210,
803
- 210, 24, 25, 26, 27, 28, 29, 30, 31, 32,
804
- 33, 34, 35, 40, 42, 47, 55, 60, 71, 74,
805
- 76, 80, 81, 87, 91, 92, 93, 94, 102, 116,
806
- 124, 125, 126, 127, 133, 136, 137, 138, 144, 150,
807
- 151, 153, 156, 158, 162, 163, 164, 170, 174, 176,
808
- 178, 179, 182, 184, 187, 189, 199, 200, 204, 205,
809
- 207, 209, 212, 214, 216, 221, 222, 228 ]
802
+ 231, 218, 231, 218, 231, 186, 186, 186, 186, 208,
803
+ 213, 227, 208, 213, 227, 234, 24, 113, 234, 113,
804
+ 114, 123, 114, 123, 210, 210, 210, 25, 26, 27,
805
+ 28, 29, 30, 31, 32, 33, 34, 35, 40, 42,
806
+ 47, 55, 60, 71, 74, 76, 80, 81, 87, 91,
807
+ 92, 93, 94, 102, 116, 124, 125, 126, 127, 133,
808
+ 136, 137, 138, 144, 150, 151, 153, 156, 158, 162,
809
+ 163, 164, 170, 174, 176, 178, 179, 182, 184, 187,
810
+ 189, 199, 200, 204, 205, 207, 209, 212, 214, 216,
811
+ 221, 222, 224, 225, 229 ]
810
812
 
811
813
  racc_action_pointer = [
812
814
  32, 23, 52, 93, nil, 31, 63, nil, 123, 68,
813
815
  74, 84, 103, 165, 94, 111, 123, 135, 141, nil,
814
- nil, nil, nil, nil, 215, 216, 217, 218, 230, 231,
815
- 232, 233, 234, 232, 233, 234, 24, 25, 31, 32,
816
- 238, -1, 242, nil, nil, nil, 43, 232, nil, nil,
817
- nil, -5, nil, nil, nil, 230, nil, nil, nil, nil,
818
- 231, nil, nil, 164, 170, 176, nil, nil, nil, nil,
819
- nil, 240, nil, 171, 241, 2, 242, nil, 177, 183,
820
- 243, 244, nil, nil, nil, nil, nil, 209, 45, nil,
821
- 63, 245, 242, 243, 202, nil, nil, -4, nil, nil,
822
- nil, nil, 256, nil, nil, nil, 182, nil, nil, nil,
823
- nil, nil, nil, 207, 221, nil, 253, 38, 188, nil,
824
- nil, nil, nil, 222, 255, 215, 218, 252, nil, nil,
825
- nil, nil, nil, 251, nil, nil, 219, 261, 250, nil,
826
- nil, nil, nil, nil, 261, nil, nil, nil, -24, nil,
827
- 219, 265, nil, 269, nil, nil, 216, nil, 256, nil,
828
- nil, nil, 266, 270, 227, 3, nil, nil, 3, nil,
829
- 228, 9, nil, nil, 232, nil, 229, 3, 236, 226,
830
- 189, nil, 236, nil, 239, nil, 162, 229, 194, 235,
831
- 10, nil, nil, nil, nil, nil, 195, nil, nil, 284,
832
- 237, 15, 200, nil, 233, 281, nil, 241, 173, 247,
833
- 176, nil, 243, 174, 285, nil, 286, 201, 206, nil,
834
- nil, 278, 241, nil, nil, nil, 175, nil, 289, nil,
835
- nil ]
816
+ nil, nil, nil, nil, 210, 221, 222, 223, 235, 236,
817
+ 237, 238, 239, 237, 238, 239, 24, 25, 31, 32,
818
+ 243, -1, 247, nil, nil, nil, 43, 237, nil, nil,
819
+ nil, -5, nil, nil, nil, 235, nil, nil, nil, nil,
820
+ 236, nil, nil, 164, 170, 176, nil, nil, nil, nil,
821
+ nil, 245, nil, 171, 246, 2, 247, nil, 177, 183,
822
+ 248, 249, nil, nil, nil, nil, nil, 214, 45, nil,
823
+ 63, 250, 247, 248, 207, nil, nil, -4, nil, nil,
824
+ nil, nil, 261, nil, nil, nil, 182, nil, nil, nil,
825
+ nil, nil, nil, 224, 227, nil, 258, 38, 188, nil,
826
+ nil, nil, nil, 228, 260, 220, 223, 257, nil, nil,
827
+ nil, nil, nil, 256, nil, nil, 224, 266, 255, nil,
828
+ nil, nil, nil, nil, 266, nil, nil, nil, -24, nil,
829
+ 224, 270, nil, 274, nil, nil, 221, nil, 261, nil,
830
+ nil, nil, 271, 275, 232, 3, nil, nil, 3, nil,
831
+ 233, 9, nil, nil, 237, nil, 234, 3, 241, 231,
832
+ 189, nil, 241, nil, 244, nil, 163, 234, 194, 240,
833
+ 10, nil, nil, nil, nil, nil, 195, nil, nil, 289,
834
+ 242, 15, 200, nil, 238, 286, nil, 246, 174, 252,
835
+ 182, nil, 248, 175, 290, nil, 244, 201, 206, nil,
836
+ nil, 283, 246, nil, 294, 259, nil, 176, nil, 296,
837
+ nil, 207, nil, nil, 180, nil ]
836
838
 
837
839
  racc_action_default = [
838
- -1, -136, -1, -3, -10, -136, -136, -2, -3, -136,
839
- -14, -14, -136, -136, -136, -136, -136, -136, -136, -28,
840
- -29, -34, -35, -36, -136, -136, -136, -136, -136, -136,
841
- -136, -136, -136, -54, -54, -54, -136, -136, -136, -136,
842
- -136, -136, -136, -13, 231, -4, -136, -14, -16, -17,
843
- -20, -131, -100, -101, -130, -18, -23, -89, -24, -25,
844
- -136, -27, -37, -136, -136, -136, -41, -42, -43, -44,
845
- -45, -46, -55, -136, -47, -136, -48, -49, -92, -136,
846
- -95, -97, -98, -50, -51, -52, -53, -136, -136, -11,
847
- -5, -7, -14, -136, -72, -15, -21, -131, -132, -133,
848
- -134, -19, -136, -26, -30, -31, -32, -38, -87, -88,
849
- -135, -39, -40, -136, -56, -58, -60, -136, -83, -85,
850
- -93, -94, -96, -136, -136, -136, -136, -136, -6, -8,
851
- -9, -128, -104, -102, -105, -73, -136, -136, -136, -90,
852
- -33, -59, -57, -61, -80, -86, -84, -99, -136, -66,
853
- -70, -136, -12, -136, -103, -109, -136, -22, -136, -62,
854
- -81, -82, -54, -136, -64, -68, -71, -74, -136, -129,
855
- -106, -107, -127, -91, -136, -67, -70, -72, -100, -72,
856
- -136, -124, -136, -109, -100, -110, -72, -72, -136, -70,
857
- -69, -75, -76, -116, -117, -118, -136, -78, -79, -136,
858
- -70, -108, -136, -111, -72, -54, -115, -63, -136, -100,
859
- -119, -125, -65, -136, -54, -114, -54, -136, -136, -120,
860
- -121, -136, -72, -112, -77, -122, -136, -126, -54, -123,
861
- -113 ]
840
+ -1, -137, -1, -3, -10, -137, -137, -2, -3, -137,
841
+ -14, -14, -137, -137, -137, -137, -137, -137, -137, -28,
842
+ -29, -34, -35, -36, -137, -137, -137, -137, -137, -137,
843
+ -137, -137, -137, -54, -54, -54, -137, -137, -137, -137,
844
+ -137, -137, -137, -13, 236, -4, -137, -14, -16, -17,
845
+ -20, -132, -100, -101, -131, -18, -23, -89, -24, -25,
846
+ -137, -27, -37, -137, -137, -137, -41, -42, -43, -44,
847
+ -45, -46, -55, -137, -47, -137, -48, -49, -92, -137,
848
+ -95, -97, -98, -50, -51, -52, -53, -137, -137, -11,
849
+ -5, -7, -14, -137, -72, -15, -21, -132, -133, -134,
850
+ -135, -19, -137, -26, -30, -31, -32, -38, -87, -88,
851
+ -136, -39, -40, -137, -56, -58, -60, -137, -83, -85,
852
+ -93, -94, -96, -137, -137, -137, -137, -137, -6, -8,
853
+ -9, -129, -104, -102, -105, -73, -137, -137, -137, -90,
854
+ -33, -59, -57, -61, -80, -86, -84, -99, -137, -66,
855
+ -70, -137, -12, -137, -103, -109, -137, -22, -137, -62,
856
+ -81, -82, -54, -137, -64, -68, -71, -74, -137, -130,
857
+ -106, -107, -128, -91, -137, -67, -70, -72, -100, -72,
858
+ -137, -125, -137, -109, -100, -110, -72, -72, -137, -70,
859
+ -69, -75, -76, -116, -117, -118, -137, -78, -79, -137,
860
+ -70, -108, -137, -111, -72, -54, -115, -63, -137, -100,
861
+ -119, -126, -65, -137, -54, -114, -72, -137, -137, -120,
862
+ -121, -137, -72, -112, -54, -100, -122, -137, -127, -54,
863
+ -77, -137, -124, -113, -137, -123 ]
862
864
 
863
865
  racc_goto_table = [
864
866
  73, 118, 136, 54, 48, 49, 164, 96, 91, 120,
865
- 121, 93, 187, 148, 107, 111, 112, 119, 134, 171,
866
- 56, 58, 59, 3, 61, 7, 78, 78, 78, 78,
867
- 62, 63, 64, 65, 115, 74, 76, 192, 1, 129,
868
- 168, 95, 187, 118, 118, 207, 204, 201, 77, 83,
869
- 84, 85, 128, 138, 147, 93, 212, 140, 154, 145,
870
- 146, 101, 130, 116, 42, 127, 103, 208, 78, 78,
871
- 219, 9, 51, 213, 141, 142, 45, 71, 159, 144,
872
- 190, 160, 161, 102, 158, 191, 132, 197, 122, 226,
873
- 170, 177, 220, 199, 203, 205, 221, 186, 153, nil,
867
+ 121, 93, 187, 208, 107, 111, 112, 119, 134, 213,
868
+ 56, 58, 59, 171, 61, 1, 78, 78, 78, 78,
869
+ 62, 63, 64, 65, 115, 227, 129, 192, 148, 74,
870
+ 76, 95, 187, 118, 118, 207, 204, 3, 234, 7,
871
+ 130, 201, 128, 138, 147, 93, 212, 140, 154, 145,
872
+ 146, 101, 9, 116, 42, 168, 103, 45, 78, 78,
873
+ 219, 127, 51, 71, 141, 142, 77, 83, 84, 85,
874
+ 159, 144, 190, 160, 161, 191, 132, 197, 102, 158,
875
+ 122, 177, 170, 220, 203, 205, 199, 186, 221, 153,
874
876
  nil, nil, nil, 116, 116, nil, 198, nil, nil, nil,
875
877
  nil, nil, 214, 78, 206, nil, 177, nil, nil, nil,
876
- nil, nil, 210, nil, nil, nil, nil, 186, 210, 174,
877
- 228, nil, nil, nil, nil, nil, nil, nil, nil, nil,
878
- nil, nil, nil, 225, 210, nil, nil, nil, nil, nil,
879
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
878
+ nil, nil, 210, nil, 224, nil, nil, 186, 210, 174,
879
+ 229, nil, nil, nil, nil, nil, nil, nil, nil, nil,
880
+ nil, nil, nil, 226, 210, nil, nil, nil, nil, nil,
881
+ nil, nil, nil, nil, nil, nil, nil, 210, nil, nil,
880
882
  nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
881
883
  nil, nil, 215, nil, nil, nil, nil, nil, nil, nil,
882
- nil, 223, nil, 224, nil, nil, nil, nil, nil, nil,
883
- nil, nil, nil, nil, nil, 230 ]
884
+ nil, 223, nil, nil, nil, nil, nil, nil, nil, nil,
885
+ nil, 230, nil, nil, nil, nil, 233 ]
884
886
 
885
887
  racc_goto_check = [
886
888
  29, 22, 42, 31, 14, 14, 35, 16, 8, 48,
887
- 48, 13, 40, 34, 24, 24, 24, 45, 52, 54,
888
- 18, 18, 18, 6, 17, 6, 31, 31, 31, 31,
889
- 17, 17, 17, 17, 30, 26, 26, 38, 1, 5,
890
- 34, 14, 40, 22, 22, 35, 38, 54, 27, 27,
891
- 27, 27, 8, 16, 48, 13, 35, 24, 52, 45,
892
- 45, 18, 9, 31, 10, 11, 17, 39, 31, 31,
893
- 38, 7, 15, 39, 30, 30, 7, 25, 32, 33,
894
- 36, 43, 44, 46, 47, 42, 14, 42, 50, 39,
895
- 53, 22, 55, 56, 42, 42, 57, 22, 58, nil,
889
+ 48, 13, 40, 39, 24, 24, 24, 45, 52, 39,
890
+ 18, 18, 18, 54, 17, 1, 31, 31, 31, 31,
891
+ 17, 17, 17, 17, 30, 39, 5, 38, 34, 26,
892
+ 26, 14, 40, 22, 22, 35, 38, 6, 39, 6,
893
+ 9, 54, 8, 16, 48, 13, 35, 24, 52, 45,
894
+ 45, 18, 7, 31, 10, 34, 17, 7, 31, 31,
895
+ 38, 11, 15, 25, 30, 30, 27, 27, 27, 27,
896
+ 32, 33, 36, 43, 44, 42, 14, 42, 46, 47,
897
+ 50, 22, 53, 55, 42, 42, 56, 22, 57, 58,
896
898
  nil, nil, nil, 31, 31, nil, 22, nil, nil, nil,
897
899
  nil, nil, 42, 31, 22, nil, 22, nil, nil, nil,
898
- nil, nil, 22, nil, nil, nil, nil, 22, 22, 29,
900
+ nil, nil, 22, nil, 42, nil, nil, 22, 22, 29,
899
901
  42, nil, nil, nil, nil, nil, nil, nil, nil, nil,
900
902
  nil, nil, nil, 22, 22, nil, nil, nil, nil, nil,
901
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
903
+ nil, nil, nil, nil, nil, nil, nil, 22, nil, nil,
902
904
  nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
903
905
  nil, nil, 29, nil, nil, nil, nil, nil, nil, nil,
904
- nil, 29, nil, 29, nil, nil, nil, nil, nil, nil,
905
- nil, nil, nil, nil, nil, 29 ]
906
+ nil, 29, nil, nil, nil, nil, nil, nil, nil, nil,
907
+ nil, 29, nil, nil, nil, nil, 29 ]
906
908
 
907
909
  racc_goto_pointer = [
908
- nil, 38, nil, nil, nil, -52, 23, 68, -38, -29,
909
- 60, -24, nil, -35, -6, 59, -44, 6, 6, nil,
910
- nil, nil, -74, nil, -49, 44, 1, 12, nil, -33,
911
- -39, -10, -66, -37, -111, -144, -96, nil, -140, -129,
912
- -159, nil, -92, -63, -62, -58, 26, -55, -69, nil,
913
- 8, nil, -75, -65, -136, -118, -88, -115, -33 ]
910
+ nil, 25, nil, nil, nil, -55, 47, 59, -38, -41,
911
+ 60, -18, nil, -35, -6, 59, -44, 6, 6, nil,
912
+ nil, nil, -74, nil, -49, 40, 5, 40, nil, -33,
913
+ -39, -10, -64, -35, -86, -144, -94, nil, -140, -183,
914
+ -159, nil, -92, -61, -60, -58, 31, -50, -69, nil,
915
+ 10, nil, -75, -63, -132, -117, -85, -113, -32 ]
914
916
 
915
917
  racc_goto_default = [
916
918
  nil, nil, 2, 8, 90, nil, nil, nil, nil, nil,
@@ -998,7 +1000,7 @@ racc_reduce_table = [
998
1000
  1, 94, :_reduce_74,
999
1001
  3, 94, :_reduce_75,
1000
1002
  3, 94, :_reduce_76,
1001
- 6, 94, :_reduce_77,
1003
+ 7, 94, :_reduce_77,
1002
1004
  3, 94, :_reduce_78,
1003
1005
  3, 94, :_reduce_79,
1004
1006
  0, 102, :_reduce_none,
@@ -1044,23 +1046,24 @@ racc_reduce_table = [
1044
1046
  1, 113, :_reduce_none,
1045
1047
  2, 97, :_reduce_121,
1046
1048
  3, 97, :_reduce_122,
1047
- 4, 97, :_reduce_123,
1048
- 0, 114, :_reduce_124,
1049
- 0, 115, :_reduce_125,
1050
- 5, 98, :_reduce_126,
1051
- 3, 95, :_reduce_127,
1052
- 0, 116, :_reduce_128,
1053
- 3, 63, :_reduce_129,
1049
+ 6, 97, :_reduce_123,
1050
+ 4, 97, :_reduce_124,
1051
+ 0, 114, :_reduce_125,
1052
+ 0, 115, :_reduce_126,
1053
+ 5, 98, :_reduce_127,
1054
+ 3, 95, :_reduce_128,
1055
+ 0, 116, :_reduce_129,
1056
+ 3, 63, :_reduce_130,
1054
1057
  1, 73, :_reduce_none,
1055
1058
  0, 74, :_reduce_none,
1056
1059
  1, 74, :_reduce_none,
1057
1060
  1, 74, :_reduce_none,
1058
1061
  1, 74, :_reduce_none,
1059
- 1, 101, :_reduce_135 ]
1062
+ 1, 101, :_reduce_136 ]
1060
1063
 
1061
- racc_reduce_n = 136
1064
+ racc_reduce_n = 137
1062
1065
 
1063
- racc_shift_n = 231
1066
+ racc_shift_n = 236
1064
1067
 
1065
1068
  racc_token_table = {
1066
1069
  false => 0,
@@ -1828,7 +1831,7 @@ module_eval(<<'.,.,', 'parser.y', 274)
1828
1831
  def _reduce_77(val, _values, result)
1829
1832
  on_action_error("intermediate %prec in a rule", val[1]) if @trailing_prec_seen
1830
1833
  builder = val[0]
1831
- builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[5])
1834
+ builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, alias_name: val[5], location: @lexer.location, args: val[3], lhs_tag: val[6])
1832
1835
  result = builder
1833
1836
 
1834
1837
  result
@@ -2192,13 +2195,20 @@ module_eval(<<'.,.,', 'parser.y', 457)
2192
2195
 
2193
2196
  module_eval(<<'.,.,', 'parser.y', 458)
2194
2197
  def _reduce_123(val, _values, result)
2195
- result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])]
2198
+ result = val[0].append(Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2].s_value, location: @lexer.location, args: val[4]))
2196
2199
  result
2197
2200
  end
2198
2201
  .,.,
2199
2202
 
2200
- module_eval(<<'.,.,', 'parser.y', 463)
2203
+ module_eval(<<'.,.,', 'parser.y', 459)
2201
2204
  def _reduce_124(val, _values, result)
2205
+ result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])]
2206
+ result
2207
+ end
2208
+ .,.,
2209
+
2210
+ module_eval(<<'.,.,', 'parser.y', 464)
2211
+ def _reduce_125(val, _values, result)
2202
2212
  if prec_seen?
2203
2213
  on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec
2204
2214
  @code_after_prec = true
@@ -2209,39 +2219,39 @@ module_eval(<<'.,.,', 'parser.y', 463)
2209
2219
  end
2210
2220
  .,.,
2211
2221
 
2212
- module_eval(<<'.,.,', 'parser.y', 471)
2213
- def _reduce_125(val, _values, result)
2222
+ module_eval(<<'.,.,', 'parser.y', 472)
2223
+ def _reduce_126(val, _values, result)
2214
2224
  end_c_declaration
2215
2225
 
2216
2226
  result
2217
2227
  end
2218
2228
  .,.,
2219
2229
 
2220
- module_eval(<<'.,.,', 'parser.y', 475)
2221
- def _reduce_126(val, _values, result)
2230
+ module_eval(<<'.,.,', 'parser.y', 476)
2231
+ def _reduce_127(val, _values, result)
2222
2232
  result = val[2]
2223
2233
 
2224
2234
  result
2225
2235
  end
2226
2236
  .,.,
2227
2237
 
2228
- module_eval(<<'.,.,', 'parser.y', 478)
2229
- def _reduce_127(val, _values, result)
2238
+ module_eval(<<'.,.,', 'parser.y', 479)
2239
+ def _reduce_128(val, _values, result)
2230
2240
  result = val[1].s_value
2231
2241
  result
2232
2242
  end
2233
2243
  .,.,
2234
2244
 
2235
- module_eval(<<'.,.,', 'parser.y', 483)
2236
- def _reduce_128(val, _values, result)
2245
+ module_eval(<<'.,.,', 'parser.y', 484)
2246
+ def _reduce_129(val, _values, result)
2237
2247
  begin_c_declaration('\Z')
2238
2248
 
2239
2249
  result
2240
2250
  end
2241
2251
  .,.,
2242
2252
 
2243
- module_eval(<<'.,.,', 'parser.y', 487)
2244
- def _reduce_129(val, _values, result)
2253
+ module_eval(<<'.,.,', 'parser.y', 488)
2254
+ def _reduce_130(val, _values, result)
2245
2255
  end_c_declaration
2246
2256
  @grammar.epilogue_first_lineno = val[0].first_line + 1
2247
2257
  @grammar.epilogue = val[2].s_value
@@ -2250,8 +2260,6 @@ module_eval(<<'.,.,', 'parser.y', 487)
2250
2260
  end
2251
2261
  .,.,
2252
2262
 
2253
- # reduce 130 omitted
2254
-
2255
2263
  # reduce 131 omitted
2256
2264
 
2257
2265
  # reduce 132 omitted
@@ -2260,8 +2268,10 @@ module_eval(<<'.,.,', 'parser.y', 487)
2260
2268
 
2261
2269
  # reduce 134 omitted
2262
2270
 
2263
- module_eval(<<'.,.,', 'parser.y', 499)
2264
- def _reduce_135(val, _values, result)
2271
+ # reduce 135 omitted
2272
+
2273
+ module_eval(<<'.,.,', 'parser.y', 500)
2274
+ def _reduce_136(val, _values, result)
2265
2275
  result = Lrama::Lexer::Token::Ident.new(s_value: val[0].s_value)
2266
2276
  result
2267
2277
  end
data/lib/lrama/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Lrama
5
- VERSION = "0.7.1".freeze #: String
5
+ VERSION = "0.8.0".freeze #: String
6
6
  end
data/parser.y CHANGED
@@ -270,11 +270,11 @@ rule
270
270
  builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]])
271
271
  result = builder
272
272
  }
273
- | rule_rhs IDENTIFIER "(" parameterized_args ")" TAG?
273
+ | rule_rhs IDENTIFIER "(" parameterized_args ")" named_ref? TAG?
274
274
  {
275
275
  on_action_error("intermediate %prec in a rule", val[1]) if @trailing_prec_seen
276
276
  builder = val[0]
277
- builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[5])
277
+ builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, alias_name: val[5], location: @lexer.location, args: val[3], lhs_tag: val[6])
278
278
  result = builder
279
279
  }
280
280
  | rule_rhs action named_ref?
@@ -456,6 +456,7 @@ rule
456
456
  end
457
457
  }
458
458
  | parameterized_args ',' symbol { result = val[0].append(val[2]) }
459
+ | parameterized_args ',' IDENTIFIER "(" parameterized_args ")" { result = val[0].append(Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2].s_value, location: @lexer.location, args: val[4])) }
459
460
  | IDENTIFIER "(" parameterized_args ")" { result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] }
460
461
 
461
462
  action:
@@ -6,8 +6,10 @@ module Lrama
6
6
  class RuleAction < Code
7
7
  @rule: Rule
8
8
 
9
- # @rbs (type: ::Symbol, token_code: Lexer::Token::UserCode, rule: Rule) -> void
10
- def initialize: (type: ::Symbol, token_code: Lexer::Token::UserCode, rule: Rule) -> void
9
+ @grammar: Grammar
10
+
11
+ # @rbs (type: ::Symbol, token_code: Lexer::Token::UserCode, rule: Rule, grammar: Grammar) -> void
12
+ def initialize: (type: ::Symbol, token_code: Lexer::Token::UserCode, rule: Rule, grammar: Grammar) -> void
11
13
 
12
14
  private
13
15
 
@@ -55,6 +57,9 @@ module Lrama
55
57
  # @rbs () -> Grammar::Symbol
56
58
  def lhs: () -> Grammar::Symbol
57
59
 
60
+ # @rbs () -> bool
61
+ def union_not_defined?: () -> bool
62
+
58
63
  # @rbs (Reference ref) -> bot
59
64
  def raise_tag_not_found_error: (Reference ref) -> bot
60
65
  end
@@ -68,8 +68,8 @@ module Lrama
68
68
  # @rbs () -> bool
69
69
  def initial_rule?: () -> bool
70
70
 
71
- # @rbs () -> String?
72
- def translated_code: () -> String?
71
+ # @rbs (Grammar grammar) -> String?
72
+ def translated_code: (Grammar grammar) -> String?
73
73
 
74
74
  # @rbs () -> bool
75
75
  def contains_at_reference?: () -> bool
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lrama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuichiro Kaneko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-12-24 00:00:00.000000000 Z
11
+ date: 2026-03-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: LALR (1) parser generator written by Ruby
14
14
  email: