Crate tree_sitter_rstml

Source
Expand description

This crate provides rstml (rust+html) template support for the tree-sitter parsing library.

This crate exposes two functions:

  1. The language_rstml function is used to add the rstml templating language to a tree-sitter Parser. You can then use that parser to parse some code:

    let code = "<div>Hello, world</div>";
    let mut parser = tree_sitter::Parser::new();
    parser.set_language(&tree_sitter_rstml::language_rstml()).expect("Error loading rstml grammar");
    let tree = parser.parse(code, None).unwrap();
  2. The language_rust_with_rstml function is used to add the rust plus the rstml templating language to a tree-sitter Parser. You can then use that parser to parse some code:

    let code = r#"
        view! {
            <div>hello, world</div>
        }
    "#;
    let mut parser = tree_sitter::Parser::new();
    parser.set_language(&tree_sitter_rstml::language_rust_with_rstml()).expect("Error loading rust_with_rstml grammar");
    let tree = parser.parse(code, None).unwrap();

You can read more about the reason there are two grammars in the project’s README.

Constants§

HIGHLIGHTS_QUERY
RSTML_NODE_TYPES
The content of the node-types.json file for the rstml grammar.
RUST_WITH_RSTML_NODE_TYPES
The content of the node-types.json file for the rust_with_rstml grammar.

Functions§

language_rstml
The tree-sitter Language for the rstml grammar.
language_rust_with_rstml
The tree-sitter Language for the rust_with_rstml grammar.