scansion/parser.lua

changeset 43
b37504fa3031
parent 42
67d50889b7fe
child 44
0dab1dc183c1
--- 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