mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-03 10:23:32 +00:00
Syntax updater: remove the conditional flags and always update to the new syntax
This commit is contained in:
parent
c16253d29f
commit
2e4d42d356
5 changed files with 43 additions and 51 deletions
12
tools/syntax_updater/README.md
Normal file
12
tools/syntax_updater/README.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Slint syntax updater
|
||||
|
||||
Use this tool to update Slint files from the current Syntax to the new experimental syntax, using the new
|
||||
component declaration and following the new rules tracked in [issue #1750](https://github.com/slint-ui/slint/issues/1750)
|
||||
|
||||
### Usage:
|
||||
|
||||
```
|
||||
export SLINT_EXPERIMENTAL_SYNTAX=true
|
||||
cargo run -p syntax_updater -- -i /path/to/my/app/ui/**/*.slint
|
||||
```
|
||||
|
|
@ -9,9 +9,8 @@ pub(crate) fn fold_node(
|
|||
node: &SyntaxNode,
|
||||
file: &mut impl Write,
|
||||
_state: &mut crate::State,
|
||||
args: &Cli,
|
||||
_args: &Cli,
|
||||
) -> std::io::Result<bool> {
|
||||
debug_assert!(args.input_output_properties);
|
||||
if node.kind() == SyntaxKind::PropertyDeclaration
|
||||
&& node
|
||||
.parent()
|
||||
|
|
|
@ -202,7 +202,7 @@ fn move_properties_to_root(
|
|||
file: &mut impl Write,
|
||||
args: &Cli,
|
||||
) -> std::io::Result<bool> {
|
||||
if state.lookup_change.property_mappings.is_empty() && !args.new_component_declaration {
|
||||
if state.lookup_change.property_mappings.is_empty() {
|
||||
return Ok(false);
|
||||
}
|
||||
let mut seen_brace = false;
|
||||
|
|
|
@ -11,7 +11,6 @@ pub(crate) fn fold_node(
|
|||
state: &mut crate::State,
|
||||
args: &Cli,
|
||||
) -> std::io::Result<bool> {
|
||||
debug_assert!(args.new_component_declaration);
|
||||
let kind = node.kind();
|
||||
if kind == SyntaxKind::Component && node.child_token(SyntaxKind::ColonEqual).is_some() {
|
||||
let is_global =
|
||||
|
|
|
@ -42,21 +42,9 @@ pub struct Cli {
|
|||
#[clap(short, long, action)]
|
||||
inline: bool,
|
||||
|
||||
/// Do the lookup changes from issue #273
|
||||
#[clap(long, action)]
|
||||
fully_qualify: bool,
|
||||
|
||||
/// Move all properties declaration to root (implies fully_qualify)
|
||||
/// Move all properties declaration to root
|
||||
#[clap(long, action)]
|
||||
move_declaration: bool,
|
||||
|
||||
/// Mark top level property as `inout` #191
|
||||
#[clap(long, action)]
|
||||
input_output_properties: bool,
|
||||
|
||||
/// New component declaration #1682 (implies fully_qualify)
|
||||
#[clap(long, action)]
|
||||
new_component_declaration: bool,
|
||||
}
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
|
@ -174,31 +162,31 @@ fn process_file(
|
|||
let syntax_node = i_slint_compiler::parser::parse(source.clone(), Some(path), &mut diag);
|
||||
let len = syntax_node.node.text_range().end().into();
|
||||
let mut state = State::default();
|
||||
if args.fully_qualify || args.move_declaration {
|
||||
let doc = syntax_node.clone().into();
|
||||
let mut type_loader = TypeLoader::new(
|
||||
i_slint_compiler::typeregister::TypeRegister::builtin(),
|
||||
i_slint_compiler::CompilerConfiguration::new(
|
||||
i_slint_compiler::generator::OutputFormat::Llr,
|
||||
),
|
||||
&mut BuildDiagnostics::default(),
|
||||
);
|
||||
let dependency_registry = Rc::new(RefCell::new(
|
||||
i_slint_compiler::typeregister::TypeRegister::new(&type_loader.global_type_registry),
|
||||
));
|
||||
let foreign_imports = spin_on::spin_on(type_loader.load_dependencies_recursively(
|
||||
&doc,
|
||||
&mut diag,
|
||||
&dependency_registry,
|
||||
));
|
||||
let current_doc = crate::object_tree::Document::from_node(
|
||||
doc,
|
||||
foreign_imports,
|
||||
&mut diag,
|
||||
&dependency_registry,
|
||||
);
|
||||
state.current_doc = Rc::new(current_doc).into()
|
||||
}
|
||||
|
||||
let doc = syntax_node.clone().into();
|
||||
let mut type_loader = TypeLoader::new(
|
||||
i_slint_compiler::typeregister::TypeRegister::builtin(),
|
||||
i_slint_compiler::CompilerConfiguration::new(
|
||||
i_slint_compiler::generator::OutputFormat::Llr,
|
||||
),
|
||||
&mut BuildDiagnostics::default(),
|
||||
);
|
||||
let dependency_registry = Rc::new(RefCell::new(
|
||||
i_slint_compiler::typeregister::TypeRegister::new(&type_loader.global_type_registry),
|
||||
));
|
||||
let foreign_imports = spin_on::spin_on(type_loader.load_dependencies_recursively(
|
||||
&doc,
|
||||
&mut diag,
|
||||
&dependency_registry,
|
||||
));
|
||||
let current_doc = crate::object_tree::Document::from_node(
|
||||
doc,
|
||||
foreign_imports,
|
||||
&mut diag,
|
||||
&dependency_registry,
|
||||
);
|
||||
state.current_doc = Rc::new(current_doc).into();
|
||||
|
||||
visit_node(syntax_node, &mut file, &mut state, args)?;
|
||||
if diag.has_error() {
|
||||
file.write_all(&source.as_bytes()[len..])?;
|
||||
|
@ -301,19 +289,13 @@ fn fold_node(
|
|||
state: &mut State,
|
||||
args: &Cli,
|
||||
) -> std::io::Result<bool> {
|
||||
if args.input_output_properties
|
||||
&& experiments::input_output_properties::fold_node(node, file, state, args)?
|
||||
{
|
||||
if experiments::input_output_properties::fold_node(node, file, state, args)? {
|
||||
return Ok(true);
|
||||
}
|
||||
if args.new_component_declaration
|
||||
&& experiments::new_component_declaration::fold_node(node, file, state, args)?
|
||||
{
|
||||
if experiments::new_component_declaration::fold_node(node, file, state, args)? {
|
||||
return Ok(true);
|
||||
}
|
||||
if (args.fully_qualify || args.move_declaration)
|
||||
&& experiments::lookup_changes::fold_node(node, file, state, args)?
|
||||
{
|
||||
if experiments::lookup_changes::fold_node(node, file, state, args)? {
|
||||
return Ok(true);
|
||||
}
|
||||
Ok(false)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue