summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/matcher/definition.lua11
-rw-r--r--src/parser/grammar.lua9
-rw-r--r--test/definition/init.lua29
3 files changed, 39 insertions, 10 deletions
diff --git a/src/matcher/definition.lua b/src/matcher/definition.lua
index 8656892a..86ea400b 100644
--- a/src/matcher/definition.lua
+++ b/src/matcher/definition.lua
@@ -61,12 +61,15 @@ function defs.LocalSet(names)
end
end
-function defs.Function(func)
- local names = func.name
- if names and #names == 1 then
+function defs.FunctionDef(names)
+ if #names == 1 then
scopeSet(names[1])
end
- return func
+ scopePush()
+end
+
+function defs.Function()
+ scopePop()
end
function defs.DoDef()
diff --git a/src/parser/grammar.lua b/src/parser/grammar.lua
index a4240df2..cb2d2e6f 100644
--- a/src/parser/grammar.lua
+++ b/src/parser/grammar.lua
@@ -233,13 +233,10 @@ TableField <- NewIndex / NewField / Exp
NewIndex <- BL Exp BR ASSIGN Exp
NewField <- Name ASSIGN Exp
-Function <- {|
- FUNCTION FuncName? PL ArgList? PR
- (!END Action)*
+Function <- (FUNCTION {| FuncName? |} PL ArgList? PR) -> FunctionDef
+ (!END Action)* -> Function
END
- |}
- -> Function
-FuncName <- {:name: {| Name (FuncSuffix)* |} :}
+FuncName <- Name (FuncSuffix)*
FuncSuffix <- DOT Name
/ COLON Name
diff --git a/test/definition/init.lua b/test/definition/init.lua
index d77acf0c..f9a0bf3e 100644
--- a/test/definition/init.lua
+++ b/test/definition/init.lua
@@ -191,3 +191,32 @@ repeat
local <!x!>
until <?x?>
]]
+
+test [[
+local <!x!>
+function _()
+ local x
+end
+<?x?> = 1
+]]
+
+test [[
+local <!x!>
+return function ()
+ <?x?> = 1
+end
+]]
+
+test [[
+local <!x!>
+local x = function ()
+ <?x?> = 1
+end
+]]
+
+test [[
+local x
+local function <!x!> ()
+ <?x?> = 1
+end
+]]