main, scansion.parser: Allow scripts to include tags in comments at the beginning, which are included in JSON output

Sat, 06 Feb 2016 14:38:25 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 06 Feb 2016 14:38:25 +0000
changeset 78
54bb54fe9ed2
parent 77
38066f635004
child 79
63d573be3f91

main, scansion.parser: Allow scripts to include tags in comments at the beginning, which are included in JSON output

main.lua file | annotate | diff | comparison | revisions
scansion/parser.lua file | annotate | diff | comparison | revisions
--- a/main.lua	Sat Feb 06 14:38:17 2016 +0000
+++ b/main.lua	Sat Feb 06 14:38:25 2016 +0000
@@ -123,7 +123,7 @@
 
 	local script = initialize_script(parse_script(read_script()));
 
-	log_data("script", { title = script.title, summary = script.summary });
+	log_data("script", { title = script.title, summary = script.summary, tags = script.tags });
 
 	if server_log_reader then
 		if skip_server_startup_log then
--- a/scansion/parser.lua	Sat Feb 06 14:38:17 2016 +0000
+++ b/scansion/parser.lua	Sat Feb 06 14:38:25 2016 +0000
@@ -36,6 +36,19 @@
 			if in_header and #line > 0 then
 				if not parsed.title and not line:match("^#!") then
 					parsed.title = line:gsub("^[#-]+%s*", "");
+				elseif line:match("^##") then
+					if not parsed.tags then
+						parsed.tags = {};
+					end
+					local tag = line:gsub("^##%s*", "");
+					local k, v = tag:match("^([^:]+):%s*(.+)$");
+					if k then
+						-- Tag format: ## tagkey:tagvalue
+						parsed.tags[k] = v;
+					else
+						-- Tag format: ## tagfoobar
+						parsed.tags[tag] = true;
+					end
 				else
 					parsed.summary = (parsed.summary and parsed.summary.."\n" or "")..line:gsub("^[#-]+%s*", "");
 				end

mercurial