racc 1.6.2 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,11 +10,11 @@
10
10
  #
11
11
  #++
12
12
 
13
- require 'racc'
14
- require 'racc/compat'
15
- require 'racc/grammar'
16
- require 'racc/parserfilegenerator'
17
- require 'racc/sourcetext'
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
- list.each do |i|
221
- case i
247
+ sprec = nil
248
+ while (sym, idx = enum.next rescue nil)
249
+ case sym
222
250
  when OrMark
223
- add_rule target, curr, sprec
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 = i.symbol
267
+ sprec = sym.symbol
229
268
  else
230
- curr.push i
269
+ curr.push sym
231
270
  end
232
271
  end
233
- add_rule target, curr, sprec
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #--
2
3
  #
3
4
  #
@@ -11,7 +12,7 @@
11
12
  #++
12
13
 
13
14
  module Racc
14
- VERSION = '1.6.2'
15
+ VERSION = '1.8.1'
15
16
  Version = VERSION
16
17
  Copyright = 'Copyright (c) 1999-2006 Minero Aoki'
17
18
  end
@@ -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,12 +11,18 @@ module Racc
12
11
  # without restriction.
13
12
  #++
14
13
 
15
- require 'racc/info'
14
+ unless $".find {|p| p.end_with?('/racc/info.rb')}
15
+ $".push "#{__dir__}/racc/info.rb"
16
+
17
+ module Racc
18
+ VERSION = '1.8.1'
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
@@ -25,7 +30,7 @@ unless defined?(::ParseError)
25
30
  ParseError = Racc::ParseError # :nodoc:
26
31
  end
27
32
 
28
- # Racc is a LALR(1) parser generator.
33
+ # Racc is an LALR(1) parser generator.
29
34
  # It is written in Ruby itself, and generates Ruby programs.
30
35
  #
31
36
  # == Command-line Reference
@@ -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 debuggin information,
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("\nparse error on value %s (%s)",
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: false
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 a LALR(1) parser generator.
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 debuggin information,
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("\nparse error on value %s (%s)",
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
- require 'racc/compat'
14
- require 'racc/sourcetext'
15
- require 'racc/parser-text'
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}]
@@ -135,8 +138,8 @@ module Racc
135
138
 
136
139
  def embed_library(src)
137
140
  line %[###### #{src.filename} begin]
138
- line %[unless $".index '#{src.filename}']
139
- line %[$".push '#{src.filename}']
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
@@ -10,9 +10,9 @@
10
10
  #
11
11
  #++
12
12
 
13
- require 'racc/iset'
14
- require 'racc/statetransitiontable'
15
- require 'racc/exception'
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
@@ -10,7 +10,7 @@
10
10
  #
11
11
  #++
12
12
 
13
- require 'racc/parser'
13
+ require_relative 'parser'
14
14
 
15
15
  module Racc
16
16
 
data/lib/racc/static.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'racc'
2
- require 'racc/parser'
3
- require 'racc/grammarfileparser'
4
- require 'racc/parserfilegenerator'
5
- require 'racc/logfilegenerator'
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
- require 'racc/compat'
2
- require 'racc/debugflags'
3
- require 'racc/grammar'
4
- require 'racc/state'
5
- require 'racc/exception'
6
- require 'racc/info'
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.6.2
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: 2022-12-23 00:00:00.000000000 Z
12
+ date: 2024-07-30 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: |
15
- Racc is a LALR(1) parser generator.
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"
@@ -86,8 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
85
  - !ruby/object:Gem::Version
87
86
  version: '0'
88
87
  requirements: []
89
- rubygems_version: 3.4.0.dev
88
+ rubygems_version: 3.5.0.dev
90
89
  signing_key:
91
90
  specification_version: 4
92
- summary: Racc is a LALR(1) parser generator
91
+ summary: Racc is an LALR(1) parser generator
93
92
  test_files: []