Skip to content

Commit 269be46

Browse files
committed
Add local function statement
1 parent a2aaa74 commit 269be46

File tree

4 files changed

+30319
-29829
lines changed

4 files changed

+30319
-29829
lines changed

corpus/functions.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,26 @@ t.a.b.c.f = function() return true end
6363

6464
(variable_declaration (variable_declarator (identifier) (property_identifier) (property_identifier) (property_identifier) (property_identifier)) (function_definition (parameters)
6565
(return_statement (true)))))
66+
67+
68+
============================================
69+
Local function statements
70+
============================================
71+
72+
local function f()
73+
return 'some string'
74+
end
75+
76+
local f
77+
f = function() return 'some string' end
78+
79+
---
80+
81+
(lua
82+
(local_function (identifier) (parameters)
83+
(return_statement (string)))
84+
85+
(local_variable_declaration (variable_declarator (identifier)))
86+
(variable_declaration (variable_declarator (identifier))
87+
(function_definition (parameters)
88+
(return_statement (string)))))

grammar.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ module.exports = grammar({
6767
$.label_statement,
6868
$._empty_statement,
6969

70-
alias($.function_statement, $.function)
70+
alias($.function_statement, $.function),
71+
alias($.local_function_statement, $.local_function)
7172
),
7273

7374
// Declarations
@@ -199,6 +200,13 @@ module.exports = grammar({
199200
$._function_body
200201
),
201202

203+
local_function_statement: $ => seq(
204+
'local',
205+
'function',
206+
$.identifier,
207+
$._function_body
208+
),
209+
202210
function_name: $ => seq(
203211
$.identifier,
204212
repeat(seq('.', alias($.identifier, $.property_identifier))),

src/grammar.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@
130130
},
131131
"named": true,
132132
"value": "function"
133+
},
134+
{
135+
"type": "ALIAS",
136+
"content": {
137+
"type": "SYMBOL",
138+
"name": "local_function_statement"
139+
},
140+
"named": true,
141+
"value": "local_function"
133142
}
134143
]
135144
},
@@ -840,6 +849,27 @@
840849
}
841850
]
842851
},
852+
"local_function_statement": {
853+
"type": "SEQ",
854+
"members": [
855+
{
856+
"type": "STRING",
857+
"value": "local"
858+
},
859+
{
860+
"type": "STRING",
861+
"value": "function"
862+
},
863+
{
864+
"type": "SYMBOL",
865+
"name": "identifier"
866+
},
867+
{
868+
"type": "SYMBOL",
869+
"name": "_function_body"
870+
}
871+
]
872+
},
843873
"function_name": {
844874
"type": "SEQ",
845875
"members": [

0 commit comments

Comments
 (0)