Add return type to function declarations
This commit is contained in:
parent
1e5f7cd5d5
commit
76b558a982
|
@ -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(
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
3287
src/parser.c
3287
src/parser.c
File diff suppressed because it is too large
Load diff
|
@ -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
|
||||
================================================================================
|
||||
|
|
Loading…
Reference in a new issue