unparser 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +38 -2
  3. data/.travis.yml +3 -6
  4. data/Changelog.md +7 -0
  5. data/Gemfile +1 -0
  6. data/Gemfile.devtools +22 -17
  7. data/README.md +3 -4
  8. data/TODO +3 -2
  9. data/bin/unparser +10 -0
  10. data/circle.yml +2 -0
  11. data/config/flay.yml +1 -1
  12. data/config/flog.yml +1 -1
  13. data/config/reek.yml +10 -0
  14. data/config/rubocop.yml +9 -17
  15. data/lib/unparser.rb +8 -1
  16. data/lib/unparser/buffer.rb +2 -0
  17. data/lib/unparser/cli.rb +113 -0
  18. data/lib/unparser/cli/differ.rb +30 -0
  19. data/lib/unparser/cli/preprocessor.rb +196 -0
  20. data/lib/unparser/cli/source.rb +118 -0
  21. data/lib/unparser/comments.rb +64 -23
  22. data/lib/unparser/constants.rb +19 -7
  23. data/lib/unparser/emitter.rb +23 -25
  24. data/lib/unparser/emitter/alias.rb +2 -0
  25. data/lib/unparser/emitter/argument.rb +2 -0
  26. data/lib/unparser/emitter/assignment.rb +3 -1
  27. data/lib/unparser/emitter/begin.rb +3 -6
  28. data/lib/unparser/emitter/binary.rb +2 -0
  29. data/lib/unparser/emitter/block.rb +2 -0
  30. data/lib/unparser/emitter/break.rb +4 -5
  31. data/lib/unparser/emitter/case.rb +2 -0
  32. data/lib/unparser/emitter/cbase.rb +2 -0
  33. data/lib/unparser/emitter/class.rb +4 -3
  34. data/lib/unparser/emitter/def.rb +2 -0
  35. data/lib/unparser/emitter/defined.rb +2 -0
  36. data/lib/unparser/emitter/empty.rb +2 -0
  37. data/lib/unparser/emitter/ensure.rb +2 -0
  38. data/lib/unparser/emitter/flipflop.rb +2 -0
  39. data/lib/unparser/emitter/for.rb +2 -0
  40. data/lib/unparser/emitter/hookexe.rb +2 -0
  41. data/lib/unparser/emitter/if.rb +2 -0
  42. data/lib/unparser/emitter/literal.rb +2 -0
  43. data/lib/unparser/emitter/literal/array.rb +33 -0
  44. data/lib/unparser/emitter/literal/dynamic.rb +21 -1
  45. data/lib/unparser/emitter/literal/dynamic_body.rb +9 -5
  46. data/lib/unparser/emitter/literal/execute_string.rb +2 -0
  47. data/lib/unparser/emitter/literal/hash.rb +136 -0
  48. data/lib/unparser/emitter/literal/primitive.rb +4 -2
  49. data/lib/unparser/emitter/literal/range.rb +2 -0
  50. data/lib/unparser/emitter/literal/regexp.rb +4 -2
  51. data/lib/unparser/emitter/literal/singleton.rb +2 -0
  52. data/lib/unparser/emitter/match.rb +2 -0
  53. data/lib/unparser/emitter/module.rb +2 -3
  54. data/lib/unparser/emitter/next.rb +2 -0
  55. data/lib/unparser/emitter/op_assign.rb +3 -1
  56. data/lib/unparser/emitter/redo.rb +2 -0
  57. data/lib/unparser/emitter/repetition.rb +2 -0
  58. data/lib/unparser/emitter/resbody.rb +2 -0
  59. data/lib/unparser/emitter/rescue.rb +2 -0
  60. data/lib/unparser/emitter/retry.rb +2 -0
  61. data/lib/unparser/emitter/return.rb +19 -4
  62. data/lib/unparser/emitter/root.rb +13 -0
  63. data/lib/unparser/emitter/send.rb +26 -22
  64. data/lib/unparser/emitter/send/arguments.rb +46 -0
  65. data/lib/unparser/emitter/send/attribute_assignment.rb +35 -0
  66. data/lib/unparser/emitter/send/binary.rb +2 -0
  67. data/lib/unparser/emitter/send/index.rb +2 -0
  68. data/lib/unparser/emitter/send/regular.rb +4 -2
  69. data/lib/unparser/emitter/send/unary.rb +3 -1
  70. data/lib/unparser/emitter/splat.rb +2 -0
  71. data/lib/unparser/emitter/super.rb +2 -0
  72. data/lib/unparser/emitter/undef.rb +2 -0
  73. data/lib/unparser/emitter/variable.rb +2 -0
  74. data/lib/unparser/emitter/yield.rb +2 -0
  75. data/lib/unparser/finalize.rb +2 -0
  76. data/lib/unparser/node_helpers.rb +19 -0
  77. data/spec/spec_helper.rb +10 -0
  78. data/spec/unit/unparser/buffer/append_spec.rb +2 -0
  79. data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +2 -0
  80. data/spec/unit/unparser/buffer/capture_content_spec.rb +2 -0
  81. data/spec/unit/unparser/buffer/content_spec.rb +3 -1
  82. data/spec/unit/unparser/buffer/fresh_line_spec.rb +2 -0
  83. data/spec/unit/unparser/buffer/indent_spec.rb +3 -1
  84. data/spec/unit/unparser/buffer/nl_spec.rb +2 -0
  85. data/spec/unit/unparser/buffer/unindent_spec.rb +2 -0
  86. data/spec/unit/unparser/comments/consume_spec.rb +2 -1
  87. data/spec/unit/unparser/comments/take_all_spec.rb +2 -1
  88. data/spec/unit/unparser/comments/take_before_spec.rb +6 -5
  89. data/spec/unit/unparser/comments/take_eol_comments_spec.rb +2 -1
  90. data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +2 -0
  91. data/spec/unit/unparser_spec.rb +110 -57
  92. data/unparser.gemspec +5 -4
  93. metadata +32 -12
  94. data/bin/test-unparser +0 -26
  95. data/lib/unparser/emitter/literal/composed.rb +0 -64
  96. data/spec/unit/unparser/comments/skip_eol_comment_spec.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b6b34a335d81e60393e168fed525e222b2c5300
4
- data.tar.gz: dafb68722a32c72bd1200db7b92a1a6477f54c95
3
+ metadata.gz: b62c76f077c1633ea95d4b674eef40c4862bd841
4
+ data.tar.gz: 77d01fff24751db00c267068880942f8df8a588a
5
5
  SHA512:
6
- metadata.gz: 77fda7c1b4c35dfad959a0a9c47bc9f5cdaae335fb3d302bb4b3f0e683c9733e6c6005ffe2495f0c91c0bf5d39e1b173bf99e1c918d13ef6f622d73079e4c534
7
- data.tar.gz: b0252bbfb29b1c29b7e1de2fc7dd3719288c5b8227684558e7db7bc2c2cb347863123a10131a52c8ea6c2261a88879d6d64aec347189f68b09a7356a8e03531d
6
+ metadata.gz: e0cf99eb3262e4d55e8899a1c924d5388cdb55d5991ce33da2ac2717a9cdf8c9bccabaf56c316c8615184627ede859e2cdbfe2472507a7d6985c7ead2e57c26f
7
+ data.tar.gz: 7b78d0c2cdedf07d26f7f7f166587a08f2142be202de2fe1bba51b6ce3a12aff60f0abdb8164342b4b7ae3c516959ae580e83c33e266263c46b6d5e2bdd584a7
data/.gitignore CHANGED
@@ -1,2 +1,38 @@
1
- /tmp
2
- /Gemfile.lock
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.sw[op]
15
+
16
+ ## Rubinius
17
+ *.rbc
18
+ .rbx
19
+
20
+ ## PROJECT::GENERAL
21
+ *.gem
22
+ coverage
23
+ profiling
24
+ turbulence
25
+ rdoc
26
+ pkg
27
+ tmp
28
+ doc
29
+ log
30
+ .yardoc
31
+ measurements
32
+
33
+ ## BUNDLER
34
+ .bundle
35
+ Gemfile.lock
36
+
37
+ ## PROJECT::SPECIFIC
38
+ /vendor
data/.travis.yml CHANGED
@@ -3,12 +3,9 @@ script: 'bundle exec rake spec'
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - jruby-19mode
7
- - jruby-head
8
- - rbx-19mode
9
- matrix:
10
- allow_failures:
11
- - rvm: ruby-head
6
+ - ruby
7
+ - jruby
8
+ - rbx
12
9
  notifications:
13
10
  irc:
14
11
  channels:
data/Changelog.md CHANGED
@@ -1,3 +1,10 @@
1
+ # v0.1.6 2013-12-31
2
+
3
+ * Emit 1.9 style hashes where possible: https://github.com/mbj/unparser/pull/23
4
+ * Fix invalid quoting of hash keys: https://github.com/mbj/unparser/issues/22
5
+ * Fix crash on take before introduced by code refactorings: https://github.com/mbj/unparser/issues/20
6
+ * Fix crash on comment reproduction https://github.com/mbj/unparser/issues/17
7
+
1
8
  # v0.1.5 2013-11-01
2
9
 
3
10
  * Fix crash with comment reproduction.
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  gemspec
data/Gemfile.devtools CHANGED
@@ -4,21 +4,24 @@ group :development do
4
4
  gem 'rake', '~> 10.1.0'
5
5
  gem 'rspec', '~> 2.14.1'
6
6
  gem 'yard', '~> 0.8.7'
7
+
8
+ platform :rbx do
9
+ gem 'rubysl-singleton', '~> 2.0.0'
10
+ end
7
11
  end
8
12
 
9
13
  group :yard do
10
- gem 'kramdown', '~> 1.2.0'
14
+ gem 'kramdown', '~> 1.3.0'
11
15
  end
12
16
 
13
17
  group :guard do
14
- gem 'guard', '~> 1.8.1'
15
- gem 'guard-bundler', '~> 1.0.0'
16
- gem 'guard-rspec', '~> 3.0.2'
17
- gem 'guard-rubocop', '~> 0.2.0'
18
- gem 'guard-mutant', '~> 0.0.1'
18
+ gem 'guard', '~> 2.2.4'
19
+ gem 'guard-bundler', '~> 2.0.0'
20
+ gem 'guard-rspec', '~> 4.2.0'
21
+ gem 'guard-rubocop', '~> 1.0.0'
19
22
 
20
23
  # file system change event handling
21
- gem 'listen', '~> 1.3.0'
24
+ gem 'listen', '~> 2.4.0'
22
25
  gem 'rb-fchange', '~> 0.0.6', require: false
23
26
  gem 'rb-fsevent', '~> 0.9.3', require: false
24
27
  gem 'rb-inotify', '~> 0.9.0', require: false
@@ -32,24 +35,26 @@ end
32
35
  group :metrics do
33
36
  gem 'coveralls', '~> 0.7.0'
34
37
  gem 'flay', '~> 2.4.0'
35
- gem 'flog', '~> 4.1.1'
38
+ gem 'flog', '~> 4.2.0'
36
39
  gem 'reek', '~> 1.3.2'
37
- gem 'rubocop', '~> 0.14.1'
38
- gem 'simplecov', '~> 0.7.1'
40
+ gem 'rubocop', '~> 0.16.0'
41
+ gem 'simplecov', '~> 0.8.2'
39
42
  gem 'yardstick', '~> 0.9.7', git: 'https://github.com/dkubb/yardstick.git'
40
43
 
41
44
  platforms :ruby_19, :ruby_20 do
42
- gem 'mutant', git: 'https://github.com/mbj/mutant.git'
45
+ gem 'mutant', '~> 0.3.0', git: 'https://github.com/mbj/mutant.git'
43
46
  gem 'yard-spellcheck', '~> 0.1.5'
44
47
  end
48
+
49
+ platform :rbx do
50
+ gem 'json', '~> 1.8.1'
51
+ gem 'racc', '~> 1.4.10'
52
+ gem 'rubysl-logger', '~> 2.0.0'
53
+ gem 'rubysl-open-uri', '~> 2.0.0'
54
+ gem 'rubysl-prettyprint', '~> 2.0.2'
55
+ end
45
56
  end
46
57
 
47
58
  group :benchmarks do
48
59
  gem 'rbench', '~> 0.2.3'
49
60
  end
50
-
51
- platform :jruby do
52
- group :jruby do
53
- gem 'jruby-openssl', '~> 0.8.5'
54
- end
55
- end
data/README.md CHANGED
@@ -7,11 +7,10 @@ unparser
7
7
 
8
8
  Generate equivalent source for ASTs from whitequarks awesome [parser](https://github.com/whitequark/parser).
9
9
 
10
- This library is in early development stage and still has some bugs/missing features.
11
- Nevertheless it is able to regenerate it own source and serves well for
12
- [mutant](https://github.cm/mbj/mutant) mutators and the in-memory vendoring for self hosting mutant.
10
+ This library is able to reproduce 100% of ruby 1.9 and 2.0 syntax. Including its own source code.
11
+ It serves well for [mutant](https://github.cm/mbj/mutant) mutators and the in-memory vendoring for self hosting.
13
12
 
14
- This library dropped the reproduction of 1.8 syntax in the 0.1.0 release.
13
+ This library dropped the reproduction of 1.8 syntax in the 0.1.0 release. It currently does not have support for 2.1 specific syntax.
15
14
 
16
15
  Usage
17
16
  -----
data/TODO CHANGED
@@ -1,3 +1,4 @@
1
- * Refactor Emitter::Send, it is ugly.
1
+ * Create an AST preprocessor that creates virtual nodes,
2
+ removing the need for explicit backreferencing and special cases in the emitter
3
+ classes.
2
4
  * Remove duplicated logic with empty or non empty bodies
3
- * Handle kwbegin and begin separately
data/bin/unparser ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ trap('INT') do |status|
5
+ exit! 128 + status
6
+ end
7
+
8
+ require 'unparser/cli'
9
+
10
+ exit Unparser::CLI.run(ARGV)
data/circle.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  ---
2
+ ruby:
3
+ version: 2.0.0-p353
2
4
  test:
3
5
  override:
4
6
  - bundle exec rake ci
data/config/flay.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 13
3
- total_score: 410
3
+ total_score: 497
data/config/flog.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  ---
2
- threshold: 13.1
2
+ threshold: 24.5
data/config/reek.yml CHANGED
@@ -36,8 +36,13 @@ LongParameterList:
36
36
  FeatureEnvy:
37
37
  exclude:
38
38
  - Unparser::Emitter::Literal::Regexp#escape # TODO Fixme!
39
+ - Unparser::Emitter::Send::Arguments#effective_arguments # False positive
39
40
  - Unparser::Emitter::Send#binary_receiver?
40
41
  - Unparser::Emitter#visit_terminated
42
+ - Unparser::CLI#add_options
43
+ - Unparser::CLI::Source#error_report
44
+ - Unparser::CLI::Preprocessor::Dstr#collapsed_children
45
+ - Unparser::Comments#take_before
41
46
  enabled: true
42
47
  ClassVariable:
43
48
  exclude: []
@@ -60,11 +65,15 @@ NestedIterators:
60
65
  exclude:
61
66
  - Unparser::Emitter#self.children
62
67
  - Unparser::Emitter::Literal::Regexp#dispatch
68
+ - Unparser::Emitter::Return#emit_break_return_arguments
69
+ - Unparser::CLI::Preprocessor::Dstr#collapsed_children
63
70
  enabled: true
64
71
  max_allowed_nesting: 1
65
72
  TooManyStatements:
66
73
  max_statements: 6
67
74
  enabled: true
75
+ exclude:
76
+ - Unparser::CLI::Source#error_report
68
77
  DuplicateMethodCall:
69
78
  allow_calls: []
70
79
  exclude: []
@@ -91,6 +100,7 @@ RepeatedConditional:
91
100
  - Unparser::Comments # FIXME
92
101
  - Unparser::Emitter::Send # TODO Fixme
93
102
  - Unparser::Emitter::If
103
+ - Unparser::CLI # False positive
94
104
  enabled: true
95
105
  max_ifs: 1
96
106
  DataClump:
data/config/rubocop.yml CHANGED
@@ -28,21 +28,12 @@ CollectionMethods:
28
28
  find: 'detect'
29
29
  find_all: 'select'
30
30
 
31
- # Do not force public/protected/private keyword to be indented at the same
32
- # level as the def keyword. My personal preference is to outdent these keywords
33
- # because I think when scanning code it makes it easier to identify the
34
- # sections of code and visually separate them. When the keyword is at the same
35
- # level I think it sort of blends in with the def keywords and makes it harder
36
- # to scan the code and see where the sections are.
37
- AccessControl:
38
- Enabled: false
39
-
40
31
  # Limit line length
41
32
  LineLength:
42
33
  Max: 113 # TODO: lower to 79 once the rubocop branch in shared/Gemfile is removed
43
34
 
44
35
  ClassLength:
45
- Max: 196
36
+ Max: 204
46
37
 
47
38
  # Disabled because of indenting with private keyword in class bodies.
48
39
  IndentationWidth:
@@ -52,13 +43,6 @@ IndentationWidth:
52
43
  SignalException:
53
44
  Enabled: false
54
45
 
55
- # Disable Symbol cop because unparse has to prodice "WIERD" symbols in his specs
56
- #
57
- # I'd love I could ignore a specific occurance.
58
- #
59
- SymbolName:
60
- Enabled: false
61
-
62
46
  # False positive in unparser source
63
47
  OneLineConditional:
64
48
  Enabled: false
@@ -89,3 +73,11 @@ TrivialAccessors:
89
73
  # Do not prefer do/end over {} for multiline blocks
90
74
  Blocks:
91
75
  Enabled: false
76
+
77
+ # I like to have an empty line before closing the currently opened body
78
+ EmptyLinesAroundBody:
79
+ Enabled: false
80
+
81
+ # I like my style more
82
+ AccessModifierIndentation:
83
+ Enabled: false
data/lib/unparser.rb CHANGED
@@ -1,4 +1,7 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'abstract_type'
4
+ require 'procto'
2
5
  require 'concord'
3
6
  require 'parser/all'
4
7
 
@@ -47,6 +50,7 @@ module Unparser
47
50
  end # Unparser
48
51
 
49
52
  require 'unparser/buffer'
53
+ require 'unparser/node_helpers'
50
54
  require 'unparser/comments'
51
55
  require 'unparser/constants'
52
56
  require 'unparser/emitter'
@@ -55,7 +59,8 @@ require 'unparser/emitter/literal/primitive'
55
59
  require 'unparser/emitter/literal/singleton'
56
60
  require 'unparser/emitter/literal/dynamic'
57
61
  require 'unparser/emitter/literal/regexp'
58
- require 'unparser/emitter/literal/composed'
62
+ require 'unparser/emitter/literal/array'
63
+ require 'unparser/emitter/literal/hash'
59
64
  require 'unparser/emitter/literal/range'
60
65
  require 'unparser/emitter/literal/dynamic_body'
61
66
  require 'unparser/emitter/literal/execute_string'
@@ -64,6 +69,8 @@ require 'unparser/emitter/send/unary'
64
69
  require 'unparser/emitter/send/binary'
65
70
  require 'unparser/emitter/send/index'
66
71
  require 'unparser/emitter/send/regular'
72
+ require 'unparser/emitter/send/arguments'
73
+ require 'unparser/emitter/send/attribute_assignment'
67
74
  require 'unparser/emitter/block'
68
75
  require 'unparser/emitter/assignment'
69
76
  require 'unparser/emitter/variable'
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Unparser
2
4
 
3
5
  # Buffer used to emit into
@@ -0,0 +1,113 @@
1
+ # encoding: utf-8
2
+
3
+ require 'unparser'
4
+ require 'mutant'
5
+ require 'optparse'
6
+
7
+ require 'unparser/cli/preprocessor'
8
+ require 'unparser/cli/source'
9
+ require 'unparser/cli/differ'
10
+
11
+ module Unparser
12
+ # Unparser CLI implementation
13
+ class CLI
14
+
15
+ EXIT_SUCCESS = 0
16
+ EXIT_FAILURE = 1
17
+
18
+ # Run CLI
19
+ #
20
+ # @param [Array<String>] arguments
21
+ #
22
+ # @return [Fixnum]
23
+ # the exit status
24
+ #
25
+ # @api private
26
+ #
27
+ def self.run(*arguments)
28
+ new(*arguments).exit_status
29
+ end
30
+
31
+ # Initialize object
32
+ #
33
+ # @param [Array<String>] arguments
34
+ #
35
+ # @return [undefined]
36
+ #
37
+ # @api private
38
+ #
39
+ def initialize(arguments)
40
+ @sources = []
41
+
42
+ @success = true
43
+ @fail_fast = false
44
+
45
+ opts = OptionParser.new do |builder|
46
+ add_options(builder)
47
+ end
48
+
49
+ file_names = opts.parse!(arguments)
50
+
51
+ file_names.each do |file_name|
52
+ @sources << Source::File.new(file_name)
53
+ end
54
+ end
55
+
56
+ # Add options
57
+ #
58
+ # @param [Optparse::Builder] builder
59
+ #
60
+ # @return [undefined]
61
+ #
62
+ # @api private
63
+ #
64
+ def add_options(builder)
65
+ builder.banner = 'usage: unparse [options] FILE [FILE]'
66
+ builder.separator('')
67
+ builder.on('-e', '--evaluate SOURCE') do |original_source|
68
+ @sources << Source::String.new(original_source)
69
+ end
70
+ builder.on('--fail-fast') do
71
+ @fail_fast = true
72
+ end
73
+ end
74
+
75
+ # Return exit status
76
+ #
77
+ # @return [Fixnum]
78
+ #
79
+ # @api private
80
+ #
81
+ def exit_status
82
+ @sources.each do |source|
83
+ process_source(source)
84
+ if @fail_fast
85
+ break unless @success
86
+ end
87
+ end
88
+
89
+ @success ? EXIT_SUCCESS : EXIT_FAILURE
90
+ end
91
+
92
+ private
93
+
94
+ # Process source
95
+ #
96
+ # @param [CLI::Source]
97
+ #
98
+ # @return [undefined]
99
+ #
100
+ # @api private
101
+ #
102
+ def process_source(source)
103
+ if source.success?
104
+ puts "Success: #{source.identification}"
105
+ else
106
+ puts source.error_report
107
+ puts "Error: #{source.identification}"
108
+ @success = false
109
+ end
110
+ end
111
+
112
+ end # CLI
113
+ end # Unparser