mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
Parser: Parse functions
This commit is contained in:
parent
18bf24e7bf
commit
851a910e41
7 changed files with 175 additions and 18 deletions
|
@ -58,6 +58,9 @@ pub fn parse_element_content(p: &mut impl Parser) {
|
|||
SyntaxKind::Identifier if p.peek().as_str() == "callback" => {
|
||||
parse_callback_declaration(&mut *p);
|
||||
}
|
||||
SyntaxKind::Identifier if p.peek().as_str() == "function" => {
|
||||
parse_function(&mut *p);
|
||||
}
|
||||
SyntaxKind::Identifier | SyntaxKind::Star if p.peek().as_str() == "animate" => {
|
||||
parse_property_animation(&mut *p);
|
||||
}
|
||||
|
@ -553,3 +556,39 @@ fn parse_transition_inner(p: &mut impl Parser) -> bool {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(test, parser_test)]
|
||||
/// ```test,Function
|
||||
/// function foo() {}
|
||||
/// function bar(xx : int) { yy = xx; }
|
||||
/// function bar(xx : int,) -> int { return 42; }
|
||||
/// ```
|
||||
fn parse_function(p: &mut impl Parser) {
|
||||
debug_assert_eq!(p.peek().as_str(), "function");
|
||||
let mut p = p.start_node(SyntaxKind::Function);
|
||||
p.consume(); // "function"
|
||||
{
|
||||
let mut p = p.start_node(SyntaxKind::DeclaredIdentifier);
|
||||
p.expect(SyntaxKind::Identifier);
|
||||
}
|
||||
if p.expect(SyntaxKind::LParent) {
|
||||
while p.peek().kind() != SyntaxKind::RParent {
|
||||
let mut p = p.start_node(SyntaxKind::ArgumentDeclaration);
|
||||
{
|
||||
let mut p = p.start_node(SyntaxKind::DeclaredIdentifier);
|
||||
p.expect(SyntaxKind::Identifier);
|
||||
}
|
||||
p.expect(SyntaxKind::Colon);
|
||||
parse_type(&mut *p);
|
||||
if !p.test(SyntaxKind::Comma) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
p.expect(SyntaxKind::RParent);
|
||||
if p.test(SyntaxKind::Arrow) {
|
||||
let mut p = p.start_node(SyntaxKind::ReturnType);
|
||||
parse_type(&mut *p);
|
||||
}
|
||||
}
|
||||
parse_code_block(&mut *p);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue