summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cratera/compiler.lua29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/cratera/compiler.lua b/src/cratera/compiler.lua
index 6b188ef..5e9b0b5 100644
--- a/src/cratera/compiler.lua
+++ b/src/cratera/compiler.lua
@@ -171,6 +171,7 @@ defs[parser.FALLBACK] = function(state, token)
                 elseif results[i-2] == TK.FUNCTION then -- we're in funcname
                     -- funcname is of the form Name {'.' Name} ':'
                     -- TODO how can we parse 'function Foo:[Bar].Baz()'...
+                    -- oh we think we need a real compiler for that
                     find_statement = false
                     break
                 else
@@ -194,6 +195,7 @@ defs[parser.FALLBACK] = function(state, token)
                 while true do
                     i = ignore_newlines(results, i)
                     if is_tk(results, i, ')') then
+                        local j = i
                         -- (prefixexp) or (funcargs)
                         -- find matching '('
                         local depth = 1
@@ -207,6 +209,11 @@ defs[parser.FALLBACK] = function(state, token)
                                 error("syntax error (unbalanced '()')")
                             end
                         until depth == 0
+                        if results[i - 1] == TK.FUNCTION then
+                            i = j
+                            -- found start
+                            break
+                        end
                     elseif is_tk(results, i, ']') then
                         -- [indexing]
                         -- find matching '['
@@ -225,12 +232,13 @@ defs[parser.FALLBACK] = function(state, token)
                         -- Name or '.' Name
                         i = i - 2
                         i = ignore_newlines(results, i)
-                        if is_tk(results, i, '.') then
-                            -- skip '.'
-                            i = i - 1
-                        else
-                            -- found start of statement
-                            break
+                        if not is_tk(results, i, '.') then
+                            if results[i] == TK.FUNCTION then
+                                i = i + 1
+                            else
+                                -- found start of statement
+                                break
+                            end
                         end
                     elseif is_tk(results, i, '}') then
                         -- prefixexp '{' table '}'
@@ -276,6 +284,14 @@ defs[parser.FALLBACK] = function(state, token)
                             error("syntax error")
                         end
                     else
+                        if results[i] == TK.FUNCTION then
+                            -- 'function' Name (funcargs)
+                            -- 'function' Name '.' Name (funcargs)
+                            -- etc
+                            repeat
+                                i = i + 1
+                            until results[i] == ')' or not results[i]
+                        end
                         -- found start of statement
                         break
                     end
@@ -289,6 +305,7 @@ defs[parser.FALLBACK] = function(state, token)
                 for k=i, #results do
                     if results[k] == END_OF_STMT then
                         local v = results[k+1]
+                        assert(v > i)
                         if v > i then -- this should always be true?
                             results[k+1] = v + 1
                         end