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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/envo/script_parser.rb', line 13
def parse(lines)
result = ParseResult.new
lines.each_with_index do |line, li|
li += 1
line.strip!
next if line.empty?
next if line[0] == '#'
line_opts = if line[0] == '{' i = line.index('}')
raise Envo::Error.new "#{li}: malformed options pack" if !i
opts = line[1...i].split(',')
line = line[i+1..]
opts
else
[]
end
raise Envo::Error.new "#{li}: missing command" if line.empty?
tokens = []
begin
tokens = CSV::parse_line(line, col_sep: ' ').compact
rescue
puts "AAAAAAA: #{line.inspect}"
raise Envo::Error.new "#{li}: malformed line"
end
raise Envo::Error.new "#{li}: missing command" if tokens.empty?
cmd = tokens.shift
raise Envo::Error.new "#{li}: unknown command '#{cmd}'" if !@known_cmds[cmd]
parsed_cmd = @known_cmds[cmd].(cmd, tokens, line_opts)
cmd_opts = {}
parsed_cmd.opts.each do |opt|
cmd_opts.merge! @known_opts.parse_script(opt)
end
parsed_cmd.opts = cmd_opts
result.cmds << parsed_cmd
end
result
end
|