lrama 0.5.10 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yaml +22 -2
  3. data/LEGAL.md +1 -0
  4. data/NEWS.md +167 -0
  5. data/README.md +1 -1
  6. data/Steepfile +8 -12
  7. data/lib/lrama/grammar/code/rule_action.rb +19 -3
  8. data/lib/lrama/grammar/parameterizing_rules/builder/base.rb +10 -2
  9. data/lib/lrama/grammar/parameterizing_rules/builder/list.rb +12 -4
  10. data/lib/lrama/grammar/parameterizing_rules/builder/nonempty_list.rb +12 -4
  11. data/lib/lrama/grammar/parameterizing_rules/builder/option.rb +12 -4
  12. data/lib/lrama/grammar/parameterizing_rules/builder/separated_list.rb +17 -6
  13. data/lib/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rb +12 -5
  14. data/lib/lrama/grammar/parameterizing_rules/builder.rb +23 -6
  15. data/lib/lrama/grammar/rule.rb +2 -1
  16. data/lib/lrama/grammar/rule_builder.rb +17 -19
  17. data/lib/lrama/grammar/symbol.rb +16 -2
  18. data/lib/lrama/grammar/type.rb +6 -0
  19. data/lib/lrama/grammar.rb +8 -3
  20. data/lib/lrama/lexer/token/parameterizing.rb +1 -1
  21. data/lib/lrama/lexer/token.rb +16 -9
  22. data/lib/lrama/lexer.rb +1 -2
  23. data/lib/lrama/parser.rb +359 -346
  24. data/lib/lrama/version.rb +1 -1
  25. data/lib/lrama.rb +0 -1
  26. data/parser.y +17 -15
  27. data/rbs_collection.lock.yaml +2 -8
  28. data/sig/lrama/grammar/error_token.rbs +11 -0
  29. data/sig/lrama/grammar/parameterizing_rules/builder/base.rbs +28 -0
  30. data/sig/lrama/grammar/parameterizing_rules/builder/list.rbs +10 -0
  31. data/sig/lrama/grammar/parameterizing_rules/builder/nonempty_list.rbs +10 -0
  32. data/sig/lrama/grammar/parameterizing_rules/builder/option.rbs +10 -0
  33. data/sig/lrama/grammar/parameterizing_rules/builder/separated_list.rbs +13 -0
  34. data/sig/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rbs +13 -0
  35. data/sig/lrama/grammar/parameterizing_rules/builder.rbs +15 -1
  36. data/sig/lrama/grammar/reference.rbs +2 -2
  37. data/sig/lrama/grammar/rule.rbs +1 -1
  38. data/sig/lrama/grammar/rule_builder.rbs +1 -0
  39. data/sig/lrama/grammar/symbol.rbs +37 -0
  40. data/sig/lrama/lexer/token/parameterizing.rbs +3 -1
  41. data/sig/lrama/lexer/token.rbs +3 -3
  42. data/template/bison/yacc.c +0 -2
  43. metadata +12 -4
  44. data/doc/TODO.md +0 -59
  45. data/lib/lrama/type.rb +0 -4
@@ -6,10 +6,23 @@
6
6
 
7
7
  module Lrama
8
8
  class Grammar
9
- class Symbol < Struct.new(:id, :alias_name, :number, :tag, :term, :token_id, :nullable, :precedence, :printer, :error_token, keyword_init: true)
10
- attr_accessor :first_set, :first_set_bitmap
9
+ class Symbol
10
+ attr_accessor :id, :alias_name, :tag, :number, :token_id, :nullable, :precedence, :printer, :error_token, :first_set, :first_set_bitmap
11
+ attr_reader :term
11
12
  attr_writer :eof_symbol, :error_symbol, :undef_symbol, :accept_symbol
12
13
 
14
+ def initialize(id:, alias_name: nil, number: nil, tag: nil, term:, token_id: nil, nullable: nil, precedence: nil, printer: nil)
15
+ @id = id
16
+ @alias_name = alias_name
17
+ @number = number
18
+ @tag = tag
19
+ @term = term
20
+ @token_id = token_id
21
+ @nullable = nullable
22
+ @precedence = precedence
23
+ @printer = printer
24
+ end
25
+
13
26
  def term?
14
27
  term
15
28
  end
@@ -41,6 +54,7 @@ module Lrama
41
54
  # name for yysymbol_kind_t
42
55
  #
43
56
  # See: b4_symbol_kind_base
57
+ # @type var name: String
44
58
  def enum_name
45
59
  case
46
60
  when accept_symbol?
@@ -0,0 +1,6 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Type < Struct.new(:id, :tag, keyword_init: true)
4
+ end
5
+ end
6
+ end
data/lib/lrama/grammar.rb CHANGED
@@ -9,9 +9,9 @@ require "lrama/grammar/reference"
9
9
  require "lrama/grammar/rule"
10
10
  require "lrama/grammar/rule_builder"
11
11
  require "lrama/grammar/symbol"
12
+ require "lrama/grammar/type"
12
13
  require "lrama/grammar/union"
13
14
  require "lrama/lexer"
14
- require "lrama/type"
15
15
 
16
16
  module Lrama
17
17
  # Grammar is the result of parsing an input grammar file
@@ -148,7 +148,7 @@ module Lrama
148
148
  def prepare
149
149
  normalize_rules
150
150
  collect_symbols
151
- replace_token_with_symbol
151
+ set_lhs_and_rhs
152
152
  fill_symbol_number
153
153
  fill_default_precedence
154
154
  fill_sym_to_rules
@@ -391,6 +391,11 @@ module Lrama
391
391
  @rules << rule
392
392
  end
393
393
 
394
+ builder.parameterizing_rules.each do |rule|
395
+ add_nterm(id: rule._lhs, tag: rule.lhs_tag)
396
+ @rules << rule
397
+ end
398
+
394
399
  builder.midrule_action_rules.each do |rule|
395
400
  add_nterm(id: rule._lhs)
396
401
  end
@@ -484,7 +489,7 @@ module Lrama
484
489
  end
485
490
  end
486
491
 
487
- def replace_token_with_symbol
492
+ def set_lhs_and_rhs
488
493
  @rules.each do |rule|
489
494
  rule.lhs = token_to_symbol(rule._lhs) if rule._lhs
490
495
 
@@ -4,7 +4,7 @@ module Lrama
4
4
  class Parameterizing < Token
5
5
  attr_accessor :args
6
6
 
7
- def initialize(s_value: nil, alias_name: nil, location: nil, args: [])
7
+ def initialize(s_value:, alias_name: nil, location: nil, args: [])
8
8
  super s_value: s_value, alias_name: alias_name, location: location
9
9
  @args = args
10
10
  end
@@ -1,8 +1,21 @@
1
+ require 'lrama/lexer/token/char'
2
+ require 'lrama/lexer/token/ident'
3
+ require 'lrama/lexer/token/parameterizing'
4
+ require 'lrama/lexer/token/tag'
5
+ require 'lrama/lexer/token/user_code'
6
+
1
7
  module Lrama
2
8
  class Lexer
3
- class Token < Struct.new(:s_value, :alias_name, :location, keyword_init: true)
4
-
5
- attr_accessor :referred
9
+ class Token
10
+ attr_reader :s_value, :location
11
+ attr_accessor :alias_name, :referred
12
+
13
+ def initialize(s_value:, alias_name: nil, location: nil)
14
+ s_value.freeze
15
+ @s_value = s_value
16
+ @alias_name = alias_name
17
+ @location = location
18
+ end
6
19
 
7
20
  def to_s
8
21
  "#{super} location: #{location}"
@@ -36,9 +49,3 @@ module Lrama
36
49
  end
37
50
  end
38
51
  end
39
-
40
- require 'lrama/lexer/token/char'
41
- require 'lrama/lexer/token/ident'
42
- require 'lrama/lexer/token/parameterizing'
43
- require 'lrama/lexer/token/tag'
44
- require 'lrama/lexer/token/user_code'
data/lib/lrama/lexer.rb CHANGED
@@ -157,8 +157,7 @@ module Lrama
157
157
  while !@scanner.eos? do
158
158
  case
159
159
  when @scanner.scan(/\n/)
160
- @line += 1
161
- @head = @scanner.pos + 1
160
+ newline
162
161
  when @scanner.scan(/\*\//)
163
162
  return
164
163
  else