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 +4 -4
- data/lib/yap/shell/parser.rb +8 -2
- data/lib/yap/shell/parser/lexer.rb +16 -9
- data/lib/yap/shell/parser/version.rb +1 -1
- data/spec/yap/shell/lexer_spec.rb +8 -0
- data/spec/yap/shell/parser_spec.rb +15 -9
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38fe37a326babe384c9ee17b218628b096392e1c
|
4
|
+
data.tar.gz: 2c2eaaf1cc9522a4b6b3db7e8011f258f1c49b4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41aee65259f186af876c993a484329da3efbda47275227df23c6e8e17c2299e342f0c9c96b210b01017accc94d617389853fe1f4bda3d8c0d187d44903991d49
|
7
|
+
data.tar.gz: d6742e6486e4178d5e90910c06ac5e7c852bcda64a5cd08b5c8f95107c0b3e49635d60cd58c6c40a04fc02ea20bdc63d75b9cb689ee5c1cbfb8ddb1010ac4562
|
data/lib/yap/shell/parser.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
require 'racc/parser'
|
2
|
+
|
1
3
|
module Yap
|
2
4
|
module Shell
|
3
5
|
module Parser
|
4
|
-
|
5
|
-
|
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
|
-
|
202
|
+
characters_read = 0
|
203
|
+
prev_char = ''
|
203
204
|
loop do
|
204
|
-
ch = @chunk[
|
205
|
+
ch = @chunk[characters_read]
|
205
206
|
if %w(' ").include?(ch)
|
206
|
-
result = process_string @chunk[
|
207
|
+
result = process_string @chunk[characters_read..-1], ch
|
207
208
|
str << result.str
|
208
|
-
|
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
|
-
|
214
|
+
characters_read += 1
|
214
215
|
end
|
215
216
|
|
216
|
-
break if
|
217
|
+
break if characters_read >= @chunk.length
|
218
|
+
|
219
|
+
prev_char = ch
|
217
220
|
end
|
218
221
|
|
219
|
-
|
220
|
-
|
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
|
|
@@ -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
|
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
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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"
|
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.
|
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-
|
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.
|
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:
|