to_source 0.1.3 → 0.2.16

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.
Files changed (89) hide show
  1. data/.gitignore +6 -6
  2. data/.rspec +1 -0
  3. data/.travis.yml +12 -1
  4. data/Changelog.md +115 -0
  5. data/Gemfile +5 -3
  6. data/Gemfile.devtools +67 -0
  7. data/Guardfile +18 -0
  8. data/LICENSE +21 -0
  9. data/README.md +52 -0
  10. data/Rakefile +3 -8
  11. data/TODO +9 -0
  12. data/bin/to_source +17 -0
  13. data/config/flay.yml +3 -0
  14. data/config/flog.yml +2 -0
  15. data/config/roodi.yml +26 -0
  16. data/config/site.reek +97 -0
  17. data/config/yardstick.yml +2 -0
  18. data/lib/to_source/command.rb +106 -0
  19. data/lib/to_source/emitter/access.rb +28 -0
  20. data/lib/to_source/emitter/actual_arguments.rb +89 -0
  21. data/lib/to_source/emitter/alias.rb +27 -0
  22. data/lib/to_source/emitter/assignment.rb +119 -0
  23. data/lib/to_source/emitter/attribute_assignment.rb +28 -0
  24. data/lib/to_source/emitter/begin.rb +71 -0
  25. data/lib/to_source/emitter/binary_operator.rb +63 -0
  26. data/lib/to_source/emitter/binary_operator_method.rb +58 -0
  27. data/lib/to_source/emitter/block.rb +29 -0
  28. data/lib/to_source/emitter/block_argument.rb +23 -0
  29. data/lib/to_source/emitter/block_pass.rb +23 -0
  30. data/lib/to_source/emitter/case.rb +85 -0
  31. data/lib/to_source/emitter/class.rb +44 -0
  32. data/lib/to_source/emitter/concat_arguments.rb +28 -0
  33. data/lib/to_source/emitter/default_arguments.rb +22 -0
  34. data/lib/to_source/emitter/define.rb +99 -0
  35. data/lib/to_source/emitter/defined.rb +24 -0
  36. data/lib/to_source/emitter/element_assignment.rb +29 -0
  37. data/lib/to_source/emitter/element_reference.rb +25 -0
  38. data/lib/to_source/emitter/empty_body.rb +21 -0
  39. data/lib/to_source/emitter/ensure.rb +50 -0
  40. data/lib/to_source/emitter/ensure_body.rb +27 -0
  41. data/lib/to_source/emitter/execute_string.rb +22 -0
  42. data/lib/to_source/emitter/formal_arguments.rb +212 -0
  43. data/lib/to_source/emitter/if.rb +96 -0
  44. data/lib/to_source/emitter/iter.rb +27 -0
  45. data/lib/to_source/emitter/keyword_value.rb +67 -0
  46. data/lib/to_source/emitter/literal/dynamic.rb +178 -0
  47. data/lib/to_source/emitter/literal.rb +232 -0
  48. data/lib/to_source/emitter/loop.rb +40 -0
  49. data/lib/to_source/emitter/match3.rb +25 -0
  50. data/lib/to_source/emitter/module.rb +28 -0
  51. data/lib/to_source/emitter/multiple_assignment.rb +49 -0
  52. data/lib/to_source/emitter/nth_ref.rb +22 -0
  53. data/lib/to_source/emitter/op_assign1.rb +27 -0
  54. data/lib/to_source/emitter/op_assign2.rb +27 -0
  55. data/lib/to_source/emitter/pattern_arguments.rb +24 -0
  56. data/lib/to_source/emitter/rescue.rb +28 -0
  57. data/lib/to_source/emitter/rescue_condition.rb +93 -0
  58. data/lib/to_source/emitter/scope.rb +24 -0
  59. data/lib/to_source/emitter/scope_name.rb +23 -0
  60. data/lib/to_source/emitter/scoped_name.rb +28 -0
  61. data/lib/to_source/emitter/send.rb +133 -0
  62. data/lib/to_source/emitter/send_with_arguments.rb +103 -0
  63. data/lib/to_source/emitter/singleton_class.rb +38 -0
  64. data/lib/to_source/emitter/splat.rb +24 -0
  65. data/lib/to_source/emitter/splat_when.rb +23 -0
  66. data/lib/to_source/emitter/static.rb +52 -0
  67. data/lib/to_source/emitter/super.rb +92 -0
  68. data/lib/to_source/emitter/to_array.rb +22 -0
  69. data/lib/to_source/emitter/to_string.rb +24 -0
  70. data/lib/to_source/emitter/toplevel.rb +24 -0
  71. data/lib/to_source/emitter/unary_operator_method.rb +27 -0
  72. data/lib/to_source/emitter/unless.rb +45 -0
  73. data/lib/to_source/emitter/util.rb +28 -0
  74. data/lib/to_source/emitter/when.rb +63 -0
  75. data/lib/to_source/emitter/yield.rb +28 -0
  76. data/lib/to_source/emitter/z_super.rb +24 -0
  77. data/lib/to_source/emitter.rb +278 -0
  78. data/lib/to_source/state.rb +144 -0
  79. data/lib/to_source.rb +78 -11
  80. data/spec/spec_helper.rb +11 -0
  81. data/spec/unit/to_source/class_methods/run_spec.rb +1254 -0
  82. data/to_source.gemspec +16 -14
  83. metadata +160 -20
  84. data/.rvmrc +0 -1
  85. data/Readme.md +0 -38
  86. data/lib/to_source/core_ext/node.rb +0 -22
  87. data/lib/to_source/version.rb +0 -3
  88. data/lib/to_source/visitor.rb +0 -377
  89. data/test/to_source/visitor_test.rb +0 -202
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
5
- .rbx
6
- *.rbc
1
+ /*.gem
2
+ /.bundle
3
+ /Gemfile.lock
4
+ /pkg/*
5
+ /.rbx
6
+ /tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml CHANGED
@@ -1,3 +1,14 @@
1
+ language: ruby
2
+ bundler_args: --without guard metrics
3
+ script: "bundle exec rake spec"
1
4
  rvm:
2
- - rbx-18mode
5
+ #- 1.8.7
6
+ - 1.9.2
7
+ - 1.9.3
8
+ #- jruby-18mode # JRuby in 1.8 mode, no cextension support on travis
9
+ #- jruby-19mode # JRuby in 1.9 mode, no cextension support on travis
10
+ #- rbx-18mode
3
11
  - rbx-19mode
12
+ notifications:
13
+ email:
14
+ - mbj@seonic.net
data/Changelog.md ADDED
@@ -0,0 +1,115 @@
1
+ # v0.2.15 2013-01-25
2
+
3
+ * [fixed] Handle Rubinius::AST::Case
4
+
5
+ # v0.2.15 2013-01-24
6
+
7
+ * [fixed] Emit dynamic regexp literals with split groups correctly
8
+
9
+ # v0.2.14 2013-01-09
10
+
11
+ * [fixed] Emit send with arguments and body correctly
12
+
13
+ [Compare v0.2.13..v0.2.14](https://github.com/mbj/to_source/compare/v0.2.13...v0.2.14)
14
+
15
+ # v0.2.13 2013-01-09
16
+
17
+ * [fixed] Emit send with arguments and body correctly
18
+
19
+ [Compare v0.2.12..v0.2.13](https://github.com/mbj/to_source/compare/v0.2.12...v0.2.13)
20
+
21
+ # v0.2.12 2013-01-09
22
+
23
+ * [fixed] Emit edge cases with dynamic literals correctly
24
+
25
+ [Compare v0.2.11..v0.2.12](https://github.com/mbj/to_source/compare/v0.2.11...v0.2.12)
26
+
27
+ # v0.2.11 2013-01-09
28
+
29
+ * [fixed] Allow all nodes to be entrypoints
30
+
31
+ [Compare v0.2.10..v0.2.11](https://github.com/mbj/to_source/compare/v0.2.10...v0.2.11)
32
+
33
+ # v0.2.10 2013-01-07
34
+
35
+ * [Changed] Rewrote internals compleatly, no outer API change
36
+ * [fixed] Emit indentation of complex nested structures with rescue statements correctly
37
+
38
+ [Compare v0.2.9..v0.2.10](https://github.com/mbj/to_source/compare/v0.2.9...v0.2.10)
39
+
40
+ # v0.2.9 2013-01-04
41
+
42
+ * [fixed] Handle regexp literals containing slashes in non shash delimiters %r(/) correctly
43
+
44
+ [Compare v0.2.8..v0.2.9](https://github.com/mbj/to_source/compare/v0.2.8...v0.2.9)
45
+
46
+ # v0.2.8 2013-01-03
47
+
48
+ * [Changed] Emit many times more ugly code, but correctnes > beautifulnes
49
+ * [fixed] Emit break with parantheses
50
+ * [fixed] Emit op assign and as "&&="
51
+ * [fixed] Emit op assign or as "||="
52
+
53
+ [Compare v0.2.7..v0.2.8](https://github.com/mbj/to_source/compare/v0.2.7...v0.2.8)
54
+
55
+ # v0.2.7 2013-01-02
56
+
57
+ * [fixed] Emit super with blocks correctly
58
+
59
+ [Compare v0.2.6..v0.2.7](https://github.com/mbj/to_source/compare/v0.2.6...v0.2.7)
60
+
61
+ # v0.2.6 2013-01-01
62
+
63
+ * [fixed] Emit super vs super() correctly
64
+
65
+ [Compare v0.2.5..v0.2.6](https://github.com/mbj/to_source/compare/v0.2.5...v0.2.6)
66
+
67
+ # v0.2.5 2012-12-14
68
+
69
+ * [fixed] Emit unary operators correctly
70
+ * [fixed] Define with optional splat and block argument
71
+ * [fixed] Emit arguments to break keyword
72
+ * [change] Uglify output of binary operators with unneded paranteses. Correct output > nice output.
73
+ * [fixed] Emit nested binary operators correctly.
74
+ * [fixed] Emit element reference on self correctly. self[foo].
75
+
76
+ [Compare v0.2.4..v0.2.5](https://github.com/mbj/to_source/compare/v0.2.4...v0.2.5)
77
+
78
+ # v0.2.4 2012-12-07
79
+
80
+ * [feature] Allow to emit pattern variables as root node
81
+ * [fixed] Emit send with splat and block argument correctly
82
+
83
+ [Compare v0.2.3..v0.2.4](https://github.com/mbj/to_source/compare/v0.2.3...v0.2.4)
84
+
85
+ # v0.2.3 2012-12-07
86
+
87
+ * [fixed] Nuke dangling require (sorry for not running specs after gemspec change)
88
+
89
+ [Compare v0.2.2..v0.2.3](https://github.com/mbj/to_source/compare/v0.2.2...v0.2.3)
90
+
91
+ # v0.2.2 2012-12-07
92
+
93
+ * [fixed] Emit of pattern arguments with no formal arguments present
94
+ * [fixed] Missed to require set
95
+
96
+ [Compare v0.2.1..v0.2.2](https://github.com/mbj/to_source/compare/v0.2.1...v0.2.2)
97
+
98
+ # v0.2.1 2012-12-07
99
+
100
+ * [fixed] Emit of def on splat with block
101
+ * [fixed] Emit of pattern args
102
+
103
+ [Compare v0.2.0..v0.2.1](https://github.com/mbj/to_source/compare/v0.2.0...v0.2.1)
104
+
105
+ # v0.2.0 2012-12-07
106
+
107
+ * [BRAKING CHANGE] Remove core extension Rubinius::AST::Node#to_source (mbj)
108
+ * [feature] Add support for MRI via melbourne gem (mbj)
109
+ * [fixed] 100% Yard covered documentation (mbj)
110
+ * [fixed] Emit most binary operators without parantheses (mbj)
111
+ * [feature] Port tests to rspec2 and greatly improve coverage and layout of these.
112
+ * [feature] Introduce metric tools via devtools
113
+ * [fixed] Lots of transitvity edge cases
114
+
115
+ [Compare v0.1.3..v0.2.0](https://github.com/mbj/to_source/ompare/v0.1.3...v0.2.0)
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
- # Specify your gem's dependencies in to_source.gemspec
4
3
  gemspec
5
- gem 'rake'
4
+
5
+ gem 'devtools', :git => 'https://github.com/datamapper/devtools.git'
6
+
7
+ eval File.read('Gemfile.devtools')
data/Gemfile.devtools ADDED
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+
3
+ group :development do
4
+ gem 'rake', '~> 10.0.3'
5
+ gem 'rspec', '~> 2.12.0'
6
+ gem 'yard', '~> 0.8.3'
7
+ end
8
+
9
+ group :yard do
10
+ gem 'redcarpet', '~> 2.2.2', :platforms => [ :mri, :rbx ]
11
+ end
12
+
13
+ group :guard do
14
+ gem 'guard', '~> 1.6.1'
15
+ gem 'guard-bundler', '~> 1.0.0'
16
+ gem 'guard-rspec', '~> 2.3.3'
17
+
18
+ # file system change event handling
19
+ gem 'rb-fchange', '~> 0.0.6', :require => false
20
+ gem 'rb-fsevent', '~> 0.9.3', :require => false
21
+ gem 'rb-inotify', '~> 0.9.0', :require => false
22
+
23
+ # Remove this one https://github.com/guard/listen/pull/78 is released
24
+ gem 'listen', '~> 0.7.2', :git => 'https://github.com/guard/listen'
25
+
26
+ # notification handling
27
+ gem 'libnotify', '~> 0.8.0', :require => false
28
+ gem 'rb-notifu', '~> 0.0.4', :require => false
29
+ gem 'terminal-notifier-guard', '~> 1.5.3', :require => false
30
+ end
31
+
32
+ group :metrics do
33
+ gem 'backports', '~> 2.7.0'
34
+ gem 'flay', '~> 1.4.3'
35
+ gem 'flog', '~> 2.5.3'
36
+ gem 'mutant', '~> 0.2.15'
37
+ gem 'reek', '~> 1.2.13', :git => 'https://github.com/troessner/reek.git', :ref => 'ef77fcecaa21c9ebcbe4d9a79d41b0e70196bf18'
38
+ gem 'roodi', '~> 2.1.0'
39
+ gem 'yardstick', '~> 0.9.0'
40
+
41
+ platforms :ruby_18, :ruby_19 do
42
+ # this indirectly depends on ffi which does not build on ruby-head
43
+ gem 'yard-spellcheck', '~> 0.1.5'
44
+ end
45
+
46
+ platforms :mri_18 do
47
+ gem 'rcov', '~> 1.0.0'
48
+ end
49
+
50
+ platforms :mri_19 do
51
+ gem 'simplecov', '~> 0.7.1'
52
+ end
53
+
54
+ platforms :rbx do
55
+ gem 'pelusa', '~> 0.2.2'
56
+ end
57
+ end
58
+
59
+ group :benchmarks do
60
+ gem 'rbench', '~> 0.2.3'
61
+ end
62
+
63
+ platform :jruby do
64
+ group :jruby do
65
+ gem 'jruby-openssl', '~> 0.8.2'
66
+ end
67
+ end
data/Guardfile ADDED
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ guard :bundler do
4
+ watch('Gemfile')
5
+ end
6
+
7
+ guard :rspec do
8
+ # run all specs if the spec_helper or supporting files files are modified
9
+ watch('spec/spec_helper.rb') { 'spec' }
10
+ watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
11
+
12
+ # run unit specs if associated lib code is modified
13
+ watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}"] }
14
+ watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec' }
15
+
16
+ # run a spec if it is modified
17
+ watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
18
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2013 Markus Schirp (mbj)
2
+ 2012 Josep M. Bach (Txus)
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ to_source
2
+ =========
3
+
4
+ [![Build Status](https://secure.travis-ci.org/mbj/to_source.png?branch=master)](http://travis-ci.org/mbj/to_source)
5
+ [![Dependency Status](https://gemnasium.com/mbj/to_source.png)](https://gemnasium.com/mbj/to_source)
6
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/mbj/to_source)
7
+
8
+ Reverse parser to generate source code from the Rubinius AST. Also works well under MRI using the mutant-melbourne gem.
9
+
10
+ Currently only support for 1.9 mode!
11
+
12
+ Installation
13
+ ------------
14
+
15
+ Install the gem ```to_source``` via your preferred method.
16
+
17
+ Examples
18
+ --------
19
+
20
+ ```ruby
21
+ require 'to_source'
22
+ some_code = "a = 123"
23
+ ast = some_code.to_ast
24
+ # => #<Rubinius::AST::LocalVariableAssignment:0x21b8
25
+ # @value=#<Rubinius::AST::FixnumLiteral:0x21bc @value=123 @line=1>
26
+ # @variable=nil @line=1 @name=:a>
27
+ ast.to_source
28
+ # => "a = 123"
29
+ ```
30
+
31
+ Credits
32
+ -------
33
+
34
+ * [Markus Schirp (mbj)](https://github.com/mbj), [@_m_b_j_](http://twitter.com/_m_b_j_) on twitter
35
+ * [Josep M. Bach (Txus)](http://txustice.me), [@txustice](http://twitter.com/txustice) on twitter
36
+
37
+
38
+ Contributing
39
+ -------------
40
+
41
+ * Fork the project.
42
+ * Make your feature addition or bug fix.
43
+ * Add tests for it. This is important so I don't break it in a
44
+ future version unintentionally.
45
+ * Commit, do not mess with Rakefile or version
46
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
47
+ * Send me a pull request. Bonus points for topic branches.
48
+
49
+ License
50
+ -------
51
+
52
+ See LICENSE
data/Rakefile CHANGED
@@ -1,10 +1,5 @@
1
- require "bundler/gem_tasks"
1
+ require 'rake'
2
2
 
3
- require 'rake/testtask'
4
- Rake::TestTask.new do |t|
5
- t.libs << "test"
6
- t.test_files = FileList['test/**/*_test.rb']
7
- t.verbose = true
8
- end
3
+ require 'devtools'
9
4
 
10
- task :default => :test
5
+ Devtools.init
data/TODO ADDED
@@ -0,0 +1,9 @@
1
+ * Do not emit parantheses around non keywords in binary operations (this will beautify source again)
2
+ * Unify code for all binary emitters
3
+ * Add YARD coverage again
4
+ * Fix all dm2 metric tools issues
5
+ * Mutation coverage!
6
+ * Fix parsing errors from ruby parser
7
+ It breaks on def $keyword.
8
+ * Report bug about missing Rubinius::AST::SClass#body
9
+ * Decide about to support 18-mode or not
data/bin/to_source ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'to_source'
4
+
5
+ ARGV.each do |path|
6
+ source = File.read(path)
7
+ ast = source.to_ast
8
+ next if ast.nil? # When file only has comments
9
+ $stderr.puts(path)
10
+ begin
11
+ $stdout.puts(ToSource.to_source(ast))
12
+ rescue
13
+ ast.ascii_graph
14
+ $stderr.puts("Error in: #{path}")
15
+ raise
16
+ end
17
+ end
data/config/flay.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ threshold: 40
3
+ total_score: 719
data/config/flog.yml ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 21.4
data/config/roodi.yml ADDED
@@ -0,0 +1,26 @@
1
+ ---
2
+ AbcMetricMethodCheck:
3
+ score: 12.2
4
+ AssignmentInConditionalCheck: {}
5
+ CaseMissingElseCheck: {}
6
+ ClassLineCountCheck:
7
+ line_count: 324
8
+ #ClassNameCheck:
9
+ # pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/
10
+ ClassVariableCheck: {}
11
+ CyclomaticComplexityBlockCheck:
12
+ complexity: 2
13
+ CyclomaticComplexityMethodCheck:
14
+ complexity: 5
15
+ EmptyRescueBodyCheck: {}
16
+ ForLoopCheck: {}
17
+ MethodLineCountCheck:
18
+ line_count: 11
19
+ MethodNameCheck:
20
+ pattern: !ruby/regexp /\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|<<|[+*&|-])\z/
21
+ ModuleLineCountCheck:
22
+ line_count: 327
23
+ ModuleNameCheck:
24
+ pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/
25
+ ParameterNumberCheck:
26
+ parameter_count: 3
data/config/site.reek ADDED
@@ -0,0 +1,97 @@
1
+ ---
2
+ UnusedParameters:
3
+ exclude:
4
+ - ToSource::Command#run
5
+ UncommunicativeParameterName:
6
+ accept: []
7
+ exclude: []
8
+ enabled: true
9
+ reject:
10
+ - !ruby/regexp /^.$/
11
+ - !ruby/regexp /[0-9]$/
12
+ - !ruby/regexp /[A-Z]/
13
+ LargeClass:
14
+ max_methods: 14 # TODO move down to 10
15
+ exclude: []
16
+ enabled: true
17
+ max_instance_variables: 3
18
+ UncommunicativeMethodName:
19
+ accept: []
20
+ exclude: []
21
+ enabled: true
22
+ reject:
23
+ - !ruby/regexp /^[a-z]$/
24
+ - !ruby/regexp /[0-9]$/
25
+ - !ruby/regexp /[A-Z]/
26
+ LongParameterList:
27
+ max_params: 2
28
+ exclude: []
29
+ enabled: true
30
+ overrides: {}
31
+ FeatureEnvy:
32
+ exclude: []
33
+ enabled: true
34
+ ClassVariable:
35
+ exclude: []
36
+ enabled: true
37
+ BooleanParameter:
38
+ exclude: []
39
+ enabled: true
40
+ IrresponsibleModule:
41
+ exclude: []
42
+ enabled: false
43
+ UncommunicativeModuleName:
44
+ accept:
45
+ - ToSource::Emitter::Match3
46
+ - ToSource::Emitter::OpAssign1
47
+ - ToSource::Emitter::OpAssign2
48
+ exclude: []
49
+ enabled: true
50
+ reject:
51
+ - !ruby/regexp /^.$/
52
+ - !ruby/regexp /[0-9]$/
53
+ NestedIterators:
54
+ ignore_iterators: []
55
+ exclude: []
56
+ enabled: true
57
+ max_allowed_nesting: 1
58
+ LongMethod:
59
+ max_statements: 8 # TODO bring down to 5-6
60
+ exclude: []
61
+ enabled: true
62
+ Duplication:
63
+ allow_calls: []
64
+ exclude: []
65
+ enabled: true
66
+ max_calls: 1
67
+ UtilityFunction:
68
+ max_helper_calls: 0
69
+ exclude: []
70
+ enabled: true
71
+ Attribute:
72
+ exclude: []
73
+ enabled: false
74
+ UncommunicativeVariableName:
75
+ accept: []
76
+ exclude: []
77
+ enabled: true
78
+ reject:
79
+ - !ruby/regexp /^.$/
80
+ - !ruby/regexp /[0-9]$/
81
+ - !ruby/regexp /[A-Z]/
82
+ SimulatedPolymorphism:
83
+ exclude: []
84
+ enabled: true
85
+ max_ifs: 1
86
+ DataClump:
87
+ exclude: []
88
+ enabled: true
89
+ max_copies: 2
90
+ min_clump_size: 2
91
+ ControlCouple:
92
+ exclude: []
93
+ enabled: true
94
+ LongYieldList:
95
+ max_params: 1
96
+ exclude: []
97
+ enabled: true
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 100
@@ -0,0 +1,106 @@
1
+ module ToSource
2
+ # Abstract base class for emitter command
3
+ class Command
4
+ include Adamantium::Flat
5
+
6
+ # A null command
7
+ NULL = Class.new(self) do
8
+
9
+ # Run command
10
+ #
11
+ # @param [State] _state
12
+ #
13
+ # @return [self]
14
+ #
15
+ # @api private
16
+ #
17
+ def run(_state)
18
+ self
19
+ end
20
+ end.new.freeze
21
+
22
+ # Command that emits token
23
+ class Token < self
24
+
25
+ # Return token content
26
+ #
27
+ # @return [String]
28
+ #
29
+ # @api private
30
+ #
31
+ attr_reader :content
32
+
33
+ # Run command
34
+ #
35
+ # @param [State] state
36
+ #
37
+ # @return [self]
38
+ #
39
+ # @api private
40
+ #
41
+ def run(state)
42
+ state.push(self)
43
+ self
44
+ end
45
+
46
+ private
47
+
48
+ # Initialize object
49
+ #
50
+ # @param [String] content
51
+ #
52
+ # @return [undefined]
53
+ #
54
+ # @api private
55
+ #
56
+ def initialize(content)
57
+ @content = content
58
+ end
59
+
60
+ end
61
+
62
+ # Command that does a shift
63
+ class Shift < self
64
+ include Equalizer.new(:width)
65
+
66
+ # Return shift width
67
+ #
68
+ # @return [Fixnum]
69
+ #
70
+ # @api private
71
+ #
72
+ attr_reader :width
73
+
74
+ # Run command
75
+ #
76
+ # @param [State] state
77
+ #
78
+ # @return [self]
79
+ #
80
+ # @api private
81
+ #
82
+ def run(state)
83
+ state.shift(width)
84
+ self
85
+ end
86
+
87
+ private
88
+
89
+ # Initialize command
90
+ #
91
+ # @param [Fixnum] width
92
+ #
93
+ # @return [undefined]
94
+ #
95
+ # @api private
96
+ #
97
+ def initialize(width)
98
+ @width = width
99
+ end
100
+
101
+ INDENT = Shift.new( 2)
102
+ UNINDENT = Shift.new(-2)
103
+ end
104
+
105
+ end
106
+ end
@@ -0,0 +1,28 @@
1
+ module ToSource
2
+ class Emitter
3
+
4
+ # Emitter for various access nodes
5
+ class Access < self
6
+
7
+ handle(Rubinius::AST::ConstantAccess)
8
+ handle(Rubinius::AST::InstanceVariableAccess)
9
+ handle(Rubinius::AST::LocalVariableAccess)
10
+ handle(Rubinius::AST::ClassVariableAccess)
11
+ handle(Rubinius::AST::GlobalVariableAccess)
12
+ handle(Rubinius::AST::PatternVariable)
13
+
14
+ private
15
+
16
+ # Perform dispatch
17
+ #
18
+ # @return [undefined]
19
+ #
20
+ # @api private
21
+ #
22
+ def dispatch
23
+ emit(node.name)
24
+ end
25
+
26
+ end
27
+ end
28
+ end