Add annotations to actions (by grabbing the preceding comment)

Tue, 27 Oct 2015 23:07:46 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 27 Oct 2015 23:07:46 +0000
changeset 43
b37504fa3031
parent 42
67d50889b7fe
child 44
0dab1dc183c1

Add annotations to actions (by grabbing the preceding comment)

main.lua file | annotate | diff | comparison | revisions
scansion/generator.lua file | annotate | diff | comparison | revisions
scansion/parser.lua file | annotate | diff | comparison | revisions
--- a/main.lua	Tue Oct 27 20:03:32 2015 +0000
+++ b/main.lua	Tue Oct 27 23:07:46 2015 +0000
@@ -55,6 +55,9 @@
 			local object = script.objects[action.object_name];
 			local handler = object.handler;
 			assert(handler[action.action], "Objects of type '"..object.type.."' do not support action '"..action.action.."'");
+			if action.annotation then
+				print(action.annotation);
+			end
 			print(object.name, action.action.."...");
 			local ok, err = pcall(handler[action.action], object, action.extra);
 			if not ok then
--- a/scansion/generator.lua	Tue Oct 27 20:03:32 2015 +0000
+++ b/scansion/generator.lua	Tue Oct 27 23:07:46 2015 +0000
@@ -2,7 +2,7 @@
 
 local script_methods = {};
 
-local excluded_fields = { name = true, defined_line = true, type = true };
+local excluded_fields = { name = true, defined_line = true, type = true, annotation = true };
 function script_methods:client(data)
 	self:_append("["..data.name.."]");
 	for k, v in pairs(data) do
--- a/scansion/parser.lua	Tue Oct 27 20:03:32 2015 +0000
+++ b/scansion/parser.lua	Tue Oct 27 23:07:46 2015 +0000
@@ -6,6 +6,7 @@
 	
 	local line_number = 0;
 	local last_object;
+	local annotation;
 	
 	for line in data:gmatch("([^\r\n]*)\r?\n") do
 		line_number = line_number + 1;
@@ -30,7 +31,18 @@
 		elseif #parsed.actions > 0 and line:sub(1,1) == "\t" then
 			table.insert(parsed.actions[#parsed.actions].extra, line:sub(2));
 		elseif line:match("^%s*$") or line:match("^#") or line:match("^([/-])%1") then
-			-- Blank line or comment
+			-- Blank line or comment, save as annotation
+			if #line == 0 then
+				if annotation then
+					annotation.closed = true;
+				end
+			else
+				if (not annotation) or annotation.closed then
+					annotation = { line };
+				else
+					table.insert(annotation, line);
+				end
+			end
 		else
 			last_object = nil;
 			local name, action, extra = line:match("^(%a+) (%a+):?%s?(.*)$");
@@ -44,7 +56,9 @@
 				object_name = name;
 				action = action:lower();
 				extra = {#extra>0 and extra or nil};
+				annotation = annotation and table.concat(annotation, "\n") or nil;
 			});
+			annotation = nil;
 		end
 	end
 	return parsed;

mercurial