Add return type to function declarations

This commit is contained in:
Bruno BELANYI 2022-06-01 22:07:05 +02:00
parent 1e5f7cd5d5
commit 76b558a982
5 changed files with 1738 additions and 1628 deletions

View file

@ -283,6 +283,7 @@ module.exports = grammar({
_function_declaration_common: ($) => seq(
field("name", $.identifier),
field("parameters", $.parameters),
optional(seq(":", field("return_type", $.identifier))),
),
parameters: ($) => seq(

View file

@ -1277,6 +1277,31 @@
"type": "SYMBOL",
"name": "parameters"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "return_type",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
}
]
},
{
"type": "BLANK"
}
]
}
]
},

View file

@ -1012,6 +1012,16 @@
"named": true
}
]
},
"return_type": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
}
}
},
@ -1452,6 +1462,16 @@
"named": true
}
]
},
"return_type": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
}
}
},

File diff suppressed because it is too large Load diff

View file

@ -130,6 +130,25 @@ function func(a: int, b: int) = "string"
type: (identifier))
body: (string_literal)))
================================================================================
Function declaration return type
================================================================================
function func(a: int, b: int) : string = "string"
--------------------------------------------------------------------------------
(source_file
(function_declaration
name: (identifier)
parameters: (parameters
name: (identifier)
type: (identifier)
name: (identifier)
type: (identifier))
return_type: (identifier)
body: (string_literal)))
================================================================================
Function declaration single parameter
================================================================================
@ -173,6 +192,20 @@ primitive prim()
name: (identifier)
parameters: (parameters)))
================================================================================
Primitive declaration with return type
================================================================================
primitive prim() : int
--------------------------------------------------------------------------------
(source_file
(primitive_declaration
name: (identifier)
parameters: (parameters)
return_type: (identifier)))
================================================================================
Variable declaration
================================================================================