racc 1.5.0 → 1.5.2

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: d8ef721486df64a0671227425cfe65236120a1fcd50eb47beb438f56ec695d84
4
- data.tar.gz: c557e798345c2048e2c6c011c7f4d5a9fca4a1a56df5f0a9e6f504b448525365
3
+ metadata.gz: edf5dcefea26cb0246401ee59480890de48d5d84885423b882f39ae4394e56fc
4
+ data.tar.gz: 0b0c54b36dbc6be20469e57cd7538c94ff6b6f060383d6946f578e3baab3a03b
5
5
  SHA512:
6
- metadata.gz: b0251224598376abd45a97a63b84eed99cad5fcb49c0046db2f5f4a6469ea76cd452f5a77c428b9dbe4d4f9b09137f538c03c1936e643f6786c6935f3584ef7c
7
- data.tar.gz: 85ff1df73d7047c567432136c8461a46b3b8d66546cbea7de47dd4c174167467d24f42123e324eb742d3b7ce0fe8d9be0f8d9bc1fa3631cb29d3cd6a78bbf3b5
6
+ metadata.gz: fecf83ab9be1bd80075e10cd966f85eb11a5a5f3b9786481e13b74401e528cf807a35b55a82408b0c638f8d320e298ec199b0599b80b3ca780a2684df04335b0
7
+ data.tar.gz: 2a6029118b2edcf9164957b1d9a7ac14292c5694bf49bb0e7c156bead403a6302920fced609b79772a6d0a4979cce5aacffd11b3125fcfc621f5b2dd6cfd54c8
@@ -16,8 +16,6 @@
16
16
  == Requirement
17
17
 
18
18
  * Ruby 1.8.x or later.
19
- (*) make and C compiler.
20
-
21
19
 
22
20
  == Installation
23
21
 
@@ -36,9 +34,9 @@
36
34
 
37
35
  You can install Racc into your favorite directory by giving
38
36
  options to setup.rb. e.g.
39
-
37
+
40
38
  $ ruby setup.rb config --prefix=/usr
41
-
39
+
42
40
  For details, try "ruby setup.rb --help".
43
41
 
44
42
 
data/Rakefile CHANGED
@@ -74,4 +74,6 @@ else
74
74
  task :compile => 'lib/racc/parser-text.rb'
75
75
  end
76
76
 
77
+ task :build => "lib/racc/parser-text.rb"
78
+
77
79
  task :test => :compile
data/bin/racc CHANGED
@@ -51,7 +51,7 @@ def main
51
51
  logfilename = path
52
52
  }
53
53
  parser.on('-e', '--executable [RUBYPATH]', 'Makes executable parser.') {|path|
54
- executable = true
54
+ make_executable = true
55
55
  rubypath = (path == 'ruby' ? nil : path)
56
56
  }
57
57
  parser.on('-E', '--embedded', "Embeds Racc runtime in output.") {
@@ -71,10 +71,6 @@ def main
71
71
  'Uses CLASSNAME instead of Racc::Parser.') {|name|
72
72
  superclass = name
73
73
  }
74
- parser.on('--runtime=FEATURE',
75
- "Uses FEATURE instead of 'racc/parser'") {|feat|
76
- runtime = feature
77
- }
78
74
  parser.on('-C', '--check-only', 'Checks syntax and quit immediately.') {|fl|
79
75
  check_only = fl
80
76
  }
@@ -88,20 +84,20 @@ def main
88
84
  debug_flags = Racc::DebugFlags.parse_option_string(flags)
89
85
  }
90
86
  #parser.on('--no-extensions', 'Run Racc without any Ruby extension.') {
91
- # Racc.const_set :Racc_No_Extentions, true
87
+ # Racc.const_set :Racc_No_Extensions, true
92
88
  #}
93
89
  parser.on('--version', 'Prints version and quit.') {
94
90
  puts "racc version #{Racc::Version}"
95
91
  exit 0
96
92
  }
97
93
  parser.on('--runtime-version', 'Prints runtime version and quit.') {
98
- printf "racc runtime version %s (rev. %s); %s\n",
94
+ printf "racc runtime version %s; %s\n",
99
95
  Racc::Parser::Racc_Runtime_Version,
100
96
  if Racc::Parser.racc_runtime_type == 'ruby'
101
- sprintf('ruby core version %s (rev. %s)',
97
+ sprintf('ruby core version %s',
102
98
  Racc::Parser::Racc_Runtime_Core_Version_R)
103
99
  else
104
- sprintf('c core version %s (rev. %s)',
100
+ sprintf('c core version %s',
105
101
  Racc::Parser::Racc_Runtime_Core_Version_C)
106
102
  end
107
103
  exit 0
@@ -184,8 +180,12 @@ def main
184
180
  log_useless states.grammar
185
181
  log_conflict states
186
182
  else
187
- report_useless states.grammar
188
- report_conflict states
183
+ has_useless = report_useless states.grammar
184
+ has_conflicts = report_conflict states
185
+ if has_useless || has_conflicts
186
+ preamble = make_logfile ? 'C' : 'Turn on logging with "-v" and c'
187
+ $stderr.puts %Q{#{preamble}heck ".output" file for details}
188
+ end
189
189
  end
190
190
 
191
191
  profiler.report
@@ -201,13 +201,29 @@ def make_filename(path, suffix)
201
201
  path.sub(/(?:\..*?)?\z/, suffix)
202
202
  end
203
203
 
204
+ LIST_LIMIT = 10
205
+ def report_list(enum, label)
206
+ c = enum.count
207
+ if c > 0
208
+ $stderr.puts "#{c} #{label}:"
209
+ enum.first(LIST_LIMIT).each do |item|
210
+ $stderr.puts " #{yield item}"
211
+ end
212
+ $stderr.puts " ..." if c > LIST_LIMIT
213
+ end
214
+ end
215
+
216
+ # @return [Boolean] if anything was reported
204
217
  def report_conflict(states)
205
218
  if states.should_report_srconflict?
219
+ reported = true
206
220
  $stderr.puts "#{states.n_srconflicts} shift/reduce conflicts"
207
221
  end
208
222
  if states.rrconflict_exist?
223
+ reported = true
209
224
  $stderr.puts "#{states.n_rrconflicts} reduce/reduce conflicts"
210
225
  end
226
+ reported
211
227
  end
212
228
 
213
229
  def log_conflict(states)
@@ -222,16 +238,17 @@ def log_conflict(states)
222
238
  }
223
239
  end
224
240
 
241
+ # @return [Boolean] if anything was reported
225
242
  def report_useless(grammar)
226
- if grammar.useless_nonterminal_exist?
227
- $stderr.puts "#{grammar.n_useless_nonterminals} useless nonterminals"
228
- end
229
- if grammar.useless_rule_exist?
230
- $stderr.puts "#{grammar.n_useless_rules} useless rules"
231
- end
243
+ reported = report_list(grammar.each_useless_nonterminal, 'useless nonterminals', &:to_s)
244
+
245
+ reported ||= report_list(grammar.each_useless_rule, 'useless rules') { |r| "##{r.ident} (#{r.target})" }
246
+
232
247
  if grammar.start.useless?
233
248
  $stderr.puts 'fatal: start symbol does not derive any sentence'
249
+ reported = true
234
250
  end
251
+ reported
235
252
  end
236
253
 
237
254
  def log_useless(grammar)
@@ -605,7 +605,7 @@ parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
605
605
  user_yyerror:
606
606
  if (v->errstatus == 3) {
607
607
  if (v->t == vFINAL_TOKEN) {
608
- v->retval = Qfalse;
608
+ v->retval = Qnil;
609
609
  v->fin = CP_FIN_EOT;
610
610
  return;
611
611
  }
@@ -819,14 +819,16 @@ reduce0(RB_BLOCK_CALL_FUNC_ARGLIST(_, data))
819
819
  void
820
820
  Init_cparse(void)
821
821
  {
822
- #undef rb_intern
823
- #define rb_intern(str) rb_intern_const(str)
822
+ #if HAVE_RB_EXT_RACTOR_SAFE
823
+ rb_ext_ractor_safe(true);
824
+ #endif
825
+
824
826
  VALUE Racc, Parser;
825
- ID id_racc = rb_intern("Racc");
827
+ ID id_racc = rb_intern_const("Racc");
826
828
 
827
829
  if (rb_const_defined(rb_cObject, id_racc)) {
828
830
  Racc = rb_const_get(rb_cObject, id_racc);
829
- Parser = rb_const_get_at(Racc, rb_intern("Parser"));
831
+ Parser = rb_const_get_at(Racc, rb_intern_const("Parser"));
830
832
  }
831
833
  else {
832
834
  Racc = rb_define_module("Racc");
@@ -846,16 +848,16 @@ Init_cparse(void)
846
848
 
847
849
  RaccBug = rb_eRuntimeError;
848
850
 
849
- id_yydebug = rb_intern("@yydebug");
850
- id_nexttoken = rb_intern("next_token");
851
- id_onerror = rb_intern("on_error");
852
- id_noreduce = rb_intern("_reduce_none");
853
- id_errstatus = rb_intern("@racc_error_status");
854
-
855
- id_d_shift = rb_intern("racc_shift");
856
- id_d_reduce = rb_intern("racc_reduce");
857
- id_d_accept = rb_intern("racc_accept");
858
- id_d_read_token = rb_intern("racc_read_token");
859
- id_d_next_state = rb_intern("racc_next_state");
860
- 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");
861
863
  }
@@ -5,9 +5,8 @@
5
5
  # Copyright (c) 1999-2006 Minero Aoki
6
6
  #
7
7
  # This program is free software.
8
- # You can distribute/modify this program under the terms of
9
- # the GNU LGPL, Lesser General Public License version 2.1.
10
- # 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".
11
10
  #
12
11
  #++
13
12
 
@@ -5,9 +5,8 @@
5
5
  # Copyright (c) 1999-2006 Minero Aoki
6
6
  #
7
7
  # This program is free software.
8
- # You can distribute/modify this program under the terms of
9
- # the GNU LGPL, Lesser General Public License version 2.1.
10
- # 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".
11
10
  #
12
11
  #++
13
12
 
@@ -86,14 +86,15 @@ module Racc
86
86
  end
87
87
 
88
88
  def n_useless_nonterminals
89
- @n_useless_nonterminals ||=
90
- begin
91
- n = 0
92
- @symboltable.each_nonterminal do |sym|
93
- n += 1 if sym.useless?
94
- end
95
- n
96
- 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
97
98
  end
98
99
 
99
100
  def useless_rule_exist?
@@ -101,14 +102,15 @@ module Racc
101
102
  end
102
103
 
103
104
  def n_useless_rules
104
- @n_useless_rules ||=
105
- begin
106
- n = 0
107
- each do |r|
108
- n += 1 if r.useless?
109
- end
110
- n
111
- 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
112
114
  end
113
115
 
114
116
  def nfa
@@ -5,9 +5,8 @@
5
5
  # Copyright (c) 1999-2006 Minero Aoki
6
6
  #
7
7
  # This program is free software.
8
- # You can distribute/modify this program under the terms of
9
- # the GNU LGPL, Lesser General Public License version 2.1.
10
- # 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".
11
10
  #
12
11
  #++
13
12
 
@@ -288,7 +287,7 @@ module Racc
288
287
  end
289
288
 
290
289
  def add_user_code(label, src)
291
- @result.params.send(USER_CODE_LABELS[label]).push src
290
+ @result.params.public_send(USER_CODE_LABELS[label]).push src
292
291
  end
293
292
 
294
293
  end
@@ -11,7 +11,7 @@
11
11
  #++
12
12
 
13
13
  module Racc
14
- VERSION = '1.5.0'
14
+ VERSION = '1.5.2'
15
15
  Version = VERSION
16
16
  Copyright = 'Copyright (c) 1999-2006 Minero Aoki'
17
17
  end
@@ -5,9 +5,8 @@
5
5
  # Copyright (c) 1999-2006 Minero Aoki
6
6
  #
7
7
  # This program is free software.
8
- # You can distribute/modify this program under the terms of
9
- # the GNU LGPL, Lesser General Public License version 2.1.
10
- # 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".
11
10
  #
12
11
  #++
13
12
 
@@ -5,9 +5,8 @@
5
5
  # Copyright (c) 1999-2006 Minero Aoki
6
6
  #
7
7
  # This program is free software.
8
- # You can distribute/modify this program under the terms of
9
- # the GNU LGPL, Lesser General Public License version 2.1.
10
- # 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".
11
10
  #
12
11
  #++
13
12
 
@@ -181,8 +181,8 @@ end
181
181
  # Your own parser is completely yours.
182
182
  module Racc
183
183
 
184
- unless defined?(Racc_No_Extentions)
185
- Racc_No_Extentions = false # :nodoc:
184
+ unless defined?(Racc_No_Extensions)
185
+ Racc_No_Extensions = false # :nodoc:
186
186
  end
187
187
 
188
188
  class Parser
@@ -202,7 +202,7 @@ module Racc
202
202
  unless new.respond_to?(:_racc_do_parse_c, true)
203
203
  raise LoadError, 'old cparse.so'
204
204
  end
205
- if Racc_No_Extentions
205
+ if Racc_No_Extensions
206
206
  raise LoadError, 'selecting ruby version of racc runtime core'
207
207
  end
208
208
 
@@ -326,7 +326,7 @@ module Racc
326
326
  # It must 'yield' the token, which format is [TOKEN-SYMBOL, VALUE].
327
327
  class_eval %{
328
328
  def yyparse(recv, mid)
329
- #{Racc_YY_Parse_Method}(recv, mid, _racc_setup(), true)
329
+ #{Racc_YY_Parse_Method}(recv, mid, _racc_setup(), false)
330
330
  end
331
331
  }
332
332
 
@@ -179,8 +179,8 @@ end
179
179
  # Your own parser is completely yours.
180
180
  module Racc
181
181
 
182
- unless defined?(Racc_No_Extentions)
183
- Racc_No_Extentions = false # :nodoc:
182
+ unless defined?(Racc_No_Extensions)
183
+ Racc_No_Extensions = false # :nodoc:
184
184
  end
185
185
 
186
186
  class Parser
@@ -200,7 +200,7 @@ module Racc
200
200
  unless new.respond_to?(:_racc_do_parse_c, true)
201
201
  raise LoadError, 'old cparse.so'
202
202
  end
203
- if Racc_No_Extentions
203
+ if Racc_No_Extensions
204
204
  raise LoadError, 'selecting ruby version of racc runtime core'
205
205
  end
206
206
 
@@ -324,7 +324,7 @@ module Racc
324
324
  # It must 'yield' the token, which format is [TOKEN-SYMBOL, VALUE].
325
325
  class_eval %{
326
326
  def yyparse(recv, mid)
327
- #{Racc_YY_Parse_Method}(recv, mid, _racc_setup(), true)
327
+ #{Racc_YY_Parse_Method}(recv, mid, _racc_setup(), false)
328
328
  end
329
329
  }
330
330
 
@@ -10,7 +10,6 @@
10
10
  #
11
11
  #++
12
12
 
13
- require 'enumerator'
14
13
  require 'racc/compat'
15
14
  require 'racc/sourcetext'
16
15
  require 'racc/parser-text'
@@ -5,9 +5,8 @@
5
5
  # Copyright (c) 1999-2006 Minero Aoki
6
6
  #
7
7
  # This program is free software.
8
- # You can distribute/modify this program under the terms of
9
- # the GNU LGPL, Lesser General Public License version 2.1.
10
- # 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".
11
10
  #
12
11
  #++
13
12
 
@@ -5,9 +5,8 @@
5
5
  # Copyright (c) 1999-2006 Minero Aoki
6
6
  #
7
7
  # This program is free software.
8
- # You can distribute/modify this program under the terms of
9
- # the GNU LGPL, Lesser General Public License version 2.1.
10
- # 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".
11
10
  #
12
11
  #++
13
12
 
@@ -231,7 +230,7 @@ module Racc
231
230
  map = '-' * 10240
232
231
 
233
232
  # sort long to short
234
- entries.sort! {|a,b| b[0].size <=> a[0].size }
233
+ entries.sort_by!.with_index {|a,i| [-a[0].size, i] }
235
234
 
236
235
  entries.each do |arr, chkval, expr, min, ptri|
237
236
  if upper + arr.size > map.size
@@ -86,11 +86,11 @@ module Racc
86
86
  end
87
87
 
88
88
  def assert_output_unchanged(asset)
89
- # racc generates the difference results in GitHub Actions
90
- omit unless RUBY_PLATFORM =~ /darwin/
91
-
92
89
  file = File.basename(asset, '.y')
93
90
 
91
+ # Code to re-generate the expectation files
92
+ # File.write("#{REGRESS_DIR}/#{file}", File.read("#{@TAB_DIR}/#{file}"))
93
+
94
94
  expected = File.read("#{REGRESS_DIR}/#{file}")
95
95
  actual = File.read("#{@TAB_DIR}/#{file}")
96
96
  result = (strip_version(expected) == strip_version(actual))