racc 1.7.1 → 1.8.1
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/BSDL +22 -0
- data/COPYING +56 -22
- data/ChangeLog +3 -3
- data/README.ja.rdoc +2 -38
- data/README.rdoc +8 -27
- 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 -47
- data/ext/racc/cparse/extconf.rb +3 -4
- data/lib/racc/grammar.rb +82 -5
- data/lib/racc/grammarfileparser.rb +119 -13
- data/lib/racc/info.rb +2 -1
- data/lib/racc/parser-text.rb +6 -20
- data/lib/racc/parser.rb +6 -8
- data/lib/racc/parserfilegenerator.rb +6 -3
- data/lib/racc/state.rb +7 -3
- data/lib/racc/statetransitiontable.rb +1 -1
- data/lib/racc/static.rb +5 -5
- data/lib/racc.rb +6 -6
- metadata +7 -8
- data/doc/en/NEWS.en.rdoc +0 -282
- data/doc/ja/NEWS.ja.rdoc +0 -307
- data/ext/racc/MANIFEST +0 -4
@@ -10,11 +10,11 @@
|
|
10
10
|
#
|
11
11
|
#++
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
require_relative '../racc'
|
14
|
+
require_relative 'compat'
|
15
|
+
require_relative 'grammar'
|
16
|
+
require_relative 'parserfilegenerator'
|
17
|
+
require_relative 'sourcetext'
|
18
18
|
require 'stringio'
|
19
19
|
|
20
20
|
module Racc
|
@@ -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", @filename, @scanner.lineno + 1)
|
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", @filename, @scanner.lineno + 1)
|
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", @filename, @scanner.lineno + 1)
|
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)
|
@@ -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
|
#
|
@@ -14,20 +13,9 @@ module Racc
|
|
14
13
|
|
15
14
|
unless $".find {|p| p.end_with?('/racc/info.rb')}
|
16
15
|
$".push "#{__dir__}/racc/info.rb"
|
17
|
-
#--
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# Copyright (c) 1999-2006 Minero Aoki
|
22
|
-
#
|
23
|
-
# This program is free software.
|
24
|
-
# You can distribute/modify this program under the same terms of ruby.
|
25
|
-
# see the file "COPYING".
|
26
|
-
#
|
27
|
-
#++
|
28
16
|
|
29
17
|
module Racc
|
30
|
-
VERSION = '1.
|
18
|
+
VERSION = '1.8.1'
|
31
19
|
Version = VERSION
|
32
20
|
Copyright = 'Copyright (c) 1999-2006 Minero Aoki'
|
33
21
|
end
|
@@ -35,10 +23,6 @@ end
|
|
35
23
|
end
|
36
24
|
|
37
25
|
|
38
|
-
unless defined?(NotImplementedError)
|
39
|
-
NotImplementedError = NotImplementError # :nodoc:
|
40
|
-
end
|
41
|
-
|
42
26
|
module Racc
|
43
27
|
class ParseError < StandardError; end
|
44
28
|
end
|
@@ -46,7 +30,7 @@ unless defined?(::ParseError)
|
|
46
30
|
ParseError = Racc::ParseError # :nodoc:
|
47
31
|
end
|
48
32
|
|
49
|
-
# Racc is
|
33
|
+
# Racc is an LALR(1) parser generator.
|
50
34
|
# It is written in Ruby itself, and generates Ruby programs.
|
51
35
|
#
|
52
36
|
# == Command-line Reference
|
@@ -76,10 +60,12 @@ end
|
|
76
60
|
# [-v, --verbose]
|
77
61
|
# verbose mode. create +filename+.output file, like yacc's y.output file.
|
78
62
|
# [-g, --debug]
|
79
|
-
# add debug code to parser class. To display
|
63
|
+
# add debug code to parser class. To display debugging information,
|
80
64
|
# use this '-g' option and set @yydebug true in parser class.
|
81
65
|
# [-E, --embedded]
|
82
66
|
# Output parser which doesn't need runtime files (racc/parser.rb).
|
67
|
+
# [-F, --frozen]
|
68
|
+
# Output parser which declares frozen_string_literals: true
|
83
69
|
# [-C, --check-only]
|
84
70
|
# Check syntax of racc grammar file and quit.
|
85
71
|
# [-S, --output-status]
|
@@ -558,7 +544,7 @@ module Racc
|
|
558
544
|
#
|
559
545
|
# If this method returns, parsers enter "error recovering mode".
|
560
546
|
def on_error(t, val, vstack)
|
561
|
-
raise ParseError, sprintf("
|
547
|
+
raise ParseError, sprintf("parse error on value %s (%s)",
|
562
548
|
val.inspect, token_to_str(t) || '?')
|
563
549
|
end
|
564
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,10 +12,6 @@
|
|
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
|
@@ -23,7 +19,7 @@ unless defined?(::ParseError)
|
|
23
19
|
ParseError = Racc::ParseError # :nodoc:
|
24
20
|
end
|
25
21
|
|
26
|
-
# Racc is
|
22
|
+
# Racc is an LALR(1) parser generator.
|
27
23
|
# It is written in Ruby itself, and generates Ruby programs.
|
28
24
|
#
|
29
25
|
# == Command-line Reference
|
@@ -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]
|
@@ -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
|
|
@@ -10,9 +10,9 @@
|
|
10
10
|
#
|
11
11
|
#++
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
require_relative 'compat'
|
14
|
+
require_relative 'sourcetext'
|
15
|
+
require_relative 'parser-text'
|
16
16
|
require 'rbconfig'
|
17
17
|
|
18
18
|
module Racc
|
@@ -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}]
|
data/lib/racc/state.rb
CHANGED
@@ -10,9 +10,9 @@
|
|
10
10
|
#
|
11
11
|
#++
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
require_relative 'iset'
|
14
|
+
require_relative 'statetransitiontable'
|
15
|
+
require_relative 'exception'
|
16
16
|
require 'forwardable'
|
17
17
|
|
18
18
|
module Racc
|
@@ -73,6 +73,10 @@ module Racc
|
|
73
73
|
(n_srconflicts() != @grammar.n_expected_srconflicts)
|
74
74
|
end
|
75
75
|
|
76
|
+
def should_error_on_expect_mismatch?
|
77
|
+
should_report_srconflict? && @grammar.error_on_expect_mismatch
|
78
|
+
end
|
79
|
+
|
76
80
|
def srconflict_exist?
|
77
81
|
n_srconflicts() != 0
|
78
82
|
end
|
data/lib/racc/static.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require_relative '../racc'
|
2
|
+
require_relative 'parser'
|
3
|
+
require_relative 'grammarfileparser'
|
4
|
+
require_relative 'parserfilegenerator'
|
5
|
+
require_relative 'logfilegenerator'
|
data/lib/racc.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
require_relative 'racc/compat'
|
2
|
+
require_relative 'racc/debugflags'
|
3
|
+
require_relative 'racc/grammar'
|
4
|
+
require_relative 'racc/state'
|
5
|
+
require_relative 'racc/exception'
|
6
|
+
require_relative 'racc/info'
|
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.
|
4
|
+
version: 1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Minero Aoki
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-07-30 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: |
|
15
|
-
Racc is
|
15
|
+
Racc is an LALR(1) parser generator.
|
16
16
|
It is written in Ruby itself, and generates Ruby program.
|
17
17
|
|
18
18
|
NOTE: Ruby 1.8.x comes with Racc runtime module. You
|
@@ -29,23 +29,21 @@ extra_rdoc_files:
|
|
29
29
|
- README.ja.rdoc
|
30
30
|
- README.rdoc
|
31
31
|
files:
|
32
|
+
- BSDL
|
32
33
|
- COPYING
|
33
34
|
- ChangeLog
|
34
35
|
- README.ja.rdoc
|
35
36
|
- README.rdoc
|
36
37
|
- TODO
|
37
38
|
- bin/racc
|
38
|
-
- doc/en/NEWS.en.rdoc
|
39
39
|
- doc/en/grammar.en.rdoc
|
40
40
|
- doc/en/grammar2.en.rdoc
|
41
|
-
- doc/ja/NEWS.ja.rdoc
|
42
41
|
- doc/ja/command.ja.html
|
43
42
|
- doc/ja/debug.ja.rdoc
|
44
43
|
- doc/ja/grammar.ja.rdoc
|
45
44
|
- doc/ja/index.ja.html
|
46
45
|
- doc/ja/parser.ja.rdoc
|
47
46
|
- doc/ja/usage.ja.html
|
48
|
-
- ext/racc/MANIFEST
|
49
47
|
- ext/racc/cparse/cparse.c
|
50
48
|
- ext/racc/cparse/extconf.rb
|
51
49
|
- lib/racc.rb
|
@@ -68,7 +66,8 @@ homepage: https://github.com/ruby/racc
|
|
68
66
|
licenses:
|
69
67
|
- Ruby
|
70
68
|
- BSD-2-Clause
|
71
|
-
metadata:
|
69
|
+
metadata:
|
70
|
+
changelog_uri: https://github.com/ruby/racc/releases
|
72
71
|
post_install_message:
|
73
72
|
rdoc_options:
|
74
73
|
- "--main"
|
@@ -89,5 +88,5 @@ requirements: []
|
|
89
88
|
rubygems_version: 3.5.0.dev
|
90
89
|
signing_key:
|
91
90
|
specification_version: 4
|
92
|
-
summary: Racc is
|
91
|
+
summary: Racc is an LALR(1) parser generator
|
93
92
|
test_files: []
|