unparser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circle.yml +4 -0
- data/.gitignore +2 -0
- data/.rspec +3 -0
- data/.travis.yml +16 -0
- data/Changelog.md +3 -0
- data/Gemfile +6 -0
- data/Gemfile.devtools +60 -0
- data/Guardfile +18 -0
- data/README.md +41 -0
- data/Rakefile +24 -0
- data/TODO +1 -0
- data/config/devtools.yml +2 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/mutant.yml +3 -0
- data/config/reek.yml +107 -0
- data/config/yardstick.yml +2 -0
- data/lib/unparser/buffer.rb +93 -0
- data/lib/unparser/constants.rb +87 -0
- data/lib/unparser/emitter/alias.rb +27 -0
- data/lib/unparser/emitter/argument.rb +154 -0
- data/lib/unparser/emitter/assignment.rb +140 -0
- data/lib/unparser/emitter/begin.rb +179 -0
- data/lib/unparser/emitter/binary.rb +52 -0
- data/lib/unparser/emitter/block.rb +53 -0
- data/lib/unparser/emitter/break.rb +28 -0
- data/lib/unparser/emitter/case.rb +97 -0
- data/lib/unparser/emitter/cbase.rb +22 -0
- data/lib/unparser/emitter/class.rb +72 -0
- data/lib/unparser/emitter/def.rb +107 -0
- data/lib/unparser/emitter/defined.rb +27 -0
- data/lib/unparser/emitter/for.rb +50 -0
- data/lib/unparser/emitter/hookexe.rb +42 -0
- data/lib/unparser/emitter/if.rb +85 -0
- data/lib/unparser/emitter/literal/composed.rb +64 -0
- data/lib/unparser/emitter/literal/dynamic.rb +54 -0
- data/lib/unparser/emitter/literal/dynamic_body.rb +109 -0
- data/lib/unparser/emitter/literal/execute_string.rb +38 -0
- data/lib/unparser/emitter/literal/primitive.rb +49 -0
- data/lib/unparser/emitter/literal/range.rb +33 -0
- data/lib/unparser/emitter/literal/regexp.rb +96 -0
- data/lib/unparser/emitter/literal/singleton.rb +24 -0
- data/lib/unparser/emitter/literal.rb +7 -0
- data/lib/unparser/emitter/module.rb +37 -0
- data/lib/unparser/emitter/next.rb +22 -0
- data/lib/unparser/emitter/not.rb +25 -0
- data/lib/unparser/emitter/op_assign.rb +63 -0
- data/lib/unparser/emitter/redo.rb +22 -0
- data/lib/unparser/emitter/repetition.rb +33 -0
- data/lib/unparser/emitter/retry.rb +22 -0
- data/lib/unparser/emitter/return.rb +38 -0
- data/lib/unparser/emitter/root.rb +7 -0
- data/lib/unparser/emitter/send/binary.rb +100 -0
- data/lib/unparser/emitter/send/index.rb +82 -0
- data/lib/unparser/emitter/send/unary.rb +29 -0
- data/lib/unparser/emitter/send.rb +273 -0
- data/lib/unparser/emitter/splat.rb +24 -0
- data/lib/unparser/emitter/super.rb +46 -0
- data/lib/unparser/emitter/undef.rb +25 -0
- data/lib/unparser/emitter/variable.rb +83 -0
- data/lib/unparser/emitter/yield.rb +28 -0
- data/lib/unparser/emitter.rb +308 -0
- data/lib/unparser.rb +87 -0
- data/spec/integration/unparser/spike_spec.rb +914 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/unit/unparser/buffer/append_spec.rb +23 -0
- data/spec/unit/unparser/buffer/content_spec.rb +38 -0
- data/spec/unit/unparser/buffer/indent_spec.rb +18 -0
- data/spec/unit/unparser/buffer/nl_spec.rb +16 -0
- data/spec/unit/unparser/buffer/unindent_spec.rb +18 -0
- data/spec/unit/unparser/class_methods/unparse_spec.rb +16 -0
- data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +17 -0
- data/spec/unit/unparser/emitter/class_methods/visit_spec.rb +37 -0
- data/spec/unit/unparser/emitter/source_map/class_methods/emit_spec.rb +20 -0
- data/unparser.gemspec +24 -0
- metadata +201 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c12f5981aa14eb3e5339a937e5d68d21a3336381
|
4
|
+
data.tar.gz: 7050a2bb94a084b42ba4504b2151e5af033d492f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d935d497ba084726fb355995640849c846c7074f4a7e85fed48d4843da646b5520c7046a48b139b187ab71dd35405d728bf199ba072db463ee13044dec2b0c02
|
7
|
+
data.tar.gz: 9fcf5e19768a9b56ff5baa637f45e69a3868e98957768d6a01f560bee0f62f339c05c001c94e928af3c0c67e3f7b920d3f2d3e66bd08e0906cace82d3d334d0a
|
data/.circle.yml
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
script: 'bundle exec rake spec'
|
3
|
+
rvm:
|
4
|
+
- 1.9.2
|
5
|
+
- 1.9.3
|
6
|
+
- 2.0.0
|
7
|
+
- ruby-head
|
8
|
+
- jruby-19mode
|
9
|
+
- jruby-head
|
10
|
+
- rbx-19mode
|
11
|
+
notifications:
|
12
|
+
irc:
|
13
|
+
channels:
|
14
|
+
- irc.freenode.org#rom-rb
|
15
|
+
on_success: never
|
16
|
+
on_failure: change
|
data/Changelog.md
ADDED
data/Gemfile
ADDED
data/Gemfile.devtools
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem 'rake', '~> 10.0.4'
|
5
|
+
gem 'rspec', '~> 2.13.0'
|
6
|
+
gem 'yard', '~> 0.8.6.1'
|
7
|
+
end
|
8
|
+
|
9
|
+
group :yard do
|
10
|
+
gem 'kramdown', '~> 1.0.1'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :guard do
|
14
|
+
gem 'guard', '~> 1.8.0'
|
15
|
+
gem 'guard-bundler', '~> 1.0.0'
|
16
|
+
gem 'guard-rspec', '~> 2.5.4'
|
17
|
+
|
18
|
+
# file system change event handling
|
19
|
+
gem 'listen', '~> 1.0.2'
|
20
|
+
gem 'rb-fchange', '~> 0.0.6', :require => false
|
21
|
+
gem 'rb-fsevent', '~> 0.9.3', :require => false
|
22
|
+
gem 'rb-inotify', '~> 0.9.0', :require => false
|
23
|
+
|
24
|
+
# notification handling
|
25
|
+
gem 'libnotify', '~> 0.8.0', :require => false
|
26
|
+
gem 'rb-notifu', '~> 0.0.4', :require => false
|
27
|
+
gem 'terminal-notifier-guard', '~> 1.5.3', :require => false
|
28
|
+
end
|
29
|
+
|
30
|
+
group :metrics do
|
31
|
+
gem 'backports', '~> 3.3', '>= 3.3.0'
|
32
|
+
gem 'coveralls', '~> 0.6.6'
|
33
|
+
gem 'flay', '~> 2.2.0'
|
34
|
+
gem 'flog', '~> 4.0.0'
|
35
|
+
gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
|
36
|
+
gem 'simplecov', '~> 0.7.1'
|
37
|
+
gem 'yardstick', '~> 0.9.6'
|
38
|
+
|
39
|
+
platforms :ruby_19 do
|
40
|
+
gem 'yard-spellcheck', '~> 0.1.5'
|
41
|
+
end
|
42
|
+
|
43
|
+
platforms :mri_19, :rbx do
|
44
|
+
gem 'mutant', '~> 0.2.20'
|
45
|
+
end
|
46
|
+
|
47
|
+
platforms :rbx do
|
48
|
+
gem 'pelusa', '~> 0.2.2'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
group :benchmarks do
|
53
|
+
gem 'rbench', '~> 0.2.3'
|
54
|
+
end
|
55
|
+
|
56
|
+
platform :jruby do
|
57
|
+
group :jruby do
|
58
|
+
gem 'jruby-openssl', '~> 0.8.5'
|
59
|
+
end
|
60
|
+
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, :all_on_start => false, :all_after_pass => false, :cli => '--fail-fast' do
|
8
|
+
# run all specs if the spec_helper or supporting files files are modified
|
9
|
+
watch('spec/spec_helper.rb') { 'spec/unit' }
|
10
|
+
watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec/unit' }
|
11
|
+
|
12
|
+
# run unit specs if associated lib code is modified
|
13
|
+
watch(%r{\Alib/(.+)\.rb\z}) { 'spec' }
|
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/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
unparser
|
2
|
+
========
|
3
|
+
|
4
|
+
[![Build Status](https://secure.travis-ci.org/mbj/unparser.png?branch=master)](http://travis-ci.org/mbj/unparser)
|
5
|
+
[![Dependency Status](https://gemnasium.com/mbj/unparser.png)](https://gemnasium.com/mbj/unparser)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/mbj/unparser.png)](https://codeclimate.com/github/mbj/unparser)
|
7
|
+
|
8
|
+
Generate equivalent inputs for ASTs from whitequarks awesome [parser](https://github.com/whitequark/parser).
|
9
|
+
|
10
|
+
Usage
|
11
|
+
-----
|
12
|
+
|
13
|
+
In spike mode, no public API currently.
|
14
|
+
|
15
|
+
Installation
|
16
|
+
------------
|
17
|
+
|
18
|
+
There is currently no gem release. Use git source in your Gemfile:
|
19
|
+
|
20
|
+
```gem 'unparser', :git => 'https://github.com/mbj/unparser'```
|
21
|
+
|
22
|
+
Credits
|
23
|
+
-------
|
24
|
+
|
25
|
+
* [Markus Schirp (mbj)](https://github.com/mbj) Author
|
26
|
+
|
27
|
+
Contributing
|
28
|
+
-------------
|
29
|
+
|
30
|
+
* Fork the project.
|
31
|
+
* Make your feature addition or bug fix.
|
32
|
+
* Add tests for it. This is important so I don't break it in a
|
33
|
+
future version unintentionally.
|
34
|
+
* Commit, do not mess with Rakefile or version
|
35
|
+
(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)
|
36
|
+
* Send me a pull request. Bonus points for topic branches.
|
37
|
+
|
38
|
+
License
|
39
|
+
-------
|
40
|
+
|
41
|
+
See LICENSE file.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'devtools'
|
2
|
+
Devtools.init_rake_tasks
|
3
|
+
|
4
|
+
class Rake::Task
|
5
|
+
def overwrite(&block)
|
6
|
+
@actions.clear
|
7
|
+
enhance(&block)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Rake.application.load_imports
|
12
|
+
|
13
|
+
Rake::Task['metrics:mutant'].overwrite do
|
14
|
+
begin
|
15
|
+
require 'mutant'
|
16
|
+
rescue LoadError
|
17
|
+
end
|
18
|
+
if defined?(Mutant)
|
19
|
+
status = Mutant::CLI.run(%W(--rspec-full -r ./spec/spec_helper.rb ::Unparser))
|
20
|
+
unless status.zero?
|
21
|
+
fail "Not mutation covered :("
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/config/devtools.yml
ADDED
data/config/flay.yml
ADDED
data/config/flog.yml
ADDED
data/config/mutant.yml
ADDED
data/config/reek.yml
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
---
|
2
|
+
UnusedParameters:
|
3
|
+
exclude: []
|
4
|
+
UncommunicativeParameterName:
|
5
|
+
accept: []
|
6
|
+
exclude: []
|
7
|
+
enabled: true
|
8
|
+
reject:
|
9
|
+
- !ruby/regexp /^.$/
|
10
|
+
- !ruby/regexp /[0-9]$/
|
11
|
+
- !ruby/regexp /[A-Z]/
|
12
|
+
TooManyInstanceVariables:
|
13
|
+
exclude: []
|
14
|
+
enabled: true
|
15
|
+
max_instance_variables: 3
|
16
|
+
TooManyMethods:
|
17
|
+
exclude:
|
18
|
+
- Unparser::Emitter # TODO: 13 methods, mostly helpers for deduplicate sublcasses
|
19
|
+
enabled: true
|
20
|
+
max_methods: 10
|
21
|
+
UncommunicativeMethodName:
|
22
|
+
accept: []
|
23
|
+
exclude: []
|
24
|
+
enabled: true
|
25
|
+
reject:
|
26
|
+
- !ruby/regexp /^[a-z]$/
|
27
|
+
- !ruby/regexp /[0-9]$/
|
28
|
+
- !ruby/regexp /[A-Z]/
|
29
|
+
LongParameterList:
|
30
|
+
max_params: 3
|
31
|
+
exclude:
|
32
|
+
- Unparser#self.transquote
|
33
|
+
enabled: true
|
34
|
+
overrides: {}
|
35
|
+
FeatureEnvy:
|
36
|
+
exclude:
|
37
|
+
- Unparser::Emitter::Literal::Regexp#escape # TODO Fixme!
|
38
|
+
- Unparser::Emitter::Send#binary_receiver?
|
39
|
+
- Unparser::Emitter::Send#effective_receiver
|
40
|
+
enabled: true
|
41
|
+
ClassVariable:
|
42
|
+
exclude: []
|
43
|
+
enabled: true
|
44
|
+
BooleanParameter:
|
45
|
+
exclude: []
|
46
|
+
enabled: true
|
47
|
+
IrresponsibleModule:
|
48
|
+
exclude: []
|
49
|
+
enabled: true
|
50
|
+
UncommunicativeModuleName:
|
51
|
+
accept: []
|
52
|
+
exclude: []
|
53
|
+
enabled: true
|
54
|
+
reject:
|
55
|
+
- !ruby/regexp /^.$/
|
56
|
+
- !ruby/regexp /[0-9]$/
|
57
|
+
NestedIterators:
|
58
|
+
ignore_iterators: []
|
59
|
+
exclude:
|
60
|
+
- Unparser::Emitter#self.children
|
61
|
+
enabled: true
|
62
|
+
max_allowed_nesting: 1
|
63
|
+
TooManyStatements:
|
64
|
+
max_statements: 5
|
65
|
+
exclude:
|
66
|
+
- Unparser::Emitter::Block#dispatch # 6 statements
|
67
|
+
- Unparser::Emitter::Def#dispatch # 6 statements
|
68
|
+
- Unparser::Emitter::Class#dispatch # 6 statements
|
69
|
+
enabled: true
|
70
|
+
DuplicateMethodCall:
|
71
|
+
allow_calls: []
|
72
|
+
exclude: []
|
73
|
+
enabled: false
|
74
|
+
max_calls: 1
|
75
|
+
UtilityFunction:
|
76
|
+
max_helper_calls: 1
|
77
|
+
exclude: []
|
78
|
+
enabled: true
|
79
|
+
Attribute:
|
80
|
+
exclude: []
|
81
|
+
enabled: false
|
82
|
+
UncommunicativeVariableName:
|
83
|
+
accept: []
|
84
|
+
exclude: []
|
85
|
+
enabled: true
|
86
|
+
reject:
|
87
|
+
- !ruby/regexp /^.$/
|
88
|
+
- !ruby/regexp /[0-9]$/
|
89
|
+
- !ruby/regexp /[A-Z]/
|
90
|
+
RepeatedConditional:
|
91
|
+
exclude:
|
92
|
+
- Unparser::Emitter::Send # TODO Fixme
|
93
|
+
- Unparser::Emitter::If
|
94
|
+
enabled: true
|
95
|
+
max_ifs: 1
|
96
|
+
DataClump:
|
97
|
+
exclude: []
|
98
|
+
enabled: true
|
99
|
+
max_copies: 1
|
100
|
+
min_clump_size: 3
|
101
|
+
ControlParameter:
|
102
|
+
exclude: []
|
103
|
+
enabled: true
|
104
|
+
LongYieldList:
|
105
|
+
max_params: 1
|
106
|
+
exclude: []
|
107
|
+
enabled: true
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Unparser
|
2
|
+
|
3
|
+
# Buffer used to emit into
|
4
|
+
class Buffer
|
5
|
+
|
6
|
+
NL = "\n".freeze
|
7
|
+
|
8
|
+
# Initialize object
|
9
|
+
#
|
10
|
+
# @return [undefined]
|
11
|
+
#
|
12
|
+
# @api private
|
13
|
+
#
|
14
|
+
def initialize
|
15
|
+
@content = ''
|
16
|
+
@indent = 0
|
17
|
+
end
|
18
|
+
|
19
|
+
# Append string
|
20
|
+
#
|
21
|
+
# @param [String] string
|
22
|
+
#
|
23
|
+
# @return [self]
|
24
|
+
#
|
25
|
+
# @api private
|
26
|
+
#
|
27
|
+
def append(string)
|
28
|
+
if @content[-1] == NL
|
29
|
+
prefix
|
30
|
+
end
|
31
|
+
@content << string
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# Increase indent
|
36
|
+
#
|
37
|
+
# @return [self]
|
38
|
+
#
|
39
|
+
# @api private
|
40
|
+
#
|
41
|
+
def indent
|
42
|
+
nl
|
43
|
+
@indent+=1
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
# Decrease indent
|
48
|
+
#
|
49
|
+
# @return [self]
|
50
|
+
#
|
51
|
+
# @api private
|
52
|
+
#
|
53
|
+
def unindent
|
54
|
+
nl
|
55
|
+
@indent-=1
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
# Write newline
|
60
|
+
#
|
61
|
+
# @return [self]
|
62
|
+
#
|
63
|
+
# @api private
|
64
|
+
#
|
65
|
+
def nl
|
66
|
+
@content << NL
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
# Return content of buffer
|
71
|
+
#
|
72
|
+
# @return [String]
|
73
|
+
#
|
74
|
+
# @api private
|
75
|
+
#
|
76
|
+
def content
|
77
|
+
@content.dup.freeze
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
# Write prefix
|
83
|
+
#
|
84
|
+
# @return [String]
|
85
|
+
#
|
86
|
+
# @api private
|
87
|
+
#
|
88
|
+
def prefix
|
89
|
+
@content << ' '*@indent
|
90
|
+
end
|
91
|
+
|
92
|
+
end # Buffer
|
93
|
+
end # Unparser
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Unparser
|
2
|
+
module Constants
|
3
|
+
|
4
|
+
UNARY_OPERATORS = %w(
|
5
|
+
!
|
6
|
+
~
|
7
|
+
-@
|
8
|
+
+@
|
9
|
+
).map(&:to_sym).to_set.freeze
|
10
|
+
|
11
|
+
|
12
|
+
BINARY_OPERATORS = %w(
|
13
|
+
+ - * / & | && || << >> ==
|
14
|
+
=== != <= < <=> > >= =~ !~ ^
|
15
|
+
**
|
16
|
+
).map(&:to_sym).to_set.freeze
|
17
|
+
|
18
|
+
WS = ' '.freeze
|
19
|
+
NL = "\n".freeze
|
20
|
+
O_DOT = '.'.freeze
|
21
|
+
O_LT = '<'.freeze
|
22
|
+
O_DLT = '<<'.freeze
|
23
|
+
O_AMP = '&'.freeze
|
24
|
+
O_ASN = '='.freeze
|
25
|
+
O_SPLAT = '*'.freeze
|
26
|
+
O_ASR = '=>'.freeze
|
27
|
+
O_PIPE = '|'.freeze
|
28
|
+
O_DCL = '::'.freeze
|
29
|
+
O_NEG = '!'.freeze
|
30
|
+
O_OR = '||'.freeze
|
31
|
+
O_AND = '&&'.freeze
|
32
|
+
|
33
|
+
M_PO = '('.freeze
|
34
|
+
M_PC = ')'.freeze
|
35
|
+
|
36
|
+
K_DO = 'do'
|
37
|
+
K_DEF = 'def'
|
38
|
+
K_END = 'end'
|
39
|
+
K_BEGIN = 'begin'
|
40
|
+
K_CASE = 'case'
|
41
|
+
K_CLASS = 'class'
|
42
|
+
K_SELF = 'self'
|
43
|
+
K_ENSURE = 'ensure'
|
44
|
+
K_DEFINE = 'define'
|
45
|
+
K_MODULE = 'module'
|
46
|
+
K_RESCUE = 'rescue'
|
47
|
+
K_RETURN = 'return'
|
48
|
+
K_UNDEF = 'undef'
|
49
|
+
K_DEFINED = 'defined?'
|
50
|
+
K_PREEXE = 'BEGIN'
|
51
|
+
K_POSTEXE = 'END'
|
52
|
+
K_SUPER = 'super'
|
53
|
+
K_BREAK = 'break'
|
54
|
+
K_RETRY = 'retry'
|
55
|
+
K_REDO = 'redo'
|
56
|
+
K_NEXT = 'next'
|
57
|
+
K_FALSE = 'false'
|
58
|
+
K_TRUE = 'true'
|
59
|
+
K_IF = 'if'
|
60
|
+
K_AND = 'and'
|
61
|
+
K_ALIAS = 'alias'
|
62
|
+
K_ELSE = 'else'
|
63
|
+
K_ELSIF = 'elsif'
|
64
|
+
K_FOR = 'for'
|
65
|
+
K_NIL = 'nil'
|
66
|
+
K_NOT = 'not'
|
67
|
+
K_IN = 'in'
|
68
|
+
K_OR = 'or'
|
69
|
+
K_UNLESS = 'unless'
|
70
|
+
K_WHEN = 'when'
|
71
|
+
K_WHILE = 'while'
|
72
|
+
K_UNTIL = 'until'
|
73
|
+
K_YIELD = 'yield'
|
74
|
+
K_ENCODING = '__ENCODING__'
|
75
|
+
K_EEND = '__END__'
|
76
|
+
K_FILE = '__FILE__'
|
77
|
+
K_THEN = 'then'
|
78
|
+
|
79
|
+
|
80
|
+
KEYWORDS = constants.map do |name|
|
81
|
+
if name.to_s.start_with?('K_')
|
82
|
+
const_get(name).freeze.to_sym
|
83
|
+
end
|
84
|
+
end.compact.freeze
|
85
|
+
|
86
|
+
end # Constants
|
87
|
+
end # Unparser
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Unparser
|
2
|
+
class Emitter
|
3
|
+
# Emitter for alias nodes
|
4
|
+
class Alias < self
|
5
|
+
|
6
|
+
handle :alias
|
7
|
+
|
8
|
+
children :target, :source
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# Perform dispatch
|
13
|
+
#
|
14
|
+
# @return [undefined]
|
15
|
+
#
|
16
|
+
# @api private
|
17
|
+
#
|
18
|
+
def dispatch
|
19
|
+
write(K_ALIAS, WS)
|
20
|
+
visit(target)
|
21
|
+
write(WS)
|
22
|
+
visit(source)
|
23
|
+
end
|
24
|
+
|
25
|
+
end # Alias
|
26
|
+
end # Emitter
|
27
|
+
end # Unparser
|
@@ -0,0 +1,154 @@
|
|
1
|
+
module Unparser
|
2
|
+
class Emitter
|
3
|
+
|
4
|
+
# Arg expr (pattern args) emitter
|
5
|
+
class ArgExpr < self
|
6
|
+
|
7
|
+
handle :arg_expr
|
8
|
+
|
9
|
+
children :body
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# Perform dispatch
|
14
|
+
#
|
15
|
+
# @return [undefined]
|
16
|
+
#
|
17
|
+
# @api private
|
18
|
+
#
|
19
|
+
def dispatch
|
20
|
+
parentheses do
|
21
|
+
visit(body)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end # ArgExpr
|
25
|
+
|
26
|
+
# Arguments emitter
|
27
|
+
class Arguments < self
|
28
|
+
|
29
|
+
handle :args
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# Perform dispatch
|
34
|
+
#
|
35
|
+
# @return [undefined]
|
36
|
+
#
|
37
|
+
# @api private
|
38
|
+
#
|
39
|
+
def dispatch
|
40
|
+
mapped = children.map do |child|
|
41
|
+
if child.type == :mlhs
|
42
|
+
Parser::AST::Node.new(:arg_expr, [child])
|
43
|
+
else
|
44
|
+
child
|
45
|
+
end
|
46
|
+
end
|
47
|
+
delimited(mapped)
|
48
|
+
end
|
49
|
+
|
50
|
+
end # Arguments
|
51
|
+
|
52
|
+
# Emitter for block arguments
|
53
|
+
class Blockarg < self
|
54
|
+
|
55
|
+
handle :blockarg
|
56
|
+
|
57
|
+
children :name
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# Perform dispatch
|
62
|
+
#
|
63
|
+
# @return [undefined]
|
64
|
+
#
|
65
|
+
# @api private
|
66
|
+
#
|
67
|
+
def dispatch
|
68
|
+
write(O_AMP, name.to_s)
|
69
|
+
end
|
70
|
+
|
71
|
+
end # Blockarg
|
72
|
+
|
73
|
+
# Optional argument emitter
|
74
|
+
class Optarg < self
|
75
|
+
|
76
|
+
handle :optarg
|
77
|
+
|
78
|
+
children :name, :value
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
# Perform dispatch
|
83
|
+
#
|
84
|
+
# @return [undefined]
|
85
|
+
#
|
86
|
+
# @api private
|
87
|
+
#
|
88
|
+
def dispatch
|
89
|
+
write(name.to_s, WS, O_ASN, WS)
|
90
|
+
visit(value)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Rest argument emitter
|
95
|
+
class Restarg < self
|
96
|
+
handle :restarg
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
# Perform dispatch
|
101
|
+
#
|
102
|
+
# @return [undefined]
|
103
|
+
#
|
104
|
+
# @api private
|
105
|
+
#
|
106
|
+
def dispatch
|
107
|
+
write(O_SPLAT, first_child.to_s)
|
108
|
+
end
|
109
|
+
|
110
|
+
end # Restarg
|
111
|
+
|
112
|
+
# Argument emitter
|
113
|
+
class Argument < self
|
114
|
+
|
115
|
+
handle :arg
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
# Perform dispatch
|
120
|
+
#
|
121
|
+
# @return [undefined]
|
122
|
+
#
|
123
|
+
# @api private
|
124
|
+
#
|
125
|
+
def dispatch
|
126
|
+
write(first_child.to_s)
|
127
|
+
end
|
128
|
+
|
129
|
+
end # Argument
|
130
|
+
|
131
|
+
# Block pass node emitter
|
132
|
+
class BlockPass < self
|
133
|
+
|
134
|
+
handle :block_pass
|
135
|
+
|
136
|
+
children :name
|
137
|
+
|
138
|
+
private
|
139
|
+
|
140
|
+
# Perform dispatch
|
141
|
+
#
|
142
|
+
# @return [undefined]
|
143
|
+
#
|
144
|
+
# @api private
|
145
|
+
#
|
146
|
+
def dispatch
|
147
|
+
write(O_AMP)
|
148
|
+
visit(name)
|
149
|
+
end
|
150
|
+
|
151
|
+
end # BlockPass
|
152
|
+
|
153
|
+
end # Emitter
|
154
|
+
end # Unparser
|