Skip to content

Commit b581fd8

Browse files
committed
Add function call statement
1 parent 269be46 commit b581fd8

File tree

4 files changed

+30157
-25760
lines changed

4 files changed

+30157
-25760
lines changed

corpus/functions.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,25 @@ f = function() return 'some string' end
8686
(variable_declaration (variable_declarator (identifier))
8787
(function_definition (parameters)
8888
(return_statement (string)))))
89+
90+
============================================
91+
Function calls
92+
============================================
93+
94+
f(3)
95+
96+
f(r(), 10)
97+
98+
g(5, r())
99+
100+
---
101+
102+
(lua
103+
(function_call (identifier)
104+
(arguments (number)))
105+
106+
(function_call (identifier)
107+
(arguments (function_call (identifier) (arguments)) (number)))
108+
109+
(function_call (identifier)
110+
(arguments (number) (function_call (identifier) (arguments)))))

grammar.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = grammar({
3131
conflicts: $ => [
3232
[$._prefix],
3333
[$._expression, $._variable_declarator],
34+
[$._expression, $.function_call_statement]
3435
],
3536

3637
externals: $ => [
@@ -68,7 +69,8 @@ module.exports = grammar({
6869
$._empty_statement,
6970

7071
alias($.function_statement, $.function),
71-
alias($.local_function_statement, $.local_function)
72+
alias($.local_function_statement, $.local_function),
73+
alias($.function_call_statement, $.function_call)
7274
),
7375

7476
// Declarations
@@ -207,6 +209,17 @@ module.exports = grammar({
207209
$._function_body
208210
),
209211

212+
function_call_statement: $ => prec.dynamic(PREC.PRIORITY, choice(
213+
seq($._prefix, $.arguments),
214+
seq($._prefix, ':', alias($.identifier, $.method), $.arguments)
215+
)),
216+
217+
arguments: $ => choice(
218+
seq('(', optional(sequence($._expression)), ')'),
219+
$.table,
220+
$.string
221+
),
222+
210223
function_name: $ => seq(
211224
$.identifier,
212225
repeat(seq('.', alias($.identifier, $.property_identifier))),
@@ -262,6 +275,7 @@ module.exports = grammar({
262275
$.this,
263276
$.self,
264277
$._variable_declarator,
278+
alias($.function_call_statement, $.function_call),
265279
seq('(', $._expression, ')')
266280
),
267281

src/grammar.json

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@
139139
},
140140
"named": true,
141141
"value": "local_function"
142+
},
143+
{
144+
"type": "ALIAS",
145+
"content": {
146+
"type": "SYMBOL",
147+
"name": "function_call_statement"
148+
},
149+
"named": true,
150+
"value": "function_call"
142151
}
143152
]
144153
},
@@ -870,6 +879,113 @@
870879
}
871880
]
872881
},
882+
"function_call_statement": {
883+
"type": "PREC_DYNAMIC",
884+
"value": 1,
885+
"content": {
886+
"type": "CHOICE",
887+
"members": [
888+
{
889+
"type": "SEQ",
890+
"members": [
891+
{
892+
"type": "SYMBOL",
893+
"name": "_prefix"
894+
},
895+
{
896+
"type": "SYMBOL",
897+
"name": "arguments"
898+
}
899+
]
900+
},
901+
{
902+
"type": "SEQ",
903+
"members": [
904+
{
905+
"type": "SYMBOL",
906+
"name": "_prefix"
907+
},
908+
{
909+
"type": "STRING",
910+
"value": ":"
911+
},
912+
{
913+
"type": "ALIAS",
914+
"content": {
915+
"type": "SYMBOL",
916+
"name": "identifier"
917+
},
918+
"named": true,
919+
"value": "method"
920+
},
921+
{
922+
"type": "SYMBOL",
923+
"name": "arguments"
924+
}
925+
]
926+
}
927+
]
928+
}
929+
},
930+
"arguments": {
931+
"type": "CHOICE",
932+
"members": [
933+
{
934+
"type": "SEQ",
935+
"members": [
936+
{
937+
"type": "STRING",
938+
"value": "("
939+
},
940+
{
941+
"type": "CHOICE",
942+
"members": [
943+
{
944+
"type": "SEQ",
945+
"members": [
946+
{
947+
"type": "SYMBOL",
948+
"name": "_expression"
949+
},
950+
{
951+
"type": "REPEAT",
952+
"content": {
953+
"type": "SEQ",
954+
"members": [
955+
{
956+
"type": "STRING",
957+
"value": ","
958+
},
959+
{
960+
"type": "SYMBOL",
961+
"name": "_expression"
962+
}
963+
]
964+
}
965+
}
966+
]
967+
},
968+
{
969+
"type": "BLANK"
970+
}
971+
]
972+
},
973+
{
974+
"type": "STRING",
975+
"value": ")"
976+
}
977+
]
978+
},
979+
{
980+
"type": "SYMBOL",
981+
"name": "table"
982+
},
983+
{
984+
"type": "SYMBOL",
985+
"name": "string"
986+
}
987+
]
988+
},
873989
"function_name": {
874990
"type": "SEQ",
875991
"members": [
@@ -1153,6 +1269,15 @@
11531269
"type": "SYMBOL",
11541270
"name": "_variable_declarator"
11551271
},
1272+
{
1273+
"type": "ALIAS",
1274+
"content": {
1275+
"type": "SYMBOL",
1276+
"name": "function_call_statement"
1277+
},
1278+
"named": true,
1279+
"value": "function_call"
1280+
},
11561281
{
11571282
"type": "SEQ",
11581283
"members": [
@@ -2299,6 +2424,10 @@
22992424
[
23002425
"_expression",
23012426
"_variable_declarator"
2427+
],
2428+
[
2429+
"_expression",
2430+
"function_call_statement"
23022431
]
23032432
],
23042433
"externals": [

0 commit comments

Comments
 (0)