7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/ath/scanner.rb', line 7
def scan(line)
ss = StringScanner.new(line)
if self.empty? and (tok = ss.scan %r{/\w+(?:\s+.*)?\z})
cmd, arg = tok.strip.split(/\s+/, 2)
cmd.slice!(0)
arg.strip! if arg
yield(Ath::Command.new(shell: @shell, command: cmd, arg: arg))
end
until ss.eos?
@buf << ' '
if (tok = ss.scan %r{[^'"`;&]+})
@buf << tok
elsif (tok = ss.scan /`(?:``|[^`])*`/)
@buf << tok
elsif (tok = ss.scan /'(?:''|[^'])*'/)
@buf << tok
elsif (tok = ss.scan /"(?:""|[^"])*"/)
@buf << tok
elsif (tok = ss.scan /(?:[;&])/)
query = @buf.strip
@buf.clear
raise Ath::Error, 'No query specified' if query.empty?
yield(Ath::Query.new(shell: @shell, query: query, detach: (tok == '&')))
else
@buf.clear
raise Ath::Error, 'You have an error in your HiveQL syntax'
end
end
@buf.strip!
end
|