unparser 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76fd3cadb7aa3c25e62d45e012c2377b6fecc0e9
4
- data.tar.gz: 9a5b5833a38bffedb47db8c578c83a09607e2ce9
3
+ metadata.gz: 699cb6f7b7346130d08e26971bb7415989814195
4
+ data.tar.gz: 67f7d1d663508c344d141a74dfebf0a375457f49
5
5
  SHA512:
6
- metadata.gz: 091f158bbe82fb41ef74e0d5367672083a21b95df31ad7493423fc13267348b1fed8331c8b3058ee0e18fad31a28498ed90c791852074d94fba986ef4a65b957
7
- data.tar.gz: a1b024cabf31dfceacdf8320d832859f6cf8ec2c4a3970373a90400e81a2d501fa2a6bd0d4fcd2bfc73a961a72f35d2386246f2884ea66c5315430768317b177
6
+ metadata.gz: 93fc7a2d83ccb9a72d3b9eca238f70d6d87c1f6c7cd919faf2f0f418cf2ae82faf00c4dd912100748c78f66dbcf82b124e9cdb7e2ba7e08135dee82024d46ee8
7
+ data.tar.gz: a15743cd3c9596c3fcf9ab6d1813964a97287a3c6fb9b7ccb666d53c70185234799aed1585fcf85fb901a11d2462bf35c949bc95981816c0d4c5782c17e62831
data/README.md CHANGED
@@ -7,8 +7,6 @@ unparser
7
7
 
8
8
  Generate equivalent inputs for ASTs from whitequarks awesome [parser](https://github.com/whitequark/parser).
9
9
 
10
- Only supports 1.9 syntax currently!
11
-
12
10
  Usage
13
11
  -----
14
12
 
data/config/flay.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  ---
2
- threshold: 14
3
- total_score: 341
2
+ threshold: 13
3
+ total_score: 353
@@ -122,7 +122,7 @@ module Unparser
122
122
  # Emitter for begin nodes
123
123
  class Begin < self
124
124
 
125
- handle :begin
125
+ handle :begin, :kwbegin
126
126
 
127
127
  private
128
128
 
@@ -133,9 +133,7 @@ module Unparser
133
133
  # @api private
134
134
  #
135
135
  def dispatch
136
- case children.length
137
- when 0
138
- when 1
136
+ if children.length == 1 and !parent.needs_begin?
139
137
  visit(first_child)
140
138
  else
141
139
  emit_normal
@@ -149,12 +147,12 @@ module Unparser
149
147
  # @api private
150
148
  #
151
149
  def emit_normal
152
- unless parent.needs_begin?
153
- emit_inner
154
- else
150
+ if parent.needs_begin?
155
151
  k_begin
156
152
  indented { emit_inner }
157
153
  k_end
154
+ else
155
+ emit_inner
158
156
  end
159
157
  end
160
158
 
@@ -1,6 +1,43 @@
1
1
  module Unparser
2
2
  class Emitter
3
3
 
4
+ # Emitter for postconditions
5
+ class Post < self
6
+
7
+ handle :while_post, :until_post
8
+
9
+ children :condition, :body
10
+
11
+ MAP = {
12
+ :while_post => K_WHILE,
13
+ :until_until => K_UNTIL
14
+ }.freeze
15
+
16
+ handle *MAP.keys
17
+
18
+ # Test if child should be emitted with explicit begin nodes
19
+ #
20
+ # @return [true]
21
+ #
22
+ # @api private
23
+ #
24
+ def needs_begin?
25
+ true
26
+ end
27
+
28
+ # Perform dispatch
29
+ #
30
+ # @return [undefined]
31
+ #
32
+ # @api private
33
+ #
34
+ def dispatch
35
+ visit(body)
36
+ write(WS, MAP.fetch(node.type), WS)
37
+ visit(condition)
38
+ end
39
+ end
40
+
4
41
  # Base class for while and until emitters
5
42
  class Repetition < self
6
43
 
@@ -956,6 +956,21 @@ describe Unparser, 'spike' do
956
956
  RUBY
957
957
  end
958
958
 
959
+ context 'post conditions' do
960
+ assert_source <<-RUBY
961
+ begin
962
+ foo
963
+ end while baz
964
+ RUBY
965
+
966
+ assert_source <<-RUBY
967
+ begin
968
+ foo
969
+ bar
970
+ end while baz
971
+ RUBY
972
+ end
973
+
959
974
  context 'while' do
960
975
  assert_source <<-RUBY
961
976
  while false
data/unparser.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'unparser'
5
- s.version = '0.0.3'
5
+ s.version = '0.0.4'
6
6
 
7
7
  s.authors = ['Markus Schirp']
8
8
  s.email = 'mbj@schir-dso.com'
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = %w(lib)
17
17
  s.extra_rdoc_files = %w(README.md)
18
18
 
19
- s.add_dependency('parser', '~> 2.0.0.beta6')
19
+ s.add_dependency('parser', '~> 2.0.0.beta7')
20
20
  s.add_dependency('concord', '~> 0.1.0')
21
21
  s.add_dependency('adamantium', '~> 0.0.7')
22
22
  s.add_dependency('equalizer', '~> 0.0.5')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Schirp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-21 00:00:00.000000000 Z
11
+ date: 2013-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0.beta6
19
+ version: 2.0.0.beta7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0.beta6
26
+ version: 2.0.0.beta7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: concord
29
29
  requirement: !ruby/object:Gem::Requirement