racc 1.6.0 → 1.8.0
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.
- checksums.yaml +4 -4
- data/ChangeLog +3 -3
- data/README.ja.rdoc +2 -38
- data/README.rdoc +12 -35
- data/TODO +1 -1
- data/bin/racc +32 -32
- data/doc/en/grammar.en.rdoc +99 -107
- data/doc/en/grammar2.en.rdoc +1 -1
- data/doc/ja/command.ja.html +5 -0
- data/doc/ja/grammar.ja.rdoc +1 -1
- data/doc/ja/parser.ja.rdoc +1 -1
- data/ext/racc/cparse/cparse.c +26 -49
- data/ext/racc/cparse/extconf.rb +3 -4
- data/lib/racc/grammar.rb +80 -7
- data/lib/racc/grammarfileparser.rb +116 -10
- data/lib/racc/info.rb +2 -1
- data/lib/racc/parser-text.rb +18 -11
- data/lib/racc/parser.rb +10 -12
- data/lib/racc/parserfilegenerator.rb +7 -2
- data/lib/racc/state.rb +4 -0
- data/lib/racc/statetransitiontable.rb +1 -1
- metadata +4 -7
- data/doc/en/NEWS.en.rdoc +0 -282
- data/doc/ja/NEWS.ja.rdoc +0 -307
- data/ext/racc/MANIFEST +0 -4
data/ext/racc/cparse/cparse.c
CHANGED
@@ -7,8 +7,6 @@
|
|
7
7
|
This library is free software.
|
8
8
|
You can distribute/modify this program under the same terms of ruby.
|
9
9
|
|
10
|
-
$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $
|
11
|
-
|
12
10
|
*/
|
13
11
|
|
14
12
|
#include <ruby.h>
|
@@ -24,7 +22,7 @@
|
|
24
22
|
Important Constants
|
25
23
|
----------------------------------------------------------------------- */
|
26
24
|
|
27
|
-
#define RACC_VERSION
|
25
|
+
#define RACC_VERSION STRINGIZE(RACC_INFO_VERSION)
|
28
26
|
|
29
27
|
#define DEFAULT_TOKEN -1
|
30
28
|
#define ERROR_TOKEN 1
|
@@ -72,12 +70,8 @@ static ID id_d_e_pop;
|
|
72
70
|
# define LONG2NUM(i) INT2NUM(i)
|
73
71
|
#endif
|
74
72
|
|
75
|
-
|
76
|
-
|
77
|
-
#endif
|
78
|
-
|
79
|
-
static ID value_to_id _((VALUE v));
|
80
|
-
static inline long num_to_long _((VALUE n));
|
73
|
+
static ID value_to_id(VALUE v);
|
74
|
+
static inline long num_to_long(VALUE n);
|
81
75
|
|
82
76
|
static ID
|
83
77
|
value_to_id(VALUE v)
|
@@ -101,8 +95,8 @@ num_to_long(VALUE n)
|
|
101
95
|
Parser Stack Interfaces
|
102
96
|
----------------------------------------------------------------------- */
|
103
97
|
|
104
|
-
static VALUE get_stack_tail
|
105
|
-
static void cut_stack_tail
|
98
|
+
static VALUE get_stack_tail(VALUE stack, long len);
|
99
|
+
static void cut_stack_tail(VALUE stack, long len);
|
106
100
|
|
107
101
|
static VALUE
|
108
102
|
get_stack_tail(VALUE stack, long len)
|
@@ -191,27 +185,27 @@ struct cparse_params {
|
|
191
185
|
Parser Main Routines
|
192
186
|
----------------------------------------------------------------------- */
|
193
187
|
|
194
|
-
static VALUE racc_cparse
|
195
|
-
static VALUE racc_yyparse
|
196
|
-
|
197
|
-
|
198
|
-
static void call_lexer
|
199
|
-
static VALUE lexer_i
|
200
|
-
|
201
|
-
static VALUE assert_array
|
202
|
-
static long assert_integer
|
203
|
-
static VALUE assert_hash
|
204
|
-
static VALUE initialize_params
|
205
|
-
|
206
|
-
static void cparse_params_mark
|
207
|
-
static size_t cparse_params_memsize
|
208
|
-
|
209
|
-
static void parse_main
|
210
|
-
|
211
|
-
static void extract_user_token
|
212
|
-
|
213
|
-
static void shift
|
214
|
-
static int reduce
|
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);
|
215
209
|
static rb_block_call_func reduce0;
|
216
210
|
|
217
211
|
#ifdef DEBUG
|
@@ -280,28 +274,11 @@ racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
|
|
280
274
|
return v->retval;
|
281
275
|
}
|
282
276
|
|
283
|
-
#ifdef HAVE_RB_BLOCK_CALL
|
284
277
|
static void
|
285
278
|
call_lexer(struct cparse_params *v)
|
286
279
|
{
|
287
280
|
rb_block_call(v->lexer, v->lexmid, 0, NULL, lexer_i, v->value_v);
|
288
281
|
}
|
289
|
-
#else
|
290
|
-
static VALUE
|
291
|
-
lexer_iter(VALUE data)
|
292
|
-
{
|
293
|
-
struct cparse_params *v = rb_check_typeddata(data, &cparse_params_type);
|
294
|
-
|
295
|
-
rb_funcall(v->lexer, v->lexmid, 0);
|
296
|
-
return Qnil;
|
297
|
-
}
|
298
|
-
|
299
|
-
static void
|
300
|
-
call_lexer(struct cparse_params *v)
|
301
|
-
{
|
302
|
-
rb_iterate(lexer_iter, v->value_v, lexer_i, v->value_v);
|
303
|
-
}
|
304
|
-
#endif
|
305
282
|
|
306
283
|
static VALUE
|
307
284
|
lexer_i(RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data))
|
data/ext/racc/cparse/extconf.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
|
4
4
|
require 'mkmf'
|
5
|
+
require_relative '../../../lib/racc/info'
|
5
6
|
|
6
|
-
|
7
|
-
have_func('rb_ary_subseq')
|
8
|
-
|
7
|
+
$defs << "-D""RACC_INFO_VERSION=#{Racc::VERSION}"
|
9
8
|
create_makefile 'racc/cparse'
|
data/lib/racc/grammar.rb
CHANGED
@@ -27,6 +27,7 @@ module Racc
|
|
27
27
|
@rules = [] # :: [Rule]
|
28
28
|
@start = nil
|
29
29
|
@n_expected_srconflicts = nil
|
30
|
+
@error_on_expect_mismatch = nil
|
30
31
|
@prec_table = []
|
31
32
|
@prec_table_closed = false
|
32
33
|
@closed = false
|
@@ -36,6 +37,7 @@ module Racc
|
|
36
37
|
attr_reader :start
|
37
38
|
attr_reader :symboltable
|
38
39
|
attr_accessor :n_expected_srconflicts
|
40
|
+
attr_accessor :error_on_expect_mismatch
|
39
41
|
|
40
42
|
def [](x)
|
41
43
|
@rules[x]
|
@@ -335,14 +337,14 @@ module Racc
|
|
335
337
|
if action
|
336
338
|
idbase = "#{type}@#{id}-#{@seqs[type] += 1}"
|
337
339
|
target = _wrap(idbase, "#{idbase}-core", action)
|
338
|
-
|
340
|
+
_register("#{idbase}-core", &block)
|
339
341
|
else
|
340
|
-
target =
|
342
|
+
target = _register("#{type}@#{id}", &block)
|
341
343
|
end
|
342
344
|
@grammar.intern(target)
|
343
345
|
end
|
344
346
|
|
345
|
-
def
|
347
|
+
def _register(target_name)
|
346
348
|
target = target_name.intern
|
347
349
|
unless _added?(@grammar.intern(target))
|
348
350
|
yield(target).each_rule do |rule|
|
@@ -787,6 +789,81 @@ module Racc
|
|
787
789
|
end
|
788
790
|
|
789
791
|
|
792
|
+
class OptionMark
|
793
|
+
def initialize(lineno)
|
794
|
+
@lineno = lineno
|
795
|
+
end
|
796
|
+
|
797
|
+
def name
|
798
|
+
'?'
|
799
|
+
end
|
800
|
+
|
801
|
+
alias inspect name
|
802
|
+
|
803
|
+
attr_reader :lineno
|
804
|
+
end
|
805
|
+
|
806
|
+
|
807
|
+
class ManyMark
|
808
|
+
def initialize(lineno)
|
809
|
+
@lineno = lineno
|
810
|
+
end
|
811
|
+
|
812
|
+
def name
|
813
|
+
'*'
|
814
|
+
end
|
815
|
+
|
816
|
+
alias inspect name
|
817
|
+
|
818
|
+
attr_reader :lineno
|
819
|
+
end
|
820
|
+
|
821
|
+
|
822
|
+
class Many1Mark
|
823
|
+
def initialize(lineno)
|
824
|
+
@lineno = lineno
|
825
|
+
end
|
826
|
+
|
827
|
+
def name
|
828
|
+
'+'
|
829
|
+
end
|
830
|
+
|
831
|
+
alias inspect name
|
832
|
+
|
833
|
+
attr_reader :lineno
|
834
|
+
end
|
835
|
+
|
836
|
+
|
837
|
+
class GroupStartMark
|
838
|
+
def initialize(lineno)
|
839
|
+
@lineno = lineno
|
840
|
+
end
|
841
|
+
|
842
|
+
def name
|
843
|
+
'('
|
844
|
+
end
|
845
|
+
|
846
|
+
alias inspect name
|
847
|
+
|
848
|
+
attr_reader :lineno
|
849
|
+
end
|
850
|
+
|
851
|
+
|
852
|
+
class GroupEndMark
|
853
|
+
def initialize(lineno)
|
854
|
+
@lineno = lineno
|
855
|
+
end
|
856
|
+
|
857
|
+
def name
|
858
|
+
')'
|
859
|
+
end
|
860
|
+
|
861
|
+
alias inspect name
|
862
|
+
|
863
|
+
attr_reader :lineno
|
864
|
+
end
|
865
|
+
|
866
|
+
|
790
867
|
class Prec
|
791
868
|
def initialize(symbol, lineno)
|
792
869
|
@symbol = symbol
|
@@ -993,10 +1070,6 @@ module Racc
|
|
993
1070
|
@to_s = '$end'
|
994
1071
|
@serialized = 'false'
|
995
1072
|
@string = false
|
996
|
-
when ErrorSymbolValue
|
997
|
-
@to_s = 'error'
|
998
|
-
@serialized = 'Object.new'
|
999
|
-
@string = false
|
1000
1073
|
else
|
1001
1074
|
raise ArgumentError, "unknown symbol value: #{value.class}"
|
1002
1075
|
end
|
@@ -76,6 +76,9 @@ module Racc
|
|
76
76
|
raise CompileError, "`expect' seen twice"
|
77
77
|
end
|
78
78
|
@grammar.n_expected_srconflicts = num
|
79
|
+
}\
|
80
|
+
| seq(:ERROR_ON_EXPECT_MISMATCH) {|*|
|
81
|
+
@grammar.error_on_expect_mismatch = true
|
79
82
|
}
|
80
83
|
|
81
84
|
g.convdef = seq(:symbol, :STRING) {|sym, code|
|
@@ -133,6 +136,21 @@ module Racc
|
|
133
136
|
| seq("|") {|*|
|
134
137
|
OrMark.new(@scanner.lineno)
|
135
138
|
}\
|
139
|
+
| seq("?") {|*|
|
140
|
+
OptionMark.new(@scanner.lineno)
|
141
|
+
}\
|
142
|
+
| seq("*") {|*|
|
143
|
+
ManyMark.new(@scanner.lineno)
|
144
|
+
}\
|
145
|
+
| seq("+") {|*|
|
146
|
+
Many1Mark.new(@scanner.lineno)
|
147
|
+
}\
|
148
|
+
| seq("(") {|*|
|
149
|
+
GroupStartMark.new(@scanner.lineno)
|
150
|
+
}\
|
151
|
+
| seq(")") {|*|
|
152
|
+
GroupEndMark.new(@scanner.lineno)
|
153
|
+
}\
|
136
154
|
| seq("=", :symbol) {|_, sym|
|
137
155
|
Prec.new(sym, @scanner.lineno)
|
138
156
|
}\
|
@@ -210,27 +228,114 @@ module Racc
|
|
210
228
|
end
|
211
229
|
|
212
230
|
def add_rule_block(list)
|
213
|
-
sprec = nil
|
214
231
|
target = list.shift
|
215
232
|
case target
|
216
|
-
when OrMark, UserAction, Prec
|
233
|
+
when OrMark, OptionMark, ManyMark, Many1Mark, GroupStartMark, GroupEndMark, UserAction, Prec
|
217
234
|
raise CompileError, "#{target.lineno}: unexpected symbol #{target.name}"
|
218
235
|
end
|
236
|
+
enum = list.each.with_index
|
237
|
+
_, sym, idx = _add_rule_block(target, enum)
|
238
|
+
if idx
|
239
|
+
# sym is Racc::GroupEndMark
|
240
|
+
raise "#{sym.lineno}: unexpected symbol ')' at pos=#{idx}"
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def _add_rule_block(target, enum)
|
245
|
+
rules = [] # [ [seqs, sprec], .. ]
|
219
246
|
curr = []
|
220
|
-
|
221
|
-
|
247
|
+
sprec = nil
|
248
|
+
while (sym, idx = enum.next rescue nil)
|
249
|
+
case sym
|
222
250
|
when OrMark
|
223
|
-
|
251
|
+
rules << [curr, sprec]
|
224
252
|
curr = []
|
225
253
|
sprec = nil
|
254
|
+
when OptionMark
|
255
|
+
curr << _add_option_rule(curr.pop)
|
256
|
+
when ManyMark
|
257
|
+
curr << _add_many_rule(curr.pop)
|
258
|
+
when Many1Mark
|
259
|
+
curr << _add_many1_rule(curr.pop)
|
260
|
+
when GroupStartMark
|
261
|
+
curr << _add_group_rule(enum)
|
262
|
+
when GroupEndMark
|
263
|
+
rules << [curr, sprec]
|
264
|
+
return rules, sym, idx
|
226
265
|
when Prec
|
227
266
|
raise CompileError, "'=<prec>' used twice in one rule" if sprec
|
228
|
-
sprec =
|
267
|
+
sprec = sym.symbol
|
229
268
|
else
|
230
|
-
curr.push
|
269
|
+
curr.push sym
|
231
270
|
end
|
232
271
|
end
|
233
|
-
|
272
|
+
rules << [curr, sprec]
|
273
|
+
rules.each do |syms, sprec|
|
274
|
+
add_rule target, syms, sprec
|
275
|
+
end
|
276
|
+
nil
|
277
|
+
end
|
278
|
+
|
279
|
+
|
280
|
+
def _add_option_rule(prev)
|
281
|
+
@option_rule_registry ||= {}
|
282
|
+
target = @option_rule_registry[prev.to_s]
|
283
|
+
return target if target
|
284
|
+
target = _gen_target_name("option", prev)
|
285
|
+
@option_rule_registry[prev.to_s] = target
|
286
|
+
act = UserAction.empty
|
287
|
+
@grammar.add Rule.new(target, [], act)
|
288
|
+
@grammar.add Rule.new(target, [prev], act)
|
289
|
+
target
|
290
|
+
end
|
291
|
+
|
292
|
+
def _add_many_rule(prev)
|
293
|
+
@many_rule_registry ||= {}
|
294
|
+
target = @many_rule_registry[prev.to_s]
|
295
|
+
return target if target
|
296
|
+
target = _gen_target_name("many", prev)
|
297
|
+
@many_rule_registry[prev.to_s] = target
|
298
|
+
src = SourceText.new("result = val[1] ? val[1].unshift(val[0]) : val", __FILE__, __LINE__)
|
299
|
+
act = UserAction.source_text(src)
|
300
|
+
@grammar.add Rule.new(target, [], act)
|
301
|
+
@grammar.add Rule.new(target, [prev, target], act)
|
302
|
+
target
|
303
|
+
end
|
304
|
+
|
305
|
+
def _add_many1_rule(prev)
|
306
|
+
@many1_rule_registry ||= {}
|
307
|
+
target = @many1_rule_registry[prev.to_s]
|
308
|
+
return target if target
|
309
|
+
target = _gen_target_name("many1", prev)
|
310
|
+
@many1_rule_registry[prev.to_s] = target
|
311
|
+
src = SourceText.new("result = val[1] ? val[1].unshift(val[0]) : val", __FILE__, __LINE__)
|
312
|
+
act = UserAction.source_text(src)
|
313
|
+
@grammar.add Rule.new(target, [prev], act)
|
314
|
+
@grammar.add Rule.new(target, [prev, target], act)
|
315
|
+
target
|
316
|
+
end
|
317
|
+
|
318
|
+
def _add_group_rule(enum)
|
319
|
+
target = @grammar.intern("-temp-group", true)
|
320
|
+
rules, _ = _add_rule_block(target, enum)
|
321
|
+
target_name = rules.map{|syms, sprec| syms.join("-")}.join("|")
|
322
|
+
@group_rule_registry ||= {}
|
323
|
+
unless target = @group_rule_registry[target_name]
|
324
|
+
target = @grammar.intern("-group@#{target_name}", true)
|
325
|
+
@group_rule_registry[target_name] = target
|
326
|
+
src = SourceText.new("result = val", __FILE__, __LINE__)
|
327
|
+
act = UserAction.source_text(src)
|
328
|
+
rules.each do |syms, sprec|
|
329
|
+
rule = Rule.new(target, syms, act)
|
330
|
+
rule.specified_prec = sprec
|
331
|
+
@grammar.add rule
|
332
|
+
end
|
333
|
+
end
|
334
|
+
target
|
335
|
+
end
|
336
|
+
|
337
|
+
def _gen_target_name(type, sym)
|
338
|
+
@grammar.intern("-#{type}@#{sym.value}", true)
|
234
339
|
end
|
235
340
|
|
236
341
|
def add_rule(target, list, sprec)
|
@@ -260,9 +365,9 @@ module Racc
|
|
260
365
|
_, *blocks = *@scanner.epilogue.split(/^----/)
|
261
366
|
blocks.each do |block|
|
262
367
|
header, *body = block.lines.to_a
|
263
|
-
label0,
|
368
|
+
label0, paths = *header.sub(/\A-+/, '').split('=', 2)
|
264
369
|
label = canonical_label(label0)
|
265
|
-
(
|
370
|
+
(paths ? paths.strip.split(' ') : []).each do |path|
|
266
371
|
add_user_code label, SourceText.new(File.read(path), path, 1)
|
267
372
|
end
|
268
373
|
add_user_code label, SourceText.new(body.join(''), @filename, line + 1)
|
@@ -391,6 +496,7 @@ module Racc
|
|
391
496
|
'options' => :OPTION,
|
392
497
|
'start' => :START,
|
393
498
|
'expect' => :EXPECT,
|
499
|
+
'error_on_expect_mismatch' => :ERROR_ON_EXPECT_MISMATCH,
|
394
500
|
'class' => :CLASS,
|
395
501
|
'rule' => :RULE,
|
396
502
|
'end' => :END
|
data/lib/racc/info.rb
CHANGED
data/lib/racc/parser-text.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Racc
|
2
2
|
PARSER_TEXT = <<'__end_of_file__'
|
3
|
-
# frozen_string_literal: false
|
4
3
|
#--
|
5
4
|
# Copyright (c) 1999-2006 Minero Aoki
|
6
5
|
#
|
@@ -12,17 +11,23 @@ module Racc
|
|
12
11
|
# without restriction.
|
13
12
|
#++
|
14
13
|
|
15
|
-
|
14
|
+
unless $".find {|p| p.end_with?('/racc/info.rb')}
|
15
|
+
$".push "#{__dir__}/racc/info.rb"
|
16
|
+
|
17
|
+
module Racc
|
18
|
+
VERSION = '1.8.0'
|
19
|
+
Version = VERSION
|
20
|
+
Copyright = 'Copyright (c) 1999-2006 Minero Aoki'
|
21
|
+
end
|
16
22
|
|
17
|
-
unless defined?(NotImplementedError)
|
18
|
-
NotImplementedError = NotImplementError # :nodoc:
|
19
23
|
end
|
20
24
|
|
25
|
+
|
21
26
|
module Racc
|
22
27
|
class ParseError < StandardError; end
|
23
28
|
end
|
24
29
|
unless defined?(::ParseError)
|
25
|
-
ParseError = Racc::ParseError
|
30
|
+
ParseError = Racc::ParseError # :nodoc:
|
26
31
|
end
|
27
32
|
|
28
33
|
# Racc is a LALR(1) parser generator.
|
@@ -55,10 +60,12 @@ end
|
|
55
60
|
# [-v, --verbose]
|
56
61
|
# verbose mode. create +filename+.output file, like yacc's y.output file.
|
57
62
|
# [-g, --debug]
|
58
|
-
# add debug code to parser class. To display
|
63
|
+
# add debug code to parser class. To display debugging information,
|
59
64
|
# use this '-g' option and set @yydebug true in parser class.
|
60
65
|
# [-E, --embedded]
|
61
66
|
# Output parser which doesn't need runtime files (racc/parser.rb).
|
67
|
+
# [-F, --frozen]
|
68
|
+
# Output parser which declares frozen_string_literals: true
|
62
69
|
# [-C, --check-only]
|
63
70
|
# Check syntax of racc grammar file and quit.
|
64
71
|
# [-S, --output-status]
|
@@ -262,11 +269,11 @@ module Racc
|
|
262
269
|
# def next_token
|
263
270
|
# @q.shift
|
264
271
|
# end
|
265
|
-
class_eval
|
272
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
266
273
|
def do_parse
|
267
274
|
#{Racc_Main_Parsing_Routine}(_racc_setup(), false)
|
268
275
|
end
|
269
|
-
|
276
|
+
RUBY
|
270
277
|
|
271
278
|
# The method to fetch next token.
|
272
279
|
# If you use #do_parse method, you must implement #next_token.
|
@@ -324,11 +331,11 @@ module Racc
|
|
324
331
|
#
|
325
332
|
# RECEIVER#METHOD_ID is a method to get next token.
|
326
333
|
# It must 'yield' the token, which format is [TOKEN-SYMBOL, VALUE].
|
327
|
-
class_eval
|
334
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
328
335
|
def yyparse(recv, mid)
|
329
336
|
#{Racc_YY_Parse_Method}(recv, mid, _racc_setup(), false)
|
330
337
|
end
|
331
|
-
|
338
|
+
RUBY
|
332
339
|
|
333
340
|
def _racc_yyparse_rb(recv, mid, arg, c_debug)
|
334
341
|
action_table, action_check, action_default, action_pointer,
|
@@ -537,7 +544,7 @@ module Racc
|
|
537
544
|
#
|
538
545
|
# If this method returns, parsers enter "error recovering mode".
|
539
546
|
def on_error(t, val, vstack)
|
540
|
-
raise ParseError, sprintf("
|
547
|
+
raise ParseError, sprintf("parse error on value %s (%s)",
|
541
548
|
val.inspect, token_to_str(t) || '?')
|
542
549
|
end
|
543
550
|
|
data/lib/racc/parser.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#--
|
3
3
|
# Copyright (c) 1999-2006 Minero Aoki
|
4
4
|
#
|
@@ -12,15 +12,11 @@
|
|
12
12
|
|
13
13
|
require 'racc/info'
|
14
14
|
|
15
|
-
unless defined?(NotImplementedError)
|
16
|
-
NotImplementedError = NotImplementError # :nodoc:
|
17
|
-
end
|
18
|
-
|
19
15
|
module Racc
|
20
16
|
class ParseError < StandardError; end
|
21
17
|
end
|
22
18
|
unless defined?(::ParseError)
|
23
|
-
ParseError = Racc::ParseError
|
19
|
+
ParseError = Racc::ParseError # :nodoc:
|
24
20
|
end
|
25
21
|
|
26
22
|
# Racc is a LALR(1) parser generator.
|
@@ -53,10 +49,12 @@ end
|
|
53
49
|
# [-v, --verbose]
|
54
50
|
# verbose mode. create +filename+.output file, like yacc's y.output file.
|
55
51
|
# [-g, --debug]
|
56
|
-
# add debug code to parser class. To display
|
52
|
+
# add debug code to parser class. To display debugging information,
|
57
53
|
# use this '-g' option and set @yydebug true in parser class.
|
58
54
|
# [-E, --embedded]
|
59
55
|
# Output parser which doesn't need runtime files (racc/parser.rb).
|
56
|
+
# [-F, --frozen]
|
57
|
+
# Output parser which declares frozen_string_literals: true
|
60
58
|
# [-C, --check-only]
|
61
59
|
# Check syntax of racc grammar file and quit.
|
62
60
|
# [-S, --output-status]
|
@@ -260,11 +258,11 @@ module Racc
|
|
260
258
|
# def next_token
|
261
259
|
# @q.shift
|
262
260
|
# end
|
263
|
-
class_eval
|
261
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
264
262
|
def do_parse
|
265
263
|
#{Racc_Main_Parsing_Routine}(_racc_setup(), false)
|
266
264
|
end
|
267
|
-
|
265
|
+
RUBY
|
268
266
|
|
269
267
|
# The method to fetch next token.
|
270
268
|
# If you use #do_parse method, you must implement #next_token.
|
@@ -322,11 +320,11 @@ module Racc
|
|
322
320
|
#
|
323
321
|
# RECEIVER#METHOD_ID is a method to get next token.
|
324
322
|
# It must 'yield' the token, which format is [TOKEN-SYMBOL, VALUE].
|
325
|
-
class_eval
|
323
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
326
324
|
def yyparse(recv, mid)
|
327
325
|
#{Racc_YY_Parse_Method}(recv, mid, _racc_setup(), false)
|
328
326
|
end
|
329
|
-
|
327
|
+
RUBY
|
330
328
|
|
331
329
|
def _racc_yyparse_rb(recv, mid, arg, c_debug)
|
332
330
|
action_table, action_check, action_default, action_pointer,
|
@@ -535,7 +533,7 @@ module Racc
|
|
535
533
|
#
|
536
534
|
# If this method returns, parsers enter "error recovering mode".
|
537
535
|
def on_error(t, val, vstack)
|
538
|
-
raise ParseError, sprintf("
|
536
|
+
raise ParseError, sprintf("parse error on value %s (%s)",
|
539
537
|
val.inspect, token_to_str(t) || '?')
|
540
538
|
end
|
541
539
|
|
@@ -45,6 +45,7 @@ module Racc
|
|
45
45
|
bool_attr :convert_line
|
46
46
|
bool_attr :convert_line_all
|
47
47
|
bool_attr :embed_runtime
|
48
|
+
bool_attr :frozen_strings
|
48
49
|
bool_attr :make_executable
|
49
50
|
attr_accessor :interpreter
|
50
51
|
|
@@ -64,6 +65,7 @@ module Racc
|
|
64
65
|
self.convert_line = true
|
65
66
|
self.convert_line_all = false
|
66
67
|
self.embed_runtime = false
|
68
|
+
self.frozen_strings = false
|
67
69
|
self.make_executable = false
|
68
70
|
self.interpreter = nil
|
69
71
|
end
|
@@ -122,6 +124,7 @@ module Racc
|
|
122
124
|
end
|
123
125
|
|
124
126
|
def notice
|
127
|
+
line %q[# frozen_string_literal: true] if @params.frozen_strings?
|
125
128
|
line %q[#]
|
126
129
|
line %q[# DO NOT MODIFY!!!!]
|
127
130
|
line %Q[# This file is automatically generated by Racc #{Racc::Version}]
|
@@ -135,8 +138,8 @@ module Racc
|
|
135
138
|
|
136
139
|
def embed_library(src)
|
137
140
|
line %[###### #{src.filename} begin]
|
138
|
-
line %[unless $".
|
139
|
-
line %[$".push
|
141
|
+
line %[unless $".find {|p| p.end_with?('/#{src.filename}')}]
|
142
|
+
line %[$".push "\#{__dir__}/#{src.filename}"]
|
140
143
|
put src, @params.convert_line?
|
141
144
|
line %[end]
|
142
145
|
line %[###### #{src.filename} end]
|
@@ -310,8 +313,10 @@ module Racc
|
|
310
313
|
racc_reduce_n,
|
311
314
|
racc_use_result_var ]
|
312
315
|
End
|
316
|
+
line "Ractor.make_shareable(Racc_arg) if defined?(Ractor)"
|
313
317
|
line
|
314
318
|
string_list 'Racc_token_to_s_table', table.token_to_s_table
|
319
|
+
line "Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor)"
|
315
320
|
line
|
316
321
|
line "Racc_debug_parser = #{table.debug_parser}"
|
317
322
|
line
|
data/lib/racc/state.rb
CHANGED