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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9143e179e798e02afb8e7b2b4b1dd64291ac9ec128c851a4b4e660c647531675
4
- data.tar.gz: 34613495597d6d8c9334034d7167f34253ca97e910752b446fa6cc26f773a2ce
3
+ metadata.gz: 1d566a5097f0fd579e70f94769cca4e68a8f0e810e10cd55556583b1c2653945
4
+ data.tar.gz: e5ab505df1a8fffe46a9f526456b593db786f36f0e998e7e3acbf5f68b76d9a9
5
5
  SHA512:
6
- metadata.gz: a54f5f7096bc3f3f984a7da54945cd3913d02a16882975e99c982f06a2dd70988dba461106f000b54cc26f06c0e62eb294c63d3d35dd606b0e63ff6a17b127d4
7
- data.tar.gz: 007f8c7b8cf7ad1690f3b59e505f790273ddfacdab18ede2f1e3667a48309487739310d065fd7c54ee7656f9ee3791e2e1ed29e69726b69a4b861c083b8e5b4e
6
+ metadata.gz: 753a7b6f0781f6b0bd2db8c98ef0e6171496d6fd8a2a16762b67dc471e34b4118b4439b89facc1915a364d4c4823edaef464d947cbda3d913ebd8eff87d91b76
7
+ data.tar.gz: 7f953657c7050c7d527bf190d284e5b56b3df5b92c2034d5f4425f73be1e21208d1869a4ffe6c9091b4adf79671e71865000797ec2d7ed1ad66cfe5d1846cd7b
@@ -54,6 +54,25 @@ jobs:
54
54
  - run: flex --help
55
55
  - run: bundle install
56
56
  - run: bundle exec rspec
57
+ test-cpp:
58
+ needs: ruby-versions
59
+ runs-on: ubuntu-20.04
60
+ strategy:
61
+ fail-fast: false
62
+ matrix:
63
+ ruby: ['head']
64
+ compiler: ['g++', 'clang++']
65
+ steps:
66
+ - uses: actions/checkout@v4
67
+ - uses: ruby/setup-ruby@v1
68
+ with:
69
+ ruby-version: ${{ matrix.ruby }}
70
+ bundler-cache: true
71
+ - run: flex --help
72
+ - run: bundle install
73
+ - run: bundle exec rspec
74
+ env:
75
+ COMPILER: ${{ matrix.compiler }}
57
76
  test-memory:
58
77
  runs-on: ubuntu-20.04
59
78
  strategy:
@@ -167,4 +186,8 @@ jobs:
167
186
  - run: ../autogen.sh
168
187
  - run: ../configure -C --disable-install-doc
169
188
  - run: make
170
- - run: make test-all
189
+ - run: make test-all RUN_OPTS="$RUN_OPTS" SPECOPTS="$SPECOPTS"
190
+ env:
191
+ EXCLUDES: '../test/.excludes-parsey'
192
+ RUN_OPTS: ${{ matrix.run_opts || '--parser=parse.y' }}
193
+ SPECOPTS: ${{ matrix.specopts || '-T --parser=parse.y' }}
data/.gitignore CHANGED
@@ -2,9 +2,11 @@
2
2
  /.bundle/
3
3
  /.gem_rbs_collection/
4
4
  /.irbrc
5
+ /.vscode/
5
6
  /Gemfile.lock
6
7
  /coverage/
7
8
  /parser.output
8
9
  /pkg/
9
10
  /tmp/
10
11
  /vendor/bundle
12
+ /.idea/
data/Gemfile CHANGED
@@ -1,17 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
5
7
  gem "pry"
6
- gem "racc", "1.7.3"
8
+ gem "racc", "1.8.1"
7
9
  gem "rake"
8
10
  gem "rspec"
9
11
  gem "simplecov", require: false
10
12
  gem "stackprof", platforms: [:ruby] # stackprof doesn't support Windows
13
+ gem "memory_profiler"
11
14
 
12
15
  # Recent steep requires Ruby >= 3.0.0.
13
16
  # Then skip install on some CI jobs.
14
17
  if !ENV['GITHUB_ACTION'] || ENV['INSTALL_STEEP'] == 'true'
15
- gem "rbs", "3.4.4", require: false
16
- gem "steep", "1.6.0", require: false
18
+ gem "rbs", "3.7.0", require: false
19
+ gem "steep", "1.9.1", require: false
17
20
  end
data/NEWS.md CHANGED
@@ -1,12 +1,267 @@
1
1
  # NEWS for Lrama
2
2
 
3
+ ## Lrama 0.6.11 (2024-12-23)
4
+
5
+ ### Add support for %type declarations using %nterm in Nonterminal Symbols
6
+
7
+ Allow to use `%nterm` in Nonterminal Symbols for `%type` declarations.
8
+
9
+ ```yacc
10
+ %nterm <type> nonterminal…
11
+ ```
12
+
13
+ This directive is also supported for compatibility with Bison, and only non-terminal symbols are allowed. In other words, definitions like the following will result in an error:
14
+
15
+ ```yacc
16
+ %{
17
+ // Prologue
18
+ %}
19
+
20
+ %token EOI 0 "EOI"
21
+ %nterm EOI
22
+
23
+ %%
24
+
25
+ program: /* empty */
26
+ ;
27
+ ```
28
+
29
+ It show an error message like the following:
30
+
31
+ ```command
32
+ ❯ exe/lrama nterm.y
33
+ nterm.y:6:7: symbol EOI redeclared as a nonterminal
34
+ %nterm EOI
35
+ ^^^
36
+ ```
37
+
38
+ ## Lrama 0.6.10 (2024-09-11)
39
+
40
+ ### Aliased Named References for actions of RHS in parameterizing rules
41
+
42
+ Allow to use aliased named references for actions of RHS in parameterizing rules.
43
+
44
+ ```yacc
45
+ %rule sum(X, Y): X[summand] '+' Y[addend] { $$ = $summand + $addend }
46
+ ;
47
+ ```
48
+
49
+ https://github.com/ruby/lrama/pull/410
50
+
51
+
52
+ ### Named References for actions of RHS in parameterizing rules caller side
53
+
54
+ Allow to use named references for actions of RHS in parameterizing rules caller side.
55
+
56
+ ```yacc
57
+ opt_nl: '\n'?[nl] <str> { $$ = $nl; }
58
+ ;
59
+ ```
60
+
61
+ https://github.com/ruby/lrama/pull/414
62
+
63
+ ### Widen the definable position of parameterizing rules
64
+
65
+ Allow to define parameterizing rules in the middle of the grammar.
66
+
67
+ ```yacc
68
+ %rule defined_option(X): /* empty */
69
+ | X
70
+ ;
71
+
72
+ %%
73
+
74
+ program : defined_option(number) <i>
75
+ | defined_list(number) <i>
76
+ ;
77
+
78
+ %rule defined_list(X): /* empty */ /* <--- here */
79
+ | defined_list(X) number
80
+ ;
81
+ ```
82
+
83
+ https://github.com/ruby/lrama/pull/420
84
+
85
+ ### Report unused terminal symbols
86
+
87
+ Support to report unused terminal symbols.
88
+ Run `exe/lrama --report=terms` to show unused terminal symbols.
89
+
90
+ ```console
91
+ $ exe/lrama --report=terms sample/calc.y
92
+ 11 Unused Terms
93
+ 0 YYerror
94
+ 1 YYUNDEF
95
+ 2 '\\\\'
96
+ 3 '\\13'
97
+ 4 keyword_class2
98
+ 5 tNUMBER
99
+ 6 tPLUS
100
+ 7 tMINUS
101
+ 8 tEQ
102
+ 9 tEQEQ
103
+ 10 '>'
104
+ ```
105
+ https://github.com/ruby/lrama/pull/439
106
+
107
+ ### Report unused rules
108
+
109
+ Support to report unused rules.
110
+ Run `exe/lrama --report=rules` to show unused rules.
111
+
112
+ ```console
113
+ $ exe/lrama --report=rules sample/calc.y
114
+ 3 Unused Rules
115
+ 0 unused_option
116
+ 1 unused_list
117
+ 2 unused_nonempty_list
118
+ ```
119
+
120
+ https://github.com/ruby/lrama/pull/441
121
+
122
+ ### Ensure compatibility with Bison for `%locations` directive
123
+
124
+ Support `%locations` directive to ensure compatibility with Bison.
125
+ Change to `%locations` directive not set by default.
126
+
127
+ https://github.com/ruby/lrama/pull/446
128
+
129
+ ### Diagnostics report for parameterizing rules redefine
130
+
131
+ Support to warning redefined parameterizing rules.
132
+ Run `exe/lrama -W` or `exe/lrama --warnings` to show redefined parameterizing rules.
133
+
134
+ ```console
135
+ $ exe/lrama -W sample/calc.y
136
+ parameterizing rule redefined: redefined_method(X)
137
+ parameterizing rule redefined: redefined_method(X)
138
+ ```
139
+
140
+ https://github.com/ruby/lrama/pull/448
141
+
142
+ ### Support `-v` and `--verbose` option
143
+
144
+ Support to `-v` and `--verbose` option.
145
+ These options align with Bison behavior. So same as '--report=state' option.
146
+
147
+ https://github.com/ruby/lrama/pull/457
148
+
149
+ ## Lrama 0.6.9 (2024-05-02)
150
+
151
+ ### Callee side tag specification of parameterizing rules
152
+
153
+ Allow to specify tag on callee side of parameterizing rules.
154
+
155
+ ```yacc
156
+ %union {
157
+ int i;
158
+ }
159
+
160
+ %rule with_tag(X) <i>: X { $$ = $1; }
161
+ ;
162
+ ```
163
+
164
+ ### Named References for actions of RHS in parameterizing rules
165
+
166
+ Allow to use named references for actions of RHS in parameterizing rules.
167
+
168
+ ```yacc
169
+ %rule option(number): /* empty */
170
+ | number { $$ = $number; }
171
+ ;
172
+ ```
173
+
174
+ ## Lrama 0.6.8 (2024-04-29)
175
+
176
+ ### Nested parameterizing rules with tag
177
+
178
+ Allow to nested parameterizing rules with tag.
179
+
180
+ ```yacc
181
+ %union {
182
+ int i;
183
+ }
184
+
185
+ %rule nested_nested_option(X): /* empty */
186
+ | X
187
+ ;
188
+
189
+ %rule nested_option(X): /* empty */
190
+ | nested_nested_option(X) <i>
191
+ ;
192
+
193
+ %rule option(Y): /* empty */
194
+ | nested_option(Y) <i>
195
+ ;
196
+ ```
197
+
198
+ ## Lrama 0.6.7 (2024-04-28)
199
+
200
+ ### RHS of user defined parameterizing rules contains `'symbol'?`, `'symbol'+` and `'symbol'*`.
201
+
202
+ User can use `'symbol'?`, `'symbol'+` and `'symbol'*` in RHS of user defined parameterizing rules.
203
+
204
+ ```
205
+ %rule with_word_seps(X): /* empty */
206
+ | X ' '+
207
+ ;
208
+ ```
209
+
210
+ ## Lrama 0.6.6 (2024-04-27)
211
+
212
+ ### Trace actions
213
+
214
+ Support trace actions for debugging.
215
+ Run `exe/lrama --trace=actions` to show grammar rules with actions.
216
+
217
+ ```console
218
+ $ exe/lrama --trace=actions sample/calc.y
219
+ Grammar rules with actions:
220
+ $accept -> list, YYEOF {}
221
+ list -> ε {}
222
+ list -> list, LF {}
223
+ list -> list, expr, LF { printf("=> %d\n", $2); }
224
+ expr -> NUM {}
225
+ expr -> expr, '+', expr { $$ = $1 + $3; }
226
+ expr -> expr, '-', expr { $$ = $1 - $3; }
227
+ expr -> expr, '*', expr { $$ = $1 * $3; }
228
+ expr -> expr, '/', expr { $$ = $1 / $3; }
229
+ expr -> '(', expr, ')' { $$ = $2; }
230
+ ```
231
+
232
+ ### Inlining
233
+
234
+ Support inlining for rules.
235
+ The `%inline` directive causes all references to symbols to be replaced with its definition.
236
+
237
+ ```yacc
238
+ %rule %inline op: PLUS { + }
239
+ | TIMES { * }
240
+ ;
241
+
242
+ %%
243
+
244
+ expr : number { $$ = $1; }
245
+ | expr op expr { $$ = $1 $2 $3; }
246
+ ;
247
+ ```
248
+
249
+ as same as
250
+
251
+ ```yacc
252
+ expr : number { $$ = $1; }
253
+ | expr '+' expr { $$ = $1 + $3; }
254
+ | expr '*' expr { $$ = $1 * $3; }
255
+ ;
256
+ ```
257
+
3
258
  ## Lrama 0.6.5 (2024-03-25)
4
259
 
5
260
  ### Typed Midrule Actions
6
261
 
7
262
  User can specify the type of mid rule action by tag (`<bar>`) instead of specifying it with in an action.
8
263
 
9
- ```
264
+ ```yacc
10
265
  primary: k_case expr_value terms?
11
266
  {
12
267
  $<val>$ = p->case_labels;
@@ -21,7 +276,7 @@ primary: k_case expr_value terms?
21
276
 
22
277
  can be written as
23
278
 
24
- ```
279
+ ```yacc
25
280
  primary: k_case expr_value terms?
26
281
  {
27
282
  $$ = p->case_labels;
@@ -46,7 +301,7 @@ Bison supports this feature from 3.1.
46
301
 
47
302
  Support `preceded`, `terminated` and `delimited` rules.
48
303
 
49
- ```
304
+ ```text
50
305
  program: preceded(opening, X)
51
306
 
52
307
  // Expanded to
@@ -82,7 +337,7 @@ In general, these resources are freed by actions or after parsing.
82
337
  However if syntax error happens in parsing, these codes may not be executed.
83
338
  Codes associated to `%destructor` are executed when semantic value is popped from the stack by an error.
84
339
 
85
- ```
340
+ ```yacc
86
341
  %token <val1> NUM
87
342
  %type <val2> expr2
88
343
  %type <val3> expr
@@ -130,7 +385,7 @@ Lrama provides these five callbacks. Registered functions are called when each e
130
385
  User also needs to access semantic value of their stack in grammar action. `$:n` provides the way to access to it. `$:n` is translated to the minus index from the top of the stack.
131
386
  For example
132
387
 
133
- ```
388
+ ```yacc
134
389
  primary: k_if expr_value then compstmt if_tail k_end
135
390
  {
136
391
  /*% ripper: if!($:2, $:4, $:5) %*/
@@ -155,7 +410,7 @@ https://github.com/ruby/lrama/pull/344
155
410
 
156
411
  Allow to pass an instantiated rule to other parameterizing rules.
157
412
 
158
- ```
413
+ ```yacc
159
414
  %rule constant(X) : X
160
415
  ;
161
416
 
@@ -172,7 +427,7 @@ program : option(constant(number)) // Nested rule
172
427
 
173
428
  Allow to use nested parameterizing rules when define parameterizing rules.
174
429
 
175
- ```
430
+ ```yacc
176
431
  %rule option(x) : /* empty */
177
432
  | X
178
433
  ;
@@ -199,7 +454,7 @@ https://github.com/ruby/lrama/pull/337
199
454
 
200
455
  Allow to define parameterizing rule by `%rule` directive.
201
456
 
202
- ```
457
+ ```yacc
203
458
  %rule pair(X, Y): X Y { $$ = $1 + $2; }
204
459
  ;
205
460
 
@@ -222,7 +477,7 @@ https://github.com/ruby/lrama/pull/285
222
477
  Allow to specify type of rules by specifying tag, `<i>` in below example.
223
478
  Tag is post-modification style.
224
479
 
225
- ```
480
+ ```yacc
226
481
  %union {
227
482
  int i;
228
483
  }
@@ -249,7 +504,7 @@ https://github.com/ruby/lrama/pull/197
249
504
 
250
505
  Support `separated_list` and `separated_nonempty_list` parameterizing rules.
251
506
 
252
- ```
507
+ ```text
253
508
  program: separated_list(',', number)
254
509
 
255
510
  // Expanded to
@@ -280,7 +535,7 @@ https://github.com/ruby/lrama/pull/204
280
535
  Parameterizing rules are template of rules.
281
536
  It's very common pattern to write "list" grammar rule like:
282
537
 
283
- ```
538
+ ```yacc
284
539
  opt_args: /* none */
285
540
  | args
286
541
  ;
@@ -312,7 +567,7 @@ https://github.com/ruby/lrama/pull/62
312
567
 
313
568
  ### Runtime configuration for error recovery
314
569
 
315
- Meke error recovery function configurable on runtime by two new macros.
570
+ Make error recovery function configurable on runtime by two new macros.
316
571
 
317
572
  * `YYMAXREPAIR`: Expected to return max length of repair operations. `%parse-param` is passed to this function.
318
573
  * `YYERROR_RECOVERY_ENABLED`: Expected to return bool value to determine error recovery is enabled or not. `%parse-param` is passed to this function.
@@ -335,7 +590,7 @@ https://github.com/ruby/lrama/pull/44
335
590
  Instead of positional references like `$1` or `$$`,
336
591
  named references allow to access to symbol by name.
337
592
 
338
- ```
593
+ ```yacc
339
594
  primary: k_class cpath superclass bodystmt k_end
340
595
  {
341
596
  $primary = new_class($cpath, $bodystmt, $superclass);
@@ -344,7 +599,7 @@ primary: k_class cpath superclass bodystmt k_end
344
599
 
345
600
  Alias name can be declared.
346
601
 
347
- ```
602
+ ```yacc
348
603
  expr[result]: expr[ex-left] '+' expr[ex.right]
349
604
  {
350
605
  $result = $[ex-left] + $[ex.right];
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/lrama.svg)](https://badge.fury.io/rb/lrama)
4
4
  [![build](https://github.com/ruby/lrama/actions/workflows/test.yaml/badge.svg)](https://github.com/ruby/lrama/actions/workflows/test.yaml)
5
+ [![RubyDoc](https://img.shields.io/badge/%F0%9F%93%9ARubyDoc-documentation-informational.svg)](https://www.rubydoc.info/gems/lrama)
5
6
 
6
7
  Lrama is LALR (1) parser generator written by Ruby. The first goal of this project is providing error tolerant parser for CRuby with minimal changes on CRuby parse.y file.
7
8
 
@@ -13,7 +14,8 @@ Lrama is LALR (1) parser generator written by Ruby. The first goal of this proje
13
14
  * [Development](#development)
14
15
  * [How to generate parser.rb](#how-to-generate-parserrb)
15
16
  * [Test](#test)
16
- * [Profiling Lrama](#profiling-lrama)
17
+ * [Call-stack Profiling Lrama](#call-stack-profiling-lrama)
18
+ * [Memory Profiling Lrama](#memory-profiling-lrama)
17
19
  * [Build Ruby](#build-ruby)
18
20
  * [Release flow](#release-flow)
19
21
  * [License](#license)
@@ -94,7 +96,7 @@ This also requires Lrama to be able to run with only default gems because BASERU
94
96
  ### How to generate parser.rb
95
97
 
96
98
  ```shell
97
- $ rake build:parser
99
+ $ bundle exec rake build:parser
98
100
  ```
99
101
 
100
102
  `parser.rb` is generated from `parser.y` by Racc.
@@ -128,7 +130,7 @@ $ bundle install
128
130
  $ bundle exec rake
129
131
  ```
130
132
 
131
- ### Profiling Lrama
133
+ ### Call-stack Profiling Lrama
132
134
 
133
135
  #### 1. Create parse.tmp.y in ruby/ruby
134
136
 
@@ -166,6 +168,41 @@ $ exe/lrama -o parse.tmp.c --header=parse.tmp.h tmp/parse.tmp.y
166
168
  $ stackprof --d3-flamegraph tmp/stackprof-cpu-myapp.dump > tmp/flamegraph.html
167
169
  ```
168
170
 
171
+ ### Memory Profiling Lrama
172
+
173
+ #### 1. Create parse.tmp.y in ruby/ruby
174
+
175
+ ```shell
176
+ $ ruby tool/id2token.rb parse.y > parse.tmp.y
177
+ $ cp parse.tmp.y dir/lrama/tmp
178
+ ```
179
+
180
+ #### 2. Enable Profiler
181
+
182
+ ```diff
183
+ diff --git a/exe/lrama b/exe/lrama
184
+ index 1aece5d141..f5f94cf7fa 100755
185
+ --- a/exe/lrama
186
+ +++ b/exe/lrama
187
+ @@ -3,5 +3,9 @@
188
+
189
+ $LOAD_PATH << File.join(__dir__, "../lib")
190
+ require "lrama"
191
+ +require 'memory_profiler'
192
+
193
+ -Lrama::Command.new.run(ARGV.dup)
194
+ +report = MemoryProfiler.report do
195
+ + Lrama::Command.new.run(ARGV.dup)
196
+ +end
197
+ +report.pretty_print
198
+ ```
199
+
200
+ #### 3. Run Lrama
201
+
202
+ ```shell
203
+ $ exe/lrama -o parse.tmp.c --header=parse.tmp.h tmp/parse.tmp.y > report.txt
204
+ ```
205
+
169
206
  ### Build Ruby
170
207
 
171
208
  1. Install Lrama
@@ -180,4 +217,4 @@ $ stackprof --d3-flamegraph tmp/stackprof-cpu-myapp.dump > tmp/flamegraph.html
180
217
 
181
218
  ## License
182
219
 
183
- See LEGAL.md file.
220
+ See [LEGAL.md](./LEGAL.md) file.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
 
3
5
  namespace "build" do
data/Steepfile CHANGED
@@ -1,30 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # D = Steep::Diagnostic
2
4
  #
3
5
  target :lib do
4
6
  repo_path '.gem_rbs_collection/'
5
7
  signature "sig"
6
8
 
7
- check "lib/lrama/grammar/binding.rb"
8
- check "lib/lrama/grammar/code/destructor_code.rb"
9
- check "lib/lrama/grammar/code/printer_code.rb"
10
- check "lib/lrama/grammar/code.rb"
11
- check "lib/lrama/grammar/counter.rb"
12
- check "lib/lrama/grammar/error_token.rb"
13
- check "lib/lrama/grammar/parameterizing_rule"
14
- check "lib/lrama/grammar/parameterizing_rules"
15
- check "lib/lrama/grammar/symbols"
16
- check "lib/lrama/grammar/percent_code.rb"
17
- check "lib/lrama/grammar/precedence.rb"
18
- check "lib/lrama/grammar/destructor.rb"
19
- check "lib/lrama/grammar/printer.rb"
20
- check "lib/lrama/grammar/reference.rb"
21
- check "lib/lrama/grammar/rule_builder.rb"
22
- check "lib/lrama/grammar/symbol.rb"
23
- check "lib/lrama/grammar/type.rb"
9
+ check "lib/lrama/grammar"
10
+
11
+ check "lib/lrama/counterexamples"
24
12
  check "lib/lrama/lexer"
25
13
  check "lib/lrama/report"
14
+ check "lib/lrama/state"
15
+ check "lib/lrama/states"
26
16
  check "lib/lrama/bitmap.rb"
17
+ check "lib/lrama/counterexamples.rb"
27
18
  check "lib/lrama/digraph.rb"
19
+ check "lib/lrama/grammar.rb"
28
20
  check "lib/lrama/options.rb"
29
21
  check "lib/lrama/warning.rb"
30
22
  end