3 unstable releases

0.10.2 Apr 15, 2022
0.10.1 Apr 15, 2022
0.8.1 Mar 23, 2021

#299 in Text editors

23 downloads per month

MIT license

180KB
6.5K SLoC

C 6K SLoC JavaScript 230 SLoC // 0.0% comments Scheme 95 SLoC // 0.1% comments Rust 27 SLoC // 0.2% comments

tree-sitter-svelte

This crate provides a Svelte grammar for the tree-sitter parsing library. To use this crate, add it to the [dependencies] section of your Cargo.toml file. (Note that you will probably also need to depend on the tree-sitter crate to use the parsed result in any useful way.)

[dependencies]
tree-sitter = "0.17"
tree-sitter-svelte = "0.1.0"

Typically, you will use the language function to add this grammar to a tree-sitter Parser, and then use the parser to parse some code:

let code = r#"
    <script>
        let x = 1
    </script>
    <div>{x}</div>
"#;
let mut parser = Parser::new();
parser.set_language(tree_sitter_svelte::language()).expect("Error loading Svelte grammar");
let parsed = parser.parse(code, None);

If you have any questions, please reach out to us in the tree-sitter discussions page.

Dependencies

~2.8–4MB
~76K SLoC