unparser 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +7 -0
  3. data/Gemfile +1 -7
  4. data/README.md +6 -1
  5. data/Rakefile +11 -2
  6. data/bin/unparser +0 -2
  7. data/config/devtools.yml +1 -1
  8. data/config/flay.yml +1 -1
  9. data/config/flog.yml +1 -1
  10. data/config/reek.yml +4 -1
  11. data/config/rubocop.yml +0 -4
  12. data/lib/unparser.rb +1 -2
  13. data/lib/unparser/ast.rb +0 -2
  14. data/lib/unparser/ast/local_variable_scope.rb +0 -2
  15. data/lib/unparser/buffer.rb +0 -2
  16. data/lib/unparser/cli.rb +3 -4
  17. data/lib/unparser/cli/color.rb +0 -2
  18. data/lib/unparser/cli/differ.rb +0 -2
  19. data/lib/unparser/cli/source.rb +1 -3
  20. data/lib/unparser/comments.rb +0 -2
  21. data/lib/unparser/constants.rb +0 -2
  22. data/lib/unparser/emitter.rb +4 -3
  23. data/lib/unparser/emitter/alias.rb +0 -2
  24. data/lib/unparser/emitter/argument.rb +0 -2
  25. data/lib/unparser/emitter/assignment.rb +0 -2
  26. data/lib/unparser/emitter/begin.rb +1 -3
  27. data/lib/unparser/emitter/binary.rb +0 -2
  28. data/lib/unparser/emitter/block.rb +0 -2
  29. data/lib/unparser/emitter/case.rb +0 -2
  30. data/lib/unparser/emitter/cbase.rb +0 -2
  31. data/lib/unparser/emitter/class.rb +1 -3
  32. data/lib/unparser/emitter/def.rb +0 -2
  33. data/lib/unparser/emitter/defined.rb +0 -2
  34. data/lib/unparser/emitter/empty.rb +0 -2
  35. data/lib/unparser/emitter/ensure.rb +0 -2
  36. data/lib/unparser/emitter/flipflop.rb +0 -2
  37. data/lib/unparser/emitter/flow_modifier.rb +0 -2
  38. data/lib/unparser/emitter/for.rb +0 -2
  39. data/lib/unparser/emitter/hookexe.rb +0 -2
  40. data/lib/unparser/emitter/if.rb +0 -2
  41. data/lib/unparser/emitter/literal.rb +0 -2
  42. data/lib/unparser/emitter/literal/array.rb +0 -2
  43. data/lib/unparser/emitter/literal/dynamic.rb +2 -43
  44. data/lib/unparser/emitter/literal/dynamic_body.rb +0 -6
  45. data/lib/unparser/emitter/literal/execute_string.rb +0 -2
  46. data/lib/unparser/emitter/literal/hash.rb +1 -3
  47. data/lib/unparser/emitter/literal/primitive.rb +0 -2
  48. data/lib/unparser/emitter/literal/range.rb +0 -2
  49. data/lib/unparser/emitter/literal/regexp.rb +0 -2
  50. data/lib/unparser/emitter/literal/singleton.rb +0 -2
  51. data/lib/unparser/emitter/match.rb +0 -2
  52. data/lib/unparser/emitter/module.rb +0 -2
  53. data/lib/unparser/emitter/op_assign.rb +0 -2
  54. data/lib/unparser/emitter/redo.rb +0 -2
  55. data/lib/unparser/emitter/repetition.rb +0 -2
  56. data/lib/unparser/emitter/resbody.rb +0 -2
  57. data/lib/unparser/emitter/rescue.rb +0 -2
  58. data/lib/unparser/emitter/retry.rb +0 -2
  59. data/lib/unparser/emitter/root.rb +0 -2
  60. data/lib/unparser/emitter/send.rb +0 -2
  61. data/lib/unparser/emitter/send/arguments.rb +0 -2
  62. data/lib/unparser/emitter/send/attribute_assignment.rb +0 -2
  63. data/lib/unparser/emitter/send/binary.rb +0 -2
  64. data/lib/unparser/emitter/send/conditional.rb +38 -0
  65. data/lib/unparser/emitter/send/index.rb +0 -2
  66. data/lib/unparser/emitter/send/regular.rb +0 -2
  67. data/lib/unparser/emitter/send/unary.rb +3 -2
  68. data/lib/unparser/emitter/splat.rb +0 -2
  69. data/lib/unparser/emitter/super.rb +0 -2
  70. data/lib/unparser/emitter/undef.rb +0 -2
  71. data/lib/unparser/emitter/variable.rb +0 -2
  72. data/lib/unparser/emitter/yield.rb +0 -2
  73. data/lib/unparser/finalize.rb +0 -2
  74. data/lib/unparser/node_helpers.rb +0 -2
  75. data/lib/unparser/preprocessor.rb +3 -80
  76. data/spec/integration/unparser/corpus_spec.rb +3 -16
  77. data/spec/integrations.yml +10 -11
  78. data/spec/spec_helper.rb +0 -2
  79. data/spec/unit/unparser/buffer/append_spec.rb +0 -2
  80. data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +0 -2
  81. data/spec/unit/unparser/buffer/capture_content_spec.rb +0 -2
  82. data/spec/unit/unparser/buffer/content_spec.rb +0 -2
  83. data/spec/unit/unparser/buffer/fresh_line_spec.rb +0 -2
  84. data/spec/unit/unparser/buffer/indent_spec.rb +0 -2
  85. data/spec/unit/unparser/buffer/nl_spec.rb +0 -2
  86. data/spec/unit/unparser/buffer/unindent_spec.rb +0 -2
  87. data/spec/unit/unparser/comments/consume_spec.rb +0 -2
  88. data/spec/unit/unparser/comments/take_all_spec.rb +0 -2
  89. data/spec/unit/unparser/comments/take_before_spec.rb +0 -2
  90. data/spec/unit/unparser/comments/take_eol_comments_spec.rb +0 -2
  91. data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +1 -3
  92. data/spec/unit/unparser_spec.rb +47 -71
  93. data/unparser.gemspec +20 -17
  94. metadata +69 -28
  95. data/.travis.yml +0 -20
  96. data/Guardfile +0 -20
  97. data/TODO +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9153738b80c2b264cca4dcdbc4e333fec8880eda
4
- data.tar.gz: d6bd39195946e4811e288fe0a3b73e393edaec44
3
+ metadata.gz: cd0aa87d79ce744a9716b80c4a33767b8cbcd662
4
+ data.tar.gz: 6209862711ac0f807c9a6f20bdfdc626236a1b86
5
5
  SHA512:
6
- metadata.gz: 5cf0d1780d1bd52776fefc33d7fb76e5e0e745143f7bc6e81f22a47a1ed6caa3c89a13ddb5a28589614ebe9743eafd6269872bf7a0465b3b483409f4a6c84f49
7
- data.tar.gz: 00365496176f10480f5bc5d1402a28b1b80a45d876c900d4616f7823c1aa9274a0cc4717fe08168d4370bac55d6a59ec30a0f1090a4d34cc5fc59acdde5edafe
6
+ metadata.gz: 9cbac595a34a132926c4c09a703ec08f57b71980e2ba711534ea188d4512703d000ebbef2d2eb743aceb2fa2d10ef2230adad17518300bb1aaba0e65d7e1361f
7
+ data.tar.gz: 2536d2b1151da2b12d2efe9dc3d45fb5de4158adfa4698d70204d343b50cac2217ad142e9d7220a43069bb912839dc080925bb9c05ea30320e8451b0b8efdaea
@@ -1,3 +1,10 @@
1
+ # v0.2.5 2016-01-24
2
+
3
+ * Add support for ruby 2.3
4
+ * Bump parser dependency to ~>2.3.0
5
+ * Trade uglier for more correct dstring / dsyms
6
+ * Drop support for ruby < 2.1
7
+
1
8
  # v0.2.4 2015-05-30
2
9
 
3
10
  * Relax parser dependency to ~>2.2.2
data/Gemfile CHANGED
@@ -1,11 +1,5 @@
1
- # encoding: UTF-8
2
1
  source 'https://rubygems.org'
3
2
 
4
3
  gemspec
5
4
 
6
- # Development only dependencies
7
- gem 'anima', '~> 0.2.0'
8
- gem 'morpher', '~> 0.2.2'
9
-
10
- gem 'devtools', git: 'https://github.com/rom-rb/devtools.git'
11
- gem 'mutant', git: 'https://github.com/mbj/mutant.git'
5
+ gem 'mutant', git: 'https://github.com/mbj/mutant.git', branch: 'feature/parser-2-3'
data/README.md CHANGED
@@ -7,10 +7,15 @@ unparser
7
7
  [![Gem Version](https://img.shields.io/gem/v/unparser.svg)](https://rubygems.org/gems/unparser)
8
8
 
9
9
  Generate equivalent source for ASTs from whitequarks [parser](https://github.com/whitequark/parser).
10
+ Excluding the macruby extensions the parser gem implemnents on top of ruby syntax.
11
+
12
+ Excluding the MacRuby / RubyMotion extensions the parser gem implemenents on top of MRI ruby syntax starting with parser release 2.3.
13
+ If you feel the need to get them supported, contact me.
10
14
 
11
15
  This library is able to reproduce 100% of ruby 1.9, 2.0 and 2.1 syntax. Including its own source code.
12
16
 
13
- It serves well for [mutant](https://github.com/mbj/mutant) mutators and the in-memory vendoring for self hosting.
17
+ It serves well for [mutant](https://github.com/mbj/mutant) mutators and the in-memory vendoring for self hosting,
18
+ and other tooling.
14
19
 
15
20
  Usage
16
21
  -----
data/Rakefile CHANGED
@@ -5,7 +5,16 @@ Rake.application.load_imports
5
5
  task('metrics:mutant').clear
6
6
 
7
7
  namespace :metrics do
8
- task :mutant => :coverage do
9
- $stderr.puts 'Mutant is disabled till flexible rspec strategy is implemented'
8
+ task mutant: :coverage do
9
+ system(*%w[
10
+ bundle exec mutant
11
+ --include lib
12
+ --require unparser
13
+ --use rspec
14
+ --zombie
15
+ --since HEAD~1
16
+ --
17
+ Unparser*
18
+ ]) or fail "Mutant task failed"
10
19
  end
11
20
  end
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
2
  trap('INT') do |status|
5
3
  exit! 128 + status
6
4
  end
@@ -1,2 +1,2 @@
1
1
  ---
2
- unit_test_timeout: 1.0
2
+ unit_test_timeout: 2.0
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 13
3
- total_score: 666
3
+ total_score: 673
@@ -1,2 +1,2 @@
1
1
  ---
2
- threshold: 23.7
2
+ threshold: 21.3
@@ -55,7 +55,7 @@ BooleanParameter:
55
55
  enabled: true
56
56
  IrresponsibleModule:
57
57
  exclude: []
58
- enabled: true
58
+ enabled: false # buggy / broken
59
59
  UncommunicativeModuleName:
60
60
  accept: []
61
61
  exclude: []
@@ -90,6 +90,9 @@ UtilityFunction:
90
90
  exclude:
91
91
  # Intent to be helper methods
92
92
  - Unparser::CLI::Source#strip
93
+ - Unparser::CLI::Source#parse
94
+ - Unparser::NodeHelpers#n
95
+ - Unparser::NodeHelpers#s
93
96
  - Unparser::CLI#sources
94
97
  enabled: true
95
98
  Attribute:
@@ -72,10 +72,6 @@ ConstantName:
72
72
  TrivialAccessors:
73
73
  Enabled: false
74
74
 
75
- # Do not prefer do/end over {} for multiline blocks
76
- Blocks:
77
- Enabled: false
78
-
79
75
  # I like to have an empty line before closing the currently opened body
80
76
  EmptyLinesAroundBlockBody:
81
77
  Enabled: false
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'set'
4
2
  require 'abstract_type'
5
3
  require 'procto'
@@ -58,6 +56,7 @@ require 'unparser/emitter/send/unary'
58
56
  require 'unparser/emitter/send/binary'
59
57
  require 'unparser/emitter/send/index'
60
58
  require 'unparser/emitter/send/regular'
59
+ require 'unparser/emitter/send/conditional'
61
60
  require 'unparser/emitter/send/arguments'
62
61
  require 'unparser/emitter/send/attribute_assignment'
63
62
  require 'unparser/emitter/block'
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module Unparser
4
2
  # Namespace for AST processing tools
5
3
  module AST
@@ -1,5 +1,3 @@
1
- # encoding: UTF-8
2
-
3
1
  module Unparser
4
2
  module AST
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
 
5
3
  # Buffer used to emit into
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'unparser'
4
2
  require 'optparse'
5
3
  require 'diff/lcs'
@@ -38,7 +36,8 @@ module Unparser
38
36
  # @api private
39
37
  #
40
38
  def initialize(arguments)
41
- @sources, @ignore = [], Set.new
39
+ @sources = []
40
+ @ignore = Set.new
42
41
 
43
42
  @success = true
44
43
  @fail_fast = false
@@ -91,7 +90,7 @@ module Unparser
91
90
  effective_sources.each do |source|
92
91
  next if @ignore.include?(source)
93
92
  process_source(source)
94
- break unless @success if @fail_fast
93
+ break if @fail_fast && !@success
95
94
  end
96
95
 
97
96
  @success ? EXIT_SUCCESS : EXIT_FAILURE
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  # Class to colorize strings
5
3
  class Color
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class CLI
5
3
  # Class to create diffs from source code
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class CLI
5
3
  # Source representation for CLI sources
@@ -20,7 +18,7 @@ module Unparser
20
18
  !error
21
19
  end
22
20
 
23
- # Build generateg source
21
+ # Build generated source
24
22
  #
25
23
  # @param [Parser::AST::Node]
26
24
  #
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
 
5
3
  # Holds the comments that remain to be emitted
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  # All unparser constants maybe included in other libraries.
5
3
  module Constants
@@ -1,8 +1,9 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
 
5
3
  # Emitter base class
4
+ #
5
+ # buggy, argument values are sends to self
6
+ # rubocop:disable CircularArgumentReference
6
7
  class Emitter
7
8
  include Adamantium::Flat, AbstractType, Constants, NodeHelpers
8
9
  include Concord.new(:node, :parent)
@@ -198,7 +199,7 @@ module Unparser
198
199
  emitter.write_to_buffer
199
200
  end
200
201
 
201
- # Visit ambigous node
202
+ # Visit ambiguous node
202
203
  #
203
204
  # @param [Parser::AST::Node] node
204
205
  #
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for alias nodes
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
 
@@ -38,7 +36,7 @@ module Unparser
38
36
  children.empty?
39
37
  end
40
38
 
41
- TERMINATING_PARENT = [:root, :dyn_str_body].to_set.freeze
39
+ TERMINATING_PARENT = %i(root interpolated dyn_str_body).to_set.freeze
42
40
 
43
41
  private
44
42
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Base class for binary emitters
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for case nodes
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for toplevel constant reference nodes
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for class nodes
@@ -41,7 +39,7 @@ module Unparser
41
39
  end # Class
42
40
 
43
41
  # Emitter for sclass nodes
44
- class SClass < self
42
+ class SClass < self
45
43
  include Terminated
46
44
 
47
45
  handle :sclass
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for def node
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for defined? nodes
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for flip flops
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter control flow modifiers
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter for for nodes
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Base class for pre and postexe emitters
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Emitter if nodes
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  # Namespace class for literal emiters
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Literal
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Unparser
4
2
  class Emitter
5
3
  class Literal
@@ -17,21 +15,7 @@ module Unparser
17
15
  #
18
16
  def dispatch
19
17
  util = self.class
20
- if interpolation?
21
- visit_parentheses(dynamic_body, util::OPEN, util::CLOSE)
22
- else
23
- emit_non_interpolated
24
- end
25
- end
26
-
27
- # Test for interpolation
28
- #
29
- # @return [Boolean]
30
- #
31
- # @api private
32
- #
33
- def interpolation?
34
- children.any? { |child| !child.type.equal?(:str) }
18
+ visit_parentheses(dynamic_body, util::OPEN, util::CLOSE)
35
19
  end
36
20
 
37
21
  # Return dynamic body
@@ -50,18 +34,6 @@ module Unparser
50
34
  OPEN = CLOSE = '"'.freeze
51
35
  handle :dstr
52
36
 
53
- private
54
-
55
- # Emit non interpolated form
56
- #
57
- # @return [undefined]
58
- #
59
- # @api private
60
- #
61
- def emit_non_interpolated
62
- delimited(children, WS)
63
- end
64
-
65
37
  end # String
66
38
 
67
39
  # Dynamic symbol literal emitter
@@ -72,21 +44,8 @@ module Unparser
72
44
 
73
45
  handle :dsym
74
46
 
75
- private
76
-
77
- # Emit non interpolated form
78
- #
79
- # @return [undefined]
80
- #
81
- # @api private
82
- #
83
- def emit_non_interpolated
84
- visit_parentheses(dynamic_body, OPEN, CLOSE)
85
- end
86
-
87
47
  end # Symbol
88
-
89
- end
48
+ end # Dynamic
90
49
  end # Literal
91
50
  end # Emitter
92
51
  end # Unparser