scansion/parser.lua

changeset 160
28aa762f11c7
parent 147
db39e8e9146c
child 162
f888f236321f
equal deleted inserted replaced
159:0aa4f7bda3f8 160:28aa762f11c7
29 end 29 end
30 local k, v = line:match("^%s+([%a_]+):%s*(.+)$") 30 local k, v = line:match("^%s+([%a_]+):%s*(.+)$")
31 last_object[k] = v; 31 last_object[k] = v;
32 elseif #parsed.actions > 0 and line:sub(1,1) == "\t" then 32 elseif #parsed.actions > 0 and line:sub(1,1) == "\t" then
33 table.insert(parsed.actions[#parsed.actions].extra, line:sub(2)); 33 table.insert(parsed.actions[#parsed.actions].extra, line:sub(2));
34 parsed.actions[#parsed.actions].line_end = line_number;
34 elseif line:match("^%s*$") or line:match("^#") or line:match("^([/-])%1") then 35 elseif line:match("^%s*$") or line:match("^#") or line:match("^([/-])%1") then
35 -- Blank line or comment 36 -- Blank line or comment
36 local in_header = (next(parsed.objects) == nil) and (next(parsed.actions) == nil); 37 local in_header = (next(parsed.objects) == nil) and (next(parsed.actions) == nil);
37 if in_header and #line > 0 then 38 if in_header and #line > 0 then
38 if not parsed.title and not line:match("^#!") then 39 if not parsed.title and not line:match("^#!") then
76 table.insert(parsed.actions, { 77 table.insert(parsed.actions, {
77 object_name = name; 78 object_name = name;
78 action = action:lower(); 79 action = action:lower();
79 extra = {#extra>0 and extra or nil}; 80 extra = {#extra>0 and extra or nil};
80 annotation = annotation and table.concat(annotation, "\n") or nil; 81 annotation = annotation and table.concat(annotation, "\n") or nil;
82 line_start = line_number;
83 line_end = line_number;
81 }); 84 });
82 annotation = nil; 85 annotation = nil;
83 end 86 end
84 end 87 end
85 return parsed; 88 return parsed;

mercurial