yap-shell-parser 0.1.0 → 0.2.0

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: f0e319c332283c42adde5fcba98b7ee4c8f8e8bb
4
- data.tar.gz: 9d1e3d51c8df81d6e3a50cca393bff86f3edbaeb
3
+ metadata.gz: 38fe37a326babe384c9ee17b218628b096392e1c
4
+ data.tar.gz: 2c2eaaf1cc9522a4b6b3db7e8011f258f1c49b4a
5
5
  SHA512:
6
- metadata.gz: eaaa6d7f6082dbb8915253dc41eb62295b98b7170398c6e4918396f19c3c714a2a5c968cc9e34f865fbe13c082d2e5ee688212952107a10fc6d41b1d0c6dbe97
7
- data.tar.gz: 2a8f4c7efa8af4a3b14c5b275da68cd8071231afb68a653f374af6f888e9bbce6b2690e053ddc3735be0810a8f86dd4966f66a91ecf5aadf832d35228bc01f92
6
+ metadata.gz: 41aee65259f186af876c993a484329da3efbda47275227df23c6e8e17c2299e342f0c9c96b210b01017accc94d617389853fe1f4bda3d8c0d187d44903991d49
7
+ data.tar.gz: d6742e6486e4178d5e90910c06ac5e7c852bcda64a5cd08b5c8f95107c0b3e49635d60cd58c6c40a04fc02ea20bdc63d75b9cb689ee5c1cbfb8ddb1010ac4562
@@ -1,8 +1,14 @@
1
+ require 'racc/parser'
2
+
1
3
  module Yap
2
4
  module Shell
3
5
  module Parser
4
- def self.new
5
- Yap::Shell::ParserImpl.new
6
+ class ParseError < ::StandardError ; end
7
+
8
+ def self.parse(input)
9
+ Yap::Shell::ParserImpl.new.parse(input)
10
+ rescue Racc::ParseError => ex
11
+ raise ParseError, "Message: #{ex.message}\nInput: #{input}"
6
12
  end
7
13
  end
8
14
  end
@@ -199,25 +199,32 @@ module Yap::Shell
199
199
  def argument_token
200
200
  if @looking_for_args
201
201
  str = ''
202
- i = 0
202
+ characters_read = 0
203
+ prev_char = ''
203
204
  loop do
204
- ch = @chunk[i]
205
+ ch = @chunk[characters_read]
205
206
  if %w(' ").include?(ch)
206
- result = process_string @chunk[i..-1], ch
207
+ result = process_string @chunk[characters_read..-1], ch
207
208
  str << result.str
208
- i += result.consumed_length
209
- elsif ch =~ /[\s\|;&\)]/
209
+ characters_read += result.consumed_length
210
+ elsif prev_char != '\\' && ch =~ /[\s\|;&\)]/
210
211
  break
211
212
  else
212
213
  str << ch
213
- i += 1
214
+ characters_read += 1
214
215
  end
215
216
 
216
- break if i >= @chunk.length
217
+ break if characters_read >= @chunk.length
218
+
219
+ prev_char = ch
217
220
  end
218
221
 
219
- token :Argument, str
220
- i
222
+ if characters_read > 0
223
+ token :Argument, str
224
+ characters_read
225
+ else
226
+ nil
227
+ end
221
228
  end
222
229
  end
223
230
 
@@ -3,7 +3,7 @@ require 'yap/shell/parser'
3
3
  module Yap
4
4
  module Shell
5
5
  module Parser
6
- VERSION = "0.1.0"
6
+ VERSION = "0.2.0"
7
7
  end
8
8
  end
9
9
  end
@@ -116,6 +116,14 @@ describe Yap::Shell::Parser::Lexer do
116
116
  ]}
117
117
  end
118
118
 
119
+ describe "commands with a escaped args: ls some\ dir" do
120
+ let(:str){ 'ls some\ dir' }
121
+ it { should eq [
122
+ t(:Command, "ls", lineno:0),
123
+ t(:Argument, 'some\ dir', lineno:0)
124
+ ]}
125
+ end
126
+
119
127
  describe "can contain asterisks: ls foo* b*r" do
120
128
  let(:str){ "ls foo* b*r" }
121
129
  it { should eq [
@@ -3,18 +3,22 @@ require 'yap/shell/parser'
3
3
  require 'pry'
4
4
 
5
5
  describe Yap::Shell::Parser do
6
- subject(:parser){ Yap::Shell::Parser.new }
6
+ subject(:parser){ Yap::Shell::Parser }
7
7
 
8
8
  def self.it_parses(str)
9
9
  context "#{str.inspect}" do
10
10
  it "parses" do
11
- expect do
12
- begin
13
- parser.parse(str)
14
- # rescue => ex
15
- # raise "Parser error:\n\t#{str}\n\n#{ex.message}\n#{ex.backtrace.join("\n")}"
16
- end
17
- end.to_not raise_error
11
+ expect { parser.parse(str) }.to_not raise_error
12
+ end
13
+ end
14
+ end
15
+
16
+ def self.it_errors(str)
17
+ context "#{str.inspect}" do
18
+ it "raises a Yap::Shell::Parser::ParseError" do
19
+ expect {
20
+ parser.parse(str)
21
+ }.to raise_error(Yap::Shell::Parser::ParseError)
18
22
  end
19
23
  end
20
24
  end
@@ -49,9 +53,11 @@ describe Yap::Shell::Parser do
49
53
  it_parses "FOO=abc bar=2314 car=14ab ls -l"
50
54
  it_parses "FOO=abc BAR='hello world' ls -l ; CAR=f echo foo && say hi"
51
55
  it_parses "`git cbranch`"
52
- it_parses "`git cbranch`.bak" # TODO THIS NEEDS TO MAYBE NOT WORK?
56
+ it_parses "`git cbranch`.bak"
53
57
  it_parses "echo `echo hi`"
54
58
  it_parses "echo `echo hi` foo"
55
59
  it_parses "`hi``bye` `what`"
56
60
  it_parses "echo && `what` && where is `that`thing | `you know`"
61
+
62
+ it_errors "ls ()"
57
63
  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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-14 00:00:00.000000000 Z
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  version: '0'
114
114
  requirements: []
115
115
  rubyforge_project:
116
- rubygems_version: 2.4.3
116
+ rubygems_version: 2.4.6
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: The parser for the yap shell
@@ -121,4 +121,3 @@ test_files:
121
121
  - spec/spec_helper.rb
122
122
  - spec/yap/shell/lexer_spec.rb
123
123
  - spec/yap/shell/parser_spec.rb
124
- has_rdoc: