Add function calls
This commit is contained in:
parent
136924cb26
commit
8921953bbb
|
@ -33,6 +33,8 @@ module.exports = grammar({
|
|||
$.array_expression,
|
||||
$.record_expression,
|
||||
|
||||
$.function_call,
|
||||
|
||||
$.unary_expression,
|
||||
$.binary_expression,
|
||||
$.sequence_expression,
|
||||
|
@ -67,6 +69,13 @@ module.exports = grammar({
|
|||
)
|
||||
),
|
||||
|
||||
function_call: ($) => seq(
|
||||
field("function", $.identifier),
|
||||
"(",
|
||||
field("arguments", sepBy(",", $._expr)),
|
||||
")",
|
||||
),
|
||||
|
||||
unary_expression: ($) => seq(
|
||||
field("operator", alias("-", $.operator)),
|
||||
field("expression", $._expr),
|
||||
|
|
|
@ -34,6 +34,10 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "record_expression"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "function_call"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "unary_expression"
|
||||
|
@ -169,6 +173,64 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"function_call": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "function",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "arguments",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expr"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expr"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
}
|
||||
]
|
||||
},
|
||||
"unary_expression": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
|
@ -53,6 +57,10 @@
|
|||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
|
@ -107,6 +115,10 @@
|
|||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
|
@ -155,6 +167,10 @@
|
|||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
|
@ -183,6 +199,68 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function_call",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"arguments": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": ",",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "array_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "nil_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "record_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "sequence_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"function": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "record_expression",
|
||||
"named": true,
|
||||
|
@ -209,6 +287,10 @@
|
|||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
|
@ -263,6 +345,10 @@
|
|||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
|
@ -306,6 +392,10 @@
|
|||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
|
@ -364,6 +454,10 @@
|
|||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
|
|
1834
src/parser.c
1834
src/parser.c
File diff suppressed because it is too large
Load diff
|
@ -85,3 +85,56 @@ record_type { a = 12, }
|
|||
field: (identifier)
|
||||
init: (integer_literal)
|
||||
(ERROR)))
|
||||
|
||||
================================================================================
|
||||
Function call
|
||||
================================================================================
|
||||
|
||||
f(12, "27")
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_call
|
||||
function: (identifier)
|
||||
arguments: (integer_literal)
|
||||
arguments: (string_literal)))
|
||||
|
||||
================================================================================
|
||||
Function call single argument
|
||||
================================================================================
|
||||
|
||||
f(12)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_call
|
||||
function: (identifier)
|
||||
arguments: (integer_literal)))
|
||||
|
||||
================================================================================
|
||||
Function call no arguments
|
||||
================================================================================
|
||||
|
||||
f()
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_call
|
||||
function: (identifier)))
|
||||
|
||||
================================================================================
|
||||
Function call trailing comma
|
||||
================================================================================
|
||||
|
||||
f(12,)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_call
|
||||
function: (identifier)
|
||||
arguments: (integer_literal)
|
||||
(ERROR)))
|
||||
|
|
Loading…
Reference in a new issue