yap-shell-parser 0.6.2 → 0.7.0
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 +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/lib/yap/shell/parser.rb +5 -1
- data/lib/yap/shell/parser/lexer.rb +20 -9
- data/lib/yap/shell/parser/nodes.rb +5 -1
- data/lib/yap/shell/parser/version.rb +1 -1
- data/spec/yap/shell/lexer_spec.rb +35 -0
- data/spec/yap/shell/parser_spec.rb +1 -0
- data/yap-shell-parser.gemspec +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 336e650e52d979ad853d6544b7dda9f44253e8ae
|
4
|
+
data.tar.gz: ad9cf9b11eab65b0a75e0552082105380cbd31a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7644b342203f0f98e5eb805756ba49735503f600ee2fc73ef820df291e1343c822bc74f035e713fae091f97d1f364fe507497a137d973ee595526c79a92e4a3
|
7
|
+
data.tar.gz: 6996c6b68c34daf2f9aa521650f1cb403b7ebc96c3d903512f5b4264016e934c19d2b5c32d921e24d673176f62022f6225b2286fb051fa7dbb5146f5aa78cd99
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.1
|
data/.travis.yml
CHANGED
data/lib/yap/shell/parser.rb
CHANGED
@@ -31,7 +31,11 @@ module Yap
|
|
31
31
|
end
|
32
32
|
|
33
33
|
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../../"
|
34
|
-
|
34
|
+
begin
|
35
|
+
require 'treefell'
|
36
|
+
rescue LoadError => ex
|
37
|
+
nil
|
38
|
+
end
|
35
39
|
require 'yap/shell/parser/lexer'
|
36
40
|
require 'yap/shell/parser/nodes'
|
37
41
|
require 'yap/shell/parser_impl'
|
@@ -52,8 +52,9 @@ module Yap::Shell
|
|
52
52
|
HEREDOC_START = /\A<<-?([A-z0-9]+)\s*\n/
|
53
53
|
INTERNAL_EVAL = /\A(?:(\!)|([0-9]+))/
|
54
54
|
SUBGROUP = /\A(\(|\))/
|
55
|
-
|
56
|
-
REDIRECTION2
|
55
|
+
REDIRECTION1 = /\A(([12]?>>)\s*(#{ARG}))/
|
56
|
+
REDIRECTION2 = /\A(([12]?>&?[12]?)\s*(?![12][\?]?>)(#{ARG})?)/
|
57
|
+
REDIRECTION3 = /\A((&>|<|&>>)\s*(#{ARG}))/
|
57
58
|
|
58
59
|
NUMERIC_RANGE = /\A\(((\d+)\.\.(\d+))\)(\.each)?/
|
59
60
|
NUMERIC_RANGE_W_CALL = /\A\(((\d+)\.\.(\d+))\)(\.each)?\s*:\s*/
|
@@ -334,14 +335,18 @@ module Yap::Shell
|
|
334
335
|
end
|
335
336
|
|
336
337
|
def redirection_token
|
337
|
-
if md=@chunk.match(
|
338
|
+
if md=@chunk.match(REDIRECTION1)
|
339
|
+
token :Redirection, md[2], attrs: { target: md[3] }
|
340
|
+
md[0].length
|
341
|
+
elsif md=@chunk.match(REDIRECTION2)
|
338
342
|
target = nil
|
339
343
|
target = md[3] if md[3] && md[3].length > 0
|
340
344
|
token :Redirection, md[2], attrs: { target: target }
|
341
345
|
md[0].length
|
342
|
-
elsif md=@chunk.match(
|
346
|
+
elsif md=@chunk.match(REDIRECTION3)
|
343
347
|
token :Redirection, md[2], attrs: { target: md[3] }
|
344
348
|
md[0].length
|
349
|
+
elsif md=@chunk.match(REDIRECTION1)
|
345
350
|
else
|
346
351
|
did_not_match
|
347
352
|
end
|
@@ -371,16 +376,23 @@ module Yap::Shell
|
|
371
376
|
str = ''
|
372
377
|
characters_read = 0
|
373
378
|
prev_char = ''
|
379
|
+
|
380
|
+
escaped = false
|
381
|
+
quoted_by = nil
|
382
|
+
|
374
383
|
loop do
|
375
384
|
ch = @chunk[characters_read]
|
376
385
|
|
377
386
|
if %w(' ").include?(ch)
|
378
|
-
|
387
|
+
quoted_by = ch
|
379
388
|
result = process_string @chunk[characters_read..-1], ch
|
380
389
|
str << result.str
|
381
390
|
characters_read += result.consumed_length
|
382
391
|
elsif ch == '\\'
|
383
|
-
#
|
392
|
+
# We're escaping the argument if this is the first character we
|
393
|
+
# see. If this comes any later then we don't care
|
394
|
+
escaped = true if characters_read == 0
|
395
|
+
|
384
396
|
characters_read += 1
|
385
397
|
elsif prev_char != '\\' && ch =~ /[\s\|;&\(\)]/
|
386
398
|
break
|
@@ -396,9 +408,8 @@ module Yap::Shell
|
|
396
408
|
|
397
409
|
if characters_read > 0
|
398
410
|
attrs = {}
|
399
|
-
if
|
400
|
-
|
401
|
-
end
|
411
|
+
attrs.merge!(escaped: escaped) if escaped
|
412
|
+
attrs.merge!(quoted_by: quoted_by) if quoted_by
|
402
413
|
token :Argument, str, attrs: attrs
|
403
414
|
characters_read
|
404
415
|
else
|
@@ -24,6 +24,10 @@ module Yap::Shell
|
|
24
24
|
@attrs = token.attrs
|
25
25
|
end
|
26
26
|
|
27
|
+
def escaped?
|
28
|
+
@attrs[:escaped]
|
29
|
+
end
|
30
|
+
|
27
31
|
def quoted?
|
28
32
|
double_quoted? || single_quoted?
|
29
33
|
end
|
@@ -41,7 +45,7 @@ module Yap::Shell
|
|
41
45
|
end
|
42
46
|
|
43
47
|
def to_s
|
44
|
-
"ArgumentNode(#{lvalue.inspect})"
|
48
|
+
"ArgumentNode(#{lvalue.inspect} escaped? #{escaped?} double_quoted? #{double_quoted?} single_quoted? #{single_quoted?})"
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
@@ -589,6 +589,16 @@ describe Yap::Shell::Parser::Lexer do
|
|
589
589
|
end
|
590
590
|
end
|
591
591
|
end
|
592
|
+
|
593
|
+
context 'escaped arguments' do
|
594
|
+
describe 'echo \$FOO' do
|
595
|
+
it { should eq [
|
596
|
+
t(:Command, "echo", lineno:0),
|
597
|
+
t(:Argument, "$FOO", lineno:0, attrs: { escaped: true })
|
598
|
+
]}
|
599
|
+
end
|
600
|
+
|
601
|
+
end
|
592
602
|
end
|
593
603
|
|
594
604
|
context "statements" do
|
@@ -946,6 +956,14 @@ describe Yap::Shell::Parser::Lexer do
|
|
946
956
|
]}
|
947
957
|
end
|
948
958
|
|
959
|
+
describe "can double up" do
|
960
|
+
let(:str){ "ls >> a.txt" }
|
961
|
+
it { should eq [
|
962
|
+
t(:Command, "ls", lineno: 0),
|
963
|
+
t(:Redirection, ">>", lineno: 0, attrs: { target: "a.txt" }),
|
964
|
+
]}
|
965
|
+
end
|
966
|
+
|
949
967
|
describe "can be the start of a command (for clearing files)" do
|
950
968
|
describe "> a.txt" do
|
951
969
|
it { should eq [
|
@@ -985,6 +1003,14 @@ describe Yap::Shell::Parser::Lexer do
|
|
985
1003
|
t(:Redirection, "2>", lineno: 0, attrs: { target: "bar.txt" }),
|
986
1004
|
]}
|
987
1005
|
end
|
1006
|
+
|
1007
|
+
describe "can double up" do
|
1008
|
+
let(:str){ "ls 2>> a.txt" }
|
1009
|
+
it { should eq [
|
1010
|
+
t(:Command, "ls", lineno: 0),
|
1011
|
+
t(:Redirection, "2>>", lineno: 0, attrs: { target: "a.txt" }),
|
1012
|
+
]}
|
1013
|
+
end
|
988
1014
|
end
|
989
1015
|
|
990
1016
|
describe "stdout / stderr" do
|
@@ -1048,6 +1074,15 @@ describe Yap::Shell::Parser::Lexer do
|
|
1048
1074
|
t(:Redirection, "1>", lineno: 0, attrs: { target: "hey.txt" })
|
1049
1075
|
]}
|
1050
1076
|
end
|
1077
|
+
|
1078
|
+
describe "redirecting both stdout and stderr with an append: du -sh &>> hey.txt" do
|
1079
|
+
let(:str){ "du -sh &>> hey.txt" }
|
1080
|
+
it { should eq [
|
1081
|
+
t(:Command, "du", lineno: 0),
|
1082
|
+
t(:Argument, "-sh", lineno: 0),
|
1083
|
+
t(:Redirection, "&>>", lineno: 0, attrs: { target: "hey.txt" })
|
1084
|
+
]}
|
1085
|
+
end
|
1051
1086
|
end
|
1052
1087
|
end
|
1053
1088
|
|
data/yap-shell-parser.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_dependency "treefell", "~> 0.2.3"
|
23
|
+
spec.add_dependency "term-ansicolor", "~> 1.3.0"
|
23
24
|
|
24
25
|
spec.add_development_dependency "bundler", "~> 1.7"
|
25
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
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.7.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: 2016-
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treefell
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: term-ansicolor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
142
|
version: '0'
|
129
143
|
requirements: []
|
130
144
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
145
|
+
rubygems_version: 2.5.1
|
132
146
|
signing_key:
|
133
147
|
specification_version: 4
|
134
148
|
summary: The parser for the yap shell
|