racc 1.7.2-java → 1.7.3-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fed59c77981adb11b5355730e2fcfabecefaeff577a2d14309a200f7ecb71d98
4
- data.tar.gz: df1bf49c9e1cac171ee60c5a0f4a879ca2e609f69090ccaac046adbf781d00f3
3
+ metadata.gz: c94aa0b9f7a7e15c7b1013f85450b9da417898183db609f1ae477d447bc8a87b
4
+ data.tar.gz: ebb5c4d587a4615c07f892e4681c6bc63554d3af6501d2bd22fac8b052d6a91c
5
5
  SHA512:
6
- metadata.gz: 7c169fde756a9b8e187831e4a3c011aa762a4f36d697b2909d22fab826f9a6e894fe16d3d075c37aee13c4e623758b9d114ec490c98dc402a8df0cf5858cd6ee
7
- data.tar.gz: 6148d85fb2d7dce4e73fd43ec74353d1ec2158c95d0ef1e697c6801168af018bb15386ce69203f1a8389649aff710350527b4cd9bdb311215d5e2b18a3083f95
6
+ metadata.gz: 52da64cac58e37e2244590b3410fcd301a7207f50c0e4b9c8dcbb1b5393d269cacc6fc2e5a682b53f1811fbe5dfd99529684318e6be901ffdc3119c162a46ab3
7
+ data.tar.gz: eea0197fb11f67526e59a1de85dd57683318fce129adbc3fc1fc764d73683f33c081021b851eff933ff4383c262d3d8b0739b7689097028131973b312c624820
@@ -131,8 +131,8 @@ Racc supports Bison's "expect" directive to declare the expected
131
131
  number of shift/reduce conflicts.
132
132
  --
133
133
  class MyParser
134
- rule
135
134
  expect 3
135
+ rule
136
136
  :
137
137
  :
138
138
  --
@@ -127,8 +127,8 @@ Racc has bison's "expect" directive.
127
127
  # Example
128
128
 
129
129
  class MyParser
130
- rule
131
130
  expect 3
131
+ rule
132
132
  :
133
133
  :
134
134
 
Binary file
data/lib/racc/info.rb CHANGED
@@ -12,7 +12,7 @@
12
12
  #++
13
13
 
14
14
  module Racc
15
- VERSION = '1.7.2'
15
+ VERSION = '1.7.3'
16
16
  Version = VERSION
17
17
  Copyright = 'Copyright (c) 1999-2006 Minero Aoki'
18
18
  end
@@ -15,7 +15,7 @@ unless $".find {|p| p.end_with?('/racc/info.rb')}
15
15
  $".push "#{__dir__}/racc/info.rb"
16
16
 
17
17
  module Racc
18
- VERSION = '1.7.2'
18
+ VERSION = '1.7.3'
19
19
  Version = VERSION
20
20
  Copyright = 'Copyright (c) 1999-2006 Minero Aoki'
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: racc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.7.3
5
5
  platform: java
6
6
  authors:
7
7
  - Minero Aoki
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-11-01 00:00:00.000000000 Z
12
+ date: 2023-11-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: |
15
15
  Racc is a LALR(1) parser generator.
@@ -42,11 +42,9 @@ files:
42
42
  - doc/ja/index.ja.html
43
43
  - doc/ja/parser.ja.rdoc
44
44
  - doc/ja/usage.ja.html
45
- - ext/racc/cparse/cparse.c
46
- - ext/racc/cparse/extconf.rb
45
+ - lib/java/racc/cparse-jruby.jar
47
46
  - lib/racc.rb
48
47
  - lib/racc/compat.rb
49
- - lib/racc/cparse-jruby.jar
50
48
  - lib/racc/debugflags.rb
51
49
  - lib/racc/exception.rb
52
50
  - lib/racc/grammar.rb
@@ -1,840 +0,0 @@
1
- /*
2
-
3
- cparse.c -- Racc Runtime Core
4
-
5
- Copyright (c) 1999-2006 Minero Aoki
6
-
7
- This library is free software.
8
- You can distribute/modify this program under the same terms of ruby.
9
-
10
- */
11
-
12
- #include <ruby.h>
13
-
14
- #ifndef FALSE
15
- #define FALSE 0
16
- #endif
17
- #ifndef TRUE
18
- #define TRUE 1
19
- #endif
20
-
21
- /* -----------------------------------------------------------------------
22
- Important Constants
23
- ----------------------------------------------------------------------- */
24
-
25
- #define RACC_VERSION STRINGIZE(RACC_INFO_VERSION)
26
-
27
- #define DEFAULT_TOKEN -1
28
- #define ERROR_TOKEN 1
29
- #define FINAL_TOKEN 0
30
-
31
- #define vDEFAULT_TOKEN INT2FIX(DEFAULT_TOKEN)
32
- #define vERROR_TOKEN INT2FIX(ERROR_TOKEN)
33
- #define vFINAL_TOKEN INT2FIX(FINAL_TOKEN)
34
-
35
- /* -----------------------------------------------------------------------
36
- File Local Variables
37
- ----------------------------------------------------------------------- */
38
-
39
- static VALUE RaccBug;
40
- static VALUE CparseParams;
41
-
42
- static ID id_yydebug;
43
- static ID id_nexttoken;
44
- static ID id_onerror;
45
- static ID id_noreduce;
46
- static ID id_errstatus;
47
-
48
- static ID id_d_shift;
49
- static ID id_d_reduce;
50
- static ID id_d_accept;
51
- static ID id_d_read_token;
52
- static ID id_d_next_state;
53
- static ID id_d_e_pop;
54
-
55
- /* -----------------------------------------------------------------------
56
- Utils
57
- ----------------------------------------------------------------------- */
58
-
59
- /* For backward compatibility */
60
- #ifndef ID2SYM
61
- # define ID2SYM(i) ULONG2NUM(i)
62
- #endif
63
- #ifndef SYM2ID
64
- # define SYM2ID(v) ((ID)NUM2ULONG(v))
65
- #endif
66
- #ifndef SYMBOL_P
67
- # define SYMBOL_P(v) FIXNUM_P(v)
68
- #endif
69
- #ifndef LONG2NUM
70
- # define LONG2NUM(i) INT2NUM(i)
71
- #endif
72
-
73
- static ID value_to_id(VALUE v);
74
- static inline long num_to_long(VALUE n);
75
-
76
- static ID
77
- value_to_id(VALUE v)
78
- {
79
- if (! SYMBOL_P(v)) {
80
- rb_raise(rb_eTypeError, "not symbol");
81
- }
82
- return SYM2ID(v);
83
- }
84
-
85
- static inline long
86
- num_to_long(VALUE n)
87
- {
88
- return NUM2LONG(n);
89
- }
90
-
91
- #define AREF(s, idx) \
92
- ((0 <= idx && idx < RARRAY_LEN(s)) ? rb_ary_entry(s, idx) : Qnil)
93
-
94
- /* -----------------------------------------------------------------------
95
- Parser Stack Interfaces
96
- ----------------------------------------------------------------------- */
97
-
98
- static VALUE get_stack_tail(VALUE stack, long len);
99
- static void cut_stack_tail(VALUE stack, long len);
100
-
101
- static VALUE
102
- get_stack_tail(VALUE stack, long len)
103
- {
104
- if (len < 0) return Qnil; /* system error */
105
- if (len > RARRAY_LEN(stack)) len = RARRAY_LEN(stack);
106
- return rb_ary_subseq(stack, RARRAY_LEN(stack) - len, len);
107
- }
108
-
109
- static void
110
- cut_stack_tail(VALUE stack, long len)
111
- {
112
- while (len > 0) {
113
- rb_ary_pop(stack);
114
- len--;
115
- }
116
- }
117
-
118
- #define STACK_INIT_LEN 64
119
- #define NEW_STACK() rb_ary_new2(STACK_INIT_LEN)
120
- #define PUSH(s, i) rb_ary_store(s, RARRAY_LEN(s), i)
121
- #define POP(s) rb_ary_pop(s)
122
- #define LAST_I(s) \
123
- ((RARRAY_LEN(s) > 0) ? rb_ary_entry(s, RARRAY_LEN(s) - 1) : Qnil)
124
- #define GET_TAIL(s, len) get_stack_tail(s, len)
125
- #define CUT_TAIL(s, len) cut_stack_tail(s, len)
126
-
127
- /* -----------------------------------------------------------------------
128
- struct cparse_params
129
- ----------------------------------------------------------------------- */
130
-
131
- struct cparse_params {
132
- VALUE value_v; /* VALUE version of this struct */
133
-
134
- VALUE parser; /* parser object */
135
-
136
- int lex_is_iterator;
137
- VALUE lexer; /* scanner object */
138
- ID lexmid; /* name of scanner method (must be an iterator) */
139
-
140
- /* State transition tables (immutable)
141
- Data structure is from Dragon Book 4.9 */
142
- /* action table */
143
- VALUE action_table;
144
- VALUE action_check;
145
- VALUE action_default;
146
- VALUE action_pointer;
147
- /* goto table */
148
- VALUE goto_table;
149
- VALUE goto_check;
150
- VALUE goto_default;
151
- VALUE goto_pointer;
152
-
153
- long nt_base; /* NonTerminal BASE index */
154
- VALUE reduce_table; /* reduce data table */
155
- VALUE token_table; /* token conversion table */
156
-
157
- /* parser stacks and parameters */
158
- VALUE state;
159
- long curstate;
160
- VALUE vstack;
161
- VALUE tstack;
162
- VALUE t;
163
- long shift_n;
164
- long reduce_n;
165
- long ruleno;
166
-
167
- long errstatus; /* nonzero in error recovering mode */
168
- long nerr; /* number of error */
169
-
170
- int use_result_var;
171
-
172
- VALUE retval; /* return value of parser routine */
173
- long fin; /* parse result status */
174
- #define CP_FIN_ACCEPT 1
175
- #define CP_FIN_EOT 2
176
- #define CP_FIN_CANTPOP 3
177
-
178
- int debug; /* user level debug */
179
- int sys_debug; /* system level debug */
180
-
181
- long i; /* table index */
182
- };
183
-
184
- /* -----------------------------------------------------------------------
185
- Parser Main Routines
186
- ----------------------------------------------------------------------- */
187
-
188
- static VALUE racc_cparse(VALUE parser, VALUE arg, VALUE sysdebug);
189
- static VALUE racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid,
190
- VALUE arg, VALUE sysdebug);
191
-
192
- static void call_lexer(struct cparse_params *v);
193
- static VALUE lexer_i(RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data));
194
-
195
- static VALUE assert_array(VALUE a);
196
- static long assert_integer(VALUE n);
197
- static VALUE assert_hash(VALUE h);
198
- static VALUE initialize_params(VALUE vparams, VALUE parser, VALUE arg,
199
- VALUE lexer, VALUE lexmid);
200
- static void cparse_params_mark(void *ptr);
201
- static size_t cparse_params_memsize(const void *ptr);
202
-
203
- static void parse_main(struct cparse_params *v,
204
- VALUE tok, VALUE val, int resume);
205
- static void extract_user_token(struct cparse_params *v,
206
- VALUE block_args, VALUE *tok, VALUE *val);
207
- static void shift(struct cparse_params* v, long act, VALUE tok, VALUE val);
208
- static int reduce(struct cparse_params* v, long act);
209
- static rb_block_call_func reduce0;
210
-
211
- #ifdef DEBUG
212
- # define D_puts(msg) if (v->sys_debug) puts(msg)
213
- # define D_printf(fmt,arg) if (v->sys_debug) printf(fmt,arg)
214
- #else
215
- # define D_puts(msg)
216
- # define D_printf(fmt,arg)
217
- #endif
218
-
219
- #undef RUBY_UNTYPED_DATA_WARNING
220
- #define RUBY_UNTYPED_DATA_WARNING 1
221
-
222
- static const rb_data_type_t cparse_params_type = {
223
- "racc/cparse",
224
- {
225
- cparse_params_mark,
226
- RUBY_TYPED_DEFAULT_FREE,
227
- cparse_params_memsize,
228
- },
229
- #ifdef RUBY_TYPED_FREE_IMMEDIATELY
230
- 0, 0,
231
- RUBY_TYPED_FREE_IMMEDIATELY,
232
- #endif
233
- };
234
-
235
- static VALUE
236
- racc_cparse(VALUE parser, VALUE arg, VALUE sysdebug)
237
- {
238
- VALUE vparams;
239
- struct cparse_params *v;
240
-
241
- vparams = TypedData_Make_Struct(CparseParams, struct cparse_params,
242
- &cparse_params_type, v);
243
- D_puts("starting cparse");
244
- v->sys_debug = RTEST(sysdebug);
245
- vparams = initialize_params(vparams, parser, arg, Qnil, Qnil);
246
- v->lex_is_iterator = FALSE;
247
- parse_main(v, Qnil, Qnil, 0);
248
-
249
- RB_GC_GUARD(vparams);
250
- return v->retval;
251
- }
252
-
253
- static VALUE
254
- racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
255
- {
256
- VALUE vparams;
257
- struct cparse_params *v;
258
-
259
- vparams = TypedData_Make_Struct(CparseParams, struct cparse_params,
260
- &cparse_params_type, v);
261
- v->sys_debug = RTEST(sysdebug);
262
- D_puts("start C yyparse");
263
- vparams = initialize_params(vparams, parser, arg, lexer, lexmid);
264
- v->lex_is_iterator = TRUE;
265
- D_puts("params initialized");
266
- parse_main(v, Qnil, Qnil, 0);
267
- call_lexer(v);
268
- if (!v->fin) {
269
- rb_raise(rb_eArgError, "%s() is finished before EndOfToken",
270
- rb_id2name(v->lexmid));
271
- }
272
-
273
- RB_GC_GUARD(vparams);
274
- return v->retval;
275
- }
276
-
277
- static void
278
- call_lexer(struct cparse_params *v)
279
- {
280
- rb_block_call(v->lexer, v->lexmid, 0, NULL, lexer_i, v->value_v);
281
- }
282
-
283
- static VALUE
284
- lexer_i(RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data))
285
- {
286
- struct cparse_params *v = rb_check_typeddata(data, &cparse_params_type);
287
- VALUE tok, val;
288
-
289
- if (v->fin)
290
- rb_raise(rb_eArgError, "extra token after EndOfToken");
291
- extract_user_token(v, block_args, &tok, &val);
292
- parse_main(v, tok, val, 1);
293
- if (v->fin && v->fin != CP_FIN_ACCEPT)
294
- rb_iter_break();
295
- return Qnil;
296
- }
297
-
298
- static VALUE
299
- assert_array(VALUE a)
300
- {
301
- Check_Type(a, T_ARRAY);
302
- return a;
303
- }
304
-
305
- static VALUE
306
- assert_hash(VALUE h)
307
- {
308
- Check_Type(h, T_HASH);
309
- return h;
310
- }
311
-
312
- static long
313
- assert_integer(VALUE n)
314
- {
315
- return NUM2LONG(n);
316
- }
317
-
318
- static VALUE
319
- initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)
320
- {
321
- struct cparse_params *v = rb_check_typeddata(vparams, &cparse_params_type);
322
-
323
- v->value_v = vparams;
324
- v->parser = parser;
325
- v->lexer = lexer;
326
- if (! NIL_P(lexmid))
327
- v->lexmid = value_to_id(lexmid);
328
-
329
- v->debug = RTEST(rb_ivar_get(parser, id_yydebug));
330
-
331
- Check_Type(arg, T_ARRAY);
332
- if (!(13 <= RARRAY_LEN(arg) && RARRAY_LEN(arg) <= 14))
333
- rb_raise(RaccBug, "[Racc Bug] wrong arg.size %ld", RARRAY_LEN(arg));
334
- v->action_table = assert_array (rb_ary_entry(arg, 0));
335
- v->action_check = assert_array (rb_ary_entry(arg, 1));
336
- v->action_default = assert_array (rb_ary_entry(arg, 2));
337
- v->action_pointer = assert_array (rb_ary_entry(arg, 3));
338
- v->goto_table = assert_array (rb_ary_entry(arg, 4));
339
- v->goto_check = assert_array (rb_ary_entry(arg, 5));
340
- v->goto_default = assert_array (rb_ary_entry(arg, 6));
341
- v->goto_pointer = assert_array (rb_ary_entry(arg, 7));
342
- v->nt_base = assert_integer(rb_ary_entry(arg, 8));
343
- v->reduce_table = assert_array (rb_ary_entry(arg, 9));
344
- v->token_table = assert_hash (rb_ary_entry(arg, 10));
345
- v->shift_n = assert_integer(rb_ary_entry(arg, 11));
346
- v->reduce_n = assert_integer(rb_ary_entry(arg, 12));
347
- if (RARRAY_LEN(arg) > 13) {
348
- v->use_result_var = RTEST(rb_ary_entry(arg, 13));
349
- }
350
- else {
351
- v->use_result_var = TRUE;
352
- }
353
-
354
- v->tstack = v->debug ? NEW_STACK() : Qnil;
355
- v->vstack = NEW_STACK();
356
- v->state = NEW_STACK();
357
- v->curstate = 0;
358
- PUSH(v->state, INT2FIX(0));
359
- v->t = INT2FIX(FINAL_TOKEN + 1); /* must not init to FINAL_TOKEN */
360
- v->nerr = 0;
361
- v->errstatus = 0;
362
- rb_ivar_set(parser, id_errstatus, LONG2NUM(v->errstatus));
363
-
364
- v->retval = Qnil;
365
- v->fin = 0;
366
-
367
- v->lex_is_iterator = FALSE;
368
-
369
- rb_iv_set(parser, "@vstack", v->vstack);
370
- if (v->debug) {
371
- rb_iv_set(parser, "@tstack", v->tstack);
372
- }
373
- else {
374
- rb_iv_set(parser, "@tstack", Qnil);
375
- }
376
-
377
- return vparams;
378
- }
379
-
380
- static void
381
- cparse_params_mark(void *ptr)
382
- {
383
- struct cparse_params *v = (struct cparse_params*)ptr;
384
-
385
- rb_gc_mark(v->value_v);
386
- rb_gc_mark(v->parser);
387
- rb_gc_mark(v->lexer);
388
- rb_gc_mark(v->action_table);
389
- rb_gc_mark(v->action_check);
390
- rb_gc_mark(v->action_default);
391
- rb_gc_mark(v->action_pointer);
392
- rb_gc_mark(v->goto_table);
393
- rb_gc_mark(v->goto_check);
394
- rb_gc_mark(v->goto_default);
395
- rb_gc_mark(v->goto_pointer);
396
- rb_gc_mark(v->reduce_table);
397
- rb_gc_mark(v->token_table);
398
- rb_gc_mark(v->state);
399
- rb_gc_mark(v->vstack);
400
- rb_gc_mark(v->tstack);
401
- rb_gc_mark(v->t);
402
- rb_gc_mark(v->retval);
403
- }
404
-
405
- static size_t
406
- cparse_params_memsize(const void *ptr)
407
- {
408
- return sizeof(struct cparse_params);
409
- }
410
-
411
- static void
412
- extract_user_token(struct cparse_params *v, VALUE block_args,
413
- VALUE *tok, VALUE *val)
414
- {
415
- if (NIL_P(block_args)) {
416
- /* EOF */
417
- *tok = Qfalse;
418
- *val = rb_str_new("$", 1);
419
- return;
420
- }
421
-
422
- if (!RB_TYPE_P(block_args, T_ARRAY)) {
423
- rb_raise(rb_eTypeError,
424
- "%s() %s %"PRIsVALUE" (must be Array[2])",
425
- v->lex_is_iterator ? rb_id2name(v->lexmid) : "next_token",
426
- v->lex_is_iterator ? "yielded" : "returned",
427
- rb_obj_class(block_args));
428
- }
429
- if (RARRAY_LEN(block_args) != 2) {
430
- rb_raise(rb_eArgError,
431
- "%s() %s wrong size of array (%ld for 2)",
432
- v->lex_is_iterator ? rb_id2name(v->lexmid) : "next_token",
433
- v->lex_is_iterator ? "yielded" : "returned",
434
- RARRAY_LEN(block_args));
435
- }
436
- *tok = AREF(block_args, 0);
437
- *val = AREF(block_args, 1);
438
- }
439
-
440
- #define SHIFT(v,act,tok,val) shift(v,act,tok,val)
441
- #define REDUCE(v,act) do {\
442
- switch (reduce(v,act)) { \
443
- case 0: /* normal */ \
444
- break; \
445
- case 1: /* yyerror */ \
446
- goto user_yyerror; \
447
- case 2: /* yyaccept */ \
448
- D_puts("u accept"); \
449
- goto accept; \
450
- default: \
451
- break; \
452
- } \
453
- } while (0)
454
-
455
- static void
456
- parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
457
- {
458
- long i; /* table index */
459
- long act; /* action type */
460
- VALUE act_value; /* action type, VALUE version */
461
- int read_next = 1; /* true if we need to read next token */
462
- VALUE tmp;
463
-
464
- if (resume)
465
- goto resume;
466
-
467
- while (1) {
468
- D_puts("");
469
- D_puts("---- enter new loop ----");
470
- D_puts("");
471
-
472
- D_printf("(act) k1=%ld\n", v->curstate);
473
- tmp = AREF(v->action_pointer, v->curstate);
474
- if (NIL_P(tmp)) goto notfound;
475
- D_puts("(act) pointer[k1] ok");
476
- i = NUM2LONG(tmp);
477
-
478
- D_printf("read_next=%d\n", read_next);
479
- if (read_next && (v->t != vFINAL_TOKEN)) {
480
- if (v->lex_is_iterator) {
481
- D_puts("resuming...");
482
- if (v->fin) rb_raise(rb_eArgError, "token given after EOF");
483
- v->i = i; /* save i */
484
- return;
485
- resume:
486
- D_puts("resumed");
487
- i = v->i; /* load i */
488
- }
489
- else {
490
- D_puts("next_token");
491
- tmp = rb_funcall(v->parser, id_nexttoken, 0);
492
- extract_user_token(v, tmp, &tok, &val);
493
- }
494
- /* convert token */
495
- v->t = rb_hash_aref(v->token_table, tok);
496
- if (NIL_P(v->t)) {
497
- v->t = vERROR_TOKEN;
498
- }
499
- D_printf("(act) t(k2)=%ld\n", NUM2LONG(v->t));
500
- if (v->debug) {
501
- rb_funcall(v->parser, id_d_read_token,
502
- 3, v->t, tok, val);
503
- }
504
- }
505
- read_next = 0;
506
-
507
- i += NUM2LONG(v->t);
508
- D_printf("(act) i=%ld\n", i);
509
- if (i < 0) goto notfound;
510
-
511
- act_value = AREF(v->action_table, i);
512
- if (NIL_P(act_value)) goto notfound;
513
- act = NUM2LONG(act_value);
514
- D_printf("(act) table[i]=%ld\n", act);
515
-
516
- tmp = AREF(v->action_check, i);
517
- if (NIL_P(tmp)) goto notfound;
518
- if (NUM2LONG(tmp) != v->curstate) goto notfound;
519
- D_printf("(act) check[i]=%ld\n", NUM2LONG(tmp));
520
-
521
- D_puts("(act) found");
522
- act_fixed:
523
- D_printf("act=%ld\n", act);
524
- goto handle_act;
525
-
526
- notfound:
527
- D_puts("(act) not found: use default");
528
- act_value = AREF(v->action_default, v->curstate);
529
- act = NUM2LONG(act_value);
530
- goto act_fixed;
531
-
532
-
533
- handle_act:
534
- if (act > 0 && act < v->shift_n) {
535
- D_puts("shift");
536
- if (v->errstatus > 0) {
537
- v->errstatus--;
538
- rb_ivar_set(v->parser, id_errstatus, LONG2NUM(v->errstatus));
539
- }
540
- SHIFT(v, act, v->t, val);
541
- read_next = 1;
542
- }
543
- else if (act < 0 && act > -(v->reduce_n)) {
544
- D_puts("reduce");
545
- REDUCE(v, act);
546
- }
547
- else if (act == -(v->reduce_n)) {
548
- goto error;
549
- error_recovered:
550
- ; /* goto label requires stmt */
551
- }
552
- else if (act == v->shift_n) {
553
- D_puts("accept");
554
- goto accept;
555
- }
556
- else {
557
- rb_raise(RaccBug, "[Racc Bug] unknown act value %ld", act);
558
- }
559
-
560
- if (v->debug) {
561
- rb_funcall(v->parser, id_d_next_state,
562
- 2, LONG2NUM(v->curstate), v->state);
563
- }
564
- }
565
- /* not reach */
566
-
567
-
568
- accept:
569
- if (v->debug) rb_funcall(v->parser, id_d_accept, 0);
570
- v->retval = rb_ary_entry(v->vstack, 0);
571
- v->fin = CP_FIN_ACCEPT;
572
- return;
573
-
574
-
575
- error:
576
- D_printf("error detected, status=%ld\n", v->errstatus);
577
- if (v->errstatus == 0) {
578
- v->nerr++;
579
- rb_funcall(v->parser, id_onerror,
580
- 3, v->t, val, v->vstack);
581
- }
582
- user_yyerror:
583
- if (v->errstatus == 3) {
584
- if (v->t == vFINAL_TOKEN) {
585
- v->retval = Qnil;
586
- v->fin = CP_FIN_EOT;
587
- return;
588
- }
589
- read_next = 1;
590
- }
591
- v->errstatus = 3;
592
- rb_ivar_set(v->parser, id_errstatus, LONG2NUM(v->errstatus));
593
-
594
- /* check if we can shift/reduce error token */
595
- D_printf("(err) k1=%ld\n", v->curstate);
596
- D_printf("(err) k2=%d (error)\n", ERROR_TOKEN);
597
- while (1) {
598
- tmp = AREF(v->action_pointer, v->curstate);
599
- if (NIL_P(tmp)) goto error_pop;
600
- D_puts("(err) pointer[k1] ok");
601
-
602
- i = NUM2LONG(tmp) + ERROR_TOKEN;
603
- D_printf("(err) i=%ld\n", i);
604
- if (i < 0) goto error_pop;
605
-
606
- act_value = AREF(v->action_table, i);
607
- if (NIL_P(act_value)) {
608
- D_puts("(err) table[i] == nil");
609
- goto error_pop;
610
- }
611
- act = NUM2LONG(act_value);
612
- D_printf("(err) table[i]=%ld\n", act);
613
-
614
- tmp = AREF(v->action_check, i);
615
- if (NIL_P(tmp)) {
616
- D_puts("(err) check[i] == nil");
617
- goto error_pop;
618
- }
619
- if (NUM2LONG(tmp) != v->curstate) {
620
- D_puts("(err) check[i] != k1");
621
- goto error_pop;
622
- }
623
-
624
- D_puts("(err) found: can handle error token");
625
- break;
626
-
627
- error_pop:
628
- D_puts("(err) act not found: can't handle error token; pop");
629
-
630
- if (RARRAY_LEN(v->state) <= 1) {
631
- v->retval = Qnil;
632
- v->fin = CP_FIN_CANTPOP;
633
- return;
634
- }
635
- POP(v->state);
636
- POP(v->vstack);
637
- v->curstate = num_to_long(LAST_I(v->state));
638
- if (v->debug) {
639
- POP(v->tstack);
640
- rb_funcall(v->parser, id_d_e_pop,
641
- 3, v->state, v->tstack, v->vstack);
642
- }
643
- }
644
-
645
- /* shift/reduce error token */
646
- if (act > 0 && act < v->shift_n) {
647
- D_puts("e shift");
648
- SHIFT(v, act, ERROR_TOKEN, val);
649
- }
650
- else if (act < 0 && act > -(v->reduce_n)) {
651
- D_puts("e reduce");
652
- REDUCE(v, act);
653
- }
654
- else if (act == v->shift_n) {
655
- D_puts("e accept");
656
- goto accept;
657
- }
658
- else {
659
- rb_raise(RaccBug, "[Racc Bug] unknown act value %ld", act);
660
- }
661
- goto error_recovered;
662
- }
663
-
664
- static void
665
- shift(struct cparse_params *v, long act, VALUE tok, VALUE val)
666
- {
667
- PUSH(v->vstack, val);
668
- if (v->debug) {
669
- PUSH(v->tstack, tok);
670
- rb_funcall(v->parser, id_d_shift,
671
- 3, tok, v->tstack, v->vstack);
672
- }
673
- v->curstate = act;
674
- PUSH(v->state, LONG2NUM(v->curstate));
675
- }
676
-
677
- static int
678
- reduce(struct cparse_params *v, long act)
679
- {
680
- VALUE code;
681
- v->ruleno = -act * 3;
682
- code = rb_catch("racc_jump", reduce0, v->value_v);
683
- v->errstatus = num_to_long(rb_ivar_get(v->parser, id_errstatus));
684
- return NUM2INT(code);
685
- }
686
-
687
- static VALUE
688
- reduce0(RB_BLOCK_CALL_FUNC_ARGLIST(_, data))
689
- {
690
- struct cparse_params *v = rb_check_typeddata(data, &cparse_params_type);
691
- VALUE reduce_to, reduce_len, method_id;
692
- long len;
693
- ID mid;
694
- VALUE tmp, tmp_t = Qundef, tmp_v = Qundef;
695
- long i, k1, k2;
696
- VALUE goto_state;
697
-
698
- reduce_len = rb_ary_entry(v->reduce_table, v->ruleno);
699
- reduce_to = rb_ary_entry(v->reduce_table, v->ruleno+1);
700
- method_id = rb_ary_entry(v->reduce_table, v->ruleno+2);
701
- len = NUM2LONG(reduce_len);
702
- mid = value_to_id(method_id);
703
-
704
- /* call action */
705
- if (len == 0) {
706
- tmp = Qnil;
707
- if (mid != id_noreduce)
708
- tmp_v = rb_ary_new();
709
- if (v->debug)
710
- tmp_t = rb_ary_new();
711
- }
712
- else {
713
- if (mid != id_noreduce) {
714
- tmp_v = GET_TAIL(v->vstack, len);
715
- tmp = rb_ary_entry(tmp_v, 0);
716
- }
717
- else {
718
- tmp = rb_ary_entry(v->vstack, RARRAY_LEN(v->vstack) - len);
719
- }
720
- CUT_TAIL(v->vstack, len);
721
- if (v->debug) {
722
- tmp_t = GET_TAIL(v->tstack, len);
723
- CUT_TAIL(v->tstack, len);
724
- }
725
- CUT_TAIL(v->state, len);
726
- }
727
- if (mid != id_noreduce) {
728
- if (v->use_result_var) {
729
- tmp = rb_funcall(v->parser, mid,
730
- 3, tmp_v, v->vstack, tmp);
731
- }
732
- else {
733
- tmp = rb_funcall(v->parser, mid,
734
- 2, tmp_v, v->vstack);
735
- }
736
- }
737
-
738
- /* then push result */
739
- PUSH(v->vstack, tmp);
740
- if (v->debug) {
741
- PUSH(v->tstack, reduce_to);
742
- rb_funcall(v->parser, id_d_reduce,
743
- 4, tmp_t, reduce_to, v->tstack, v->vstack);
744
- }
745
-
746
- /* calculate transition state */
747
- if (RARRAY_LEN(v->state) == 0)
748
- rb_raise(RaccBug, "state stack unexpectedly empty");
749
- k2 = num_to_long(LAST_I(v->state));
750
- k1 = num_to_long(reduce_to) - v->nt_base;
751
- D_printf("(goto) k1=%ld\n", k1);
752
- D_printf("(goto) k2=%ld\n", k2);
753
-
754
- tmp = AREF(v->goto_pointer, k1);
755
- if (NIL_P(tmp)) goto notfound;
756
-
757
- i = NUM2LONG(tmp) + k2;
758
- D_printf("(goto) i=%ld\n", i);
759
- if (i < 0) goto notfound;
760
-
761
- goto_state = AREF(v->goto_table, i);
762
- if (NIL_P(goto_state)) {
763
- D_puts("(goto) table[i] == nil");
764
- goto notfound;
765
- }
766
- D_printf("(goto) table[i]=%ld (goto_state)\n", NUM2LONG(goto_state));
767
-
768
- tmp = AREF(v->goto_check, i);
769
- if (NIL_P(tmp)) {
770
- D_puts("(goto) check[i] == nil");
771
- goto notfound;
772
- }
773
- if (tmp != LONG2NUM(k1)) {
774
- D_puts("(goto) check[i] != table[i]");
775
- goto notfound;
776
- }
777
- D_printf("(goto) check[i]=%ld\n", NUM2LONG(tmp));
778
-
779
- D_puts("(goto) found");
780
- transit:
781
- PUSH(v->state, goto_state);
782
- v->curstate = NUM2LONG(goto_state);
783
- return INT2FIX(0);
784
-
785
- notfound:
786
- D_puts("(goto) not found: use default");
787
- /* overwrite `goto-state' by default value */
788
- goto_state = AREF(v->goto_default, k1);
789
- goto transit;
790
- }
791
-
792
- /* -----------------------------------------------------------------------
793
- Ruby Interface
794
- ----------------------------------------------------------------------- */
795
-
796
- void
797
- Init_cparse(void)
798
- {
799
- #ifdef HAVE_RB_EXT_RACTOR_SAFE
800
- rb_ext_ractor_safe(true);
801
- #endif
802
-
803
- VALUE Racc, Parser;
804
- ID id_racc = rb_intern_const("Racc");
805
-
806
- if (rb_const_defined(rb_cObject, id_racc)) {
807
- Racc = rb_const_get(rb_cObject, id_racc);
808
- Parser = rb_const_get_at(Racc, rb_intern_const("Parser"));
809
- }
810
- else {
811
- Racc = rb_define_module("Racc");
812
- Parser = rb_define_class_under(Racc, "Parser", rb_cObject);
813
- }
814
- rb_define_private_method(Parser, "_racc_do_parse_c", racc_cparse, 2);
815
- rb_define_private_method(Parser, "_racc_yyparse_c", racc_yyparse, 4);
816
- rb_define_const(Parser, "Racc_Runtime_Core_Version_C",
817
- rb_str_new2(RACC_VERSION));
818
- rb_define_const(Parser, "Racc_Runtime_Core_Id_C",
819
- rb_str_new2("$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $"));
820
-
821
- CparseParams = rb_define_class_under(Racc, "CparseParams", rb_cObject);
822
- rb_undef_alloc_func(CparseParams);
823
- rb_undef_method(CparseParams, "initialize");
824
- rb_undef_method(CparseParams, "initialize_copy");
825
-
826
- RaccBug = rb_eRuntimeError;
827
-
828
- id_yydebug = rb_intern_const("@yydebug");
829
- id_nexttoken = rb_intern_const("next_token");
830
- id_onerror = rb_intern_const("on_error");
831
- id_noreduce = rb_intern_const("_reduce_none");
832
- id_errstatus = rb_intern_const("@racc_error_status");
833
-
834
- id_d_shift = rb_intern_const("racc_shift");
835
- id_d_reduce = rb_intern_const("racc_reduce");
836
- id_d_accept = rb_intern_const("racc_accept");
837
- id_d_read_token = rb_intern_const("racc_read_token");
838
- id_d_next_state = rb_intern_const("racc_next_state");
839
- id_d_e_pop = rb_intern_const("racc_e_pop");
840
- }
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
- #
3
-
4
- require 'mkmf'
5
- require_relative '../../../lib/racc/info'
6
-
7
- $defs << "-D""RACC_INFO_VERSION=#{Racc::VERSION}"
8
- create_makefile 'racc/cparse'
Binary file