scansion/parser.lua

changeset 147
db39e8e9146c
parent 79
63d573be3f91
child 160
28aa762f11c7
equal deleted inserted replaced
146:885fa9f5929d 147:db39e8e9146c
1 local function parse(data) 1 local function parse(data)
2 local parsed = { 2 local parsed = {
3 objects = {}; 3 objects = {};
4 actions = {}; 4 actions = {};
5 tags = {};
5 }; 6 };
6 7
7 local line_number = 0; 8 local line_number = 0;
8 local last_object; 9 local last_object;
9 local annotation; 10 local annotation;
35 local in_header = (next(parsed.objects) == nil) and (next(parsed.actions) == nil); 36 local in_header = (next(parsed.objects) == nil) and (next(parsed.actions) == nil);
36 if in_header and #line > 0 then 37 if in_header and #line > 0 then
37 if not parsed.title and not line:match("^#!") then 38 if not parsed.title and not line:match("^#!") then
38 parsed.title = line:gsub("^[#-]+%s*", ""); 39 parsed.title = line:gsub("^[#-]+%s*", "");
39 elseif line:match("^##") then 40 elseif line:match("^##") then
40 if not parsed.tags then
41 parsed.tags = {};
42 end
43 local tag = line:gsub("^##%s*", ""); 41 local tag = line:gsub("^##%s*", "");
44 local k, v = tag:match("^([^:]+):%s*(.+)$"); 42 local k, v = tag:match("^([^:]+):%s*(.+)$");
45 if k then 43 if k then
46 -- Tag format: ## tagkey:tagvalue 44 -- Tag format: ## tagkey:tagvalue
47 parsed.tags[k] = v; 45 parsed.tags[k] = v;

mercurial