Skip to content
R Code
Syntax Tree
Query

Basic usage

This interactive playground allows you to write R code and see how the tree-sitter parser analyzes its syntax structure. The tree-sitter grammar for R enables precise parsing of R code for various applications like syntax highlighting, code navigation, and static analysis.

You can:

  • Enter R code in the editor on the left
  • See the parsed syntax tree on the right
  • Click in the code to highlight the corresponding node
  • Click on a tree node to highlight the corresponding code

Advanced Features

Query Mode

Toggle on the “query” checkbox to use tree-sitter queries. This allows you to write pattern-matching expressions to find nodes in your code.

Example queries:

(function_definition) @function

This will match all function definitions in your code.

(binary (identifier) @left_id (#eq? @left_id "x"))

This will match binary expressions where the left operand is the identifier “x”.

Anonymous Nodes

Toggle on “show anonymous nodes” to display all nodes in the tree, including unnamed ones like operators and punctuation.

Unimplemented features

The “log” and “accessibility” checkboxes may not be functioning here (yet), but have just been ported over from the analogous page in the documentation for tree-sitter itself: https://tree-sitter.github.io/tree-sitter/7-playground.html. For that matter, the “query” functionality may also not really be working (yet).

About Tree-sitter

Tree-sitter is a parser generator tool and incremental parsing library. It can build a concrete syntax tree for source files and efficiently update the syntax tree as the source file is edited.

The tree-sitter-r grammar enables precise parsing of R code for various applications like syntax highlighting, code navigation, and static analysis.