Skip to content

small-tech/tree-sitter-nodekit

 
 

Repository files navigation

Tree-sitter-svelte

Tree-sitter grammar for svelte

Install

npm i tree-sitter-svelte tree-sitter

Dev

After installation (npm i),

npm run dev

Usage

To get started with exploring the grammar in a web-ui. Run:

NOTE: emcc must be installed and in your path

npm run ui

To use the grammar from javascript:

const Parser = require("tree-sitter");
const Svelte = require("tree-sitter-svelte");

const parser = new Parser();
parser.setLanguage(Svelte);

const sourceCode = `
<script context="module">
    let name = 'world';
</script>
<h1>Hello {name'<>{}``"\\''""``{}}!</h1>
`;

const tree = parser.parse(sourceCode);
console.log(tree.rootNode.toString());

// (document
//    (script_element
//        (start_tag (tag_name)
//            (attribute (attribute_name) (quoted_attribute_value (attribute_value))))
//        (raw_text)
//        (end_tag (tag_name))
//    )
//    (element
//        (start_tag (tag_name))
//        (text) (raw_text_expr) (text)
//        (end_tag (tag_name)
//    )
//  )
//)

Languages supported:

  • JavaScript/TypeScript
  • Rust
  • Go
  • Nim
  • Python

LICENSE

MIT

About

Tree sitter grammar for NodeKit

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages

  • C 89.2%
  • JavaScript 6.9%
  • Rust 1.3%
  • Svelte 1.1%
  • Scheme 0.9%
  • C++ 0.4%
  • Python 0.2%