scansion.parser: Read any comments at top of the file as script title (first line) and summary (following lines)

Fri, 01 Jan 2016 20:43:08 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 01 Jan 2016 20:43:08 +0000
changeset 70
2b62a714b5df
parent 69
1de0ebd8832f
child 71
f7dbb46b5770

scansion.parser: Read any comments at top of the file as script title (first line) and summary (following lines)

scansion/parser.lua file | annotate | diff | comparison | revisions
--- a/scansion/parser.lua	Fri Jan 01 20:42:03 2016 +0000
+++ b/scansion/parser.lua	Fri Jan 01 20:43:08 2016 +0000
@@ -31,16 +31,26 @@
 		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, save as annotation
-			if #line == 0 then
-				if annotation then
-					annotation.closed = true;
+			-- Blank line or comment
+			local in_header = (next(parsed.objects) == nil) and (next(parsed.actions) == nil);
+			if in_header and #line > 0 then
+				if line_number == 1 then
+					parsed.title = line:gsub("^[#-]+%s*", "");
+				else
+					parsed.summary = (parsed.summary and parsed.summary.."\n" or "")..line:gsub("^[#-]+%s*", "");
 				end
 			else
-				if (not annotation) or annotation.closed then
-					annotation = { line };
-				else
-					table.insert(annotation, line);
+				-- Save as annotation for the following action
+				if #line == 0 then
+					if annotation then
+						annotation.closed = true;
+					end
+				elseif annotation or not line:match("^%-+$") then
+					if (not annotation) or annotation.closed then
+						annotation = { line };
+					else
+						table.insert(annotation, line);
+					end
 				end
 			end
 		else

mercurial