racc 1.4.14-java → 1.5.2-java

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.
Files changed (102) hide show
  1. checksums.yaml +5 -5
  2. data/COPYING +22 -515
  3. data/README.ja.rdoc +3 -4
  4. data/README.rdoc +6 -8
  5. data/Rakefile +32 -53
  6. data/bin/racc +39 -27
  7. data/ext/racc/com/headius/racc/Cparse.java +66 -23
  8. data/ext/racc/{cparse.c → cparse/cparse.c} +82 -47
  9. data/ext/racc/{extconf.rb → cparse/extconf.rb} +2 -1
  10. data/lib/racc/compat.rb +5 -4
  11. data/lib/racc/cparse-jruby.jar +0 -0
  12. data/lib/racc/debugflags.rb +5 -4
  13. data/lib/racc/exception.rb +5 -4
  14. data/lib/racc/grammar.rb +25 -22
  15. data/lib/racc/grammarfileparser.rb +10 -8
  16. data/lib/racc/info.rb +6 -5
  17. data/lib/racc/iset.rb +6 -5
  18. data/lib/racc/logfilegenerator.rb +6 -5
  19. data/lib/racc/parser-text.rb +20 -23
  20. data/lib/racc/parser.rb +20 -23
  21. data/lib/racc/parserfilegenerator.rb +10 -10
  22. data/lib/racc/sourcetext.rb +5 -4
  23. data/lib/racc/state.rb +13 -12
  24. data/lib/racc/statetransitiontable.rb +7 -6
  25. data/rdoc/ja/command.ja.html +1 -1
  26. data/sample/array.y +1 -1
  27. data/sample/array2.y +1 -1
  28. data/sample/calc-ja.y +2 -2
  29. data/sample/calc.y +2 -2
  30. data/sample/conflict.y +1 -1
  31. data/sample/hash.y +1 -1
  32. data/sample/lalr.y +1 -1
  33. data/sample/lists.y +1 -1
  34. data/sample/syntax.y +1 -1
  35. data/sample/yyerr.y +1 -1
  36. data/test/assets/cadenza.y +170 -0
  37. data/test/assets/cast.y +926 -0
  38. data/test/assets/csspool.y +729 -0
  39. data/test/assets/edtf.y +583 -0
  40. data/test/assets/huia.y +318 -0
  41. data/test/assets/intp.y +4 -4
  42. data/test/assets/journey.y +47 -0
  43. data/test/assets/liquor.y +313 -0
  44. data/test/assets/machete.y +423 -0
  45. data/test/assets/macruby.y +2197 -0
  46. data/test/assets/mailp.y +27 -27
  47. data/test/assets/mediacloth.y +599 -0
  48. data/test/assets/mof.y +649 -0
  49. data/test/assets/namae.y +302 -0
  50. data/test/assets/nasl.y +626 -0
  51. data/test/assets/nokogiri-css.y +255 -0
  52. data/test/assets/nullbug2.y +2 -2
  53. data/test/assets/opal.y +1807 -0
  54. data/test/assets/php_serialization.y +98 -0
  55. data/test/assets/recv.y +20 -20
  56. data/test/assets/riml.y +665 -0
  57. data/test/assets/ruby18.y +1943 -0
  58. data/test/assets/ruby19.y +2174 -0
  59. data/test/assets/ruby20.y +2350 -0
  60. data/test/assets/ruby21.y +2359 -0
  61. data/test/assets/ruby22.y +2381 -0
  62. data/test/assets/syntax.y +1 -1
  63. data/test/assets/tp_plus.y +622 -0
  64. data/test/assets/twowaysql.y +278 -0
  65. data/test/helper.rb +68 -41
  66. data/test/regress/cadenza +796 -0
  67. data/test/regress/cast +3428 -0
  68. data/test/regress/csspool +2314 -0
  69. data/test/regress/edtf +1794 -0
  70. data/test/regress/huia +1392 -0
  71. data/test/regress/journey +222 -0
  72. data/test/regress/liquor +885 -0
  73. data/test/regress/machete +833 -0
  74. data/test/regress/mediacloth +1463 -0
  75. data/test/regress/mof +1368 -0
  76. data/test/regress/namae +634 -0
  77. data/test/regress/nasl +2058 -0
  78. data/test/regress/nokogiri-css +836 -0
  79. data/test/regress/opal +6431 -0
  80. data/test/regress/php_serialization +336 -0
  81. data/test/regress/riml +3283 -0
  82. data/test/regress/ruby18 +6344 -0
  83. data/test/regress/ruby22 +7460 -0
  84. data/test/regress/tp_plus +1933 -0
  85. data/test/regress/twowaysql +556 -0
  86. data/test/test_chk_y.rb +1 -0
  87. data/test/test_racc_command.rb +177 -2
  88. data/test/test_scan_y.rb +1 -0
  89. data/test/testscanner.rb +1 -1
  90. metadata +55 -80
  91. data/.gemtest +0 -0
  92. data/DEPENDS +0 -4
  93. data/Manifest.txt +0 -102
  94. data/bin/racc2y +0 -195
  95. data/bin/y2racc +0 -339
  96. data/ext/racc/depend +0 -1
  97. data/fastcache/extconf.rb +0 -2
  98. data/fastcache/fastcache.c +0 -185
  99. data/misc/dist.sh +0 -31
  100. data/setup.rb +0 -1587
  101. data/tasks/doc.rb +0 -12
  102. data/tasks/email.rb +0 -55
@@ -1,9 +1,9 @@
1
1
  /*
2
2
 
3
3
  cparse.c -- Racc Runtime Core
4
-
4
+
5
5
  Copyright (c) 1999-2006 Minero Aoki
6
-
6
+
7
7
  This library is free software.
8
8
  You can distribute/modify this program under the same terms of ruby.
9
9
 
@@ -13,11 +13,18 @@
13
13
 
14
14
  #include <ruby.h>
15
15
 
16
+ #ifndef FALSE
17
+ #define FALSE 0
18
+ #endif
19
+ #ifndef TRUE
20
+ #define TRUE 1
21
+ #endif
22
+
16
23
  /* -----------------------------------------------------------------------
17
24
  Important Constants
18
25
  ----------------------------------------------------------------------- */
19
26
 
20
- #define RACC_VERSION "1.4.14"
27
+ #define RACC_VERSION "1.4.15"
21
28
 
22
29
  #define DEFAULT_TOKEN -1
23
30
  #define ERROR_TOKEN 1
@@ -189,7 +196,7 @@ static VALUE racc_yyparse _((VALUE parser, VALUE lexer, VALUE lexmid,
189
196
  VALUE arg, VALUE sysdebug));
190
197
 
191
198
  static void call_lexer _((struct cparse_params *v));
192
- static VALUE lexer_i _((VALUE block_args, VALUE data, VALUE self));
199
+ static VALUE lexer_i _((RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data)));
193
200
 
194
201
  static VALUE assert_array _((VALUE a));
195
202
  static long assert_integer _((VALUE n));
@@ -197,6 +204,7 @@ static VALUE assert_hash _((VALUE h));
197
204
  static VALUE initialize_params _((VALUE vparams, VALUE parser, VALUE arg,
198
205
  VALUE lexer, VALUE lexmid));
199
206
  static void cparse_params_mark _((void *ptr));
207
+ static size_t cparse_params_memsize _((const void *ptr));
200
208
 
201
209
  static void parse_main _((struct cparse_params *v,
202
210
  VALUE tok, VALUE val, int resume));
@@ -204,7 +212,7 @@ static void extract_user_token _((struct cparse_params *v,
204
212
  VALUE block_args, VALUE *tok, VALUE *val));
205
213
  static void shift _((struct cparse_params* v, long act, VALUE tok, VALUE val));
206
214
  static int reduce _((struct cparse_params* v, long act));
207
- static VALUE reduce0 _((VALUE block_args, VALUE data, VALUE self));
215
+ static rb_block_call_func reduce0;
208
216
 
209
217
  #ifdef DEBUG
210
218
  # define D_puts(msg) if (v->sys_debug) puts(msg)
@@ -214,35 +222,52 @@ static VALUE reduce0 _((VALUE block_args, VALUE data, VALUE self));
214
222
  # define D_printf(fmt,arg)
215
223
  #endif
216
224
 
225
+ #undef RUBY_UNTYPED_DATA_WARNING
226
+ #define RUBY_UNTYPED_DATA_WARNING 1
227
+
228
+ static const rb_data_type_t cparse_params_type = {
229
+ "racc/cparse",
230
+ {
231
+ cparse_params_mark,
232
+ RUBY_TYPED_DEFAULT_FREE,
233
+ cparse_params_memsize,
234
+ },
235
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
236
+ 0, 0,
237
+ RUBY_TYPED_FREE_IMMEDIATELY,
238
+ #endif
239
+ };
240
+
217
241
  static VALUE
218
242
  racc_cparse(VALUE parser, VALUE arg, VALUE sysdebug)
219
243
  {
220
- volatile VALUE vparams;
244
+ VALUE vparams;
221
245
  struct cparse_params *v;
222
246
 
223
- vparams = Data_Make_Struct(CparseParams, struct cparse_params,
224
- cparse_params_mark, -1, v);
247
+ vparams = TypedData_Make_Struct(CparseParams, struct cparse_params,
248
+ &cparse_params_type, v);
225
249
  D_puts("starting cparse");
226
250
  v->sys_debug = RTEST(sysdebug);
227
251
  vparams = initialize_params(vparams, parser, arg, Qnil, Qnil);
228
- v->lex_is_iterator = Qfalse;
252
+ v->lex_is_iterator = FALSE;
229
253
  parse_main(v, Qnil, Qnil, 0);
230
254
 
255
+ RB_GC_GUARD(vparams);
231
256
  return v->retval;
232
257
  }
233
258
 
234
259
  static VALUE
235
260
  racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
236
261
  {
237
- volatile VALUE vparams;
262
+ VALUE vparams;
238
263
  struct cparse_params *v;
239
264
 
240
- vparams = Data_Make_Struct(CparseParams, struct cparse_params,
241
- cparse_params_mark, -1, v);
265
+ vparams = TypedData_Make_Struct(CparseParams, struct cparse_params,
266
+ &cparse_params_type, v);
242
267
  v->sys_debug = RTEST(sysdebug);
243
268
  D_puts("start C yyparse");
244
269
  vparams = initialize_params(vparams, parser, arg, lexer, lexmid);
245
- v->lex_is_iterator = Qtrue;
270
+ v->lex_is_iterator = TRUE;
246
271
  D_puts("params initialized");
247
272
  parse_main(v, Qnil, Qnil, 0);
248
273
  call_lexer(v);
@@ -251,6 +276,7 @@ racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
251
276
  rb_id2name(v->lexmid));
252
277
  }
253
278
 
279
+ RB_GC_GUARD(vparams);
254
280
  return v->retval;
255
281
  }
256
282
 
@@ -264,9 +290,8 @@ call_lexer(struct cparse_params *v)
264
290
  static VALUE
265
291
  lexer_iter(VALUE data)
266
292
  {
267
- struct cparse_params *v;
293
+ struct cparse_params *v = rb_check_typeddata(data, &cparse_params_type);
268
294
 
269
- Data_Get_Struct(data, struct cparse_params, v);
270
295
  rb_funcall(v->lexer, v->lexmid, 0);
271
296
  return Qnil;
272
297
  }
@@ -279,18 +304,17 @@ call_lexer(struct cparse_params *v)
279
304
  #endif
280
305
 
281
306
  static VALUE
282
- lexer_i(VALUE block_args, VALUE data, VALUE self)
307
+ lexer_i(RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data))
283
308
  {
284
- struct cparse_params *v;
309
+ struct cparse_params *v = rb_check_typeddata(data, &cparse_params_type);
285
310
  VALUE tok, val;
286
311
 
287
- Data_Get_Struct(data, struct cparse_params, v);
288
312
  if (v->fin)
289
313
  rb_raise(rb_eArgError, "extra token after EndOfToken");
290
314
  extract_user_token(v, block_args, &tok, &val);
291
315
  parse_main(v, tok, val, 1);
292
316
  if (v->fin && v->fin != CP_FIN_ACCEPT)
293
- rb_iter_break();
317
+ rb_iter_break();
294
318
  return Qnil;
295
319
  }
296
320
 
@@ -317,9 +341,8 @@ assert_integer(VALUE n)
317
341
  static VALUE
318
342
  initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)
319
343
  {
320
- struct cparse_params *v;
344
+ struct cparse_params *v = rb_check_typeddata(vparams, &cparse_params_type);
321
345
 
322
- Data_Get_Struct(vparams, struct cparse_params, v);
323
346
  v->value_v = vparams;
324
347
  v->parser = parser;
325
348
  v->lexer = lexer;
@@ -348,7 +371,7 @@ initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lex
348
371
  v->use_result_var = RTEST(rb_ary_entry(arg, 13));
349
372
  }
350
373
  else {
351
- v->use_result_var = Qtrue;
374
+ v->use_result_var = TRUE;
352
375
  }
353
376
 
354
377
  v->tstack = v->debug ? NEW_STACK() : Qnil;
@@ -364,7 +387,7 @@ initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lex
364
387
  v->retval = Qnil;
365
388
  v->fin = 0;
366
389
 
367
- v->lex_is_iterator = Qfalse;
390
+ v->lex_is_iterator = FALSE;
368
391
 
369
392
  rb_iv_set(parser, "@vstack", v->vstack);
370
393
  if (v->debug) {
@@ -402,6 +425,12 @@ cparse_params_mark(void *ptr)
402
425
  rb_gc_mark(v->retval);
403
426
  }
404
427
 
428
+ static size_t
429
+ cparse_params_memsize(const void *ptr)
430
+ {
431
+ return sizeof(struct cparse_params);
432
+ }
433
+
405
434
  static void
406
435
  extract_user_token(struct cparse_params *v, VALUE block_args,
407
436
  VALUE *tok, VALUE *val)
@@ -413,12 +442,12 @@ extract_user_token(struct cparse_params *v, VALUE block_args,
413
442
  return;
414
443
  }
415
444
 
416
- if (TYPE(block_args) != T_ARRAY) {
445
+ if (!RB_TYPE_P(block_args, T_ARRAY)) {
417
446
  rb_raise(rb_eTypeError,
418
- "%s() %s %s (must be Array[2])",
447
+ "%s() %s %"PRIsVALUE" (must be Array[2])",
419
448
  v->lex_is_iterator ? rb_id2name(v->lexmid) : "next_token",
420
449
  v->lex_is_iterator ? "yielded" : "returned",
421
- rb_class2name(CLASS_OF(block_args)));
450
+ rb_obj_class(block_args));
422
451
  }
423
452
  if (RARRAY_LEN(block_args) != 2) {
424
453
  rb_raise(rb_eArgError,
@@ -457,7 +486,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
457
486
 
458
487
  if (resume)
459
488
  goto resume;
460
-
489
+
461
490
  while (1) {
462
491
  D_puts("");
463
492
  D_puts("---- enter new loop ----");
@@ -516,7 +545,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
516
545
  act_fixed:
517
546
  D_printf("act=%ld\n", act);
518
547
  goto handle_act;
519
-
548
+
520
549
  notfound:
521
550
  D_puts("(act) not found: use default");
522
551
  act_value = AREF(v->action_default, v->curstate);
@@ -576,7 +605,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
576
605
  user_yyerror:
577
606
  if (v->errstatus == 3) {
578
607
  if (v->t == vFINAL_TOKEN) {
579
- v->retval = Qfalse;
608
+ v->retval = Qnil;
580
609
  v->fin = CP_FIN_EOT;
581
610
  return;
582
611
  }
@@ -617,7 +646,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
617
646
 
618
647
  D_puts("(err) found: can handle error token");
619
648
  break;
620
-
649
+
621
650
  error_pop:
622
651
  D_puts("(err) act not found: can't handle error token; pop");
623
652
 
@@ -679,9 +708,9 @@ reduce(struct cparse_params *v, long act)
679
708
  }
680
709
 
681
710
  static VALUE
682
- reduce0(VALUE val, VALUE data, VALUE self)
711
+ reduce0(RB_BLOCK_CALL_FUNC_ARGLIST(_, data))
683
712
  {
684
- struct cparse_params *v;
713
+ struct cparse_params *v = rb_check_typeddata(data, &cparse_params_type);
685
714
  VALUE reduce_to, reduce_len, method_id;
686
715
  long len;
687
716
  ID mid;
@@ -689,7 +718,6 @@ reduce0(VALUE val, VALUE data, VALUE self)
689
718
  long i, k1, k2;
690
719
  VALUE goto_state;
691
720
 
692
- Data_Get_Struct(data, struct cparse_params, v);
693
721
  reduce_len = rb_ary_entry(v->reduce_table, v->ruleno);
694
722
  reduce_to = rb_ary_entry(v->reduce_table, v->ruleno+1);
695
723
  method_id = rb_ary_entry(v->reduce_table, v->ruleno+2);
@@ -791,12 +819,16 @@ reduce0(VALUE val, VALUE data, VALUE self)
791
819
  void
792
820
  Init_cparse(void)
793
821
  {
822
+ #if HAVE_RB_EXT_RACTOR_SAFE
823
+ rb_ext_ractor_safe(true);
824
+ #endif
825
+
794
826
  VALUE Racc, Parser;
795
- ID id_racc = rb_intern("Racc");
827
+ ID id_racc = rb_intern_const("Racc");
796
828
 
797
829
  if (rb_const_defined(rb_cObject, id_racc)) {
798
830
  Racc = rb_const_get(rb_cObject, id_racc);
799
- Parser = rb_const_get_at(Racc, rb_intern("Parser"));
831
+ Parser = rb_const_get_at(Racc, rb_intern_const("Parser"));
800
832
  }
801
833
  else {
802
834
  Racc = rb_define_module("Racc");
@@ -810,19 +842,22 @@ Init_cparse(void)
810
842
  rb_str_new2("$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $"));
811
843
 
812
844
  CparseParams = rb_define_class_under(Racc, "CparseParams", rb_cObject);
845
+ rb_undef_alloc_func(CparseParams);
846
+ rb_undef_method(CparseParams, "initialize");
847
+ rb_undef_method(CparseParams, "initialize_copy");
813
848
 
814
849
  RaccBug = rb_eRuntimeError;
815
850
 
816
- id_yydebug = rb_intern("@yydebug");
817
- id_nexttoken = rb_intern("next_token");
818
- id_onerror = rb_intern("on_error");
819
- id_noreduce = rb_intern("_reduce_none");
820
- id_errstatus = rb_intern("@racc_error_status");
821
-
822
- id_d_shift = rb_intern("racc_shift");
823
- id_d_reduce = rb_intern("racc_reduce");
824
- id_d_accept = rb_intern("racc_accept");
825
- id_d_read_token = rb_intern("racc_read_token");
826
- id_d_next_state = rb_intern("racc_next_state");
827
- id_d_e_pop = rb_intern("racc_e_pop");
851
+ id_yydebug = rb_intern_const("@yydebug");
852
+ id_nexttoken = rb_intern_const("next_token");
853
+ id_onerror = rb_intern_const("on_error");
854
+ id_noreduce = rb_intern_const("_reduce_none");
855
+ id_errstatus = rb_intern_const("@racc_error_status");
856
+
857
+ id_d_shift = rb_intern_const("racc_shift");
858
+ id_d_reduce = rb_intern_const("racc_reduce");
859
+ id_d_accept = rb_intern_const("racc_accept");
860
+ id_d_read_token = rb_intern_const("racc_read_token");
861
+ id_d_next_state = rb_intern_const("racc_next_state");
862
+ id_d_e_pop = rb_intern_const("racc_e_pop");
828
863
  }
@@ -1,4 +1,5 @@
1
- # $Id: 1e30abedf4eea155815d1efa5500ec817b10a2ab $
1
+ # frozen_string_literal: false
2
+ #
2
3
 
3
4
  require 'mkmf'
4
5
 
@@ -1,13 +1,14 @@
1
+ #--
2
+ #
1
3
  #
2
- # $Id: 14fa1118eb3a23e85265e4f7afe2d5a297d69f9c $
3
4
  #
4
5
  # Copyright (c) 1999-2006 Minero Aoki
5
6
  #
6
7
  # This program is free software.
7
- # You can distribute/modify this program under the terms of
8
- # the GNU LGPL, Lesser General Public License version 2.1.
9
- # For details of the GNU LGPL, see the file "COPYING".
8
+ # You can distribute/modify this program under the same terms of ruby.
9
+ # see the file "COPYING".
10
10
  #
11
+ #++
11
12
 
12
13
  unless Object.method_defined?(:__send)
13
14
  class Object
Binary file
@@ -1,13 +1,14 @@
1
+ #--
2
+ #
1
3
  #
2
- # $Id: 74ff4369ce53c7f45cfc2644ce907785104ebf6e $
3
4
  #
4
5
  # Copyright (c) 1999-2006 Minero Aoki
5
6
  #
6
7
  # This program is free software.
7
- # You can distribute/modify this program under the terms of
8
- # the GNU LGPL, Lesser General Public License version 2.1.
9
- # For details of LGPL, see the file "COPYING".
8
+ # You can distribute/modify this program under the same terms of ruby.
9
+ # see the file "COPYING".
10
10
  #
11
+ #++
11
12
 
12
13
  module Racc
13
14
 
@@ -1,13 +1,14 @@
1
+ #--
2
+ #
1
3
  #
2
- # $Id: a26517cc7b6a673ce1985c8c75fba88492e1e820 $
3
4
  #
4
5
  # Copyright (c) 1999-2006 Minero Aoki
5
6
  #
6
7
  # This program is free software.
7
- # You can distribute/modify this program under the terms of
8
- # the GNU LGPL, Lesser General Public License version 2.1.
9
- # For details of the GNU LGPL, see the file "COPYING".
8
+ # You can distribute/modify this program under the same terms of ruby.
9
+ # see the file "COPYING".
10
10
  #
11
+ #++
11
12
 
12
13
  module Racc
13
14
  class Error < StandardError; end
@@ -1,13 +1,14 @@
1
+ #--
2
+ #
1
3
  #
2
- # $Id: 733f7084ff1dca50994cba55c8a05aba8d82eb31 $
3
4
  #
4
5
  # Copyright (c) 1999-2006 Minero Aoki
5
6
  #
6
7
  # This program is free software.
7
- # You can distribute/modify this program under the terms of
8
- # the GNU LGPL, Lesser General Public License version 2.1.
9
- # For details of the GNU LGPL, see the file "COPYING".
8
+ # You can distribute/modify this program under the same terms of ruby.
9
+ # see the file "COPYING".
10
10
  #
11
+ #++
11
12
 
12
13
  require 'racc/compat'
13
14
  require 'racc/iset'
@@ -85,14 +86,15 @@ module Racc
85
86
  end
86
87
 
87
88
  def n_useless_nonterminals
88
- @n_useless_nonterminals ||=
89
- begin
90
- n = 0
91
- @symboltable.each_nonterminal do |sym|
92
- n += 1 if sym.useless?
93
- end
94
- n
95
- end
89
+ @n_useless_nonterminals ||= each_useless_nonterminal.count
90
+ end
91
+
92
+ def each_useless_nonterminal
93
+ return to_enum __method__ unless block_given?
94
+
95
+ @symboltable.each_nonterminal do |sym|
96
+ yield sym if sym.useless?
97
+ end
96
98
  end
97
99
 
98
100
  def useless_rule_exist?
@@ -100,14 +102,15 @@ module Racc
100
102
  end
101
103
 
102
104
  def n_useless_rules
103
- @n_useless_rules ||=
104
- begin
105
- n = 0
106
- each do |r|
107
- n += 1 if r.useless?
108
- end
109
- n
110
- end
105
+ @n_useless_rules ||= each_useless_rule.count
106
+ end
107
+
108
+ def each_useless_rule
109
+ return to_enum __method__ unless block_given?
110
+
111
+ each do |r|
112
+ yield r if r.useless?
113
+ end
111
114
  end
112
115
 
113
116
  def nfa
@@ -571,7 +574,7 @@ module Racc
571
574
  check_symbols_useless s
572
575
  end until r.size == rs and s.size == ss
573
576
  end
574
-
577
+
575
578
  def check_rules_useless(rules)
576
579
  rules.delete_if do |rule|
577
580
  rule.useless = false
@@ -855,7 +858,7 @@ module Racc
855
858
  end
856
859
 
857
860
  private
858
-
861
+
859
862
  def ptr_bug!
860
863
  raise "racc: fatal: pointer not exist: self: #{to_s}"
861
864
  end