ruby_parser 2.0.6 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby_parser might be problematic. Click here for more details.

data.tar.gz.sig CHANGED
Binary file
data/.autotest CHANGED
@@ -1,11 +1,12 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  require 'autotest/restart'
4
+ require 'autotest/isolate'
4
5
  require 'autotest/rcov' if ENV['RCOV']
5
6
 
6
7
  Autotest.add_hook :initialize do |at|
7
- at.extra_files << "../../ParseTree/dev/test/pt_testcase.rb"
8
- at.libs << ":../../ParseTree/dev/test:../../sexp_processor/dev/lib"
8
+ at.extra_files << "../../sexp_processor/dev/lib/pt_testcase.rb"
9
+ at.libs << ":../../sexp_processor/dev/lib"
9
10
  at.add_exception 'unit'
10
11
  at.add_exception 'coverage'
11
12
  at.add_exception 'coverage.info'
@@ -13,7 +14,6 @@ Autotest.add_hook :initialize do |at|
13
14
 
14
15
  at.libs << ':../../minitest/dev/lib'
15
16
  at.testlib = "minitest/autorun"
16
- at.unit_diff = "unit_diff -u -b"
17
17
 
18
18
  at.add_mapping(/^lib\/.*\.y$/) do |f, _|
19
19
  at.files_matching %r%^test/.*#{File.basename(f, '.y').gsub '_', '_?'}.rb$%
data/History.txt CHANGED
@@ -1,3 +1,15 @@
1
+ === 2.1.0 / 2011-08-15
2
+
3
+ * 2 minor enhancements:
4
+
5
+ * Added new accessor canonicalize_conditions to toggle conditional canonicalization (on by default). (confused)
6
+ * Awesome cleanup: Replaced call to append_block by block_append. (Confusion)
7
+
8
+ * 2 bug fixes:
9
+
10
+ * Fixed handling last line of =begin/=end. (raybaxter)
11
+ * Fixed source line numbers after heredocs. (jbarreneche)
12
+
1
13
  === 2.0.6 / 2011-02-18
2
14
 
3
15
  * 1 minor enhancement:
data/README.txt CHANGED
@@ -1,6 +1,7 @@
1
1
  = ruby_parser
2
2
 
3
- * http://parsetree.rubyforge.org/
3
+ home :: https://github.com/seattlerb/ruby_parser
4
+ rdoc :: http://parsetree.rubyforge.org/ruby_parser
4
5
 
5
6
  == DESCRIPTION:
6
7
 
data/Rakefile CHANGED
@@ -5,18 +5,16 @@ require 'hoe'
5
5
 
6
6
  Hoe.plugin :seattlerb
7
7
  Hoe.plugin :racc
8
+ Hoe.plugin :isolate
8
9
 
9
- Hoe.add_include_dirs("../../ParseTree/dev/test",
10
- "../../RubyInline/dev/lib",
11
- "../../sexp_processor/dev/lib")
10
+ Hoe.add_include_dirs "../../sexp_processor/dev/lib"
12
11
 
13
12
  Hoe.spec 'ruby_parser' do
14
13
  developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
15
14
 
16
15
  self.rubyforge_name = 'parsetree'
17
16
 
18
- extra_dev_deps << ['ParseTree', '~> 3.0']
19
- extra_deps << ['sexp_processor', '~> 3.0']
17
+ dependency 'sexp_processor', '~> 3.0'
20
18
 
21
19
  self.perforce_ignore << "lib/ruby_parser.rb" if plugin? :perforce
22
20
  end
data/lib/ruby_lexer.rb CHANGED
@@ -199,6 +199,7 @@ class RubyLexer
199
199
  # TODO: think about storing off the char range instead
200
200
  line = src.string[src.pos, src.matched_size]
201
201
  src.string[src.pos, src.matched_size] = "\n"
202
+ src.extra_lines_added += 1
202
203
  src.pos += 1
203
204
  else
204
205
  line = nil
@@ -727,7 +728,7 @@ class RubyLexer
727
728
  # @comments << '=' << src.matched
728
729
  @comments << src.matched
729
730
 
730
- unless src.scan(/.*?\n=end\s*(\n|\z)/m) then
731
+ unless src.scan(/.*?\n=end( |\t|\f)*[^(\n|\z)]*(\n|\z)/m) then
731
732
  @comments.clear
732
733
  rb_compile_error("embedded document meets end of file")
733
734
  end
data/lib/ruby_parser.rb CHANGED
@@ -5370,7 +5370,7 @@ def _reduce_460(val, _values, result)
5370
5370
  end
5371
5371
 
5372
5372
  def _reduce_461(val, _values, result)
5373
- result = self.append_to_block val[0], val[2]
5373
+ result = self.block_append val[0], val[2]
5374
5374
 
5375
5375
  result
5376
5376
  end
data/lib/ruby_parser.y CHANGED
@@ -1679,7 +1679,7 @@ xstring_contents: none
1679
1679
  }
1680
1680
  | f_optarg tCOMMA f_opt
1681
1681
  {
1682
- result = self.append_to_block val[0], val[2]
1682
+ result = self.block_append val[0], val[2]
1683
1683
  }
1684
1684
 
1685
1685
  restarg_mark: tSTAR2 | tSTAR
@@ -29,13 +29,20 @@ class RPStringScanner < StringScanner
29
29
  # old_getch
30
30
  # end
31
31
  # end
32
-
33
32
  def current_line # HAHA fuck you (HACK)
34
33
  string[0..pos][/\A.*__LINE__/m].split(/\n/).size
35
34
  end
36
35
 
36
+ def extra_lines_added
37
+ @extra_lines_added ||= 0
38
+ end
39
+
40
+ def extra_lines_added= val
41
+ @extra_lines_added = val
42
+ end
43
+
37
44
  def lineno
38
- string[0...pos].count("\n") + 1
45
+ string[0...pos].count("\n") + 1 - extra_lines_added
39
46
  end
40
47
 
41
48
  # TODO: once we get rid of these, we can make things like
@@ -48,6 +55,7 @@ class RPStringScanner < StringScanner
48
55
 
49
56
  def unread_many str # TODO: remove this entirely - we should not need it
50
57
  warn({:unread_many => caller[0]}.inspect) if ENV['TALLY']
58
+ self.extra_lines_added += str.count("\n")
51
59
  string[pos, 0] = str
52
60
  end
53
61
 
@@ -115,20 +123,11 @@ class RPStringScanner < StringScanner
115
123
  end
116
124
 
117
125
  class RubyParser < Racc::Parser
118
- VERSION = '2.0.6' unless constants.include? "VERSION" # SIGH
126
+ VERSION = '2.1.0' unless constants.include? "VERSION" # SIGH
119
127
 
120
128
  attr_accessor :lexer, :in_def, :in_single, :file
121
129
  attr_reader :env, :comments
122
130
 
123
- def append_to_block head, tail # FIX: wtf is this?!? switch to block_append
124
- return head if tail.nil?
125
- return tail if head.nil?
126
-
127
- head = s(:block, head) unless head.node_type == :block
128
- head << tail
129
- head
130
- end
131
-
132
131
  def arg_add(node1, node2) # TODO: nuke
133
132
  return s(:arglist, node2) unless node1
134
133
 
@@ -217,9 +216,9 @@ class RubyParser < Racc::Parser
217
216
  return result
218
217
  end
219
218
 
220
- def block_append(head, tail, strip_tail_block=false)
221
- return head unless tail
222
- return tail unless head
219
+ def block_append(head, tail)
220
+ return head if tail.nil?
221
+ return tail if head.nil?
223
222
 
224
223
  case head[0]
225
224
  when :lit, :str then
@@ -229,16 +228,10 @@ class RubyParser < Racc::Parser
229
228
  line = [head.line, tail.line].compact.min
230
229
 
231
230
  head = remove_begin(head)
232
- head = s(:block, head) unless head[0] == :block
233
-
234
- if strip_tail_block and Sexp === tail and tail[0] == :block then
235
- head.push(*tail.values)
236
- else
237
- head << tail
238
- end
231
+ head = s(:block, head) unless head.node_type == :block
239
232
 
240
233
  head.line = line
241
- head
234
+ head << tail
242
235
  end
243
236
 
244
237
  def cond node
@@ -335,13 +328,26 @@ class RubyParser < Racc::Parser
335
328
  raise "identifier #{id.inspect} is not valid"
336
329
  end
337
330
 
338
- def initialize
339
- super
331
+ ##
332
+ # Canonicalize conditionals. Eg:
333
+ #
334
+ # not x ? a : b
335
+ #
336
+ # becomes:
337
+ #
338
+ # x ? b : a
339
+
340
+ attr_accessor :canonicalize_conditions
341
+
342
+ def initialize(options = {})
343
+ super()
340
344
  self.lexer = RubyLexer.new
341
345
  self.lexer.parser = self
342
346
  @env = Environment.new
343
347
  @comments = []
344
348
 
349
+ @canonicalize_conditions = true
350
+
345
351
  self.reset
346
352
  end
347
353
 
@@ -534,7 +540,7 @@ class RubyParser < Racc::Parser
534
540
  def new_if c, t, f
535
541
  l = [c.line, t && t.line, f && f.line].compact.min
536
542
  c = cond c
537
- c, t, f = c.last, f, t if c[0] == :not
543
+ c, t, f = c.last, f, t if c[0] == :not and canonicalize_conditions
538
544
  s(:if, c, t, f).line(l)
539
545
  end
540
546
 
@@ -658,26 +664,31 @@ class RubyParser < Racc::Parser
658
664
  end
659
665
  end
660
666
 
661
- def new_until block, expr, pre
662
- expr = (expr.first == :not ? expr.last : s(:not, expr)).line(expr.line)
663
- new_while block, expr, pre
664
- end
665
-
666
- def new_while block, expr, pre
667
+ def new_until_or_while type, block, expr, pre
668
+ other = type == :until ? :while : :until
667
669
  line = [block && block.line, expr.line].compact.min
668
670
  block, pre = block.last, false if block && block[0] == :begin
669
671
 
670
672
  expr = cond expr
671
- result = if expr.first == :not then
672
- s(:until, expr.last, block, pre)
673
+
674
+ result = unless expr.first == :not and canonicalize_conditions then
675
+ s(type, expr, block, pre)
673
676
  else
674
- s(:while, expr, block, pre)
677
+ s(other, expr.last, block, pre)
675
678
  end
676
679
 
677
680
  result.line = line
678
681
  result
679
682
  end
680
683
 
684
+ def new_until block, expr, pre
685
+ new_until_or_while :until, block, expr, pre
686
+ end
687
+
688
+ def new_while block, expr, pre
689
+ new_until_or_while :while, block, expr, pre
690
+ end
691
+
681
692
  def new_xstring str
682
693
  if str then
683
694
  case str[0]
@@ -255,6 +255,11 @@ class TestRubyLexer < MiniTest::Unit::TestCase
255
255
  assert_equal "=begin blah\nblah\n=end\n", @lex.comments
256
256
  end
257
257
 
258
+ def test_yylex_comment_end_space_and_text
259
+ util_lex_token("=begin blah\nblah\n=end blab\n")
260
+ assert_equal "=begin blah\nblah\n=end blab\n", @lex.comments
261
+ end
262
+
258
263
  def test_yylex_comment_eos
259
264
  util_lex_token("# comment")
260
265
  end
@@ -33,8 +33,6 @@ class TestRubyParser < RubyParserTestCase
33
33
  def setup
34
34
  super
35
35
 
36
- # puts self.name
37
-
38
36
  @processor = RubyParser.new
39
37
  end
40
38
 
@@ -178,7 +176,7 @@ class TestRubyParser < RubyParserTestCase
178
176
  def test_bug_comment_eq_begin
179
177
  rb = "\n\n#\n=begin\nblah\n=end\n\n"
180
178
  pt = nil
181
- exp = rb[2..-1]
179
+ exp = rb.strip + "\n"
182
180
 
183
181
  assert_equal pt, @processor.parse(rb)
184
182
  assert_equal exp, @processor.lexer.comments
@@ -422,13 +420,13 @@ class TestRubyParser < RubyParserTestCase
422
420
  "case_nested_inner_no_expr" => 2,
423
421
  "case_no_expr" => 2,
424
422
  "case_splat" => 2,
425
- "dstr_heredoc_expand" => 2,
426
- "dstr_heredoc_windoze_sucks" => 2,
427
- "dstr_heredoc_yet_again" => 2,
428
- "str_heredoc" => 2,
429
- "str_heredoc_call" => 2,
430
- "str_heredoc_empty" => 2,
431
- "str_heredoc_indent" => 2,
423
+ "dstr_heredoc_expand" => 1,
424
+ "dstr_heredoc_windoze_sucks" => 1,
425
+ "dstr_heredoc_yet_again" => 1,
426
+ "str_heredoc" => 1,
427
+ "str_heredoc_call" => 1,
428
+ "str_heredoc_empty" => 1,
429
+ "str_heredoc_indent" => 1,
432
430
  "structure_unused_literal_wwtt" => 3, # yes, 3... odd test
433
431
  "undef_block_1" => 2,
434
432
  "undef_block_2" => 2,
@@ -441,7 +439,7 @@ class TestRubyParser < RubyParserTestCase
441
439
  assert_equal expected, @result.line, "should have proper line number"
442
440
  end
443
441
 
444
- def test_position_info
442
+ def test_position_info_block
445
443
  rb = "a = 42\np a"
446
444
  pt = s(:block,
447
445
  s(:lasgn, :a, s(:lit, 42)),
@@ -465,7 +463,7 @@ class TestRubyParser < RubyParserTestCase
465
463
  assert_same result.file, result.call.file
466
464
  end
467
465
 
468
- def test_position_info2
466
+ def test_position_info_defn
469
467
  rb = "def x(y)\n p(y)\n y *= 2\n return y;\nend" # TODO: remove () & ;
470
468
  pt = s(:defn, :x, s(:args, :y),
471
469
  s(:scope,
@@ -486,4 +484,83 @@ class TestRubyParser < RubyParserTestCase
486
484
  assert_equal 3, body.lasgn.line, "lasgn should have line number"
487
485
  assert_equal 4, body.return.line, "return should have line number"
488
486
  end
487
+
488
+ def test_position_info_heredoc
489
+ rb = <<-CODE
490
+ string = <<-HEREDOC
491
+ very long string
492
+ HEREDOC
493
+ puts string
494
+ CODE
495
+
496
+ result = @processor.parse rb
497
+ assert_equal 1, result.lasgn.line
498
+ assert_equal 4, result.call.line
499
+ end
500
+
501
+ def test_parse_if_not_canonical
502
+ rb = "if not var.nil? then 'foo' else 'bar'\nend"
503
+ pt = s(:if,
504
+ s(:call, s(:call, nil, :var, s(:arglist)), :nil?, s(:arglist)),
505
+ s(:str, "bar"),
506
+ s(:str, "foo"))
507
+
508
+ assert_equal pt, @processor.parse(rb)
509
+ end
510
+
511
+ def test_parse_if_not_noncanonical
512
+ rb = "if not var.nil? then 'foo' else 'bar'\nend"
513
+ pt = s(:if,
514
+ s(:not,
515
+ s(:call, s(:call, nil, :var, s(:arglist)), :nil?, s(:arglist))),
516
+ s(:str, "foo"),
517
+ s(:str, "bar"))
518
+
519
+ @processor.canonicalize_conditions = false
520
+
521
+ assert_equal pt, @processor.parse(rb)
522
+ end
523
+
524
+ def test_parse_while_not_canonical
525
+ rb = "while not var.nil?\n 'foo'\nend"
526
+ pt = s(:until,
527
+ s(:call, s(:call, nil, :var, s(:arglist)), :nil?, s(:arglist)),
528
+ s(:str, "foo"), true)
529
+
530
+ assert_equal pt, @processor.parse(rb)
531
+ end
532
+
533
+ def test_parse_while_not_noncanonical
534
+ rb = "while not var.nil?\n 'foo'\nend"
535
+ pt = s(:while,
536
+ s(:not,
537
+ s(:call, s(:call, nil, :var, s(:arglist)), :nil?, s(:arglist))),
538
+ s(:str, "foo"), true)
539
+
540
+ @processor.canonicalize_conditions = false
541
+
542
+ assert_equal pt, @processor.parse(rb)
543
+ end
544
+
545
+ def test_parse_until_not_canonical
546
+ rb = "until not var.nil?\n 'foo'\nend"
547
+
548
+ pt = s(:while,
549
+ s(:call, s(:call, nil, :var, s(:arglist)), :nil?, s(:arglist)),
550
+ s(:str, "foo"), true)
551
+
552
+ assert_equal pt, @processor.parse(rb)
553
+ end
554
+
555
+ def test_parse_until_not_noncanonical
556
+ rb = "until not var.nil?\n 'foo'\nend"
557
+ pt = s(:until,
558
+ s(:not,
559
+ s(:call, s(:call, nil, :var, s(:arglist)), :nil?, s(:arglist))),
560
+ s(:str, "foo"), true)
561
+
562
+ @processor.canonicalize_conditions = false
563
+
564
+ assert_equal pt, @processor.parse(rb)
565
+ end
489
566
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_parser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
+ - 1
8
9
  - 0
9
- - 6
10
- version: 2.0.6
10
+ version: 2.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Davis
@@ -36,8 +36,7 @@ cert_chain:
36
36
  FBHgymkyj/AOSqKRIpXPhjC6
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2011-02-18 00:00:00 -08:00
40
- default_executable:
39
+ date: 2011-08-15 00:00:00 Z
41
40
  dependencies:
42
41
  - !ruby/object:Gem::Dependency
43
42
  name: sexp_processor
@@ -62,12 +61,12 @@ dependencies:
62
61
  requirements:
63
62
  - - ~>
64
63
  - !ruby/object:Gem::Version
65
- hash: 9
64
+ hash: 11
66
65
  segments:
67
66
  - 1
68
67
  - 4
69
- - 7
70
- version: 1.4.7
68
+ - 6
69
+ version: 1.4.6
71
70
  type: :development
72
71
  version_requirements: *id002
73
72
  - !ruby/object:Gem::Dependency
@@ -76,47 +75,30 @@ dependencies:
76
75
  requirement: &id003 !ruby/object:Gem::Requirement
77
76
  none: false
78
77
  requirements:
79
- - - ">="
78
+ - - ~>
80
79
  - !ruby/object:Gem::Version
81
80
  hash: 11
82
81
  segments:
83
82
  - 2
84
- - 0
85
- - 2
86
- version: 2.0.2
83
+ - 4
84
+ version: "2.4"
87
85
  type: :development
88
86
  version_requirements: *id003
89
87
  - !ruby/object:Gem::Dependency
90
- name: ParseTree
88
+ name: hoe
91
89
  prerelease: false
92
90
  requirement: &id004 !ruby/object:Gem::Requirement
93
91
  none: false
94
92
  requirements:
95
93
  - - ~>
96
94
  - !ruby/object:Gem::Version
97
- hash: 7
98
- segments:
99
- - 3
100
- - 0
101
- version: "3.0"
102
- type: :development
103
- version_requirements: *id004
104
- - !ruby/object:Gem::Dependency
105
- name: hoe
106
- prerelease: false
107
- requirement: &id005 !ruby/object:Gem::Requirement
108
- none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- hash: 41
95
+ hash: 21
113
96
  segments:
114
97
  - 2
115
- - 9
116
- - 1
117
- version: 2.9.1
98
+ - 11
99
+ version: "2.11"
118
100
  type: :development
119
- version_requirements: *id005
101
+ version_requirements: *id004
120
102
  description: |-
121
103
  ruby_parser (RP) is a ruby parser written in pure ruby (utilizing
122
104
  racc--which does by default use a C extension). RP's output is
@@ -169,8 +151,7 @@ files:
169
151
  - test/test_ruby_parser.rb
170
152
  - test/test_ruby_parser_extras.rb
171
153
  - .gemtest
172
- has_rdoc: true
173
- homepage: http://parsetree.rubyforge.org/
154
+ homepage: https://github.com/seattlerb/ruby_parser
174
155
  licenses: []
175
156
 
176
157
  post_install_message:
@@ -200,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
181
  requirements: []
201
182
 
202
183
  rubyforge_project: parsetree
203
- rubygems_version: 1.4.2
184
+ rubygems_version: 1.8.5
204
185
  signing_key:
205
186
  specification_version: 3
206
187
  summary: ruby_parser (RP) is a ruby parser written in pure ruby (utilizing racc--which does by default use a C extension)
metadata.gz.sig CHANGED
Binary file