Update grammar; Fix built-in function type checks
This commit is contained in:
parent
3096cf5959
commit
500a579910
@ -111,7 +111,21 @@ impl AbstractTree for FunctionCall {
|
||||
value_node.expected_type(context)
|
||||
}
|
||||
}
|
||||
Expression::Identifier(identifier) => identifier.expected_type(context),
|
||||
Expression::Identifier(identifier) => {
|
||||
for built_in_function in BUILT_IN_FUNCTIONS {
|
||||
if identifier.inner() == built_in_function.name() {
|
||||
if let Type::Function {
|
||||
parameter_types: _,
|
||||
return_type,
|
||||
} = built_in_function.r#type()
|
||||
{
|
||||
return Ok(*return_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
identifier.expected_type(context)
|
||||
}
|
||||
Expression::Index(index) => index.expected_type(context),
|
||||
Expression::Math(math) => math.expected_type(context),
|
||||
Expression::Logic(logic) => logic.expected_type(context),
|
||||
|
@ -163,3 +163,27 @@ x = (fn cb <() -> bool>) <bool> {
|
||||
(expression
|
||||
(value
|
||||
(boolean))))))))))))
|
||||
|
||||
================================================================================
|
||||
Nested Function Call
|
||||
================================================================================
|
||||
|
||||
(from_json (read 'file.json'))
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(function_call
|
||||
(expression
|
||||
(identifier
|
||||
(built_in_function)))
|
||||
(expression
|
||||
(function_call
|
||||
(expression
|
||||
(identifier
|
||||
(built_in_function)))
|
||||
(expression
|
||||
(value
|
||||
(string)))))))))
|
||||
|
@ -60,12 +60,14 @@ module.exports = grammar({
|
||||
),
|
||||
),
|
||||
|
||||
identifier: $ => choice(
|
||||
identifier: $ =>
|
||||
choice(
|
||||
$._identifier_pattern,
|
||||
$.built_in_function,
|
||||
),
|
||||
|
||||
_identifier_pattern: $ => /[_a-zA-Z]+[_a-zA-Z0-9]?/,
|
||||
_identifier_pattern: $ =>
|
||||
/[_a-zA-Z]+[_a-zA-Z0-9]?/,
|
||||
|
||||
value: $ =>
|
||||
choice(
|
||||
@ -288,10 +290,7 @@ module.exports = grammar({
|
||||
'{',
|
||||
repeat1(
|
||||
seq(
|
||||
choice(
|
||||
$.expression,
|
||||
'*',
|
||||
),
|
||||
choice($.expression, '*'),
|
||||
'=>',
|
||||
$.statement,
|
||||
optional(','),
|
||||
@ -390,19 +389,23 @@ module.exports = grammar({
|
||||
|
||||
built_in_function: $ =>
|
||||
choice(
|
||||
"assert",
|
||||
"assert_equal",
|
||||
"bash",
|
||||
"download",
|
||||
"fish",
|
||||
"length",
|
||||
"metadata",
|
||||
"output",
|
||||
"output_error",
|
||||
"random",
|
||||
"random_boolean",
|
||||
"random_float",
|
||||
"random_integer",
|
||||
'assert',
|
||||
'assert_equal',
|
||||
'bash',
|
||||
'download',
|
||||
'fish',
|
||||
'from_json',
|
||||
'length',
|
||||
'metadata',
|
||||
'output',
|
||||
'output_error',
|
||||
'random',
|
||||
'random_boolean',
|
||||
'random_float',
|
||||
'random_integer',
|
||||
'read',
|
||||
'to_json',
|
||||
'write',
|
||||
),
|
||||
},
|
||||
});
|
||||
|
@ -1294,6 +1294,10 @@
|
||||
"type": "STRING",
|
||||
"value": "fish"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "from_json"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "length"
|
||||
@ -1325,6 +1329,18 @@
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "random_integer"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "read"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "to_json"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "write"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -716,11 +716,11 @@
|
||||
},
|
||||
{
|
||||
"type": "float",
|
||||
"named": false
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "float",
|
||||
"named": true
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "fn",
|
||||
@ -730,6 +730,10 @@
|
||||
"type": "for",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "from_json",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "if",
|
||||
"named": false
|
||||
@ -790,6 +794,10 @@
|
||||
"type": "random_integer",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "read",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "return",
|
||||
"named": false
|
||||
@ -802,6 +810,10 @@
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "to_json",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "true",
|
||||
"named": false
|
||||
@ -810,6 +822,10 @@
|
||||
"type": "while",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "write",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "{",
|
||||
"named": false
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user