lsl 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -5
- data/.rspec +1 -1
- data/Gemfile +17 -13
- data/Gemfile.lock +13 -0
- data/LICENSE.txt +20 -20
- data/README.rdoc +19 -19
- data/Rakefile +50 -50
- data/VERSION +1 -1
- data/bin/lsl +4 -0
- data/lib/lsl.rb +60 -0
- data/lib/lsl/grammars/base.treetop +16 -0
- data/lib/lsl/grammars/compound_command.treetop +9 -0
- data/lib/lsl/grammars/file.treetop +7 -0
- data/lib/lsl/grammars/list.treetop +8 -0
- data/lib/lsl/grammars/quoting.treetop +14 -0
- data/lib/lsl/grammars/single_command.treetop +54 -0
- data/lib/lsl/sandbox.rb +43 -0
- data/lib/lsl/server.rb +6 -0
- data/lsl.gemspec +91 -0
- data/spec/compound_command_spec.rb +15 -0
- data/spec/lsl_spec.rb +11 -7
- data/spec/quoting_spec.rb +25 -0
- data/spec/single_command_spec.rb +81 -0
- data/spec/spec_helper.rb +76 -12
- metadata +67 -28
data/.document
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
lib/**/*.rb
|
2
|
-
bin/*
|
3
|
-
-
|
4
|
-
features/**/*.feature
|
5
|
-
LICENSE.txt
|
1
|
+
lib/**/*.rb
|
2
|
+
bin/*
|
3
|
+
-
|
4
|
+
features/**/*.feature
|
5
|
+
LICENSE.txt
|
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--color
|
1
|
+
--color
|
data/Gemfile
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
|
-
|
6
|
-
# Add dependencies to develop your gem here.
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
|
-
group :development do
|
9
|
-
gem "rspec", "~> 2.1.0"
|
10
|
-
gem "bundler", "~> 1.0.0"
|
11
|
-
gem "jeweler", "~> 1.5.1"
|
12
|
-
gem "rcov", ">= 0"
|
13
|
-
end
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.1.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.1"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
14
|
+
|
15
|
+
gem 'andand'
|
16
|
+
gem "treetop"
|
17
|
+
gem 'mharris_ext'
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
andand (1.3.1)
|
4
5
|
diff-lcs (1.1.2)
|
6
|
+
facets (2.8.4)
|
7
|
+
fattr (2.1.0)
|
5
8
|
git (1.2.5)
|
6
9
|
jeweler (1.5.1)
|
7
10
|
bundler (~> 1.0.0)
|
8
11
|
git (>= 1.2.5)
|
9
12
|
rake
|
13
|
+
mharris_ext (1.5.0)
|
14
|
+
facets
|
15
|
+
fattr
|
16
|
+
polyglot (0.3.1)
|
10
17
|
rake (0.8.7)
|
11
18
|
rcov (0.9.9)
|
12
19
|
rspec (2.1.0)
|
@@ -17,12 +24,18 @@ GEM
|
|
17
24
|
rspec-expectations (2.1.0)
|
18
25
|
diff-lcs (~> 1.1.2)
|
19
26
|
rspec-mocks (2.1.0)
|
27
|
+
treetop (1.4.8)
|
28
|
+
polyglot (>= 0.3.1)
|
20
29
|
|
21
30
|
PLATFORMS
|
31
|
+
ruby
|
22
32
|
x86-mingw32
|
23
33
|
|
24
34
|
DEPENDENCIES
|
35
|
+
andand
|
25
36
|
bundler (~> 1.0.0)
|
26
37
|
jeweler (~> 1.5.1)
|
38
|
+
mharris_ext
|
27
39
|
rcov
|
28
40
|
rspec (~> 2.1.0)
|
41
|
+
treetop
|
data/LICENSE.txt
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright (c) 2010 mharris717
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2010 mharris717
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
= lsl
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Contributing to lsl
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
-
* Fork the project
|
10
|
-
* Start a feature/bugfix branch
|
11
|
-
* Commit and push until you are happy with your contribution
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2010 mharris717. See LICENSE.txt for
|
18
|
-
further details.
|
19
|
-
|
1
|
+
= lsl
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to lsl
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 mharris717. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
CHANGED
@@ -1,50 +1,50 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'rake'
|
11
|
-
|
12
|
-
require 'jeweler'
|
13
|
-
Jeweler::Tasks.new do |gem|
|
14
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
-
gem.name = "lsl"
|
16
|
-
gem.homepage = "http://github.com/mharris717/lsl"
|
17
|
-
gem.license = "MIT"
|
18
|
-
gem.summary = %Q{little shell language}
|
19
|
-
gem.description = %Q{little shell language}
|
20
|
-
gem.email = "mharris717@gmail.com"
|
21
|
-
gem.authors = ["mharris717"]
|
22
|
-
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
-
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
-
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
-
end
|
27
|
-
Jeweler::RubygemsDotOrgTasks.new
|
28
|
-
|
29
|
-
require 'rspec/core'
|
30
|
-
require 'rspec/core/rake_task'
|
31
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
-
end
|
34
|
-
|
35
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
-
spec.rcov = true
|
38
|
-
end
|
39
|
-
|
40
|
-
task :default => :spec
|
41
|
-
|
42
|
-
require 'rake/rdoctask'
|
43
|
-
Rake::RDocTask.new do |rdoc|
|
44
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
-
|
46
|
-
rdoc.rdoc_dir = 'rdoc'
|
47
|
-
rdoc.title = "lsl #{version}"
|
48
|
-
rdoc.rdoc_files.include('README*')
|
49
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "lsl"
|
16
|
+
gem.homepage = "http://github.com/mharris717/lsl"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{little shell language}
|
19
|
+
gem.description = %Q{little shell language}
|
20
|
+
gem.email = "mharris717@gmail.com"
|
21
|
+
gem.authors = ["mharris717"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "lsl #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/bin/lsl
ADDED
data/lib/lsl.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'andand'
|
2
|
+
require 'treetop'
|
3
|
+
require 'mharris_ext'
|
4
|
+
|
5
|
+
%w(base quoting list file single_command compound_command).each do |g|
|
6
|
+
require File.dirname(__FILE__) + "/lsl/grammars/#{g}"
|
7
|
+
end
|
8
|
+
|
9
|
+
class Object
|
10
|
+
def blank?
|
11
|
+
to_s.strip == ''
|
12
|
+
end
|
13
|
+
def present?
|
14
|
+
!blank?
|
15
|
+
end
|
16
|
+
def unquoted
|
17
|
+
((self[0..0]+self[-1..-1]) == '""') ? self[1..-2] : self
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Object
|
22
|
+
def list_values
|
23
|
+
elements.map { |x| x.text_value.strip }.select { |x| x.present? }.map { |x| x.unquoted }
|
24
|
+
end
|
25
|
+
def find_child_node(node)
|
26
|
+
|
27
|
+
elements.each do |e|
|
28
|
+
return e.send(node) if e.respond_to?(node)
|
29
|
+
end
|
30
|
+
#return send(node) if respond_to?(node)
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
def find_child_node2(node)
|
34
|
+
|
35
|
+
elements.each do |e|
|
36
|
+
return e.send(node) if e.respond_to?(node)
|
37
|
+
end
|
38
|
+
#return send(node) if respond_to?(node)
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
class SingleCommandObj
|
45
|
+
attr_accessor :ex, :args, :options
|
46
|
+
include FromHash
|
47
|
+
def to_h
|
48
|
+
{:ex => ex, :args => args, :options => options}
|
49
|
+
end
|
50
|
+
def url
|
51
|
+
"http://localhost:4567/#{ex}" + args.map { |x| "/#{x}" }.join
|
52
|
+
end
|
53
|
+
def method
|
54
|
+
ex.split(".").last
|
55
|
+
end
|
56
|
+
def obj
|
57
|
+
a = ex.split(".")
|
58
|
+
(a.size > 1) ? eval(a.first) : nil
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module LSL
|
2
|
+
grammar SingleCommand
|
3
|
+
include LSL::Quoting
|
4
|
+
include LSL::List
|
5
|
+
rule single_command
|
6
|
+
ex (ws args)? (ws options)? {
|
7
|
+
def args
|
8
|
+
find_child_node(:args)
|
9
|
+
end
|
10
|
+
def options
|
11
|
+
find_child_node(:options)
|
12
|
+
end
|
13
|
+
def command_hash
|
14
|
+
SingleCommandObj.new(:ex => ex.text_value, :args => args.andand.list_values || [], :options => options.andand.hash_values || {})
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
rule ex
|
20
|
+
word
|
21
|
+
end
|
22
|
+
|
23
|
+
rule arg
|
24
|
+
comma_list
|
25
|
+
end
|
26
|
+
rule args
|
27
|
+
arg (ws arg)*
|
28
|
+
end
|
29
|
+
|
30
|
+
rule option_flag
|
31
|
+
'-' word
|
32
|
+
end
|
33
|
+
rule option
|
34
|
+
option_flag (ws optionally_quoted_string)? {
|
35
|
+
def kv
|
36
|
+
n = find_child_node2(:optionally_quoted_string)
|
37
|
+
{option_flag.word.text_value => n.andand.text_value}
|
38
|
+
end
|
39
|
+
}
|
40
|
+
end
|
41
|
+
rule options
|
42
|
+
option (ws option)* {
|
43
|
+
def hash_values
|
44
|
+
res = option.kv
|
45
|
+
elements[1..-1].each do |e|
|
46
|
+
n = e.find_child_node2(:option)
|
47
|
+
res = res.merge(n.kv) if n
|
48
|
+
end
|
49
|
+
res
|
50
|
+
end
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/lsl/sandbox.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../lsl"
|
2
|
+
require 'open-uri'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
class CommandEnv
|
6
|
+
def echo(str)
|
7
|
+
puts "ECHOING #{str}"
|
8
|
+
end
|
9
|
+
def cp(a,b)
|
10
|
+
puts "gonna copy #{a} to #{b}"
|
11
|
+
end
|
12
|
+
def del(a)
|
13
|
+
puts "deleting #{a}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Foo
|
18
|
+
def self.bar(*args)
|
19
|
+
puts "bar #{args.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Shell
|
24
|
+
fattr(:env) { CommandEnv.new }
|
25
|
+
fattr(:parser) { LSL::SingleCommandParser.new }
|
26
|
+
def run(str)
|
27
|
+
command = parser.parse(str).command_hash
|
28
|
+
obj = command.obj || env
|
29
|
+
obj.send(command.method,*command.args)
|
30
|
+
#open(command.url)
|
31
|
+
rescue => exp
|
32
|
+
puts "command failed #{exp.message}"
|
33
|
+
end
|
34
|
+
def run_loop
|
35
|
+
loop do
|
36
|
+
str = STDIN.gets.strip
|
37
|
+
run(str)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
s = Shell.new
|
43
|
+
s.run_loop
|
data/lib/lsl/server.rb
ADDED
data/lsl.gemspec
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{lsl}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["mharris717"]
|
12
|
+
s.date = %q{2010-12-27}
|
13
|
+
s.default_executable = %q{lsl}
|
14
|
+
s.description = %q{little shell language}
|
15
|
+
s.email = %q{mharris717@gmail.com}
|
16
|
+
s.executables = ["lsl"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"bin/lsl",
|
31
|
+
"lib/lsl.rb",
|
32
|
+
"lib/lsl/grammars/base.treetop",
|
33
|
+
"lib/lsl/grammars/compound_command.treetop",
|
34
|
+
"lib/lsl/grammars/file.treetop",
|
35
|
+
"lib/lsl/grammars/list.treetop",
|
36
|
+
"lib/lsl/grammars/quoting.treetop",
|
37
|
+
"lib/lsl/grammars/single_command.treetop",
|
38
|
+
"lib/lsl/sandbox.rb",
|
39
|
+
"lib/lsl/server.rb",
|
40
|
+
"lsl.gemspec",
|
41
|
+
"spec/compound_command_spec.rb",
|
42
|
+
"spec/lsl_spec.rb",
|
43
|
+
"spec/quoting_spec.rb",
|
44
|
+
"spec/single_command_spec.rb",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
s.homepage = %q{http://github.com/mharris717/lsl}
|
48
|
+
s.licenses = ["MIT"]
|
49
|
+
s.require_paths = ["lib"]
|
50
|
+
s.rubygems_version = %q{1.3.6}
|
51
|
+
s.summary = %q{little shell language}
|
52
|
+
s.test_files = [
|
53
|
+
"spec/compound_command_spec.rb",
|
54
|
+
"spec/lsl_spec.rb",
|
55
|
+
"spec/quoting_spec.rb",
|
56
|
+
"spec/single_command_spec.rb",
|
57
|
+
"spec/spec_helper.rb"
|
58
|
+
]
|
59
|
+
|
60
|
+
if s.respond_to? :specification_version then
|
61
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
62
|
+
s.specification_version = 3
|
63
|
+
|
64
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
65
|
+
s.add_runtime_dependency(%q<andand>, [">= 0"])
|
66
|
+
s.add_runtime_dependency(%q<treetop>, [">= 0"])
|
67
|
+
s.add_runtime_dependency(%q<mharris_ext>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
|
69
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
71
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<andand>, [">= 0"])
|
74
|
+
s.add_dependency(%q<treetop>, [">= 0"])
|
75
|
+
s.add_dependency(%q<mharris_ext>, [">= 0"])
|
76
|
+
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
77
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
78
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
79
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
80
|
+
end
|
81
|
+
else
|
82
|
+
s.add_dependency(%q<andand>, [">= 0"])
|
83
|
+
s.add_dependency(%q<treetop>, [">= 0"])
|
84
|
+
s.add_dependency(%q<mharris_ext>, [">= 0"])
|
85
|
+
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
86
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
87
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
88
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "CompoundCommand" do
|
4
|
+
before do
|
5
|
+
@parser = LSL::CompoundCommandParser.new
|
6
|
+
end
|
7
|
+
def parser; @parser; end
|
8
|
+
it 'single_command' do
|
9
|
+
parser.should be_parsed("cp a b -v a")
|
10
|
+
end
|
11
|
+
it 'command with output redirection' do
|
12
|
+
parser.should be_parsed("cp a b > foo.txt")
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/spec/lsl_spec.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "Lsl" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Lsl" do
|
4
|
+
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
a = <<EOF
|
9
|
+
output redirection
|
10
|
+
quoting
|
11
|
+
EOF
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Quoting" do
|
4
|
+
before do
|
5
|
+
@parser = LSL::QuotingParser.new
|
6
|
+
end
|
7
|
+
def parser; @parser; end
|
8
|
+
it "smoke" do
|
9
|
+
2.should == 2
|
10
|
+
end
|
11
|
+
it 'quoted word' do
|
12
|
+
parser.should be_parsed('"abc"')
|
13
|
+
end
|
14
|
+
it 'unquoted word' do
|
15
|
+
parser.should be_parsed('abc')
|
16
|
+
end
|
17
|
+
it 'quoted phrase' do
|
18
|
+
parser.should be_parsed('"abc xyz"')
|
19
|
+
end
|
20
|
+
it "unquoted phrase" do
|
21
|
+
parser.should_not be_parsed("abc xyz")
|
22
|
+
end
|
23
|
+
#it "escaped quotes"
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Command" do
|
4
|
+
before do
|
5
|
+
@parser = LSL::SingleCommandParser.new
|
6
|
+
end
|
7
|
+
def parser; @parser; end
|
8
|
+
def parse(str); parser.parse(str); end
|
9
|
+
describe "boolean parse checks" do
|
10
|
+
it 'naked ex' do
|
11
|
+
parser.should be_parsed("cp")
|
12
|
+
end
|
13
|
+
it "ex with arg" do
|
14
|
+
parser.should be_parsed("cp abc")
|
15
|
+
end
|
16
|
+
it "ex with args" do
|
17
|
+
parser.should be_parsed("cp abc xyz")
|
18
|
+
end
|
19
|
+
it "ex with option" do
|
20
|
+
parser.should be_parsed("cp -v")
|
21
|
+
end
|
22
|
+
it "ex with arg and option" do
|
23
|
+
parser.should be_parsed("cp abc -vv")
|
24
|
+
end
|
25
|
+
it "ex with quoted arg" do
|
26
|
+
parser.should be_parsed('cp "a b"')
|
27
|
+
end
|
28
|
+
it "ex with list arg" do
|
29
|
+
parser.should be_parsed('cp a,b c')
|
30
|
+
end
|
31
|
+
describe "options" do
|
32
|
+
it "option with value" do
|
33
|
+
parser.should be_parsed("cp -name abc")
|
34
|
+
end
|
35
|
+
it "option with quoted word" do
|
36
|
+
parser.should be_parsed('cp -name "abc"')
|
37
|
+
end
|
38
|
+
it "option with quoted phrase" do
|
39
|
+
parser.should be_parsed('cp -name "abc xyz"')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
it "should have ex" do
|
44
|
+
parse("cp a b").ex.text_value.should == "cp"
|
45
|
+
parser.should parse_as("cp a b",:ex,:cp)
|
46
|
+
end
|
47
|
+
it "should have args" do
|
48
|
+
parser.should parse_as("cp a b",:args,"a b")
|
49
|
+
parse("cp a b").args.list_values.should == ['a','b']
|
50
|
+
end
|
51
|
+
describe "command hash" do
|
52
|
+
it "naked ex" do
|
53
|
+
parse("cp").command_hash.to_h.should == {:ex => "cp", :args => [], :options => {}}
|
54
|
+
end
|
55
|
+
it "ex and args" do
|
56
|
+
parse("cp a b").command_hash.to_h.should == {:ex => "cp", :args => ['a','b'], :options => {}}
|
57
|
+
end
|
58
|
+
it 'quoted arg' do
|
59
|
+
parse('cp "abc"').command_hash.args.should == ['abc']
|
60
|
+
end
|
61
|
+
it "ex and options" do
|
62
|
+
parse("cp -v").command_hash.to_h.should == {:ex => "cp", :args => [], :options => {"v" => nil}}
|
63
|
+
end
|
64
|
+
it "ex and multiple options" do
|
65
|
+
parse("cp -v -x").command_hash.to_h.should == {:ex => "cp", :args => [], :options => {"v" => nil, "x" => nil}}
|
66
|
+
end
|
67
|
+
it "ex and option value" do
|
68
|
+
parse("cp -v a").command_hash.to_h.should == {:ex => "cp", :args => [], :options => {"v" => 'a'}}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
a = <<EOF
|
75
|
+
output redirection
|
76
|
+
quoting
|
77
|
+
|
78
|
+
going to ignore list arguments for now
|
79
|
+
how to i break out into raw code
|
80
|
+
ability to bring code directly into the shell
|
81
|
+
EOF
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,76 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
require 'rspec'
|
4
|
-
require 'lsl'
|
5
|
-
|
6
|
-
# Requires supporting files with custom matchers and macros, etc,
|
7
|
-
# in ./support/ and its subdirectories.
|
8
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
-
|
10
|
-
RSpec.configure do |config|
|
11
|
-
|
12
|
-
end
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'lsl'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
# class Object
|
15
|
+
# def should_parse(str)
|
16
|
+
# res = parse(str)
|
17
|
+
# raise "can't parse" unless res
|
18
|
+
# end
|
19
|
+
# def should_not_parse(str)
|
20
|
+
# res = parse(str)
|
21
|
+
# raise "can parse" if res
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
|
25
|
+
class Object
|
26
|
+
def local_methods
|
27
|
+
res = methods - 7.methods - "".methods
|
28
|
+
res.sort_by { |x| x.to_s }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec::Matchers.define :be_parsed do |str|
|
33
|
+
match do |parser|
|
34
|
+
!!parser.parse(str)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Object
|
39
|
+
def rt?(meth)
|
40
|
+
send(meth)
|
41
|
+
true
|
42
|
+
rescue => exp
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
RSpec::Matchers.define :parse_as do |str,node,exp|
|
48
|
+
|
49
|
+
def res_error_message(str,node,exp)
|
50
|
+
if !@res
|
51
|
+
"no parse result"
|
52
|
+
elsif !@res.rt?(node)
|
53
|
+
#puts @res.elements.first.class
|
54
|
+
#raise @res.elements.first.local_methods.inspect
|
55
|
+
#raise @res.instance_variables.inspect
|
56
|
+
"no syntax node #{node}, nodes are " + @res.elements.map { |x| x.inspect }.join(",")
|
57
|
+
else
|
58
|
+
act = @res.send(node).text_value
|
59
|
+
if act != exp.to_s
|
60
|
+
"#{act} doesn't equal #{exp}"
|
61
|
+
else
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
match do |parser|
|
67
|
+
@res = res = parser.parse(str)
|
68
|
+
!res_error_message(str,node,exp)
|
69
|
+
end
|
70
|
+
description do
|
71
|
+
"FOO"
|
72
|
+
end
|
73
|
+
failure_message_for_should do |player|
|
74
|
+
res_error_message(str,node,exp)
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 31
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- mharris717
|
@@ -15,17 +14,51 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-12-
|
19
|
-
default_executable:
|
17
|
+
date: 2010-12-27 00:00:00 -05:00
|
18
|
+
default_executable: lsl
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
21
|
+
name: andand
|
23
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
segments:
|
27
|
+
- 0
|
28
|
+
version: "0"
|
29
|
+
type: :runtime
|
30
|
+
prerelease: false
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: treetop
|
34
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
segments:
|
39
|
+
- 0
|
40
|
+
version: "0"
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: mharris_ext
|
46
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
version: "0"
|
53
|
+
type: :runtime
|
54
|
+
prerelease: false
|
55
|
+
version_requirements: *id003
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
25
59
|
requirements:
|
26
60
|
- - ~>
|
27
61
|
- !ruby/object:Gem::Version
|
28
|
-
hash: 11
|
29
62
|
segments:
|
30
63
|
- 2
|
31
64
|
- 1
|
@@ -33,15 +66,13 @@ dependencies:
|
|
33
66
|
version: 2.1.0
|
34
67
|
type: :development
|
35
68
|
prerelease: false
|
36
|
-
version_requirements: *
|
69
|
+
version_requirements: *id004
|
37
70
|
- !ruby/object:Gem::Dependency
|
38
71
|
name: bundler
|
39
|
-
requirement: &
|
40
|
-
none: false
|
72
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
41
73
|
requirements:
|
42
74
|
- - ~>
|
43
75
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 23
|
45
76
|
segments:
|
46
77
|
- 1
|
47
78
|
- 0
|
@@ -49,15 +80,13 @@ dependencies:
|
|
49
80
|
version: 1.0.0
|
50
81
|
type: :development
|
51
82
|
prerelease: false
|
52
|
-
version_requirements: *
|
83
|
+
version_requirements: *id005
|
53
84
|
- !ruby/object:Gem::Dependency
|
54
85
|
name: jeweler
|
55
|
-
requirement: &
|
56
|
-
none: false
|
86
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
57
87
|
requirements:
|
58
88
|
- - ~>
|
59
89
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 1
|
61
90
|
segments:
|
62
91
|
- 1
|
63
92
|
- 5
|
@@ -65,25 +94,23 @@ dependencies:
|
|
65
94
|
version: 1.5.1
|
66
95
|
type: :development
|
67
96
|
prerelease: false
|
68
|
-
version_requirements: *
|
97
|
+
version_requirements: *id006
|
69
98
|
- !ruby/object:Gem::Dependency
|
70
99
|
name: rcov
|
71
|
-
requirement: &
|
72
|
-
none: false
|
100
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
73
101
|
requirements:
|
74
102
|
- - ">="
|
75
103
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 3
|
77
104
|
segments:
|
78
105
|
- 0
|
79
106
|
version: "0"
|
80
107
|
type: :development
|
81
108
|
prerelease: false
|
82
|
-
version_requirements: *
|
109
|
+
version_requirements: *id007
|
83
110
|
description: little shell language
|
84
111
|
email: mharris717@gmail.com
|
85
|
-
executables:
|
86
|
-
|
112
|
+
executables:
|
113
|
+
- lsl
|
87
114
|
extensions: []
|
88
115
|
|
89
116
|
extra_rdoc_files:
|
@@ -98,8 +125,21 @@ files:
|
|
98
125
|
- README.rdoc
|
99
126
|
- Rakefile
|
100
127
|
- VERSION
|
128
|
+
- bin/lsl
|
101
129
|
- lib/lsl.rb
|
130
|
+
- lib/lsl/grammars/base.treetop
|
131
|
+
- lib/lsl/grammars/compound_command.treetop
|
132
|
+
- lib/lsl/grammars/file.treetop
|
133
|
+
- lib/lsl/grammars/list.treetop
|
134
|
+
- lib/lsl/grammars/quoting.treetop
|
135
|
+
- lib/lsl/grammars/single_command.treetop
|
136
|
+
- lib/lsl/sandbox.rb
|
137
|
+
- lib/lsl/server.rb
|
138
|
+
- lsl.gemspec
|
139
|
+
- spec/compound_command_spec.rb
|
102
140
|
- spec/lsl_spec.rb
|
141
|
+
- spec/quoting_spec.rb
|
142
|
+
- spec/single_command_spec.rb
|
103
143
|
- spec/spec_helper.rb
|
104
144
|
has_rdoc: true
|
105
145
|
homepage: http://github.com/mharris717/lsl
|
@@ -111,30 +151,29 @@ rdoc_options: []
|
|
111
151
|
require_paths:
|
112
152
|
- lib
|
113
153
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
154
|
requirements:
|
116
155
|
- - ">="
|
117
156
|
- !ruby/object:Gem::Version
|
118
|
-
hash: 3
|
119
157
|
segments:
|
120
158
|
- 0
|
121
159
|
version: "0"
|
122
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
161
|
requirements:
|
125
162
|
- - ">="
|
126
163
|
- !ruby/object:Gem::Version
|
127
|
-
hash: 3
|
128
164
|
segments:
|
129
165
|
- 0
|
130
166
|
version: "0"
|
131
167
|
requirements: []
|
132
168
|
|
133
169
|
rubyforge_project:
|
134
|
-
rubygems_version: 1.3.
|
170
|
+
rubygems_version: 1.3.6
|
135
171
|
signing_key:
|
136
172
|
specification_version: 3
|
137
173
|
summary: little shell language
|
138
174
|
test_files:
|
175
|
+
- spec/compound_command_spec.rb
|
139
176
|
- spec/lsl_spec.rb
|
177
|
+
- spec/quoting_spec.rb
|
178
|
+
- spec/single_command_spec.rb
|
140
179
|
- spec/spec_helper.rb
|