# HG changeset patch # User Matthew Wild # Date 1445987266 0 # Node ID b37504fa30315208ceee86488bdb01f952b06fda # Parent 67d50889b7fea6f168cf48a05859e78f116b0df9 Add annotations to actions (by grabbing the preceding comment) diff -r 67d50889b7fe -r b37504fa3031 main.lua --- 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 diff -r 67d50889b7fe -r b37504fa3031 scansion/generator.lua --- 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 diff -r 67d50889b7fe -r b37504fa3031 scansion/parser.lua --- 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;