yap-shell-parser 0.6.1 → 0.6.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b2657fa735f9d2e2c946e120f9c5aad74919824
4
- data.tar.gz: 7eeb54709d154f1a5c19919cc2757a9da3ba15ef
3
+ metadata.gz: c452309759a871f7506451fd55282318434a5b25
4
+ data.tar.gz: 7a9aed6543577d6c8e9b5244320d02877c2502a2
5
5
  SHA512:
6
- metadata.gz: 97abaa67b6f96ed4622b79c63699ed8232c2f276102e4093596979973d00228e3d62bbf9fd14fe880b174181c4f021fd25c818dd57790e80237377a7633ee55e
7
- data.tar.gz: 3fea542b32d29319b14f854f31c91761ee8a0dec21563b6f78c62323e276db50404e7a0ee6fdff11e08f5b806700723e9e6a727f35e9ad1e73e6cf43c1afede8
6
+ metadata.gz: 8219284d09acbb0537f352b33c12aaf52fbd7418b8e3c2562443547fd0d30e012035a4dfe5c981b0ec5c07c797fdd6ec875c637122f99b98cca53db1c7ece7ba
7
+ data.tar.gz: c962d71ed8207bd23593a12bb4e9150d370914623a755411527e19fcbbd7515e9e668d5c058c6b4a9e9e9152d08719c84f0cbe3c5792b21d31213f86cf9a3f58
@@ -67,7 +67,7 @@ module Yap::Shell
67
67
 
68
68
  LINE_CONTINUATION = /.*\\\Z/
69
69
 
70
- SPLIT_BLOCK_PARAMS_RGX = /\s*,\s*|\s*/
70
+ SPLIT_BLOCK_PARAMS_RGX = /\s*,\s*/
71
71
 
72
72
  # Loop over the given input and yield command substitutions. This yields
73
73
  # an object that responds to #str, and #position.
@@ -168,10 +168,7 @@ module Yap::Shell
168
168
  if md=@chunk.match(BLOCK_BEGIN)
169
169
  @looking_for_args = false
170
170
  token :BlockBegin, md[1]
171
- if md[2]
172
- params = md[2].split(SPLIT_BLOCK_PARAMS_RGX)
173
- token :BlockParams, params
174
- end
171
+ block_params_token(md[2])
175
172
  md[0].length
176
173
  elsif md=@chunk.match(BLOCK_END)
177
174
  @looking_for_args = false
@@ -182,6 +179,13 @@ module Yap::Shell
182
179
  end
183
180
  end
184
181
 
182
+ def block_params_token(string)
183
+ if string
184
+ params = string.split(SPLIT_BLOCK_PARAMS_RGX).map(&:strip)
185
+ token :BlockParams, params
186
+ end
187
+ end
188
+
185
189
  def comment_token
186
190
  if md=@chunk.match(COMMENT)
187
191
  token :Comment, md[0]
@@ -208,8 +212,7 @@ module Yap::Shell
208
212
  start, stop = md[2].to_i, md[3].to_i
209
213
  token :Range, (start..stop)
210
214
  token :BlockBegin, '{'
211
- params = md[4].split(SPLIT_BLOCK_PARAMS_RGX)
212
- token :BlockParams, params
215
+ block_params_token(md[4])
213
216
  @tokens_to_add_when_done << [:BlockEnd, '}']
214
217
  md[0].length
215
218
 
@@ -224,8 +227,7 @@ module Yap::Shell
224
227
  start, stop = 1, md[2].to_i
225
228
  token :Range, (start..stop)
226
229
  token :BlockBegin, '{'
227
- params = md[4].split(SPLIT_BLOCK_PARAMS_RGX)
228
- token :BlockParams, params
230
+ block_params_token(md[4])
229
231
  @tokens_to_add_when_done << [:BlockEnd, '}']
230
232
  md[0].length
231
233
 
@@ -3,7 +3,7 @@ require 'yap/shell/parser'
3
3
  module Yap
4
4
  module Shell
5
5
  module Parser
6
- VERSION = "0.6.1"
6
+ VERSION = "0.6.2"
7
7
  end
8
8
  end
9
9
  end
@@ -97,31 +97,31 @@ describe Yap::Shell::Parser::Lexer do
97
97
  end
98
98
 
99
99
  describe "can take block params" do
100
- describe "ls { |a| this_is_a_block }" do
100
+ describe "ls { |param1| this_is_a_block }" do
101
101
  it { should eq [
102
102
  t(:Command, "ls", lineno:0),
103
103
  t(:BlockBegin, '{', lineno: 0),
104
- t(:BlockParams, ['a'], lineno: 0),
104
+ t(:BlockParams, ['param1'], lineno: 0),
105
105
  t(:Command, "this_is_a_block", lineno:0),
106
106
  t(:BlockEnd, '}', lineno: 0)
107
107
  ]}
108
108
  end
109
109
 
110
- describe "ls { |a,b| this_is_a_block }" do
110
+ describe "ls { |param1,b| this_is_a_block }" do
111
111
  it { should eq [
112
112
  t(:Command, "ls", lineno:0),
113
113
  t(:BlockBegin, '{', lineno: 0),
114
- t(:BlockParams, ['a', 'b'], lineno: 0),
114
+ t(:BlockParams, ['param1', 'b'], lineno: 0),
115
115
  t(:Command, "this_is_a_block", lineno:0),
116
116
  t(:BlockEnd, '}', lineno: 0)
117
117
  ]}
118
118
  end
119
119
 
120
- describe "ls { |a, b, c| this_is_a_block }" do
120
+ describe "ls { |a1, b2, c3| this_is_a_block }" do
121
121
  it { should eq [
122
122
  t(:Command, "ls", lineno:0),
123
123
  t(:BlockBegin, '{', lineno: 0),
124
- t(:BlockParams, ['a', 'b', 'c'], lineno: 0),
124
+ t(:BlockParams, ['a1', 'b2', 'c3'], lineno: 0),
125
125
  t(:Command, "this_is_a_block", lineno:0),
126
126
  t(:BlockEnd, '}', lineno: 0)
127
127
  ]}
@@ -66,4 +66,5 @@ describe Yap::Shell::Parser do
66
66
  it { is_expected.to fail_parsing "ls ()" }
67
67
  it { is_expected.to parse("echo 'hi'")}
68
68
  it { is_expected.to parse("ls > foo.txt")}
69
+ it { is_expected.to parse("ls * { |file1, file2, file3| echo $file1 $file2 $file3 }")}
69
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yap-shell-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-08 00:00:00.000000000 Z
11
+ date: 2016-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: treefell