4 actions = {}; |
4 actions = {}; |
5 }; |
5 }; |
6 |
6 |
7 local line_number = 0; |
7 local line_number = 0; |
8 local last_object; |
8 local last_object; |
|
9 local annotation; |
9 |
10 |
10 for line in data:gmatch("([^\r\n]*)\r?\n") do |
11 for line in data:gmatch("([^\r\n]*)\r?\n") do |
11 line_number = line_number + 1; |
12 line_number = line_number + 1; |
12 if line:sub(1,1) == "[" then |
13 if line:sub(1,1) == "[" then |
13 local obj_type, name, extra = line:match("^%[(%a+)%] (.+)$"); |
14 local obj_type, name, extra = line:match("^%[(%a+)%] (.+)$"); |
28 local k, v = line:match("^%s+(%a+):%s*(.+)$") |
29 local k, v = line:match("^%s+(%a+):%s*(.+)$") |
29 last_object[k] = v; |
30 last_object[k] = v; |
30 elseif #parsed.actions > 0 and line:sub(1,1) == "\t" then |
31 elseif #parsed.actions > 0 and line:sub(1,1) == "\t" then |
31 table.insert(parsed.actions[#parsed.actions].extra, line:sub(2)); |
32 table.insert(parsed.actions[#parsed.actions].extra, line:sub(2)); |
32 elseif line:match("^%s*$") or line:match("^#") or line:match("^([/-])%1") then |
33 elseif line:match("^%s*$") or line:match("^#") or line:match("^([/-])%1") then |
33 -- Blank line or comment |
34 -- Blank line or comment, save as annotation |
|
35 if #line == 0 then |
|
36 if annotation then |
|
37 annotation.closed = true; |
|
38 end |
|
39 else |
|
40 if (not annotation) or annotation.closed then |
|
41 annotation = { line }; |
|
42 else |
|
43 table.insert(annotation, line); |
|
44 end |
|
45 end |
34 else |
46 else |
35 last_object = nil; |
47 last_object = nil; |
36 local name, action, extra = line:match("^(%a+) (%a+):?%s?(.*)$"); |
48 local name, action, extra = line:match("^(%a+) (%a+):?%s?(.*)$"); |
37 if not name then |
49 if not name then |
38 return nil, "Unable to parse action on line "..line_number; |
50 return nil, "Unable to parse action on line "..line_number; |