lsl 0.1.0 → 0.1.1

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -68,8 +68,24 @@ module LSL
68
68
  fattr(:args) do
69
69
  command_args + fixed_input_args
70
70
  end
71
+ def my_eval(ops,str)
72
+ OpenStruct.new(ops).instance_eval(str)
73
+ rescue => exp
74
+ puts "failed #{exp.message}"
75
+ end
71
76
  fattr(:result) do
72
- if obj.respond_to?(command.method)
77
+ if command.eval?
78
+ res = []
79
+ if args.empty?
80
+ res << my_eval(command.raw[1..-2],:args => [], :arg => nil)
81
+ else
82
+ args.each_with_expansion do |a|
83
+ res << my_eval(command.raw[1..-2],:args => a, :arg => a.first)
84
+ end
85
+ end
86
+ #puts res.inspect
87
+ res
88
+ elsif obj.respond_to?(command.method)
73
89
  res = obj.send_with_expansion(command.method,*args)
74
90
  #puts "RES #{res.inspect}" if res
75
91
  res
@@ -84,7 +100,7 @@ module LSL
84
100
  end
85
101
  end
86
102
  class Compound < Base
87
- fattr(:command) { shell.parser.parse(command_str).command_hash }
103
+ fattr(:command) { shell.parser.parse(command_str).andand.command_hash }
88
104
  fattr(:command_executions) do
89
105
  exes = []
90
106
  input_args = lambda { exes.last.andand.result || [] }
@@ -96,16 +112,25 @@ module LSL
96
112
  exes
97
113
  end
98
114
  def run!
115
+ if !command
116
+ puts "can't parse"
117
+ return
118
+ end
99
119
  command_executions
100
120
  if command.output_filename
101
121
  ::File.create(command.output_filename,result.join("\n"))
102
122
  else
103
- puts result.join("\n") if result
123
+ puts result_str if result
104
124
  end
105
125
  end
106
126
  def result
107
127
  command_executions.last.result
108
128
  end
129
+ def result_str
130
+ res = result
131
+ res = res.join("\n") if res.respond_to?(:join)
132
+ res
133
+ end
109
134
  end
110
135
  end
111
136
  end
@@ -3,6 +3,9 @@ module LSL
3
3
  class Single
4
4
  attr_accessor :ex, :args, :options, :raw
5
5
  include FromHash
6
+ def eval?
7
+ raw[0..0] == "{"
8
+ end
6
9
  def to_h
7
10
  {:ex => ex, :args => args, :options => options}
8
11
  end
@@ -1,7 +1,7 @@
1
1
  module LSL
2
2
  grammar Base
3
3
  rule word
4
- [0-9a-zA-Z\.\/\\:\*_]+
4
+ [0-9a-zA-Z\.\/\\:\*_\+]+
5
5
  end
6
6
  rule ws1
7
7
  ' '
@@ -3,14 +3,15 @@ module LSL
3
3
  include LSL::SingleCommand
4
4
  include LSL::File
5
5
  rule full_command
6
- single_command (ows "|" ows single_command)* (ows ">" ows filename)? {
6
+ some_command (ows "|" ows some_command)* (ows ">" ows filename)? {
7
7
  def filename
8
8
  find_child_node(:filename)
9
9
  end
10
10
  def single_commands
11
-
12
- res = [single_command.command_hash]
13
- rest = find_child_nodes(:single_command).map { |x| x.command_hash }
11
+
12
+ res = [some_command.command_hash]
13
+ #res = [elements.first.command_hash]
14
+ rest = find_child_nodes(:some_command).map { |x| x.command_hash }
14
15
  #puts "rest #{rest.size}"
15
16
  res + rest
16
17
  end
@@ -21,5 +22,15 @@ module LSL
21
22
  end
22
23
  }
23
24
  end
25
+ rule eval_str
26
+ "{" (!"}" .)+ "}" {
27
+ def command_hash
28
+ LSL::Command::Single.new(:raw => text_value, :args => [], :options => {})
29
+ end
30
+ }
31
+ end
32
+ rule some_command
33
+ single_command / eval_str
34
+ end
24
35
  end
25
36
  end
@@ -17,9 +17,16 @@ module LSL
17
17
  module Inner
18
18
  def echo(*args)
19
19
  #puts args.inspect
20
- puts args.join(" ")
20
+ ops = (args.last.kind_of?(Hash) ? args.pop : {})
21
+ str = args.join(" ")
22
+ str = str.upcase if ops.has_key?('upper')
23
+ puts str
21
24
  nil
22
25
  end
26
+ def echot(*args)
27
+ echo(*args)
28
+ echo(*args)
29
+ end
23
30
  def ls(d=".")
24
31
  ec_array "ls #{d}"
25
32
  end
@@ -52,6 +59,15 @@ module LSL
52
59
  puts "Exiting"
53
60
  Kernel.exit(*args)
54
61
  end
62
+ def eval(*args)
63
+ Kernel.eval(args.join(" "))
64
+ end
65
+ def rand
66
+ Kernel.rand()
67
+ end
68
+ def pt(a,b)
69
+ puts a==b
70
+ end
55
71
  end
56
72
  include FileUtils
57
73
  include Inner
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lsl}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mharris717"]
@@ -46,5 +46,8 @@ describe "CompoundCommand" do
46
46
  res.should == [[],14]
47
47
  end
48
48
  end
49
+ it 'takes eval str' do
50
+ parse_obj("{2 + 2}")
51
+ end
49
52
 
50
53
  end
@@ -14,7 +14,7 @@ describe "Shell" do
14
14
  end
15
15
  it 'piping' do
16
16
  @shell.run('ls VERSION | pf')
17
- $printed.should == ['0.0.1']
17
+ $printed.should == ['0.1.0']
18
18
  end
19
19
  it 'foo' do
20
20
  #30.times do
@@ -32,7 +32,10 @@ describe "Shell" do
32
32
  run("remote_call foo | echo")
33
33
  end
34
34
  it 'rake' do
35
- run("abc").result.should == "ran"
35
+ #run("abc").result.should == "ran"
36
+ end
37
+ it 'eval' do
38
+ run("{2 + 2}").result.should == 4
36
39
  end
37
40
  describe 'output redirection' do
38
41
  before do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - mharris717