unparser 0.4.8 → 0.5.3

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 (143) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -5
  3. data/bin/unparser +1 -1
  4. data/lib/unparser.rb +115 -61
  5. data/lib/unparser/ast.rb +0 -1
  6. data/lib/unparser/ast/local_variable_scope.rb +6 -76
  7. data/lib/unparser/buffer.rb +19 -16
  8. data/lib/unparser/cli.rb +26 -39
  9. data/lib/unparser/color.rb +0 -3
  10. data/lib/unparser/comments.rb +0 -26
  11. data/lib/unparser/constants.rb +4 -53
  12. data/lib/unparser/diff.rb +0 -17
  13. data/lib/unparser/dsl.rb +0 -32
  14. data/lib/unparser/emitter.rb +23 -425
  15. data/lib/unparser/emitter/alias.rb +2 -8
  16. data/lib/unparser/emitter/args.rb +45 -0
  17. data/lib/unparser/emitter/argument.rb +8 -166
  18. data/lib/unparser/emitter/array.rb +27 -0
  19. data/lib/unparser/emitter/array_pattern.rb +29 -0
  20. data/lib/unparser/emitter/assignment.rb +36 -127
  21. data/lib/unparser/emitter/begin.rb +9 -84
  22. data/lib/unparser/emitter/binary.rb +7 -20
  23. data/lib/unparser/emitter/block.rb +57 -41
  24. data/lib/unparser/emitter/case.rb +6 -48
  25. data/lib/unparser/emitter/case_guard.rb +27 -0
  26. data/lib/unparser/emitter/case_match.rb +40 -0
  27. data/lib/unparser/emitter/cbase.rb +1 -3
  28. data/lib/unparser/emitter/class.rb +6 -26
  29. data/lib/unparser/emitter/const_pattern.rb +24 -0
  30. data/lib/unparser/emitter/def.rb +7 -51
  31. data/lib/unparser/emitter/defined.rb +2 -12
  32. data/lib/unparser/emitter/dstr.rb +22 -0
  33. data/lib/unparser/emitter/dsym.rb +41 -0
  34. data/lib/unparser/emitter/flipflop.rb +11 -10
  35. data/lib/unparser/emitter/float.rb +29 -0
  36. data/lib/unparser/emitter/flow_modifier.rb +8 -55
  37. data/lib/unparser/emitter/for.rb +5 -19
  38. data/lib/unparser/emitter/hash.rb +74 -0
  39. data/lib/unparser/emitter/hash_pattern.rb +67 -0
  40. data/lib/unparser/emitter/hookexe.rb +5 -11
  41. data/lib/unparser/emitter/if.rb +9 -73
  42. data/lib/unparser/emitter/in_match.rb +21 -0
  43. data/lib/unparser/emitter/in_pattern.rb +34 -0
  44. data/lib/unparser/emitter/index.rb +21 -88
  45. data/lib/unparser/emitter/kwbegin.rb +31 -0
  46. data/lib/unparser/emitter/lambda.rb +0 -8
  47. data/lib/unparser/emitter/masgn.rb +20 -0
  48. data/lib/unparser/emitter/match.rb +3 -17
  49. data/lib/unparser/emitter/match_alt.rb +23 -0
  50. data/lib/unparser/emitter/match_as.rb +21 -0
  51. data/lib/unparser/emitter/match_rest.rb +26 -0
  52. data/lib/unparser/emitter/match_var.rb +19 -0
  53. data/lib/unparser/emitter/mlhs.rb +40 -0
  54. data/lib/unparser/emitter/module.rb +3 -9
  55. data/lib/unparser/emitter/op_assign.rb +12 -27
  56. data/lib/unparser/emitter/pin.rb +19 -0
  57. data/lib/unparser/emitter/primitive.rb +93 -0
  58. data/lib/unparser/emitter/range.rb +35 -0
  59. data/lib/unparser/emitter/regexp.rb +35 -0
  60. data/lib/unparser/emitter/repetition.rb +17 -57
  61. data/lib/unparser/emitter/rescue.rb +1 -97
  62. data/lib/unparser/emitter/root.rb +17 -1
  63. data/lib/unparser/emitter/send.rb +10 -219
  64. data/lib/unparser/emitter/simple.rb +33 -0
  65. data/lib/unparser/emitter/splat.rb +2 -18
  66. data/lib/unparser/emitter/super.rb +1 -29
  67. data/lib/unparser/emitter/undef.rb +1 -9
  68. data/lib/unparser/emitter/variable.rb +1 -31
  69. data/lib/unparser/emitter/xstr.rb +72 -0
  70. data/lib/unparser/emitter/yield.rb +1 -9
  71. data/lib/unparser/generation.rb +250 -0
  72. data/lib/unparser/node_details.rb +21 -0
  73. data/lib/unparser/node_details/send.rb +62 -0
  74. data/lib/unparser/node_helpers.rb +45 -6
  75. data/lib/unparser/validation.rb +58 -35
  76. data/lib/unparser/writer.rb +15 -0
  77. data/lib/unparser/writer/binary.rb +99 -0
  78. data/lib/unparser/writer/dynamic_string.rb +233 -0
  79. data/lib/unparser/writer/resbody.rb +40 -0
  80. data/lib/unparser/writer/rescue.rb +39 -0
  81. data/lib/unparser/writer/send.rb +124 -0
  82. data/lib/unparser/{emitter → writer}/send/attribute_assignment.rb +11 -26
  83. data/lib/unparser/writer/send/binary.rb +27 -0
  84. data/lib/unparser/writer/send/conditional.rb +25 -0
  85. data/lib/unparser/writer/send/regular.rb +33 -0
  86. data/lib/unparser/{emitter → writer}/send/unary.rb +10 -17
  87. metadata +65 -89
  88. data/.github/workflows/ci.yml +0 -90
  89. data/.gitignore +0 -37
  90. data/.rspec +0 -4
  91. data/.rubocop.yml +0 -126
  92. data/Changelog.md +0 -162
  93. data/Gemfile +0 -9
  94. data/Gemfile.lock +0 -111
  95. data/LICENSE +0 -20
  96. data/Rakefile +0 -22
  97. data/config/devtools.yml +0 -2
  98. data/config/flay.yml +0 -3
  99. data/config/flog.yml +0 -2
  100. data/config/mutant.yml +0 -6
  101. data/config/reek.yml +0 -98
  102. data/config/yardstick.yml +0 -2
  103. data/lib/unparser/emitter/empty.rb +0 -23
  104. data/lib/unparser/emitter/ensure.rb +0 -37
  105. data/lib/unparser/emitter/literal.rb +0 -10
  106. data/lib/unparser/emitter/literal/array.rb +0 -29
  107. data/lib/unparser/emitter/literal/dynamic.rb +0 -53
  108. data/lib/unparser/emitter/literal/dynamic_body.rb +0 -132
  109. data/lib/unparser/emitter/literal/execute_string.rb +0 -38
  110. data/lib/unparser/emitter/literal/hash.rb +0 -156
  111. data/lib/unparser/emitter/literal/primitive.rb +0 -145
  112. data/lib/unparser/emitter/literal/range.rb +0 -36
  113. data/lib/unparser/emitter/literal/regexp.rb +0 -114
  114. data/lib/unparser/emitter/literal/singleton.rb +0 -26
  115. data/lib/unparser/emitter/meta.rb +0 -16
  116. data/lib/unparser/emitter/redo.rb +0 -25
  117. data/lib/unparser/emitter/resbody.rb +0 -76
  118. data/lib/unparser/emitter/retry.rb +0 -25
  119. data/lib/unparser/emitter/send/binary.rb +0 -57
  120. data/lib/unparser/emitter/send/conditional.rb +0 -40
  121. data/lib/unparser/emitter/send/regular.rb +0 -40
  122. data/lib/unparser/preprocessor.rb +0 -159
  123. data/spec/integration/unparser/corpus_spec.rb +0 -125
  124. data/spec/integrations.yml +0 -92
  125. data/spec/spec_helper.rb +0 -42
  126. data/spec/unit/unparser/buffer/append_spec.rb +0 -24
  127. data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +0 -23
  128. data/spec/unit/unparser/buffer/capture_content_spec.rb +0 -17
  129. data/spec/unit/unparser/buffer/content_spec.rb +0 -38
  130. data/spec/unit/unparser/buffer/fresh_line_spec.rb +0 -20
  131. data/spec/unit/unparser/buffer/indent_spec.rb +0 -20
  132. data/spec/unit/unparser/buffer/nl_spec.rb +0 -16
  133. data/spec/unit/unparser/buffer/unindent_spec.rb +0 -20
  134. data/spec/unit/unparser/color_spec.rb +0 -40
  135. data/spec/unit/unparser/comments/consume_spec.rb +0 -22
  136. data/spec/unit/unparser/comments/take_all_spec.rb +0 -19
  137. data/spec/unit/unparser/comments/take_before_spec.rb +0 -46
  138. data/spec/unit/unparser/comments/take_eol_comments_spec.rb +0 -32
  139. data/spec/unit/unparser/diff_spec.rb +0 -189
  140. data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +0 -17
  141. data/spec/unit/unparser/validation_spec.rb +0 -327
  142. data/spec/unit/unparser_spec.rb +0 -1920
  143. data/unparser.gemspec +0 -35
@@ -1,125 +0,0 @@
1
- require 'spec_helper'
2
- describe 'Unparser on ruby corpus', mutant: false do
3
- ROOT = Pathname.new(__FILE__).parent.parent.parent.parent
4
-
5
- TMP = ROOT.join('tmp')
6
-
7
- class Project
8
- include Anima.new(:name, :repo_uri, :repo_ref, :exclude)
9
-
10
- # Perform verification via unparser cli
11
- #
12
- # @return [self]
13
- # if successful
14
- #
15
- # @raise [Exception]
16
- # otherwise
17
- #
18
- def verify
19
- checkout
20
- command = %W(unparser #{repo_path})
21
- exclude.each do |name|
22
- command.concat(%W(--ignore #{repo_path.join(name)}))
23
- end
24
- system(command) do
25
- raise "Verifing #{name} failed!"
26
- end
27
- self
28
- end
29
-
30
- # Checkout repository
31
- #
32
- # @return [self]
33
- #
34
- # @api private
35
- #
36
- def checkout
37
- TMP.mkdir unless TMP.directory?
38
- if repo_path.exist?
39
- Dir.chdir(repo_path) do
40
- system(%w(git pull origin master))
41
- system(%w(git clean -f -d -x))
42
- end
43
- else
44
- system(%W(git clone #{repo_uri} #{repo_path}))
45
- end
46
-
47
- Dir.chdir(repo_path) do
48
- system(%W(git checkout #{repo_ref}))
49
- system(%w(git reset --hard))
50
- system(%w(git clean -f -d -x))
51
- end
52
-
53
- self
54
- end
55
-
56
- private
57
-
58
- # Return repository path
59
- #
60
- # @return [Pathname]
61
- #
62
- # @api private
63
- #
64
- def repo_path
65
- TMP.join(name)
66
- end
67
-
68
- # Helper method to execute system commands
69
- #
70
- # @param [Array<String>] arguments
71
- #
72
- # @api private
73
- #
74
- def system(arguments)
75
- return if Kernel.system(*arguments)
76
-
77
- if block_given?
78
- yield
79
- else
80
- raise "System command #{arguments.inspect} failed!"
81
- end
82
- end
83
-
84
- transform = Mutant::Transform
85
- string = transform::Primitive.new(String)
86
- string_array = transform::Array.new(string)
87
- path = ROOT.join('spec', 'integrations.yml')
88
-
89
- loader =
90
- transform::Named.new(
91
- path.to_s,
92
- transform::Sequence.new(
93
- [
94
- transform::Exception.new(SystemCallError, :read.to_proc),
95
- transform::Exception.new(YAML::SyntaxError, YAML.method(:safe_load)),
96
- transform::Array.new(
97
- transform::Sequence.new(
98
- [
99
- transform::Hash.new(
100
- optional: [],
101
- required: [
102
- transform::Hash::Key.new('exclude', string_array),
103
- transform::Hash::Key.new('name', string),
104
- transform::Hash::Key.new('repo_ref', string),
105
- transform::Hash::Key.new('repo_uri', string)
106
- ]
107
- ),
108
- transform::Hash::Symbolize.new,
109
- transform::Exception.new(Anima::Error, Project.public_method(:new))
110
- ]
111
- )
112
- )
113
- ]
114
- )
115
- )
116
-
117
- ALL = loader.apply(path).lmap(&:compact_message).from_right
118
- end
119
-
120
- Project::ALL.each do |project|
121
- specify "unparsing #{project.name}" do
122
- project.verify
123
- end
124
- end
125
- end
@@ -1,92 +0,0 @@
1
- ---
2
- - name: anima
3
- repo_uri: 'https://github.com/mbj/anima.git'
4
- repo_ref: 'origin/master'
5
- exclude: []
6
- - name: mutant
7
- repo_uri: 'https://github.com/mbj/mutant.git'
8
- repo_ref: 'origin/master'
9
- exclude: []
10
- - name: yaks
11
- repo_uri: 'https://github.com/plexus/yaks.git'
12
- repo_ref: 'origin/master'
13
- exclude: []
14
- - name: chassis
15
- repo_uri: 'https://github.com/ahawkins/chassis.git'
16
- repo_ref: 'origin/master'
17
- exclude: []
18
- - name: rubyspec
19
- repo_uri: 'https://github.com/ruby/spec.git'
20
- # Revision of rubyspec on the last CI build of unparser that passed
21
- repo_ref: 'b40189b88'
22
- exclude:
23
- - command_line/fixtures/bad_syntax.rb
24
- - core/array/pack/shared/float.rb
25
- - core/array/pack/shared/integer.rb
26
- - core/array/pack/shared/string.rb
27
- - core/array/pack/{b,c,h,m}_spec.rb
28
- - core/array/pack/{u,w}_spec.rb
29
- - core/encoding/compatible_spec.rb
30
- - core/encoding/converter/convert_spec.rb
31
- - core/encoding/converter/last_error_spec.rb
32
- - core/encoding/converter/primitive_convert_spec.rb
33
- - core/encoding/converter/primitive_errinfo_spec.rb
34
- - core/encoding/converter/putback_spec.rb
35
- - core/encoding/fixtures/classes.rb
36
- - core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
37
- - core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
38
- - core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
39
- - core/encoding/replicate_spec.rb
40
- - core/env/element_reference_spec.rb
41
- - core/io/readpartial_spec.rb
42
- - core/io/shared/gets_ascii.rb
43
- - core/kernel/shared/sprintf_encoding.rb
44
- - core/marshal/dump_spec.rb
45
- - core/marshal/fixtures/marshal_data.rb
46
- - core/marshal/shared/load.rb
47
- - core/random/bytes_spec.rb
48
- - core/regexp/shared/new.rb
49
- - core/regexp/shared/new_ascii.rb
50
- - core/regexp/shared/new_ascii_8bit.rb
51
- - core/regexp/shared/quote.rb
52
- - core/string/byteslice_spec.rb
53
- - core/string/casecmp_spec.rb
54
- - core/string/codepoints_spec.rb
55
- - core/string/count_spec.rb
56
- - core/string/encode_spec.rb
57
- - core/string/inspect_spec.rb
58
- - core/string/shared/codepoints.rb
59
- - core/string/shared/each_codepoint_without_block.rb
60
- - core/string/shared/eql.rb
61
- - core/string/shared/succ.rb
62
- - core/string/shared/to_sym.rb
63
- - core/string/squeeze_spec.rb
64
- - core/string/unpack/shared/float.rb
65
- - core/string/unpack/shared/integer.rb
66
- - core/string/unpack/{b,c,h,m}_spec.rb
67
- - core/string/unpack/{u,w}_spec.rb
68
- - core/symbol/casecmp_spec.rb
69
- - core/time/_dump_spec.rb
70
- - core/time/_load_spec.rb
71
- - language/fixtures/binary_symbol.rb
72
- - language/fixtures/squiggly_heredoc.rb
73
- - language/for_spec.rb
74
- - language/regexp/encoding_spec.rb
75
- - language/regexp/escapes_spec.rb
76
- - language/source_encoding_spec.rb
77
- - language/string_spec.rb
78
- - library/base64/decode64_spec.rb
79
- - library/digest/md5/shared/constants.rb
80
- - library/digest/md5/shared/sample.rb
81
- - library/digest/sha1/shared/constants.rb
82
- - library/digest/sha256/shared/constants.rb
83
- - library/digest/sha384/shared/constants.rb
84
- - library/digest/sha512/shared/constants.rb
85
- - library/openssl/shared/constants.rb
86
- - library/socket/basicsocket/recv_spec.rb
87
- - library/socket/socket/gethostbyname_spec.rb
88
- - library/stringscanner/getch_spec.rb
89
- - library/stringscanner/shared/get_byte.rb
90
- - library/zlib/inflate/set_dictionary_spec.rb
91
- - optional/capi/integer_spec.rb
92
- - security/cve_2010_1330_spec.rb
@@ -1,42 +0,0 @@
1
- require 'anima'
2
- require 'mutant'
3
- require 'pathname'
4
- require 'timeout'
5
- require 'unparser'
6
- require 'yaml'
7
-
8
- require 'parser/current'
9
-
10
- RSpec.configuration.around(file_path: %r{spec/unit}) do |example|
11
- Timeout.timeout(0.1, &example)
12
- end
13
-
14
- RSpec.shared_examples_for 'a command method' do
15
- it 'returns self' do
16
- should equal(object)
17
- end
18
- end
19
-
20
- RSpec.shared_examples_for 'an idempotent method' do
21
- it 'is idempotent' do
22
- first = subject
23
- fail 'RSpec not configured for threadsafety' unless RSpec.configuration.threadsafe?
24
- mutex = __memoized.instance_variable_get(:@mutex)
25
- memoized = __memoized.instance_variable_get(:@memoized)
26
-
27
- mutex.synchronize { memoized.delete(:subject) }
28
- should equal(first)
29
- end
30
- end
31
-
32
- module SpecHelper
33
- def s(type, *children)
34
- Parser::AST::Node.new(type, children)
35
- end
36
- end
37
-
38
- RSpec.configure do |config|
39
- config.include(SpecHelper)
40
- config.extend(SpecHelper)
41
- config.raise_errors_for_deprecations!
42
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#append' do
4
- subject { object.append(string) }
5
-
6
- let(:object) { described_class.new }
7
- let(:string) { 'foo' }
8
-
9
- specify do
10
- expect { subject }.to change { object.content }.from('').to('foo')
11
- end
12
-
13
- # Yeah duplicate, mutant will be improved ;)
14
- it 'should prefix with indentation if line is empty' do
15
- object.append('foo')
16
- object.nl
17
- object.indent
18
- object.append('bar')
19
- object.append('baz')
20
- expect(object.content).to eql("foo\n barbaz")
21
- end
22
-
23
- it_should_behave_like 'a command method'
24
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#append_without_prefix' do
4
- subject { object.append_without_prefix(string) }
5
-
6
- let(:object) { described_class.new }
7
- let(:string) { 'foo' }
8
-
9
- specify do
10
- expect { subject }.to change { object.content }.from('').to('foo')
11
- end
12
-
13
- it 'should not prefix with indentation' do
14
- object.append_without_prefix('foo')
15
- object.nl
16
- object.indent
17
- object.append_without_prefix('bar')
18
- object.append_without_prefix('baz')
19
- expect(object.content).to eql("foo\nbarbaz")
20
- end
21
-
22
- it_should_behave_like 'a command method'
23
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#capture_content' do
4
-
5
- let(:object) { described_class.new }
6
-
7
- it 'should capture only the content appended within the block' do
8
- object.append('foo')
9
- object.nl
10
- object.indent
11
- captured = object.capture_content do
12
- object.append('bar')
13
- object.nl
14
- end
15
- expect(captured).to eql(" bar\n")
16
- end
17
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#content' do
4
- subject { object.content }
5
-
6
- let(:object) { described_class.new }
7
-
8
- shared_examples_for 'buffer content' do
9
- it 'contains expected content' do
10
- should eql(expected_content)
11
- end
12
-
13
- it { should be_frozen }
14
-
15
- it 'returns fresh string copies' do
16
- first = object.content
17
- second = object.content
18
- expect(first).to eql(second)
19
- expect(first).not_to be(second)
20
- end
21
- end
22
-
23
- context 'with empty buffer' do
24
- let(:expected_content) { '' }
25
-
26
- it_should_behave_like 'buffer content'
27
- end
28
-
29
- context 'with filled buffer' do
30
- before do
31
- object.append('foo')
32
- end
33
-
34
- let(:expected_content) { 'foo' }
35
-
36
- it_behaves_like 'buffer content'
37
- end
38
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#fresh_line?' do
4
- let(:object) { described_class.new }
5
-
6
- it 'should return true while buffer is empty' do
7
- expect(object.fresh_line?).to eql(true)
8
- end
9
-
10
- it 'should return false after content has been appended' do
11
- object.append('foo')
12
- expect(object.fresh_line?).to eql(false)
13
- end
14
-
15
- it 'should return true after a nl has been appended' do
16
- object.append('foo')
17
- object.nl
18
- expect(object.fresh_line?).to eql(true)
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#indent' do
4
- let(:object) { described_class.new }
5
-
6
- subject { object.indent }
7
-
8
- it 'should indent with two spaces' do
9
- object.append('foo')
10
- object.nl
11
- object.indent
12
- object.append('bar')
13
- object.nl
14
- object.indent
15
- object.append('baz')
16
- expect(object.content).to eql("foo\n bar\n baz")
17
- end
18
-
19
- it_should_behave_like 'a command method'
20
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#nl' do
4
- let(:object) { described_class.new }
5
-
6
- subject { object.nl }
7
-
8
- it 'writes a newline' do
9
- object.append('foo')
10
- subject
11
- object.append('bar')
12
- expect(object.content).to eql("foo\nbar")
13
- end
14
-
15
- it_should_behave_like 'a command method'
16
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#unindent' do
4
- let(:object) { described_class.new }
5
-
6
- subject { object.unindent }
7
-
8
- it 'unindents two chars' do
9
- object.append('foo')
10
- object.nl
11
- object.indent
12
- object.append('bar')
13
- object.nl
14
- object.unindent
15
- object.append('baz')
16
- expect(object.content).to eql("foo\n bar\nbaz")
17
- end
18
-
19
- it_should_behave_like 'a command method'
20
- end