getgrit / gritql

GritQL is a query language for searching, linting, and modifying code.
https://docs.grit.io/
MIT License
2.77k stars 55 forks source link

Vue module breaks tree-sitter for other grammars. #90

Open ilevyor opened 3 months ago

ilevyor commented 3 months ago

this test:

    #[test]
    fn print_sexp() {
        let code = r#"<Hello attr="foo"></Hello>"#;
        let mut parser = tree_sitter::Parser::new().unwrap();
        let lang = tree_sitter_html::language().into();
        parser.set_language(&lang).unwrap();
        let tree = parser.parse(code, None).unwrap().unwrap();
        let root = tree.root_node();
        let sexp = root.to_sexp();
        assert!(!sexp.contains("ERROR"));
        println!("{sexp}");
    }

fails even though the snippet is valid html, and parses correctly through the tree-sitter cli. commenting out the vue module in in language/src/lib.rs fixes this which is odd as the test does not make use of any functionality outside of tree-sitter

urbit-pilled commented 3 months ago

It may be because the tree-sitter-vue module has it's own html parser that implements the same external scanner functions? (idk, haven't checked this properly yet)

https://github.com/getgrit/gritql/blob/c18a96efbb6fa2ec1301e8f6d50ef83125833b0a/resources/language-metavariables/tree-sitter-html/src/scanner.c#L338-L341

https://github.com/getgrit/gritql/blob/c18a96efbb6fa2ec1301e8f6d50ef83125833b0a/resources/language-metavariables/tree-sitter-vue/src/tree_sitter_html/scanner.cc#L285-L287