1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
3 | |
4 | use crate::Cli; |
5 | use i_slint_compiler::parser::{syntax_nodes, SyntaxKind, SyntaxNode}; |
6 | use std::io::Write; |
7 | |
8 | pub(crate) fn fold_node( |
9 | node: &SyntaxNode, |
10 | file: &mut impl Write, |
11 | state: &mut crate::State, |
12 | args: &Cli, |
13 | ) -> std::io::Result<bool> { |
14 | if let Some(s) = syntax_nodes::State::new(node.clone()) { |
15 | if let Some(element) = state.current_elem.clone() { |
16 | let state_id = i_slint_compiler::parser::normalize_identifier( |
17 | s.DeclaredIdentifier().to_string().as_str(), |
18 | ); |
19 | if !element.borrow().transitions.is_empty() { |
20 | for c in node.children_with_tokens() { |
21 | if c.kind() == SyntaxKind::RBrace { |
22 | let whitespace = c |
23 | .as_token() |
24 | .and_then(|t| t.prev_token()) |
25 | .filter(|t| t.kind() == SyntaxKind::Whitespace); |
26 | for t in element.borrow().transitions.clone() { |
27 | if t.state_id == state_id |
28 | && t.node |
29 | .parent() |
30 | .map_or(false, |p| p.kind() == SyntaxKind::Transitions) |
31 | { |
32 | for c in t.node.children_with_tokens() { |
33 | if !matches!( |
34 | c.kind(), |
35 | SyntaxKind::DeclaredIdentifier | SyntaxKind::Colon, |
36 | ) { |
37 | crate::visit_node_or_token(c, file, state, args)?; |
38 | } |
39 | } |
40 | if let Some(ws) = whitespace.as_ref() { |
41 | write!(file, " {ws}" )? |
42 | } |
43 | } |
44 | } |
45 | } |
46 | crate::visit_node_or_token(c, file, state, args)?; |
47 | } |
48 | return Ok(true); |
49 | } |
50 | } |
51 | } |
52 | if node.kind() == SyntaxKind::Transitions { |
53 | if let Some(element) = state.current_elem.clone() { |
54 | if !element.borrow().transitions.is_empty() { |
55 | return Ok(true); |
56 | } |
57 | } |
58 | } |
59 | Ok(false) |
60 | } |
61 | |