1
0

Update grammar; Fix built-in function type checks

This commit is contained in:
Jeff 2023-12-16 21:15:36 -05:00
parent 3096cf5959
commit 500a579910
6 changed files with 5140 additions and 4277 deletions

View File

@ -111,7 +111,21 @@ impl AbstractTree for FunctionCall {
value_node.expected_type(context) 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::Index(index) => index.expected_type(context),
Expression::Math(math) => math.expected_type(context), Expression::Math(math) => math.expected_type(context),
Expression::Logic(logic) => logic.expected_type(context), Expression::Logic(logic) => logic.expected_type(context),

View File

@ -163,3 +163,27 @@ x = (fn cb <() -> bool>) <bool> {
(expression (expression
(value (value
(boolean)))))))))))) (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)))))))))

View File

@ -60,12 +60,14 @@ module.exports = grammar({
), ),
), ),
identifier: $ => choice( identifier: $ =>
$._identifier_pattern, choice(
$.built_in_function, $._identifier_pattern,
), $.built_in_function,
),
_identifier_pattern: $ => /[_a-zA-Z]+[_a-zA-Z0-9]?/, _identifier_pattern: $ =>
/[_a-zA-Z]+[_a-zA-Z0-9]?/,
value: $ => value: $ =>
choice( choice(
@ -288,10 +290,7 @@ module.exports = grammar({
'{', '{',
repeat1( repeat1(
seq( seq(
choice( choice($.expression, '*'),
$.expression,
'*',
),
'=>', '=>',
$.statement, $.statement,
optional(','), optional(','),
@ -390,19 +389,23 @@ module.exports = grammar({
built_in_function: $ => built_in_function: $ =>
choice( choice(
"assert", 'assert',
"assert_equal", 'assert_equal',
"bash", 'bash',
"download", 'download',
"fish", 'fish',
"length", 'from_json',
"metadata", 'length',
"output", 'metadata',
"output_error", 'output',
"random", 'output_error',
"random_boolean", 'random',
"random_float", 'random_boolean',
"random_integer", 'random_float',
'random_integer',
'read',
'to_json',
'write',
), ),
}, },
}); });

View File

@ -1294,6 +1294,10 @@
"type": "STRING", "type": "STRING",
"value": "fish" "value": "fish"
}, },
{
"type": "STRING",
"value": "from_json"
},
{ {
"type": "STRING", "type": "STRING",
"value": "length" "value": "length"
@ -1325,6 +1329,18 @@
{ {
"type": "STRING", "type": "STRING",
"value": "random_integer" "value": "random_integer"
},
{
"type": "STRING",
"value": "read"
},
{
"type": "STRING",
"value": "to_json"
},
{
"type": "STRING",
"value": "write"
} }
] ]
} }

View File

@ -716,11 +716,11 @@
}, },
{ {
"type": "float", "type": "float",
"named": false "named": true
}, },
{ {
"type": "float", "type": "float",
"named": true "named": false
}, },
{ {
"type": "fn", "type": "fn",
@ -730,6 +730,10 @@
"type": "for", "type": "for",
"named": false "named": false
}, },
{
"type": "from_json",
"named": false
},
{ {
"type": "if", "type": "if",
"named": false "named": false
@ -790,6 +794,10 @@
"type": "random_integer", "type": "random_integer",
"named": false "named": false
}, },
{
"type": "read",
"named": false
},
{ {
"type": "return", "type": "return",
"named": false "named": false
@ -802,6 +810,10 @@
"type": "string", "type": "string",
"named": true "named": true
}, },
{
"type": "to_json",
"named": false
},
{ {
"type": "true", "type": "true",
"named": false "named": false
@ -810,6 +822,10 @@
"type": "while", "type": "while",
"named": false "named": false
}, },
{
"type": "write",
"named": false
},
{ {
"type": "{", "type": "{",
"named": false "named": false

File diff suppressed because it is too large Load Diff