lrama 0.6.9 → 0.6.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yaml +24 -1
  3. data/.gitignore +2 -0
  4. data/Gemfile +6 -3
  5. data/NEWS.md +269 -14
  6. data/README.md +41 -4
  7. data/Rakefile +2 -0
  8. data/Steepfile +9 -17
  9. data/doc/development/compressed_state_table/main.md +635 -0
  10. data/doc/development/compressed_state_table/parse.output +174 -0
  11. data/doc/development/compressed_state_table/parse.y +22 -0
  12. data/doc/development/compressed_state_table/parser.rb +282 -0
  13. data/exe/lrama +1 -0
  14. data/lib/lrama/bitmap.rb +3 -1
  15. data/lib/lrama/command.rb +8 -14
  16. data/lib/lrama/context.rb +11 -9
  17. data/lib/lrama/counterexamples/derivation.rb +8 -5
  18. data/lib/lrama/counterexamples/example.rb +9 -4
  19. data/lib/lrama/counterexamples/path.rb +6 -0
  20. data/lib/lrama/counterexamples/production_path.rb +2 -0
  21. data/lib/lrama/counterexamples/start_path.rb +2 -0
  22. data/lib/lrama/counterexamples/state_item.rb +2 -0
  23. data/lib/lrama/counterexamples/transition_path.rb +2 -0
  24. data/lib/lrama/counterexamples/triple.rb +2 -0
  25. data/lib/lrama/counterexamples.rb +36 -24
  26. data/lib/lrama/diagnostics.rb +36 -0
  27. data/lib/lrama/digraph.rb +2 -0
  28. data/lib/lrama/grammar/auxiliary.rb +2 -0
  29. data/lib/lrama/grammar/binding.rb +12 -1
  30. data/lib/lrama/grammar/code/destructor_code.rb +2 -0
  31. data/lib/lrama/grammar/code/initial_action_code.rb +2 -0
  32. data/lib/lrama/grammar/code/no_reference_code.rb +2 -0
  33. data/lib/lrama/grammar/code/printer_code.rb +2 -0
  34. data/lib/lrama/grammar/code/rule_action.rb +7 -3
  35. data/lib/lrama/grammar/code.rb +7 -5
  36. data/lib/lrama/grammar/counter.rb +2 -0
  37. data/lib/lrama/grammar/destructor.rb +2 -0
  38. data/lib/lrama/grammar/error_token.rb +2 -0
  39. data/lib/lrama/grammar/parameterizing_rule/resolver.rb +7 -1
  40. data/lib/lrama/grammar/parameterizing_rule/rhs.rb +6 -3
  41. data/lib/lrama/grammar/parameterizing_rule/rule.rb +6 -0
  42. data/lib/lrama/grammar/parameterizing_rule.rb +2 -0
  43. data/lib/lrama/grammar/percent_code.rb +2 -0
  44. data/lib/lrama/grammar/precedence.rb +2 -0
  45. data/lib/lrama/grammar/printer.rb +2 -0
  46. data/lib/lrama/grammar/reference.rb +2 -0
  47. data/lib/lrama/grammar/rule.rb +10 -3
  48. data/lib/lrama/grammar/rule_builder.rb +64 -65
  49. data/lib/lrama/grammar/symbol.rb +2 -0
  50. data/lib/lrama/grammar/symbols/resolver.rb +9 -1
  51. data/lib/lrama/grammar/symbols.rb +2 -0
  52. data/lib/lrama/grammar/type.rb +2 -0
  53. data/lib/lrama/grammar/union.rb +2 -0
  54. data/lib/lrama/grammar.rb +53 -32
  55. data/lib/lrama/grammar_validator.rb +37 -0
  56. data/lib/lrama/lexer/grammar_file.rb +2 -0
  57. data/lib/lrama/lexer/location.rb +2 -0
  58. data/lib/lrama/lexer/token/char.rb +2 -0
  59. data/lib/lrama/lexer/token/ident.rb +2 -0
  60. data/lib/lrama/lexer/token/instantiate_rule.rb +2 -0
  61. data/lib/lrama/lexer/token/tag.rb +2 -0
  62. data/lib/lrama/lexer/token/user_code.rb +4 -2
  63. data/lib/lrama/lexer/token.rb +7 -5
  64. data/lib/lrama/lexer.rb +12 -8
  65. data/lib/lrama/{warning.rb → logger.rb} +5 -13
  66. data/lib/lrama/option_parser.rb +58 -33
  67. data/lib/lrama/options.rb +5 -2
  68. data/lib/lrama/output.rb +38 -69
  69. data/lib/lrama/parser.rb +677 -773
  70. data/lib/lrama/report/duration.rb +2 -0
  71. data/lib/lrama/report/profile.rb +2 -0
  72. data/lib/lrama/report.rb +4 -2
  73. data/lib/lrama/state/reduce.rb +4 -2
  74. data/lib/lrama/state/reduce_reduce_conflict.rb +2 -0
  75. data/lib/lrama/state/resolved_conflict.rb +3 -1
  76. data/lib/lrama/state/shift.rb +2 -0
  77. data/lib/lrama/state/shift_reduce_conflict.rb +2 -0
  78. data/lib/lrama/state.rb +7 -5
  79. data/lib/lrama/states/item.rb +5 -3
  80. data/lib/lrama/states.rb +18 -46
  81. data/lib/lrama/states_reporter.rb +60 -19
  82. data/lib/lrama/trace_reporter.rb +30 -0
  83. data/lib/lrama/version.rb +3 -1
  84. data/lib/lrama.rb +22 -17
  85. data/lrama.gemspec +3 -1
  86. data/parser.y +129 -237
  87. data/rbs_collection.lock.yaml +10 -2
  88. data/sig/lrama/counterexamples/derivation.rbs +33 -0
  89. data/sig/lrama/counterexamples/example.rbs +45 -0
  90. data/sig/lrama/counterexamples/path.rbs +21 -0
  91. data/sig/lrama/counterexamples/production_path.rbs +11 -0
  92. data/sig/lrama/counterexamples/start_path.rbs +13 -0
  93. data/sig/lrama/counterexamples/state_item.rbs +10 -0
  94. data/sig/lrama/counterexamples/transition_path.rbs +11 -0
  95. data/sig/lrama/counterexamples/triple.rbs +20 -0
  96. data/sig/lrama/counterexamples.rbs +29 -0
  97. data/sig/lrama/grammar/auxiliary.rbs +10 -0
  98. data/sig/lrama/grammar/binding.rbs +4 -0
  99. data/sig/lrama/grammar/code/destructor_code.rbs +3 -4
  100. data/sig/lrama/grammar/code/initial_action_code.rbs +15 -0
  101. data/sig/lrama/grammar/code/no_reference_code.rbs +15 -0
  102. data/sig/lrama/grammar/code/printer_code.rbs +3 -4
  103. data/sig/lrama/grammar/code/rule_action.rbs +19 -0
  104. data/sig/lrama/grammar/code.rbs +3 -3
  105. data/sig/lrama/grammar/destructor.rbs +3 -1
  106. data/sig/lrama/grammar/error_token.rbs +4 -2
  107. data/sig/lrama/grammar/parameterizing_rule/resolver.rbs +2 -1
  108. data/sig/lrama/grammar/parameterizing_rule/rhs.rbs +1 -1
  109. data/sig/lrama/grammar/precedence.rbs +3 -1
  110. data/sig/lrama/grammar/printer.rbs +3 -1
  111. data/sig/lrama/grammar/rule.rbs +35 -3
  112. data/sig/lrama/grammar/rule_builder.rbs +10 -9
  113. data/sig/lrama/grammar/symbol.rbs +6 -6
  114. data/sig/lrama/grammar/symbols/resolver.rbs +24 -5
  115. data/sig/lrama/grammar/type.rbs +2 -2
  116. data/sig/lrama/grammar/union.rbs +12 -0
  117. data/sig/lrama/grammar.rbs +104 -1
  118. data/sig/lrama/options.rbs +3 -2
  119. data/sig/lrama/state/reduce.rbs +20 -0
  120. data/sig/lrama/state/reduce_reduce_conflict.rbs +13 -0
  121. data/sig/lrama/state/resolved_conflict.rbs +14 -0
  122. data/sig/lrama/state/shift.rbs +14 -0
  123. data/sig/lrama/state/shift_reduce_conflict.rbs +13 -0
  124. data/sig/lrama/state.rbs +79 -0
  125. data/sig/lrama/states/item.rbs +30 -0
  126. data/sig/lrama/states.rbs +101 -0
  127. data/template/bison/yacc.c +24 -19
  128. metadata +32 -6
  129. data/sample/calc.output +0 -263
  130. data/sample/calc.y +0 -101
  131. data/sample/parse.y +0 -59
@@ -0,0 +1,11 @@
1
+ module Lrama
2
+ class Counterexamples
3
+ class ProductionPath < Path
4
+ def type: () -> :production
5
+
6
+ def transition?: () -> false
7
+
8
+ def production?: () -> true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Lrama
2
+ class Counterexamples
3
+ class StartPath < Path
4
+ def initialize: (StateItem to_state_item) -> void
5
+
6
+ def type: () -> :start
7
+
8
+ def transition?: () -> false
9
+
10
+ def production?: () -> false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module Lrama
2
+ class Counterexamples
3
+ class StateItem
4
+ attr_accessor state: State
5
+ attr_accessor item: States::Item
6
+
7
+ def initialize: (State state, States::Item item) -> void
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module Lrama
2
+ class Counterexamples
3
+ class TransitionPath < Path
4
+ def type: () -> :transition
5
+
6
+ def transition?: () -> true
7
+
8
+ def production?: () -> false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ module Lrama
2
+ class Counterexamples
3
+ class Triple
4
+ attr_accessor s: State
5
+ attr_accessor itm: States::Item
6
+ attr_accessor l: Set[Grammar::Symbol]
7
+
8
+ alias state s
9
+ alias item itm
10
+ alias precise_lookahead_set l
11
+
12
+ def initialize: (State s, States::Item itm, Set[Grammar::Symbol] l) -> void
13
+
14
+ def state_item: () -> StateItem
15
+ def inspect: () -> ::String
16
+
17
+ alias to_s inspect
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ module Lrama
2
+ class Counterexamples
3
+ @states: States
4
+ @transitions: Hash[[StateItem, Grammar::Symbol], StateItem]
5
+ @reverse_transitions: Hash[[StateItem, Grammar::Symbol], Set[StateItem]]
6
+ @productions: Hash[StateItem, Set[States::Item]]
7
+ @reverse_productions: Hash[[State, Grammar::Symbol], Set[States::Item]]
8
+
9
+ attr_reader transitions: Hash[[StateItem, Grammar::Symbol], StateItem]
10
+ attr_reader productions: Hash[StateItem, Set[States::Item]]
11
+
12
+ def initialize: (States states) -> void
13
+ def to_s: () -> "#<Counterexamples>"
14
+ alias inspect to_s
15
+ def compute: (State conflict_state) -> Array[Example]
16
+
17
+ private
18
+
19
+ def setup_transitions: () -> void
20
+ def setup_productions: () -> void
21
+ def shift_reduce_example: (State conflict_state, State::ShiftReduceConflict conflict) -> Example
22
+ def reduce_reduce_examples: (State conflict_state, State::ReduceReduceConflict conflict) -> Example
23
+ def find_shift_conflict_shortest_path: (::Array[StartPath|TransitionPath|ProductionPath]? reduce_path, State conflict_state, States::Item conflict_item) -> ::Array[StartPath|TransitionPath|ProductionPath]
24
+ def find_shift_conflict_shortest_state_items: (::Array[StartPath|TransitionPath|ProductionPath]? reduce_path, State conflict_state, States::Item conflict_item) -> Array[StateItem]
25
+ def build_paths_from_state_items: (Array[StateItem] state_items) -> ::Array[StartPath|TransitionPath|ProductionPath]
26
+ def shortest_path: (State conflict_state, States::Item conflict_reduce_item, Grammar::Symbol conflict_term) -> ::Array[StartPath|TransitionPath|ProductionPath]?
27
+ def follow_l: (States::Item item, Set[Grammar::Symbol] current_l) -> Set[Grammar::Symbol]
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Auxiliary
4
+ attr_accessor prologue_first_lineno: Integer
5
+ attr_accessor prologue: String
6
+ attr_accessor epilogue_first_lineno: Integer
7
+ attr_accessor epilogue: String
8
+ end
9
+ end
10
+ end
@@ -10,6 +10,10 @@ module Lrama
10
10
 
11
11
  def initialize: (Grammar::ParameterizingRule::Rule parameterizing_rule, Array[Lexer::Token] actual_args) -> void
12
12
  def resolve_symbol: (Lexer::Token symbol) -> Lexer::Token
13
+
14
+ private
15
+
16
+ def parameter_to_arg: (Lexer::Token symbol) -> Lexer::Token?
13
17
  end
14
18
  end
15
19
  end
@@ -2,13 +2,12 @@ module Lrama
2
2
  class Grammar
3
3
  class Code
4
4
  class DestructorCode < Code
5
- @tag: untyped
6
- def initialize: (type: untyped, token_code: untyped, tag: untyped) -> void
5
+ @tag: Lexer::Token::Tag
6
+ def initialize: (type: ::Symbol, token_code: Grammar::Code, tag: Lexer::Token::Tag) -> void
7
7
 
8
8
  private
9
9
 
10
- # ref: Lrama::Grammar::Code.token_code.references
11
- def reference_to_c: (untyped ref) -> untyped
10
+ def reference_to_c: (Reference ref) -> (String | bot)
12
11
  end
13
12
  end
14
13
  end
@@ -0,0 +1,15 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Code
4
+ class InitialActionCode < Code
5
+ private
6
+
7
+ # * ($$) yylval
8
+ # * (@$) yylloc
9
+ # * ($1) error
10
+ # * (@1) error
11
+ def reference_to_c: (Reference ref) -> (String | bot)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Code
4
+ class NoReferenceCode < Code
5
+ private
6
+
7
+ # * ($$) error
8
+ # * (@$) error
9
+ # * ($1) error
10
+ # * (@1) error
11
+ def reference_to_c: (Reference ref) -> bot
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,13 +2,12 @@ module Lrama
2
2
  class Grammar
3
3
  class Code
4
4
  class PrinterCode < Code
5
- @tag: untyped
6
- def initialize: (type: untyped, token_code: untyped, tag: untyped) -> void
5
+ @tag: Lexer::Token::Tag
6
+ def initialize: (type: ::Symbol, token_code: Grammar::Code, tag: Lexer::Token::Tag) -> void
7
7
 
8
8
  private
9
9
 
10
- # ref: Lrama::Grammar::Code.token_code.references
11
- def reference_to_c: (untyped ref) -> untyped
10
+ def reference_to_c: (Reference ref) -> (String | bot)
12
11
  end
13
12
  end
14
13
  end
@@ -0,0 +1,19 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Code
4
+ class RuleAction < Code
5
+ @rule: Rule
6
+
7
+ def initialize: (type: ::Symbol, token_code: Grammar::Code, rule: Rule) -> void
8
+
9
+ private
10
+
11
+ def reference_to_c: (Reference ref) -> String
12
+ def position_in_rhs: () -> Integer
13
+ def rhs: () -> Array[Grammar::Symbol]
14
+ def lhs: () -> Grammar::Symbol
15
+ def raise_tag_not_found_error: (Reference ref) -> bot
16
+ end
17
+ end
18
+ end
19
+ end
@@ -3,8 +3,8 @@ module Lrama
3
3
  class Code
4
4
  extend Forwardable
5
5
 
6
- attr_accessor type: Symbol
7
- attr_accessor token_code: Lexer::Token::UserCode
6
+ attr_accessor type: ::Symbol
7
+ attr_accessor token_code: Grammar::Code
8
8
 
9
9
  # delegated
10
10
  def s_value: -> String
@@ -12,7 +12,7 @@ module Lrama
12
12
  def column: -> Integer
13
13
  def references: -> Array[Lrama::Grammar::Reference]
14
14
 
15
- def initialize: (type: Symbol, token_code: Lexer::Token::UserCode) -> void
15
+ def initialize: (type: ::Symbol, token_code: Grammar::Code) -> void
16
16
 
17
17
  def translated_code: () -> String
18
18
 
@@ -5,7 +5,9 @@ module Lrama
5
5
  attr_accessor token_code: Grammar::Code
6
6
  attr_accessor lineno: Integer
7
7
 
8
- def translated_code: (Lexer::Token member) -> String
8
+ def initialize: (ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag], token_code: Grammar::Code, lineno: Integer) -> void
9
+
10
+ def translated_code: (Lexer::Token::Tag tag) -> String
9
11
  end
10
12
  end
11
13
  end
@@ -2,10 +2,12 @@ module Lrama
2
2
  class Grammar
3
3
  class ErrorToken
4
4
  attr_accessor ident_or_tags: Array[Lexer::Token::Ident | Lexer::Token::Tag]
5
- attr_accessor token_code: Symbol
5
+ attr_accessor token_code: Grammar::Code
6
6
  attr_accessor lineno: Integer
7
7
 
8
- def translated_code: (Lexer::Token? tag) -> String
8
+ def initialize: (?ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag], ?token_code: Grammar::Code, ?lineno: Integer) -> void
9
+
10
+ def translated_code: (Lexer::Token::Tag tag) -> String
9
11
  end
10
12
  end
11
13
  end
@@ -2,12 +2,13 @@ module Lrama
2
2
  class Grammar
3
3
  class ParameterizingRule
4
4
  class Resolver
5
+ attr_accessor rules: Array[Grammar::ParameterizingRule::Rule]
5
6
  attr_accessor created_lhs_list: Array[Lexer::Token]
6
7
 
7
8
  @rules: Array[Grammar::ParameterizingRule::Rule]
8
9
 
9
10
  def initialize: () -> void
10
- def add_parameterizing_rule: (Grammar::ParameterizingRule::Rule rule) -> void
11
+ def add_parameterizing_rule: (Grammar::ParameterizingRule::Rule rule) -> Array[Grammar::ParameterizingRule::Rule]
11
12
  def find_rule: (Lexer::Token::InstantiateRule token) -> Grammar::ParameterizingRule::Rule?
12
13
  def find_inline: (Lexer::Token token) -> Grammar::ParameterizingRule::Rule?
13
14
  def created_lhs: (String lhs_s_value) -> Lexer::Token?
@@ -4,7 +4,7 @@ module Lrama
4
4
  class Rhs
5
5
  attr_reader symbols: Array[untyped]
6
6
  attr_reader user_code: Lexer::Token::UserCode?
7
- attr_reader precedence_sym: Lexer::Token?
7
+ attr_reader precedence_sym: Grammar::Symbol?
8
8
 
9
9
  def initialize: () -> void
10
10
  def resolve_user_code: (Grammar::Binding bindings) -> Lexer::Token::UserCode?
@@ -2,9 +2,11 @@ module Lrama
2
2
  class Grammar
3
3
  class Precedence
4
4
  include Comparable
5
- attr_accessor type: Symbol
5
+ attr_accessor type: ::Symbol
6
6
  attr_accessor precedence: Integer
7
7
 
8
+ def initialize: (?type: ::Symbol, ?precedence: Integer) -> void
9
+
8
10
  def <=>: (Precedence other) -> Integer
9
11
  end
10
12
  end
@@ -5,7 +5,9 @@ module Lrama
5
5
  attr_accessor token_code: Grammar::Code
6
6
  attr_accessor lineno: Integer
7
7
 
8
- def translated_code: (Lexer::Token member) -> String
8
+ def initialize: (?ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag], ?token_code: Grammar::Code, ?lineno: Integer) -> void
9
+
10
+ def translated_code: (Lexer::Token::Tag tag) -> String
9
11
  end
10
12
  end
11
13
  end
@@ -1,13 +1,45 @@
1
1
  module Lrama
2
2
  class Grammar
3
3
  class Rule
4
+ attr_accessor id: Integer
5
+ attr_accessor _lhs: Lexer::Token
6
+ attr_accessor lhs: Grammar::Symbol
7
+ attr_accessor lhs_tag: Lexer::Token::Tag?
8
+ attr_accessor _rhs: Array[Lexer::Token]
9
+ attr_accessor rhs: Array[Grammar::Symbol]
10
+ attr_accessor token_code: Grammar::Code?
11
+ attr_accessor position_in_original_rule_rhs: Integer
12
+ attr_accessor nullable: bool
13
+ attr_accessor precedence_sym: Grammar::Symbol?
14
+ attr_accessor lineno: Integer?
4
15
  attr_accessor original_rule: Rule
5
16
 
6
17
  def initialize: (
7
- ?id: untyped, ?_lhs: untyped, ?lhs: untyped, ?lhs_tag: untyped, ?_rhs: untyped, ?rhs: untyped,
8
- ?token_code: untyped, ?position_in_original_rule_rhs: untyped, ?nullable: untyped,
9
- ?precedence_sym: untyped, ?lineno: untyped
18
+ ?id: Integer, ?_lhs: Lexer::Token, ?lhs: Lexer::Token, ?lhs_tag: Lexer::Token::Tag?, ?_rhs: Array[Lexer::Token], ?rhs: Array[Grammar::Symbol],
19
+ ?token_code: Lexer::Token::UserCode?, ?position_in_original_rule_rhs: Integer?, ?nullable: bool,
20
+ ?precedence_sym: Grammar::Symbol?, ?lineno: Integer?
10
21
  ) -> void
22
+
23
+ def display_name: () -> String
24
+
25
+ def as_comment: -> String
26
+
27
+ def empty_rule?: -> bool
28
+
29
+ def initial_rule?: -> bool
30
+
31
+ def precedence: -> Precedence?
32
+
33
+ def translated_code: -> String?
34
+
35
+ def with_actions: -> String
36
+
37
+ def contains_at_reference?: -> bool
38
+
39
+ interface _DelegatedMethods
40
+ def lhs: -> Grammar::Symbol
41
+ def rhs: -> Array[Grammar::Symbol]
42
+ end
11
43
  end
12
44
  end
13
45
  end
@@ -6,28 +6,29 @@ module Lrama
6
6
  attr_reader lhs_tag: Lexer::Token::Tag?
7
7
  attr_reader rhs: Array[Lexer::Token]
8
8
  attr_reader user_code: Lexer::Token::UserCode?
9
- attr_reader precedence_sym: Lexer::Token?
9
+ attr_reader precedence_sym: Grammar::Symbol?
10
10
 
11
11
  @rule_counter: Counter
12
12
  @midrule_action_counter: Counter
13
+ @parameterizing_rule_resolver: Grammar::ParameterizingRule::Resolver
13
14
  @position_in_original_rule_rhs: Integer?
14
15
  @skip_preprocess_references: bool
15
16
  @user_code: Lexer::Token::UserCode?
16
17
  @rule_builders_for_parameterizing_rules: Array[RuleBuilder]
17
18
  @rule_builders_for_derived_rules: Array[RuleBuilder]
18
- @rule_builders_for_inline_rules: Array[RuleBuilder]
19
19
  @rules: Array[Rule]
20
20
  @replaced_rhs: Array[Lexer::Token]
21
21
  @parameterizing_rules: Array[Rule]
22
- @inline_rules: Array[Rule]
23
22
  @midrule_action_rules: Array[Rule]
24
23
 
25
- def initialize: (Counter rule_counter, Counter midrule_action_counter, ?Integer position_in_original_rule_rhs, ?lhs_tag: Lexer::Token::Tag?, ?skip_preprocess_references: bool) -> void
24
+ def initialize: (Counter rule_counter, Counter midrule_action_counter, Grammar::ParameterizingRule::Resolver parameterizing_rule_resolver, ?Integer position_in_original_rule_rhs, ?lhs_tag: Lexer::Token::Tag?, ?skip_preprocess_references: bool) -> void
26
25
  def add_rhs: (Lexer::Token rhs) -> void
26
+ def has_inline_rules?: -> bool
27
+ def resolve_inline_rules: -> Array[RuleBuilder]
27
28
  def user_code=: (Lexer::Token::UserCode? user_code) -> void
28
- def precedence_sym=: (Lexer::Token? precedence_sym) -> void
29
+ def precedence_sym=: (Grammar::Symbol? precedence_sym) -> void
29
30
  def complete_input: () -> void
30
- def setup_rules: (Grammar::ParameterizingRule::Resolver parameterizing_rule_resolver) -> void
31
+ def setup_rules: () -> void
31
32
  def rules: () -> Array[Rule]
32
33
 
33
34
  private
@@ -35,10 +36,10 @@ module Lrama
35
36
  def freeze_rhs: () -> void
36
37
  def preprocess_references: () -> void
37
38
  def build_rules: () -> void
38
- def process_rhs: (Grammar::ParameterizingRule::Resolver parameterizing_rule_resolver) -> void
39
+ def process_rhs: () -> void
39
40
  def lhs_s_value: (Lexer::Token::InstantiateRule token, Grammar::Binding bindings) -> String
40
- def resolve_inline: (Grammar::ParameterizingRule::Resolver parameterizing_rule_resolver) -> void
41
- def resolve_inline_rhs: (RuleBuilder rule_builder, Grammar::ParameterizingRule::Rhs inline_rhs, Integer index) -> void
41
+ def resolve_inline: () -> void
42
+ def resolve_inline_rhs: (RuleBuilder rule_builder, Grammar::ParameterizingRule::Rhs inline_rhs, Integer index, ?Binding bindings) -> void
42
43
  def replace_inline_user_code: (Grammar::ParameterizingRule::Rhs inline_rhs, Integer index) -> Lexer::Token::UserCode?
43
44
  def numberize_references: () -> void
44
45
  def flush_user_code: () -> void
@@ -4,7 +4,7 @@ module Lrama
4
4
  attr_accessor id: Lexer::Token
5
5
  attr_accessor alias_name: String?
6
6
  attr_accessor number: Integer
7
- attr_accessor tag: Lexer::Token?
7
+ attr_accessor tag: Lexer::Token::Tag?
8
8
  attr_accessor term: bool
9
9
  attr_accessor token_id: Integer
10
10
  attr_accessor nullable: bool
@@ -13,12 +13,12 @@ module Lrama
13
13
  attr_accessor destructor: Destructor?
14
14
  attr_accessor error_token: ErrorToken
15
15
 
16
- attr_accessor first_set: Set[Array[Symbol]]
16
+ attr_accessor first_set: Set[Grammar::Symbol]
17
17
  attr_accessor first_set_bitmap: Integer
18
- attr_writer eof_symbol: Symbol
19
- attr_writer error_symbol: Symbol
20
- attr_writer undef_symbol: Symbol
21
- attr_writer accept_symbol: Symbol
18
+ attr_writer eof_symbol: bool
19
+ attr_writer error_symbol: bool
20
+ attr_writer undef_symbol: bool
21
+ attr_writer accept_symbol: bool
22
22
 
23
23
  def initialize: (
24
24
  id: Lexer::Token, term: bool, ?alias_name: String?, ?number: Integer?, ?tag: Lexer::Token?,
@@ -11,16 +11,17 @@ module Lrama
11
11
 
12
12
  def initialize: () -> void
13
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
14
+ def sort_by_number!: () -> Array[Grammar::Symbol]
15
+ def add_term: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token::Tag?, ?token_id: Integer?, ?replace: bool) -> Grammar::Symbol
16
+ def add_nterm: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token::Tag?) -> Grammar::Symbol
17
+ def find_symbol_by_s_value: (::String s_value) -> Grammar::Symbol?
18
+ def find_symbol_by_s_value!: (::String s_value) -> Grammar::Symbol
19
19
  def find_symbol_by_id: (Lexer::Token id) -> Grammar::Symbol?
20
20
  def find_symbol_by_id!: (Lexer::Token id) -> Grammar::Symbol
21
21
  def find_symbol_by_token_id: (Integer token_id) -> Grammar::Symbol?
22
22
  def find_symbol_by_number!: (Integer number) -> Grammar::Symbol
23
23
  def fill_symbol_number: () -> void
24
+ def fill_destructor: (Array[Destructor] destructors) -> (Array[Grammar::Symbol] | bot)
24
25
  def fill_nterm_type: (Array[Grammar::Type] types) -> void
25
26
  def fill_printer: (Array[Grammar::Printer] printers) -> void
26
27
  def fill_error_token: (Array[Grammar::ErrorToken] error_tokens) -> void
@@ -36,6 +37,24 @@ module Lrama
36
37
  def validate_number_uniqueness!: () -> void
37
38
  def validate_alias_name_uniqueness!: () -> void
38
39
  end
40
+
41
+ interface _DelegatedMethods
42
+ def symbols: () -> Array[Grammar::Symbol]
43
+ def nterms: () -> Array[Grammar::Symbol]
44
+ def terms: () -> Array[Grammar::Symbol]
45
+ def add_nterm: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token::Tag?) -> Grammar::Symbol
46
+ def add_term: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token::Tag?, ?token_id: Integer?, ?replace: bool) -> Grammar::Symbol
47
+ def find_symbol_by_number!: (Integer number) -> Grammar::Symbol
48
+ def find_symbol_by_id!: (Lexer::Token id) -> Grammar::Symbol
49
+ def token_to_symbol: (Lexer::Token token) -> Grammar::Symbol
50
+ def find_symbol_by_s_value!: (::String s_value) -> Grammar::Symbol
51
+ def fill_nterm_type: (Array[Grammar::Type] types) -> void
52
+ def fill_symbol_number: () -> void
53
+ def fill_printer: (Array[Grammar::Printer] printers) -> void
54
+ def fill_destructor: (Array[Destructor] destructors) -> (Destructor | bot)
55
+ def fill_error_token: (Array[Grammar::ErrorToken] error_tokens) -> void
56
+ def sort_by_number!: () -> Array[Grammar::Symbol]
57
+ end
39
58
  end
40
59
  end
41
60
  end
@@ -2,9 +2,9 @@ module Lrama
2
2
  class Grammar
3
3
  class Type
4
4
  attr_reader id: Lexer::Token
5
- attr_reader tag: Lexer::Token
5
+ attr_reader tag: Lexer::Token::Tag
6
6
 
7
- def initialize: (id: Lexer::Token, tag: Lexer::Token) -> void
7
+ def initialize: (id: Lexer::Token, tag: Lexer::Token::Tag) -> void
8
8
  def ==: (Grammar::Type other) -> bool
9
9
  end
10
10
  end
@@ -0,0 +1,12 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Union
4
+ attr_accessor code: Grammar::Code::NoReferenceCode
5
+ attr_accessor lineno: Integer
6
+
7
+ def initialize: (code: Grammar::Code::NoReferenceCode, lineno: Integer) -> void
8
+
9
+ def braces_less_code: () -> String
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,108 @@
1
1
  module Lrama
2
2
  class Grammar
3
- def numberize_references: (Lexer::Token lhs, Array[Lexer::Token] rhs, Array[Reference]) -> void
3
+ include Symbols::_DelegatedMethods
4
+
5
+ @rule_counter: Counter
6
+ @percent_codes: Array[PercentCode]
7
+ @printers: Array[Printer]
8
+ @destructors: Array[Destructor]
9
+ @error_tokens: Array[ErrorToken]
10
+ @symbols_resolver: Symbols::Resolver
11
+ @types: Array[Type]
12
+ @rule_builders: Array[RuleBuilder]
13
+ @rules: Array[Rule]
14
+ @sym_to_rules: Hash[Integer, Array[Rule]]
15
+ @parameterizing_rule_resolver: ParameterizingRule::Resolver
16
+ @empty_symbol: Grammar::Symbol
17
+ @eof_symbol: Grammar::Symbol
18
+ @error_symbol: Grammar::Symbol
19
+ @undef_symbol: Grammar::Symbol
20
+ @accept_symbol: Grammar::Symbol
21
+ @aux: Auxiliary
22
+ @no_stdlib: bool
23
+ @locations: bool
24
+ @union: Union
25
+
26
+ extend Forwardable
27
+
28
+ attr_reader percent_codes: Array[PercentCode]
29
+ attr_reader eof_symbol: Grammar::Symbol
30
+ attr_reader error_symbol: Grammar::Symbol
31
+ attr_reader undef_symbol: Grammar::Symbol
32
+ attr_reader accept_symbol: Grammar::Symbol
33
+ attr_reader aux: Auxiliary
34
+ attr_accessor union: Union
35
+ attr_accessor expect: Integer
36
+ attr_accessor printers: Array[Printer]
37
+ attr_accessor error_tokens: Array[ErrorToken]
38
+ attr_accessor lex_param: String
39
+ attr_accessor parse_param: String
40
+ attr_accessor initial_action: Grammar::Code::InitialActionCode
41
+ attr_accessor after_shift: Lexer::Token
42
+ attr_accessor before_reduce: Lexer::Token
43
+ attr_accessor after_reduce: Lexer::Token
44
+ attr_accessor after_shift_error_token: Lexer::Token
45
+ attr_accessor after_pop_stack: Lexer::Token
46
+ attr_accessor symbols_resolver: Symbols::Resolver
47
+ attr_accessor types: Array[Type]
48
+ attr_accessor rules: Array[Rule]
49
+ attr_accessor rule_builders: Array[RuleBuilder]
50
+ attr_accessor sym_to_rules: Hash[Integer, Array[Rule]]
51
+ attr_accessor no_stdlib: bool
52
+
53
+ def initialize: (Counter rule_counter) -> void
54
+ def create_rule_builder: (Counter rule_counter, Counter midrule_action_counter) -> RuleBuilder
55
+ def add_percent_code: (id: Lexer::Token, code: Lexer::Token::UserCode) -> Array[PercentCode]
56
+ def add_destructor: (ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag], token_code: Code, lineno: Integer) -> Array[Destructor]
57
+ def add_printer: (ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag], token_code: Code, lineno: Integer) -> Array[Printer]
58
+ def add_error_token: (ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag], token_code: Code, lineno: Integer) -> Array[ErrorToken]
59
+ def add_type: (id: Lexer::Token, tag: Lexer::Token::Tag) -> Array[Type]
60
+ def add_nonassoc: (Grammar::Symbol sym, Integer precedence) -> Precedence
61
+ def add_left: (Grammar::Symbol sym, Integer precedence) -> Precedence
62
+ def add_right: (Grammar::Symbol sym, Integer precedence) -> Precedence
63
+ def add_precedence: (Grammar::Symbol sym, Integer precedence) -> Precedence
64
+ def set_precedence: (Grammar::Symbol sym, Precedence precedence) -> (Precedence | bot)
65
+ def set_union: (Grammar::Code::NoReferenceCode code, Integer lineno) -> Union
66
+ def add_rule_builder: (RuleBuilder builder) -> Array[RuleBuilder]
67
+ def add_parameterizing_rule: (ParameterizingRule::Rule rule) -> Array[ParameterizingRule::Rule]
68
+ def parameterizing_rules: () -> Array[ParameterizingRule::Rule]
69
+ def insert_before_parameterizing_rules: (Array[ParameterizingRule::Rule] rules) -> Array[ParameterizingRule::Rule]
70
+ def prologue_first_lineno=: (Integer prologue_first_lineno) -> Integer
71
+ def prologue=: (String prologue) -> String
72
+ def epilogue_first_lineno=: (Integer epilogue_first_lineno) -> Integer
73
+ def epilogue=: (String epilogue) -> String
74
+ def prepare: () -> void
75
+ def validate!: () -> void
76
+ def find_rules_by_symbol!: (Grammar::Symbol sym) -> Array[Rule]
77
+ def find_rules_by_symbol: (Grammar::Symbol sym) -> Array[Rule]?
78
+
79
+ private
80
+
81
+ def compute_nullable: () -> Array[Grammar::Symbol]
82
+ def compute_first_set: () -> Array[Grammar::Symbol]
83
+ def resolve_inline_rules: () -> void
84
+ def setup_rules: () -> Array[RuleBuilder]
85
+ def append_special_symbols: () -> Grammar::Symbol
86
+ def normalize_rules: () -> Array[Rule]
87
+ def collect_symbols: () -> Array[Lexer::Token]
88
+ def set_lhs_and_rhs: () -> void
89
+ def fill_default_precedence: () -> void
90
+ def fill_symbols: () -> Array[Grammar::Symbol]
91
+ def fill_sym_to_rules: () -> Array[Rule]
92
+ def validate_rule_lhs_is_nterm!: () -> void
93
+ def set_locations: () -> void
94
+
95
+ interface _DelegatedMethods
96
+ def rules: () -> Array[Rule]
97
+ def accept_symbol: () -> Grammar::Symbol
98
+ def eof_symbol: () -> Grammar::Symbol
99
+ def undef_symbol: () -> Grammar::Symbol
100
+
101
+ # delegate to @symbols_resolver
102
+ def symbols: () -> Array[Grammar::Symbol]
103
+ def terms: () -> Array[Grammar::Symbol]
104
+ def nterms: () -> Array[Grammar::Symbol]
105
+ def find_symbol_by_s_value!: (::String s_value) -> Grammar::Symbol
106
+ end
4
107
  end
5
108
  end
@@ -1,5 +1,5 @@
1
1
  module Lrama
2
- class Options
2
+ class Options
3
3
  attr_accessor skeleton: String
4
4
  attr_accessor header: bool
5
5
  attr_accessor header_file: String?
@@ -9,9 +9,10 @@ module Lrama
9
9
  attr_accessor grammar_file: String?
10
10
  attr_accessor trace_opts: Hash[Symbol, bool]?
11
11
  attr_accessor report_opts: Hash[Symbol, bool]?
12
+ attr_accessor diagnostic: bool
12
13
  attr_accessor y: IO
13
14
  attr_accessor debug: bool
14
15
 
15
16
  def initialize: () -> void
16
- end
17
+ end
17
18
  end