pub fn parse(source: &str) -> Result<Document, String>Examples found in repository?
examples/debug_codegen.rs (line 12)
1fn main() {
2 let src = r#"---
3use fncc_runtime::*;
4---
5
6<Stack direction="vertical" gap="12">
7 <Text size="xl">Olá mundo</Text>
8 <Text>Este é o fncc 🦊</Text>
9 <Button onclick="handle_click">Clique aqui</Button>
10</Stack>"#;
11
12 match fncc_core::parser::parse(src) {
13 Ok(doc) => {
14 println!("=== AST ===");
15 println!("{:#?}", doc);
16 println!("\n=== GENERATED ===");
17 println!("{}", fncc_core::codegen::generate(&doc));
18 }
19 Err(e) => println!("ERROR: {e}"),
20 }
21}More examples
examples/debug_parse.rs (line 16)
3fn main() {
4 let sources = vec![
5 r#"<Text size="xl">hello</Text>"#,
6 r#"<Stack direction="vertical"><Text>oi</Text></Stack>"#,
7 "---\nuse crate::foo;\n---\n<App></App>",
8 r#"<Text>{state.msg}</Text>"#,
9 r#"<Button onclick="handle_click">Click</Button>"#,
10 ];
11
12 for src in sources {
13 println!("=== INPUT ===");
14 println!("{src}");
15 println!("=== AST ===");
16 match parser::parse(src) {
17 Ok(doc) => println!("{:#?}", doc),
18 Err(e) => println!("ERROR: {e}"),
19 }
20 println!();
21 }
22}