unparser 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/unparser/constants.rb +4 -1
- data/lib/unparser/emitter.rb +10 -8
- data/lib/unparser/emitter/class.rb +4 -0
- data/lib/unparser/emitter/module.rb +4 -0
- data/spec/unit/unparser_spec.rb +61 -25
- data/unparser.gemspec +1 -1
- metadata +7 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 791317b7c757ff21dccc078c1dc82a53690194bb
|
4
|
+
data.tar.gz: 41cdfad7c83f3e88eae3cdf3351bb3830014345f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed041a27c4747aacd924ed08fc8118eb13be9d82ca598c597f9dbbc9d5e8de28c67a2812b285cf4cacb7c0b4dc2925c52c3f1940060cde6eeb0788b5d1c1137d
|
7
|
+
data.tar.gz: 1c55d2b791abf9ca336d78745f08f56e75d1ed92106c0fd08317f3d69524080a72a5b2a3e2102c0dd93e31ef027c267334d3e1caa0e7726fd3cc733d58be5f09
|
data/lib/unparser/constants.rb
CHANGED
@@ -12,6 +12,8 @@ module Unparser
|
|
12
12
|
** %
|
13
13
|
).map(&:to_sym).to_set
|
14
14
|
|
15
|
+
COMMENT = '#'.freeze
|
16
|
+
|
15
17
|
WS = ' '
|
16
18
|
NL = "\n"
|
17
19
|
T_DOT = '.'
|
@@ -78,7 +80,8 @@ module Unparser
|
|
78
80
|
TERMINATED = [
|
79
81
|
:int, :float, :self, :kwbegin, :const, :regexp, :args, :lvar,
|
80
82
|
:ivar, :gvar, :cvar, :if, :case, :module, :class, :sclass, :super,
|
81
|
-
:yield, :zsuper, :break, :next, :defined?, :str, :block
|
83
|
+
:yield, :zsuper, :break, :next, :defined?, :str, :block, :while, :loop, :until,
|
84
|
+
:def, :defs, :true, :false, :nil, :array, :hash, :sym, :return
|
82
85
|
].to_set
|
83
86
|
|
84
87
|
KEYWORDS = constants.each_with_object([]) do |name, keywords|
|
data/lib/unparser/emitter.rb
CHANGED
@@ -121,14 +121,6 @@ module Unparser
|
|
121
121
|
#
|
122
122
|
abstract_method :dispatch
|
123
123
|
|
124
|
-
# Return node
|
125
|
-
#
|
126
|
-
# @return [Parser::AST::Node] node
|
127
|
-
#
|
128
|
-
# @api private
|
129
|
-
#
|
130
|
-
attr_reader :node
|
131
|
-
|
132
124
|
# Test if node is emitted as terminated expression
|
133
125
|
#
|
134
126
|
# @return [false]
|
@@ -404,6 +396,16 @@ module Unparser
|
|
404
396
|
Parser::AST::Node.new(type, *children)
|
405
397
|
end
|
406
398
|
|
399
|
+
# Helper to introduce comment
|
400
|
+
#
|
401
|
+
# @return [undefined]
|
402
|
+
#
|
403
|
+
# @api private
|
404
|
+
#
|
405
|
+
def comment
|
406
|
+
write(WS, COMMENT, WS)
|
407
|
+
end
|
408
|
+
|
407
409
|
# Emitter that fully relies on parser source maps
|
408
410
|
class SourceMap < self
|
409
411
|
|
data/spec/unit/unparser_spec.rb
CHANGED
@@ -331,6 +331,28 @@ describe Unparser do
|
|
331
331
|
assert_source '$var.bar'
|
332
332
|
assert_source '"".bar'
|
333
333
|
assert_source 'defined?(@foo).bar'
|
334
|
+
assert_source 'break.foo'
|
335
|
+
assert_source 'next.foo'
|
336
|
+
assert_source 'super(a).foo'
|
337
|
+
assert_source 'a || return'
|
338
|
+
assert_source 'super.foo'
|
339
|
+
assert_source 'nil.foo'
|
340
|
+
assert_source ':sym.foo'
|
341
|
+
assert_source '1.foo'
|
342
|
+
assert_source '1.0.foo'
|
343
|
+
assert_source '[].foo'
|
344
|
+
assert_source '{}.foo'
|
345
|
+
assert_source 'false.foo'
|
346
|
+
assert_source 'true.foo'
|
347
|
+
assert_source 'self.foo'
|
348
|
+
assert_source 'yield(a).foo'
|
349
|
+
assert_source 'yield.foo'
|
350
|
+
assert_source 'Foo::Bar.foo'
|
351
|
+
assert_source '::BAZ.foo'
|
352
|
+
assert_source 'array[i].foo'
|
353
|
+
assert_source '(array[i] = 1).foo'
|
354
|
+
assert_source 'array[1..2].foo'
|
355
|
+
assert_source '(a.attribute ||= foo).bar'
|
334
356
|
|
335
357
|
assert_source <<-RUBY
|
336
358
|
begin
|
@@ -349,16 +371,30 @@ describe Unparser do
|
|
349
371
|
end.bar
|
350
372
|
RUBY
|
351
373
|
|
352
|
-
assert_source
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
assert_source
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
374
|
+
assert_source <<-RUBY
|
375
|
+
def self.foo
|
376
|
+
end.bar
|
377
|
+
RUBY
|
378
|
+
|
379
|
+
assert_source <<-RUBY
|
380
|
+
def foo
|
381
|
+
end.bar
|
382
|
+
RUBY
|
383
|
+
|
384
|
+
assert_source <<-RUBY
|
385
|
+
until foo
|
386
|
+
end.bar
|
387
|
+
RUBY
|
388
|
+
|
389
|
+
assert_source <<-RUBY
|
390
|
+
while foo
|
391
|
+
end.bar
|
392
|
+
RUBY
|
393
|
+
|
394
|
+
assert_source <<-RUBY
|
395
|
+
loop do
|
396
|
+
end.bar
|
397
|
+
RUBY
|
362
398
|
|
363
399
|
assert_source <<-RUBY
|
364
400
|
class Foo
|
@@ -827,7 +863,7 @@ describe Unparser do
|
|
827
863
|
context 'class' do
|
828
864
|
assert_source <<-RUBY
|
829
865
|
class TestClass
|
830
|
-
end
|
866
|
+
end # TestClass
|
831
867
|
RUBY
|
832
868
|
|
833
869
|
assert_source <<-RUBY
|
@@ -843,22 +879,22 @@ describe Unparser do
|
|
843
879
|
|
844
880
|
assert_source <<-RUBY
|
845
881
|
class SomeNameSpace::TestClass
|
846
|
-
end
|
882
|
+
end # SomeNameSpace::TestClass
|
847
883
|
RUBY
|
848
884
|
|
849
885
|
assert_source <<-RUBY
|
850
886
|
class Some::Name::Space::TestClass
|
851
|
-
end
|
887
|
+
end # Some::Name::Space::TestClass
|
852
888
|
RUBY
|
853
889
|
|
854
890
|
assert_source <<-RUBY
|
855
891
|
class TestClass < Object
|
856
|
-
end
|
892
|
+
end # TestClass
|
857
893
|
RUBY
|
858
894
|
|
859
895
|
assert_source <<-RUBY
|
860
896
|
class TestClass < SomeNameSpace::Object
|
861
|
-
end
|
897
|
+
end # TestClass
|
862
898
|
RUBY
|
863
899
|
|
864
900
|
assert_source <<-RUBY
|
@@ -866,12 +902,12 @@ describe Unparser do
|
|
866
902
|
def foo
|
867
903
|
:bar
|
868
904
|
end
|
869
|
-
end
|
905
|
+
end # TestClass
|
870
906
|
RUBY
|
871
907
|
|
872
908
|
assert_source <<-RUBY
|
873
909
|
class ::TestClass
|
874
|
-
end
|
910
|
+
end # ::TestClass
|
875
911
|
RUBY
|
876
912
|
end
|
877
913
|
|
@@ -879,17 +915,17 @@ describe Unparser do
|
|
879
915
|
|
880
916
|
assert_source <<-RUBY
|
881
917
|
module TestModule
|
882
|
-
end
|
918
|
+
end # TestModule
|
883
919
|
RUBY
|
884
920
|
|
885
921
|
assert_source <<-RUBY
|
886
922
|
module SomeNameSpace::TestModule
|
887
|
-
end
|
923
|
+
end # SomeNameSpace::TestModule
|
888
924
|
RUBY
|
889
925
|
|
890
926
|
assert_source <<-RUBY
|
891
927
|
module Some::Name::Space::TestModule
|
892
|
-
end
|
928
|
+
end # Some::Name::Space::TestModule
|
893
929
|
RUBY
|
894
930
|
|
895
931
|
assert_source <<-RUBY
|
@@ -897,7 +933,7 @@ describe Unparser do
|
|
897
933
|
def foo
|
898
934
|
:bar
|
899
935
|
end
|
900
|
-
end
|
936
|
+
end # TestModule
|
901
937
|
RUBY
|
902
938
|
|
903
939
|
end
|
@@ -975,10 +1011,10 @@ describe Unparser do
|
|
975
1011
|
end
|
976
1012
|
|
977
1013
|
context 'binary operator' do
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
1014
|
+
assert_source 'a || (break(foo))'
|
1015
|
+
assert_source '(break(foo)) || a'
|
1016
|
+
assert_source '(a || b).foo'
|
1017
|
+
assert_source 'a || (b || c)'
|
982
1018
|
end
|
983
1019
|
|
984
1020
|
{ :or => :'||', :and => :'&&' }.each do |word, symbol|
|
data/unparser.gemspec
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Markus Schirp
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: parser
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: concord
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: adamantium
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: equalizer
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ~>
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ~>
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -78,7 +69,6 @@ dependencies:
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: abstract_type
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ~>
|
84
74
|
- !ruby/object:Gem::Version
|
@@ -86,7 +76,6 @@ dependencies:
|
|
86
76
|
type: :runtime
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - ~>
|
92
81
|
- !ruby/object:Gem::Version
|
@@ -184,27 +173,26 @@ files:
|
|
184
173
|
homepage: http://github.com/mbj/unparser
|
185
174
|
licenses:
|
186
175
|
- MIT
|
176
|
+
metadata: {}
|
187
177
|
post_install_message:
|
188
178
|
rdoc_options: []
|
189
179
|
require_paths:
|
190
180
|
- lib
|
191
181
|
required_ruby_version: !ruby/object:Gem::Requirement
|
192
|
-
none: false
|
193
182
|
requirements:
|
194
|
-
- -
|
183
|
+
- - '>='
|
195
184
|
- !ruby/object:Gem::Version
|
196
185
|
version: '0'
|
197
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
|
-
none: false
|
199
187
|
requirements:
|
200
|
-
- -
|
188
|
+
- - '>='
|
201
189
|
- !ruby/object:Gem::Version
|
202
190
|
version: '0'
|
203
191
|
requirements: []
|
204
192
|
rubyforge_project:
|
205
|
-
rubygems_version:
|
193
|
+
rubygems_version: 2.0.2
|
206
194
|
signing_key:
|
207
|
-
specification_version:
|
195
|
+
specification_version: 4
|
208
196
|
summary: Generate equivalent source for parser gem AST nodes
|
209
197
|
test_files:
|
210
198
|
- spec/spec_helper.rb
|