qcmd 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/qcmd/cli.rb +1 -5
- data/lib/qcmd/commands.rb +2 -1
- data/lib/qcmd/input_completer.rb +2 -1
- data/lib/qcmd/parser.rb +47 -0
- data/lib/qcmd/version.rb +1 -1
- data/spec/parser_spec.rb +28 -0
- metadata +5 -3
data/lib/qcmd/cli.rb
CHANGED
@@ -96,9 +96,6 @@ module Qcmd
|
|
96
96
|
when 'connect'
|
97
97
|
Qcmd.debug "(connect command received args: #{ args.inspect })"
|
98
98
|
|
99
|
-
# remove quoted strings
|
100
|
-
args = args.map {|a| a.gsub(/^"/, '').gsub(/"$/, '')}
|
101
|
-
|
102
99
|
machine_name = args.shift
|
103
100
|
passcode = args.shift
|
104
101
|
|
@@ -114,7 +111,7 @@ module Qcmd
|
|
114
111
|
when 'use'
|
115
112
|
Qcmd.debug "(use command received args: #{ args.inspect })"
|
116
113
|
|
117
|
-
workspace_name = args.shift
|
114
|
+
workspace_name = args.shift
|
118
115
|
passcode = args.shift
|
119
116
|
|
120
117
|
Qcmd.debug "(using workspace: #{ workspace_name.inspect })"
|
@@ -139,7 +136,6 @@ module Qcmd
|
|
139
136
|
# pull off cue number
|
140
137
|
cue_number = args.shift
|
141
138
|
cue_action = args.shift
|
142
|
-
args = args.map {|a| a.gsub(/^"/, '').gsub(/"$/, '')}
|
143
139
|
|
144
140
|
if cue_number.nil?
|
145
141
|
print "no cue command given. cue commands should be in the form:"
|
data/lib/qcmd/commands.rb
CHANGED
@@ -12,7 +12,7 @@ module Qcmd
|
|
12
12
|
uniqueID hasFileTargets hasCueTargets allowsEditingDuration isLoaded
|
13
13
|
isRunning isPaused isBroken preWaitElapsed actionElapsed
|
14
14
|
postWaitElapsed percentPreWaitElapsed percentActionElapsed
|
15
|
-
percentPostWaitElapsed type
|
15
|
+
percentPostWaitElapsed type sliderLevels
|
16
16
|
basics children
|
17
17
|
)
|
18
18
|
|
@@ -20,6 +20,7 @@ module Qcmd
|
|
20
20
|
NO_ARG_CUE_RESPONSE = %w(
|
21
21
|
number name notes cueTargetNumber cueTargetId preWait duration
|
22
22
|
postWait continueMode flagged armed colorName
|
23
|
+
sliderLevel
|
23
24
|
)
|
24
25
|
|
25
26
|
class << self
|
data/lib/qcmd/input_completer.rb
CHANGED
@@ -17,6 +17,7 @@ module Qcmd
|
|
17
17
|
percentPreWaitElapsed percentActionElapsed percentPostWaitElapsed
|
18
18
|
type number name notes cueTargetNumber cueTargetId preWait duration
|
19
19
|
postWait continueMode flagged armed colorName basics children
|
20
|
+
sliderLevel sliderLevels
|
20
21
|
]
|
21
22
|
|
22
23
|
CompletionProc = Proc.new {|input|
|
@@ -25,7 +26,7 @@ module Qcmd
|
|
25
26
|
matcher = /^#{Regexp.escape(input)}/
|
26
27
|
commands = ReservedWords.grep(matcher)
|
27
28
|
|
28
|
-
if Qcmd.connected?
|
29
|
+
if Qcmd.connected?
|
29
30
|
# have selected a machine
|
30
31
|
if Qcmd.context.workspace_connected?
|
31
32
|
# have selected a workspace
|
data/lib/qcmd/parser.rb
CHANGED
@@ -37,10 +37,57 @@ module Qcmd
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
# A helper method to take care of the repetitive stuff for us
|
41
|
+
def is_match?( string, pattern)
|
42
|
+
match = string.match(pattern)
|
43
|
+
return false unless match
|
44
|
+
# Make sure that the matched pattern consumes the entire token
|
45
|
+
match[0].length == string.length
|
46
|
+
end
|
47
|
+
|
48
|
+
# Detect a symbol
|
49
|
+
def is_symbol?( string )
|
50
|
+
# Anything other than parentheses, single or double quote and commas
|
51
|
+
return is_match?( string, /[^\"\'\,\(\)]+/ )
|
52
|
+
end
|
53
|
+
|
54
|
+
# Detect an integer literal
|
55
|
+
def is_integer_literal?( string )
|
56
|
+
# Any number of numerals optionally preceded by a plus or minus sign
|
57
|
+
return is_match?( string, /[\-\+]?[0-9]+/ )
|
58
|
+
end
|
59
|
+
|
60
|
+
def is_float_literal?( string )
|
61
|
+
# Any number of numerals optionally preceded by a plus or minus sign
|
62
|
+
return is_match?( string, /[\-\+]?[0-9]+(\.[0-9]*)?/ )
|
63
|
+
end
|
64
|
+
|
65
|
+
# Detect a string literal
|
66
|
+
def is_string_literal?( string )
|
67
|
+
# Any characters except double quotes
|
68
|
+
# (except if preceded by a backslash), surrounded by quotes
|
69
|
+
return is_match?( string, /"([^"\\]|\\.)*"/)
|
70
|
+
end
|
71
|
+
|
72
|
+
def convert_tokens( token_array )
|
73
|
+
converted_tokens = []
|
74
|
+
token_array.each do |t|
|
75
|
+
converted_tokens << t.to_i and next if( is_integer_literal?(t) )
|
76
|
+
converted_tokens << t.to_f and next if( is_float_literal?(t) )
|
77
|
+
converted_tokens << t.to_s and next if( is_symbol?(t) )
|
78
|
+
converted_tokens << eval(t) and next if( is_string_literal?(t) )
|
79
|
+
# If we haven't recognized the token by now we need to raise
|
80
|
+
# an exception as there are no more rules left to check against!
|
81
|
+
raise Exception, "Unrecognized token: #{t}"
|
82
|
+
end
|
83
|
+
return converted_tokens
|
84
|
+
end
|
85
|
+
|
40
86
|
def parse( string )
|
41
87
|
string, string_literals = extract_string_literals(string)
|
42
88
|
token_array = tokenize_string(string)
|
43
89
|
token_array = restore_string_literals(token_array, string_literals)
|
90
|
+
token_array = convert_tokens(token_array)
|
44
91
|
return token_array
|
45
92
|
end
|
46
93
|
end
|
data/lib/qcmd/version.rb
CHANGED
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'qcmd'
|
2
|
+
|
3
|
+
describe Qcmd::Parser do
|
4
|
+
it "should parse simple commands" do
|
5
|
+
tokens = Qcmd::Parser.parse "go"
|
6
|
+
tokens.should eql(['go'])
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should parse embedded strings" do
|
10
|
+
tokens = Qcmd::Parser.parse 'go "word word"'
|
11
|
+
tokens.should eql(['go', 'word word'])
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should parse integers" do
|
15
|
+
tokens = Qcmd::Parser.parse 'go "word word" 10'
|
16
|
+
tokens.should eql(['go', 'word word', 10])
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should parse floats" do
|
20
|
+
tokens = Qcmd::Parser.parse 'go "word word" 10 -12.3'
|
21
|
+
tokens.should eql(['go', 'word word', 10, -12.3])
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should parse nested quotes" do
|
25
|
+
tokens = Qcmd::Parser.parse 'go "word word" 10 -12.3 "life \"is good\" yeah"'
|
26
|
+
tokens.should eql(['go', 'word word', 10, -12.3, 'life "is good" yeah'])
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qcmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adam Bachman
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- sample/dnssd.rb
|
186
186
|
- spec/cli_spec.rb
|
187
187
|
- spec/commands_spec.rb
|
188
|
+
- spec/parser_spec.rb
|
188
189
|
- spec/qcmd_spec.rb
|
189
190
|
- spec/qlab_spec.rb
|
190
191
|
has_rdoc: true
|
@@ -226,5 +227,6 @@ test_files:
|
|
226
227
|
- features/support/setup.rb
|
227
228
|
- spec/cli_spec.rb
|
228
229
|
- spec/commands_spec.rb
|
230
|
+
- spec/parser_spec.rb
|
229
231
|
- spec/qcmd_spec.rb
|
230
232
|
- spec/qlab_spec.rb
|