lrama 0.6.2 → 0.6.3

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.
data/lib/lrama/state.rb CHANGED
@@ -29,8 +29,8 @@ module Lrama
29
29
  end
30
30
 
31
31
  def non_default_reduces
32
- reduces.select do |reduce|
33
- reduce.rule != @default_reduction_rule
32
+ reduces.reject do |reduce|
33
+ reduce.rule == @default_reduction_rule
34
34
  end
35
35
  end
36
36
 
@@ -105,8 +105,8 @@ module Lrama
105
105
  end
106
106
 
107
107
  def selected_term_transitions
108
- term_transitions.select do |shift, next_state|
109
- !shift.not_selected
108
+ term_transitions.reject do |shift, next_state|
109
+ shift.not_selected
110
110
  end
111
111
  end
112
112
 
@@ -1,8 +1,14 @@
1
1
  # TODO: Validate position is not over rule rhs
2
2
 
3
+ require "forwardable"
4
+
3
5
  module Lrama
4
6
  class States
5
7
  class Item < Struct.new(:rule, :position, keyword_init: true)
8
+ extend Forwardable
9
+
10
+ def_delegators "rule", :lhs, :rhs
11
+
6
12
  # Optimization for States#setup_state
7
13
  def hash
8
14
  [rule_id, position].hash
@@ -20,14 +26,6 @@ module Lrama
20
26
  rhs.count - position
21
27
  end
22
28
 
23
- def lhs
24
- rule.lhs
25
- end
26
-
27
- def rhs
28
- rule.rhs
29
- end
30
-
31
29
  def next_sym
32
30
  rhs[position]
33
31
  end
@@ -109,8 +109,8 @@ module Lrama
109
109
  io << "\n"
110
110
 
111
111
  # Report shifts
112
- tmp = state.term_transitions.select do |shift, _|
113
- !shift.not_selected
112
+ tmp = state.term_transitions.reject do |shift, _|
113
+ shift.not_selected
114
114
  end.map do |shift, next_state|
115
115
  [shift.next_sym, next_state.id]
116
116
  end
data/lib/lrama/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lrama
2
- VERSION = "0.6.2".freeze
2
+ VERSION = "0.6.3".freeze
3
3
  end
data/lrama.gemspec CHANGED
@@ -16,6 +16,13 @@ Gem::Specification.new do |spec|
16
16
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
17
17
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
18
18
  end
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = spec.homepage
22
+ spec.metadata["documentation_uri"] = spec.homepage
23
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/releases"
24
+ spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
25
+
19
26
  spec.bindir = "exe"
20
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
28
  spec.require_paths = ["lib"]
data/parser.y CHANGED
@@ -129,6 +129,26 @@ rule
129
129
  lineno: val[3].line
130
130
  )
131
131
  }
132
+ | "%after-shift" IDENTIFIER
133
+ {
134
+ @grammar.after_shift = val[1]
135
+ }
136
+ | "%before-reduce" IDENTIFIER
137
+ {
138
+ @grammar.before_reduce = val[1]
139
+ }
140
+ | "%after-reduce" IDENTIFIER
141
+ {
142
+ @grammar.after_reduce = val[1]
143
+ }
144
+ | "%after-shift-error-token" IDENTIFIER
145
+ {
146
+ @grammar.after_shift_error_token = val[1]
147
+ }
148
+ | "%after-pop-stack" IDENTIFIER
149
+ {
150
+ @grammar.after_pop_stack = val[1]
151
+ }
132
152
 
133
153
  symbol_declaration: "%token" token_declarations
134
154
  | "%type" symbol_declarations
@@ -3,6 +3,7 @@ module Lrama
3
3
  class Reference
4
4
  attr_accessor type: ::Symbol
5
5
  attr_accessor name: String
6
+ attr_accessor number: Integer
6
7
  attr_accessor index: Integer
7
8
  attr_accessor ex_tag: Lexer::Token?
8
9
  attr_accessor first_column: Integer
@@ -10,7 +11,7 @@ module Lrama
10
11
  attr_accessor position_in_rhs: Integer?
11
12
 
12
13
  def initialize: (
13
- type: ::Symbol, ?name: String, ?index: Integer, ?ex_tag: Lexer::Token?,
14
+ type: ::Symbol, ?name: String, ?number: Integer, ?index: Integer, ?ex_tag: Lexer::Token?,
14
15
  first_column: Integer, last_column: Integer,
15
16
  ?position_in_rhs: Integer?
16
17
  ) -> void
@@ -2,7 +2,7 @@ module Lrama
2
2
  class Grammar
3
3
  class Symbol
4
4
  attr_accessor id: Lexer::Token
5
- attr_accessor alias_name: String
5
+ attr_accessor alias_name: String?
6
6
  attr_accessor number: Integer
7
7
  attr_accessor tag: Lexer::Token?
8
8
  attr_accessor term: bool
@@ -20,8 +20,8 @@ module Lrama
20
20
  attr_writer accept_symbol: Symbol
21
21
 
22
22
  def initialize: (
23
- id: Lexer::Token, alias_name: String?, number: Integer?, tag: Lexer::Token?,
24
- term: bool, token_id: Integer?, nullable: bool?, precedence: Precedence?, printer: Printer?) -> void
23
+ id: Lexer::Token, term: bool, ?alias_name: String?, ?number: Integer?, ?tag: Lexer::Token?,
24
+ ?token_id: Integer?, ?nullable: bool?, ?precedence: Precedence?, ?printer: Printer?) -> void
25
25
 
26
26
  def term?: () -> bool
27
27
  def nterm?: () -> bool
@@ -31,7 +31,7 @@ module Lrama
31
31
  def accept_symbol?: () -> bool
32
32
  def display_name: () -> String
33
33
  def enum_name: () -> String
34
- def comment: () -> String
34
+ def comment: () -> String?
35
35
  end
36
36
  end
37
37
  end
@@ -0,0 +1,41 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Symbols
4
+ class Resolver
5
+ attr_reader terms: Array[Grammar::Symbol]
6
+ attr_reader nterms: Array[Grammar::Symbol]
7
+
8
+ @symbols: Array[Grammar::Symbol]?
9
+ @number: Integer
10
+ @used_numbers: Hash[Integer, bool]
11
+
12
+ def initialize: () -> void
13
+ def symbols: () -> Array[Grammar::Symbol]
14
+ def sort_by_number!: () -> void
15
+ def add_term: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token?, ?token_id: Integer?, ?replace: bool) -> Grammar::Symbol
16
+ def add_nterm: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token?) -> Grammar::Symbol?
17
+ def find_symbol_by_s_value: (Grammar::Symbol s_value) -> Grammar::Symbol?
18
+ def find_symbol_by_s_value!: (Grammar::Symbol s_value) -> Grammar::Symbol
19
+ def find_symbol_by_id: (Lexer::Token id) -> Grammar::Symbol?
20
+ def find_symbol_by_id!: (Lexer::Token id) -> Grammar::Symbol
21
+ def find_symbol_by_token_id: (Integer token_id) -> Grammar::Symbol?
22
+ def find_symbol_by_number!: (Integer number) -> Grammar::Symbol
23
+ def fill_symbol_number: () -> void
24
+ def fill_nterm_type: (Array[Grammar::Type] types) -> void
25
+ def fill_printer: (Array[Grammar::Printer] printers) -> void
26
+ def fill_error_token: (Array[Grammar::ErrorToken] error_tokens) -> void
27
+ def token_to_symbol: (Lexer::Token token) -> Grammar::Symbol
28
+ def validate!: () -> void
29
+
30
+ private
31
+
32
+ def find_nterm_by_id!: (Lexer::Token id) -> Grammar::Symbol
33
+ def fill_terms_number: () -> void
34
+ def fill_nterms_number: () -> void
35
+ def used_numbers: () -> Hash[Integer, bool]
36
+ def validate_number_uniqueness!: () -> void
37
+ def validate_alias_name_uniqueness!: () -> void
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Type
4
+ attr_reader id: Lexer::Token
5
+ attr_reader tag: Lexer::Token
6
+
7
+ def initialize: (id: Lexer::Token, tag: Lexer::Token) -> void
8
+ def ==: (Grammar::Type other) -> bool
9
+ end
10
+ end
11
+ end
@@ -1752,6 +1752,7 @@ yybackup:
1752
1752
  *++yyvsp = yylval;
1753
1753
  YY_IGNORE_MAYBE_UNINITIALIZED_END
1754
1754
  *++yylsp = yylloc;
1755
+ <%= output.after_shift_function("/* %after-shift code. */") %>
1755
1756
 
1756
1757
  /* Discard the shifted token. */
1757
1758
  yychar = YYEMPTY;
@@ -1784,6 +1785,7 @@ yyreduce:
1784
1785
  unconditionally makes the parser a bit smaller, and it avoids a
1785
1786
  GCC warning that YYVAL may be used uninitialized. */
1786
1787
  yyval = yyvsp[1-yylen];
1788
+ <%= output.before_reduce_function("/* %before-reduce function. */") %>
1787
1789
 
1788
1790
  /* Default location. */
1789
1791
  YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
@@ -1809,6 +1811,7 @@ yyreduce:
1809
1811
  YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc<%= output.user_args %>);
1810
1812
 
1811
1813
  YYPOPSTACK (yylen);
1814
+ <%= output.after_reduce_function("/* %after-reduce function. */") %>
1812
1815
  yylen = 0;
1813
1816
 
1814
1817
  *++yyvsp = yyval;
@@ -1910,6 +1913,7 @@ yyerrorlab:
1910
1913
  /* Do not reclaim the symbols of the rule whose action triggered
1911
1914
  this YYERROR. */
1912
1915
  YYPOPSTACK (yylen);
1916
+ <%= output.after_pop_stack_function("yylen", "/* %after-pop-stack function. */") %>
1913
1917
  yylen = 0;
1914
1918
  YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>);
1915
1919
  yystate = *yyssp;
@@ -1969,6 +1973,7 @@ yyerrlab1:
1969
1973
  yydestruct ("Error: popping",
1970
1974
  YY_ACCESSING_SYMBOL (yystate), yyvsp, yylsp<%= output.user_args %>);
1971
1975
  YYPOPSTACK (1);
1976
+ <%= output.after_pop_stack_function(1, "/* %after-pop-stack function. */") %>
1972
1977
  yystate = *yyssp;
1973
1978
  YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>);
1974
1979
  }
@@ -1983,6 +1988,7 @@ yyerrlab1:
1983
1988
 
1984
1989
  /* Shift the error token. */
1985
1990
  YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp<%= output.user_args %>);
1991
+ <%= output.after_shift_error_token_function("/* %after-shift-error-token code. */") %>
1986
1992
 
1987
1993
  yystate = yyn;
1988
1994
  goto yynewstate;
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.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuichiro Kaneko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-27 00:00:00.000000000 Z
11
+ date: 2024-02-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: LALR (1) parser generator written by Ruby
14
14
  email:
@@ -68,6 +68,8 @@ files:
68
68
  - lib/lrama/grammar/rule_builder.rb
69
69
  - lib/lrama/grammar/stdlib.y
70
70
  - lib/lrama/grammar/symbol.rb
71
+ - lib/lrama/grammar/symbols.rb
72
+ - lib/lrama/grammar/symbols/resolver.rb
71
73
  - lib/lrama/grammar/type.rb
72
74
  - lib/lrama/grammar/union.rb
73
75
  - lib/lrama/lexer.rb
@@ -123,6 +125,8 @@ files:
123
125
  - sig/lrama/grammar/rule.rbs
124
126
  - sig/lrama/grammar/rule_builder.rbs
125
127
  - sig/lrama/grammar/symbol.rbs
128
+ - sig/lrama/grammar/symbols/resolver.rbs
129
+ - sig/lrama/grammar/type.rbs
126
130
  - sig/lrama/lexer/grammar_file.rbs
127
131
  - sig/lrama/lexer/location.rbs
128
132
  - sig/lrama/lexer/token.rbs
@@ -141,7 +145,12 @@ files:
141
145
  homepage: https://github.com/ruby/lrama
142
146
  licenses:
143
147
  - GPL-3.0-or-later
144
- metadata: {}
148
+ metadata:
149
+ homepage_uri: https://github.com/ruby/lrama
150
+ source_code_uri: https://github.com/ruby/lrama
151
+ documentation_uri: https://github.com/ruby/lrama
152
+ changelog_uri: https://github.com/ruby/lrama/releases
153
+ bug_tracker_uri: https://github.com/ruby/lrama/issues
145
154
  post_install_message:
146
155
  rdoc_options: []
147
156
  require_paths: