Skip to content

Latest commit

 

History

History

tree-sitter-writeup

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Tree-sitter writeup

Learn something about the tree-sitter.

Development workflow

  1. Create a new parser project mkdir tree-sitter-{language}.

  2. Initialize the project with dependencies.

      cd tree-sitter-{language}
      pnpm init
      pnpm add nan node-gyp
      pnpm add tree-sitter-cli -D
  3. Initialize global config for tree-sitter, add Paths.

    ./node_modules/.bin/tree-sitter init-config
         ^ this would print out the path to config file
    
    # add the parent folder of `tree-sitter-{language}` to the field "parser-directories"
    # so that tree-sitter can find the parser project
  4. Write some grammar in grammar.js. Here is an example.

  5. Call ./node_modules/.bin/tree-sitter generate path-to-grammar.js to generate several new files important.

  6. Run node-gyp configure && node-gyp build to build the final parser.

Test

  1. Add test files in the directory corpus. Check out the example.

  2. Run ./node_modules/.bin/tree-sitter test to verify. Add --update option to update the syntax.

Highlight

  1. Add highlights.scm in the directory queries. Check out the example.

  2. Run ./node_modules/.bin/tree-sitter highlight --html ./examples/source.imp to generate a result in html.

  3. Open that html to view the grammar highlight output.

Acknowledgement

Watch the video: Tree-sitter: a new parsing system for programming tools - GitHub Universe 2017

Read some blogs: