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
data/lib/lrama/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lrama
2
- VERSION = "0.5.10".freeze
2
+ VERSION = "0.5.12".freeze
3
3
  end
data/lib/lrama.rb CHANGED
@@ -13,6 +13,5 @@ require "lrama/report"
13
13
  require "lrama/state"
14
14
  require "lrama/states"
15
15
  require "lrama/states_reporter"
16
- require "lrama/type"
17
16
  require "lrama/version"
18
17
  require "lrama/warning"
data/parser.y CHANGED
@@ -1,5 +1,5 @@
1
1
  class Lrama::Parser
2
- expect 1
2
+ expect 0
3
3
 
4
4
  token C_DECLARATION CHARACTER IDENT_COLON IDENTIFIER INTEGER STRING TAG
5
5
 
@@ -31,7 +31,6 @@ rule
31
31
  bison_declaration: grammar_declaration
32
32
  | "%expect" INTEGER { @grammar.expect = val[1] }
33
33
  | "%define" variable value
34
- | "%require" STRING
35
34
  | "%param" params
36
35
  | "%lex-param" params
37
36
  {
@@ -327,27 +326,24 @@ rule
327
326
  builder.add_rhs(token)
328
327
  result = builder
329
328
  }
330
- | rhs IDENTIFIER parameterizing_suffix
329
+ | rhs IDENTIFIER parameterizing_suffix tag_opt
331
330
  {
332
331
  token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[2], location: @lexer.location, args: [val[1]])
333
332
  builder = val[0]
334
333
  builder.add_rhs(token)
334
+ builder.lhs_tag = val[3]
335
+ builder.line = val[1].first_line
335
336
  result = builder
336
337
  }
337
- | rhs IDENTIFIER "(" symbol ")"
338
+ | rhs IDENTIFIER "(" parameterizing_args ")" tag_opt
338
339
  {
339
- token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1].s_value, location: @lexer.location, args: [val[3]])
340
+ token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1].s_value, location: @lexer.location, args: val[3])
340
341
  builder = val[0]
341
342
  builder.add_rhs(token)
343
+ builder.lhs_tag = val[5]
344
+ builder.line = val[1].first_line
342
345
  result = builder
343
346
  }
344
- | rhs IDENTIFIER "(" symbol "," symbol ")"
345
- {
346
- token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1].s_value, location: @lexer.location, args: [val[3], val[5]])
347
- builder = val[0]
348
- builder.add_rhs(token)
349
- result = builder
350
- }
351
347
  | rhs "{"
352
348
  {
353
349
  if @prec_seen
@@ -362,10 +358,10 @@ rule
362
358
  }
363
359
  "}" named_ref_opt
364
360
  {
365
- token = val[3]
366
- token.alias_name = val[6]
361
+ user_code = val[3]
362
+ user_code.alias_name = val[6]
367
363
  builder = val[0]
368
- builder.user_code = token
364
+ builder.user_code = user_code
369
365
  result = builder
370
366
  }
371
367
  | rhs "%prec" symbol
@@ -381,6 +377,9 @@ rule
381
377
  | "+"
382
378
  | "*"
383
379
 
380
+ parameterizing_args: symbol { result = [val[0]] }
381
+ | parameterizing_args ',' symbol { result = val[0].append(val[2]) }
382
+
384
383
  named_ref_opt: # empty
385
384
  | '[' IDENTIFIER ']' { result = val[1].s_value }
386
385
 
@@ -412,6 +411,9 @@ rule
412
411
  | TAG
413
412
 
414
413
  string_as_id: STRING { result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) }
414
+
415
+ tag_opt: # empty
416
+ | TAG
415
417
  end
416
418
 
417
419
  ---- inner
@@ -1,10 +1,4 @@
1
1
  ---
2
- sources:
3
- - type: git
4
- name: ruby/gem_rbs_collection
5
- revision: 25286c51a19927f28623aee3cd36655f902399ba
6
- remote: https://github.com/ruby/gem_rbs_collection.git
7
- repo_dir: gems
8
2
  path: ".gem_rbs_collection"
9
3
  gems:
10
4
  - name: erb
@@ -24,7 +18,7 @@ gems:
24
18
  source:
25
19
  type: git
26
20
  name: ruby/gem_rbs_collection
27
- revision: 2de2d4535caba275f3b8533684aab110d921f553
21
+ revision: 4b0d2f72e63b6c3e92dc54e19ce23dd24524f9a7
28
22
  remote: https://github.com/ruby/gem_rbs_collection.git
29
23
  repo_dir: gems
30
24
  - name: stackprof
@@ -32,7 +26,7 @@ gems:
32
26
  source:
33
27
  type: git
34
28
  name: ruby/gem_rbs_collection
35
- revision: 28208148c7e64a25e9b86b9723b4c3a2cef14e81
29
+ revision: 4b0d2f72e63b6c3e92dc54e19ce23dd24524f9a7
36
30
  remote: https://github.com/ruby/gem_rbs_collection.git
37
31
  repo_dir: gems
38
32
  - name: strscan
@@ -0,0 +1,11 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ErrorToken
4
+ attr_accessor ident_or_tags: Array[Lexer::Token::Ident | Lexer::Token::Tag]
5
+ attr_accessor token_code: Symbol
6
+ attr_accessor lineno: Integer
7
+
8
+ def translated_code: (Lexer::Token? tag) -> String
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ class Base
6
+ attr_reader build_token: Lexer::Token::Ident
7
+
8
+ def initialize: (Lexer::Token::Parameterizing token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
9
+ def build: () -> Array[Rule]
10
+
11
+ @args: Array[Lexer::Token]
12
+ @token: Lexer::Token::Parameterizing
13
+ @key: Symbol
14
+ @rule_counter: Counter
15
+ @lhs_tag: untyped
16
+ @user_code: Lexer::Token::UserCode?
17
+ @precedence_sym: Lexer::Token?
18
+ @line: Integer?
19
+ @expected_argument_num: Integer
20
+
21
+ private
22
+
23
+ def validate_argument_number!: () -> void
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,10 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ class List < Base
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ class NonemptyList < Base
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ class Option < Base
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ class SeparatedList < Base
6
+ @separator: Lexer::Token
7
+
8
+ def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ class SeparatedNonemptyList < Base
6
+ @separator: Lexer::Token
7
+
8
+ def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,8 +2,22 @@ module Lrama
2
2
  class Grammar
3
3
  class ParameterizingRules
4
4
  class Builder
5
- def initialize: (Lexer::Token token, Counter rule_counter, Lexer::Token lhs, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
5
+ RULES: Hash[Symbol, singleton(Base)]
6
+
7
+ @token: Lexer::Token::Parameterizing
8
+ @key: Symbol
9
+ @rule_counter: Counter
10
+ @lhs_tag: untyped
11
+ @user_code: Lexer::Token::UserCode?
12
+ @precedence_sym: Lexer::Token?
13
+ @line: Integer?
14
+ @builder: Grammar::ParameterizingRules::Builder::Base
15
+
16
+ def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
6
17
  def build: () -> Array[Rule]
18
+ def build_token: () -> Lexer::Token
19
+ def create_builder: () -> void
20
+ def validate_key!: () -> void
7
21
  end
8
22
  end
9
23
  end
@@ -1,7 +1,7 @@
1
1
  module Lrama
2
2
  class Grammar
3
3
  class Reference
4
- attr_accessor type: Symbol
4
+ attr_accessor type: ::Symbol
5
5
  attr_accessor name: String
6
6
  attr_accessor index: Integer
7
7
  attr_accessor ex_tag: Lexer::Token?
@@ -10,7 +10,7 @@ module Lrama
10
10
  attr_accessor position_in_rhs: Integer?
11
11
 
12
12
  def initialize: (
13
- type: Symbol, ?name: String, ?index: Integer, ?ex_tag: Lexer::Token?,
13
+ type: ::Symbol, ?name: String, ?index: Integer, ?ex_tag: Lexer::Token?,
14
14
  first_column: Integer, last_column: Integer,
15
15
  ?position_in_rhs: Integer?
16
16
  ) -> void
@@ -4,7 +4,7 @@ module Lrama
4
4
  attr_accessor original_rule: Rule
5
5
 
6
6
  def initialize: (
7
- ?id: untyped, ?_lhs: untyped, ?lhs: untyped, ?_rhs: untyped, ?rhs: untyped,
7
+ ?id: untyped, ?_lhs: untyped, ?lhs: untyped, ?lhs_tag: untyped, ?_rhs: untyped, ?rhs: untyped,
8
8
  ?token_code: untyped, ?position_in_original_rule_rhs: untyped, ?nullable: untyped,
9
9
  ?precedence_sym: untyped, ?lineno: untyped
10
10
  ) -> void
@@ -2,6 +2,7 @@ module Lrama
2
2
  class Grammar
3
3
  class RuleBuilder
4
4
  attr_accessor lhs: Lexer::Token
5
+ attr_accessor lhs_tag: untyped
5
6
  attr_accessor line: Integer?
6
7
  attr_reader rhs: Array[Lexer::Token]
7
8
  attr_reader user_code: Lexer::Token::UserCode?
@@ -0,0 +1,37 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Symbol
4
+ attr_accessor id: Lexer::Token
5
+ attr_accessor alias_name: String
6
+ attr_accessor number: Integer
7
+ attr_accessor tag: Lexer::Token?
8
+ attr_accessor term: bool
9
+ attr_accessor token_id: Integer
10
+ attr_accessor nullable: bool
11
+ attr_accessor precedence: Precedence?
12
+ attr_accessor printer: Printer?
13
+ attr_accessor error_token: ErrorToken
14
+
15
+ attr_accessor first_set: Set[Array[Symbol]]
16
+ attr_accessor first_set_bitmap: Integer
17
+ attr_writer eof_symbol: Symbol
18
+ attr_writer error_symbol: Symbol
19
+ attr_writer undef_symbol: Symbol
20
+ attr_writer accept_symbol: Symbol
21
+
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
25
+
26
+ def term?: () -> bool
27
+ def nterm?: () -> bool
28
+ def eof_symbol?: () -> bool
29
+ def error_symbol?: () -> bool
30
+ def undef_symbol?: () -> bool
31
+ def accept_symbol?: () -> bool
32
+ def display_name: () -> String
33
+ def enum_name: () -> String
34
+ def comment: () -> String
35
+ end
36
+ end
37
+ end
@@ -2,7 +2,9 @@ module Lrama
2
2
  class Lexer
3
3
  class Token
4
4
  class Parameterizing < Token
5
- attr_accessor args: Array[Lrama::Lexer::Token]
5
+ attr_accessor args: Array[Lexer::Token]
6
+
7
+ def initialize: (s_value: String, ?alias_name: String, ?location: Location, ?args: Array[Lexer::Token]) -> void
6
8
 
7
9
  def option?: () -> bool
8
10
  def nonempty_list?: () -> bool
@@ -1,12 +1,12 @@
1
1
  module Lrama
2
2
  class Lexer
3
3
  class Token
4
- attr_accessor s_value: String
4
+ attr_reader s_value: String
5
5
  attr_accessor alias_name: String
6
- attr_accessor location: Location
6
+ attr_reader location: Location
7
7
  attr_accessor referred: bool
8
8
 
9
- def initialize: (?s_value: String, ?alias_name: String, ?location: Location) -> void
9
+ def initialize: (s_value: String, ?alias_name: String, ?location: Location) -> void
10
10
 
11
11
  def to_s: () -> String
12
12
  def referred_by?: (String string) -> bool
@@ -72,7 +72,6 @@
72
72
  <%- if output.aux.prologue -%>
73
73
  /* First part of user prologue. */
74
74
  #line <%= output.aux.prologue_first_lineno %> "<%= output.grammar_file_path %>"
75
-
76
75
  <%= output.aux.prologue %>
77
76
  #line [@oline@] [@ofile@]
78
77
  <%- end -%>
@@ -2048,7 +2047,6 @@ yyreturnlab:
2048
2047
  <%# b4_percent_code_get([[epilogue]]) -%>
2049
2048
  <%- if output.aux.epilogue -%>
2050
2049
  #line <%= output.aux.epilogue_first_lineno - 1 %> "<%= output.grammar_file_path %>"
2051
-
2052
2050
  <%= output.aux.epilogue -%>
2053
2051
  <%- end -%>
2054
2052
 
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.5.10
4
+ version: 0.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuichiro Kaneko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-18 00:00:00.000000000 Z
11
+ date: 2023-12-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: LALR (1) parser generator written by Ruby
14
14
  email:
@@ -27,10 +27,10 @@ files:
27
27
  - Gemfile
28
28
  - LEGAL.md
29
29
  - MIT
30
+ - NEWS.md
30
31
  - README.md
31
32
  - Rakefile
32
33
  - Steepfile
33
- - doc/TODO.md
34
34
  - exe/lrama
35
35
  - lib/lrama.rb
36
36
  - lib/lrama/bitmap.rb
@@ -69,6 +69,7 @@ files:
69
69
  - lib/lrama/grammar/rule.rb
70
70
  - lib/lrama/grammar/rule_builder.rb
71
71
  - lib/lrama/grammar/symbol.rb
72
+ - lib/lrama/grammar/type.rb
72
73
  - lib/lrama/grammar/union.rb
73
74
  - lib/lrama/lexer.rb
74
75
  - lib/lrama/lexer/location.rb
@@ -94,7 +95,6 @@ files:
94
95
  - lib/lrama/states.rb
95
96
  - lib/lrama/states/item.rb
96
97
  - lib/lrama/states_reporter.rb
97
- - lib/lrama/type.rb
98
98
  - lib/lrama/version.rb
99
99
  - lib/lrama/warning.rb
100
100
  - lrama.gemspec
@@ -110,13 +110,21 @@ files:
110
110
  - sig/lrama/grammar/code.rbs
111
111
  - sig/lrama/grammar/code/printer_code.rbs
112
112
  - sig/lrama/grammar/counter.rbs
113
+ - sig/lrama/grammar/error_token.rbs
113
114
  - sig/lrama/grammar/parameterizing_rules/builder.rbs
115
+ - sig/lrama/grammar/parameterizing_rules/builder/base.rbs
116
+ - sig/lrama/grammar/parameterizing_rules/builder/list.rbs
117
+ - sig/lrama/grammar/parameterizing_rules/builder/nonempty_list.rbs
118
+ - sig/lrama/grammar/parameterizing_rules/builder/option.rbs
119
+ - sig/lrama/grammar/parameterizing_rules/builder/separated_list.rbs
120
+ - sig/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rbs
114
121
  - sig/lrama/grammar/percent_code.rbs
115
122
  - sig/lrama/grammar/precedence.rbs
116
123
  - sig/lrama/grammar/printer.rbs
117
124
  - sig/lrama/grammar/reference.rbs
118
125
  - sig/lrama/grammar/rule.rbs
119
126
  - sig/lrama/grammar/rule_builder.rbs
127
+ - sig/lrama/grammar/symbol.rbs
120
128
  - sig/lrama/lexer/location.rbs
121
129
  - sig/lrama/lexer/token.rbs
122
130
  - sig/lrama/lexer/token/char.rbs
data/doc/TODO.md DELETED
@@ -1,59 +0,0 @@
1
- # TODO
2
-
3
- * command
4
- * lexer
5
- * [x] Basic functionalities
6
- * parser
7
- * [x] Basic functionalities
8
- * [x] Precedence in grammar
9
- * LALR
10
- * [x] compute_nullable
11
- * [x] compute_lr0_states
12
- * [x] Direct Read Sets
13
- * [x] Reads Relation
14
- * [x] Read Sets
15
- * [x] Includes Relation
16
- * [x] Lookback Relation
17
- * [x] Follow Sets
18
- * [x] Look-Ahead Sets
19
- * [x] Precedence support
20
- * [x] Conflict check
21
- * [x] Algorithm Digraph
22
- * [ ] Conflict resolution
23
- * [x] Do not generate default action if states have conflicts
24
- * [ ] Fix number of s/r conflicts of basic.y. See basic.output file generated by Bison.
25
- * Rendering
26
- * [x] Table compaction
27
- * [x] -d option
28
- * yacc.c
29
- * [x] %lex-param
30
- * [x] %parse-param
31
- * [x] %printer
32
- * [x] Replace $, @ in user codes
33
- * [x] `[@oline@]`
34
- * [ ] b4_symbol (for eof, error and so on)
35
- * Assumption
36
- * b4_locations_if is true
37
- * b4_pure_if is true
38
- * b4_pull_if is false
39
- * b4_lac_if is false
40
- * Performance improvement
41
- * [ ]
42
- * Licenses
43
- * [x] Write down something about licenses
44
- * Reporting
45
- * [ ] Bison style
46
- * [ ] Wrap not selected reduce with "[]". See basic.output file generated by Bison.
47
- * Counterexamples
48
- * [x] Nonunifying Counterexamples
49
- * [ ] Unifying Counterexamples
50
- * [ ] Performance improvement using reverse_transitions and reverse_productions
51
- * Error Tolerance
52
- * [x] Corchuelo et al. algorithm with N = 1 (this means the next token when error is raised)
53
- * [x] Add new decl for error token semantic value initialization (%error-token)
54
- * [x] Use YYMALLOC & YYFREE
55
- * Lex state
56
- * CI
57
- * [x] Setup CI
58
- * [x] Add ruby 3.1 or under
59
- * [x] Add integration tests which installs Lrama, build ruby and run `make test`
data/lib/lrama/type.rb DELETED
@@ -1,4 +0,0 @@
1
- module Lrama
2
- class Type < Struct.new(:id, :tag, keyword_init: true)
3
- end
4
- end