unparser 0.1.14 → 0.1.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fbc42b2270dfea79002ff8d2bf543618237f65e
4
- data.tar.gz: 992ce6239c5de55bf3cb5f3b182a2e6d8368ae06
3
+ metadata.gz: 51f39ff818f38c725475d8e6970391c4f7a771a1
4
+ data.tar.gz: 6838c26d95b6bf42ecf19e9b1874c39223d00d6a
5
5
  SHA512:
6
- metadata.gz: 90e80a39138d2cf49d9be5e303f9255be55ff8200ddb1dcb5181951ddce109816749e8cd72388a5a935b966ab6d67a23175eb714fa5038dde99cb846a547a6f4
7
- data.tar.gz: f51ab9def69f2641e819f1c57741d808f61f25cfc2738257ea846daff6a1a4562683e9972d8fde4f58b023fdc0e1edf1a03fe996157c89bc9efe5a2aa940f75f
6
+ metadata.gz: e71bf25de61e37a461f9f09d3b1600070d84c7458d9717c11ce768d5eafd3881a5ea1eca3e8926d0704dbc06862d4d1bfb718f335fb2e9a23d9362a3797a0bea
7
+ data.tar.gz: 2df198d4fd9b6807af07b7a45f5a781f1b969a4b716fb6ef407f7c3cdca0613b9b66fbf84eddfba9b73b59e81e4b076f86a08f4df823b9e80a46aa3a6b4b799f
data/.travis.yml CHANGED
@@ -4,6 +4,7 @@ rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
6
  - 2.1.2
7
+ - 2.1.3
7
8
  - rbx-2
8
9
  matrix:
9
10
  include:
data/Changelog.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.1.15 2014-09-24
2
+
3
+ * Handle syntax edge case for MRI 2.1.3 parser.
4
+
1
5
  # v0.1.14 2014-06-15
2
6
 
3
7
  * Fix emitter to correctly unparse foo[] = 1
data/Gemfile.devtools CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  group :development do
4
4
  gem 'rake', '~> 10.3.2'
5
- gem 'rspec', '~> 2.99.0'
6
- gem 'rspec-core', '~> 2.99.0'
5
+ gem 'rspec', '~> 3.1.0'
6
+ gem 'rspec-its', '~> 1.0.1'
7
7
  gem 'yard', '~> 0.8.7.4'
8
8
 
9
9
  platform :rbx do
@@ -38,13 +38,13 @@ group :metrics do
38
38
  gem 'flay', '~> 2.5.0'
39
39
  gem 'flog', '~> 4.2.1'
40
40
  gem 'reek', '~> 1.3.7'
41
- gem 'rubocop', '~> 0.23.0'
41
+ gem 'rubocop', '~> 0.26.1'
42
42
  gem 'simplecov', '~> 0.7.1'
43
43
  gem 'yardstick', '~> 0.9.9'
44
44
 
45
45
  platforms :mri do
46
- gem 'mutant', '~> 0.5.19'
47
- gem 'mutant-rspec', '~> 0.5.19'
46
+ gem 'mutant', '~> 0.6.3'
47
+ gem 'mutant-rspec', '~> 0.6.3'
48
48
  end
49
49
 
50
50
  platforms :ruby_19, :ruby_20 do
data/README.md CHANGED
@@ -5,7 +5,6 @@ unparser
5
5
  [![Dependency Status](https://gemnasium.com/mbj/unparser.png)](https://gemnasium.com/mbj/unparser)
6
6
  [![Code Climate](https://codeclimate.com/github/mbj/unparser.png)](https://codeclimate.com/github/mbj/unparser)
7
7
  [![Gem Version](https://img.shields.io/gem/v/unparser.svg)](https://rubygems.org/gems/unparser)
8
- [![Gittip](https://img.shields.io/gittip/mbj.svg)](https://gittip.com/mbj)
9
8
 
10
9
  Generate equivalent source for ASTs from whitequarks [parser](https://github.com/whitequark/parser).
11
10
 
data/config/flay.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 13
3
- total_score: 701
3
+ total_score: 698
data/config/flog.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  ---
2
- threshold: 21.3
2
+ threshold: 22.1
data/lib/unparser/ast.rb CHANGED
@@ -21,11 +21,7 @@ module Unparser
21
21
  #
22
22
  # @param [Parser::AST::Node] node
23
23
  #
24
- # @return [true]
25
- # if local variable scope must NOT be reset
26
- #
27
- # @return [false]
28
- # otherwise
24
+ # @return [Boolean]
29
25
  #
30
26
  # @api private
31
27
  #
@@ -37,11 +33,7 @@ module Unparser
37
33
  #
38
34
  # @param [Parser::AST::Node] node
39
35
  #
40
- # @return [true]
41
- # if local variable scope must NOT be reset
42
- #
43
- # @return [false]
44
- # otherwise
36
+ # @return [Boolean]
45
37
  #
46
38
  # @api private
47
39
  #
@@ -132,7 +124,7 @@ module Unparser
132
124
  # @api private
133
125
  #
134
126
  def type(type)
135
- select { |node| node.type == type }
127
+ select { |node| node.type.equal?(type) }
136
128
  end
137
129
 
138
130
  # Return frozne set of objects
@@ -28,11 +28,7 @@ module Unparser
28
28
  #
29
29
  # @param [Parser::AST::Node] node
30
30
  #
31
- # @return [true]
32
- # if local variable was firstly introduced in body
33
- #
34
- # @return [false]
35
- # otherwise
31
+ # @return [Boolean]
36
32
  #
37
33
  # @api private
38
34
  #
@@ -48,11 +44,7 @@ module Unparser
48
44
  # @param [Parser::AST::Node] node
49
45
  # @param [Symbol] name
50
46
  #
51
- # @return [true]
52
- # if local variable is defined
53
- #
54
- # @return [false]
55
- # otherwise
47
+ # @return [Boolean]
56
48
  #
57
49
  # @api private
58
50
  #
@@ -89,11 +81,7 @@ module Unparser
89
81
  # @param [Parser::AST::Node] node
90
82
  # if block given
91
83
  #
92
- # @return [true]
93
- # if found an matched
94
- #
95
- # @return [false]
96
- # otherwise
84
+ # @return [Boolean]
97
85
  #
98
86
  # @api private
99
87
  #
@@ -27,7 +27,7 @@ module Unparser
27
27
  # @api private
28
28
  #
29
29
  def append(string)
30
- if @content[-1] == NL
30
+ if @content[-1].eql?(NL)
31
31
  prefix
32
32
  end
33
33
  write(string)
@@ -82,16 +82,12 @@ module Unparser
82
82
 
83
83
  # Test for a fresh line
84
84
  #
85
- # @return [true]
86
- # if the buffer content ends with a fresh line
87
- #
88
- # @return [false]
89
- # otherwise
85
+ # @return [Boolean]
90
86
  #
91
87
  # @api private
92
88
  #
93
89
  def fresh_line?
94
- @content.empty? || @content[-1] == NL
90
+ @content.empty? || @content[-1].eql?(NL)
95
91
  end
96
92
 
97
93
  # Return content of buffer
data/lib/unparser/cli.rb CHANGED
@@ -128,7 +128,7 @@ module Unparser
128
128
  if @start_with
129
129
  reject = true
130
130
  @sources.reject do |source|
131
- if reject && source == @start_with
131
+ if reject && source.eql?(@start_with)
132
132
  reject = false
133
133
  end
134
134
 
@@ -36,15 +36,12 @@ module Unparser
36
36
 
37
37
  # Test if source could be unparsed successfully
38
38
  #
39
- # @return [true]
40
- # if source could be unparsed successfully
41
- #
42
- # @return [false]
39
+ # @return [Boolean]
43
40
  #
44
41
  # @api private
45
42
  #
46
43
  def success?
47
- generated.success? && original_ast && generated_ast && original_ast == generated_ast
44
+ generated.success? && original_ast && generated_ast && original_ast.eql?(generated_ast)
48
45
  end
49
46
 
50
47
  # Return error report
@@ -337,7 +337,7 @@ module Unparser
337
337
  def emit_comments(comments)
338
338
  max = comments.size - 1
339
339
  comments.each_with_index do |comment, index|
340
- if comment.type == :document
340
+ if comment.type.equal?(:document)
341
341
  buffer.append_without_prefix(comment.text.chomp)
342
342
  else
343
343
  write(comment.text)
@@ -30,7 +30,7 @@ module Unparser
30
30
 
31
31
  handle :args
32
32
 
33
- SHADOWARGS = ->(node) { node.type == :shadowarg }.freeze
33
+ SHADOWARGS = ->(node) { node.type.equal?(:shadowarg) }.freeze
34
34
 
35
35
  private
36
36
 
@@ -55,7 +55,7 @@ module Unparser
55
55
  #
56
56
  def normal_arguments
57
57
  children.reject(&SHADOWARGS).map do |child|
58
- if child.type == :mlhs
58
+ if child.type.equal?(:mlhs)
59
59
  Parser::AST::Node.new(:arg_expr, [child])
60
60
  else
61
61
  child
@@ -132,7 +132,7 @@ module Unparser
132
132
 
133
133
  private
134
134
 
135
- NO_COMMA = [:splat, :restarg, :mlhs]
135
+ NO_COMMA = [:splat, :restarg, :mlhs].to_set.freeze
136
136
 
137
137
  # Perform dispatch
138
138
  #
@@ -141,11 +141,11 @@ module Unparser
141
141
  # @api private
142
142
  #
143
143
  def dispatch
144
- conditional_parentheses(parent_type == :mlhs) do
144
+ conditional_parentheses(parent_type.equal?(:mlhs)) do
145
145
  delimited(children)
146
146
  end
147
147
 
148
- write(',') if children.one? && !NO_COMMA.include?(children.first.type) && parent_type != :arg_expr
148
+ write(',') if children.one? && !NO_COMMA.include?(children.first.type) && !parent_type.equal?(:arg_expr)
149
149
  end
150
150
 
151
151
  end # MLHS
@@ -27,6 +27,16 @@ module Unparser
27
27
 
28
28
  NON_EMPTY_PARENS = [:root, :dstr, :dyn_str_body].to_set.freeze
29
29
 
30
+ # Test if begin is terminated
31
+ #
32
+ # @return [Boolean]
33
+ #
34
+ # @api private
35
+ #
36
+ def terminated?
37
+ children.empty? && !NON_EMPTY_PARENS.include?(parent_type)
38
+ end
39
+
30
40
  private
31
41
 
32
42
  # Perform dispatch
@@ -36,10 +46,10 @@ module Unparser
36
46
  # @api private
37
47
  #
38
48
  def dispatch
39
- if children.empty? && !NON_EMPTY_PARENS.include?(parent_type)
49
+ if terminated?
40
50
  write('()')
41
51
  else
42
- conditional_parentheses(parent_type == :optarg) do
52
+ conditional_parentheses(parent_type.equal?(:optarg)) do
43
53
  emit_inner
44
54
  end
45
55
  end
@@ -97,11 +97,7 @@ module Unparser
97
97
 
98
98
  # Test if subject needs parentheses
99
99
  #
100
- # @return [true]
101
- # if subject needs parentheses
102
- #
103
- # @return [false]
104
- # otherwise
100
+ # @return [Boolean]
105
101
  #
106
102
  # @api private
107
103
  #
@@ -22,7 +22,7 @@ module Unparser
22
22
  # @api private
23
23
  #
24
24
  def dispatch
25
- conditional_parentheses((parent_type == :or || parent_type == :and) && children.any?) do
25
+ conditional_parentheses((parent_type.equal?(:or) || parent_type.equal?(:and)) && children.any?) do
26
26
  write(MAP.fetch(node.type))
27
27
  emit_arguments if children.any?
28
28
  end
@@ -27,11 +27,7 @@ module Unparser
27
27
 
28
28
  # Test for postcondition
29
29
  #
30
- # @return [true]
31
- # if node must be emitted in postcondition style
32
- #
33
- # @return [false]
34
- # otherwise
30
+ # @return [Boolean]
35
31
  #
36
32
  # @api private
37
33
  #
@@ -69,13 +65,9 @@ module Unparser
69
65
  k_end
70
66
  end
71
67
 
72
- # Test for unless
73
- #
74
- # @return [true]
75
- # if to emit as unless
68
+ # Test if AST can be emitted as unless
76
69
  #
77
- # @return [false]
78
- # otherwise
70
+ # @return [Boolean]
79
71
  #
80
72
  # @api private
81
73
  #
@@ -26,16 +26,12 @@ module Unparser
26
26
 
27
27
  # Test for interpolation
28
28
  #
29
- # @return [true]
30
- # if dynamic component was interpolated
31
- #
32
- # @return [false]
33
- # otherwise
29
+ # @return [Boolean]
34
30
  #
35
31
  # @api private
36
32
  #
37
33
  def interpolation?
38
- children.any? { |child| child.type != :str }
34
+ children.any? { |child| !child.type.equal?(:str) }
39
35
  end
40
36
 
41
37
  # Return dynamic body
@@ -62,7 +62,7 @@ module Unparser
62
62
  end
63
63
 
64
64
  pairs = Parser::Lexer::ESCAPES.invert.map do |key, value|
65
- [key, "\\#{value}"] unless key == WS
65
+ [key, "\\#{value}"] unless key.eql?(WS)
66
66
  end.compact
67
67
 
68
68
  pairs << ['#{', '\#{']
@@ -7,6 +7,23 @@ module Unparser
7
7
  # Abstract namespace class for hash pair emitters
8
8
  class HashPair < self
9
9
 
10
+ children :key, :value
11
+
12
+ private
13
+
14
+ # Emit value
15
+ #
16
+ # @return [undefined]
17
+ #
18
+ # @api private
19
+ #
20
+ def emit_value
21
+ value_type = value.type
22
+ conditional_parentheses(value_type.equal?(:if)) do
23
+ visit_terminated(value)
24
+ end
25
+ end
26
+
10
27
  # Pair emitter that emits hash-rocket separated key values
11
28
  class Rocket < self
12
29
  HASHROCKET = ' => '.freeze
@@ -22,7 +39,9 @@ module Unparser
22
39
  # @api private
23
40
  #
24
41
  def dispatch
25
- delimited(children, HASHROCKET)
42
+ visit(key)
43
+ write(HASHROCKET)
44
+ emit_value
26
45
  end
27
46
 
28
47
  end # Rocket
@@ -33,8 +52,6 @@ module Unparser
33
52
 
34
53
  handle :pair_colon
35
54
 
36
- children :key, :value
37
-
38
55
  private
39
56
 
40
57
  # Perform dispatch
@@ -45,7 +62,7 @@ module Unparser
45
62
  #
46
63
  def dispatch
47
64
  write(key.children.first.to_s, COLON)
48
- visit_terminated(value)
65
+ emit_value
49
66
  end
50
67
 
51
68
  end # Colon
@@ -80,11 +97,11 @@ module Unparser
80
97
  #
81
98
  def effective_body
82
99
  children.map do |pair|
83
- if pair.type == :kwsplat
100
+ if pair.type.equal?(:kwsplat)
84
101
  pair
85
102
  else
86
103
  key, _value = *pair
87
- if key.type == :sym && key.children.first.to_s =~ BAREWORD
104
+ if key.type.equal?(:sym) && key.children.first.to_s =~ BAREWORD
88
105
  n(:pair_colon, pair.children)
89
106
  else
90
107
  n(:pair_rocket, pair.children)
@@ -58,13 +58,9 @@ module Unparser
58
58
  end
59
59
  end
60
60
 
61
- # Test for postcontrol
61
+ # Test if node must be emitted in postcontrol form
62
62
  #
63
- # @return [true]
64
- # if repetition must be emitted as post control
65
- #
66
- # @return [false]
67
- # otherwise
63
+ # @return [Boolean]
68
64
  #
69
65
  # @api private
70
66
  #
@@ -37,16 +37,12 @@ module Unparser
37
37
 
38
38
  # Test if rescue node ist standalone
39
39
  #
40
- # @return [true]
41
- # if rescue node is standalone
42
- #
43
- # @return [false]
44
- # otherwise
40
+ # @return [Boolean]
45
41
  #
46
42
  # @api private
47
43
  #
48
44
  def standalone?
49
- if parent_type == :ensure
45
+ if parent_type.equal?(:ensure)
50
46
  !parent.node.children.first.equal?(node)
51
47
  else
52
48
  !EMBEDDED_TYPES.include?(parent_type)
@@ -105,7 +105,7 @@ module Unparser
105
105
  # @api private
106
106
  #
107
107
  def binary_operator?
108
- BINARY_OPERATORS.include?(selector) && arguments.one? && arguments.first.type != :splat
108
+ BINARY_OPERATORS.include?(selector) && arguments.one? && !arguments.first.type.equal?(:splat)
109
109
  end
110
110
 
111
111
  # Emit selector
@@ -141,15 +141,12 @@ module Unparser
141
141
  # @api private
142
142
  #
143
143
  def assignment?
144
- string_selector[-1] == ASSIGN_SUFFIX
144
+ string_selector[-1].eql?(ASSIGN_SUFFIX)
145
145
  end
146
146
 
147
147
  # Test for attribute assignment
148
148
  #
149
- # @return [true]
150
- # if node represetns and attribute assignment
151
- #
152
- # @return [false]
149
+ # @return [Boolean]
153
150
  #
154
151
  # @api private
155
152
  #
@@ -159,11 +156,7 @@ module Unparser
159
156
 
160
157
  # Test for empty arguments
161
158
  #
162
- # @return [true]
163
- # if arguments are empty
164
- #
165
- # @return [false]
166
- # otherwise
159
+ # @return [Boolean]
167
160
  #
168
161
  # @api private
169
162
  #
@@ -198,11 +191,7 @@ module Unparser
198
191
 
199
192
  # Test for local variable clash
200
193
  #
201
- # @return [true]
202
- # if selector clashes with a local variable
203
- #
204
- # @return [false]
205
- # otherwise
194
+ # @return [Boolean]
206
195
  #
207
196
  # @api private
208
197
  #
@@ -32,7 +32,7 @@ module Unparser
32
32
  def effective_arguments
33
33
  last = children.length - 1
34
34
  children.each_with_index.map do |argument, index|
35
- if last == index && argument.type == :hash && argument.children.any?
35
+ if last.equal?(index) && argument.type.equal?(:hash) && argument.children.any?
36
36
  argument.updated(:hash_body)
37
37
  else
38
38
  argument
@@ -22,7 +22,7 @@ module Unparser
22
22
  def dispatch
23
23
  name = selector
24
24
  write(MAP.fetch(name, name).to_s)
25
- if receiver.type == :int && selector == :'+@' && receiver.children.first > 0
25
+ if receiver.type.equal?(:int) && selector.equal?(:'+@') && receiver.children.first > 0
26
26
  write('+')
27
27
  end
28
28
 
@@ -53,7 +53,7 @@ module Unparser
53
53
  def emit_scope
54
54
  return unless scope
55
55
  visit(scope)
56
- write(T_DCL) if scope.type != :cbase
56
+ write(T_DCL) unless scope.type.equal?(:cbase)
57
57
  end
58
58
  end
59
59
 
@@ -130,7 +130,7 @@ module Unparser
130
130
  #
131
131
  def collapsed_children
132
132
  chunked_children.each_with_object([]) do |(type, nodes), aggregate|
133
- if type == :str
133
+ if type.equal?(:str)
134
134
  aggregate << s(:str, nodes.map { |node| node.children.first }.join)
135
135
  else
136
136
  aggregate.concat(nodes)
@@ -163,7 +163,7 @@ module Unparser
163
163
  # @api private
164
164
  #
165
165
  def result
166
- if children.all? { |child| child.type == :str }
166
+ if children.all? { |child| child.type.equal?(:str) }
167
167
  node.updated(:str, [children.map { |child| child.children.first }.join])
168
168
  else
169
169
  node
@@ -215,6 +215,9 @@ describe Unparser do
215
215
  assert_source '{ 1 => 2 }'
216
216
  assert_source '{ 1 => 2, 3 => 4 }'
217
217
 
218
+ # special case for 2.1.3
219
+ assert_source "{ foo: (if true\nend) }"
220
+
218
221
  context 'with symbol keys' do
219
222
  assert_source '{ a: (1 rescue(foo)), b: 2 }'
220
223
  assert_source '{ a: 1, b: 2 }'
data/unparser.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'unparser'
5
- gem.version = '0.1.14'
5
+ gem.version = '0.1.15'
6
6
 
7
7
  gem.authors = ['Markus Schirp']
8
8
  gem.email = 'mbj@schir-dso.com'
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.required_ruby_version = '>= 1.9.3'
21
21
 
22
- gem.add_dependency('parser', '~> 2.1')
22
+ gem.add_dependency('parser', '~> 2.2.0.pre.4')
23
23
  gem.add_dependency('procto', '~> 0.0.2')
24
24
  gem.add_dependency('concord', '~> 0.1.5')
25
25
  gem.add_dependency('adamantium', '~> 0.2.0')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Schirp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-15 00:00:00.000000000 Z
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
19
+ version: 2.2.0.pre.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.1'
26
+ version: 2.2.0.pre.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: procto
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -248,4 +248,3 @@ test_files:
248
248
  - spec/unit/unparser/comments/take_eol_comments_spec.rb
249
249
  - spec/unit/unparser/emitter/class_methods/handle_spec.rb
250
250
  - spec/unit/unparser_spec.rb
251
- has_rdoc: