tree-sitter explained

TJ DeVries
8 Mar 202415:00

Summary

TLDRThis video script demystifies Tree-sitter, a parser generator tool that powers various editor functionalities by focusing on incremental parsing and syntax tree analysis. It clarifies that Tree-sitter is not an interpreter or compiler but a library for text interaction, enabling quick feedback and error recovery. The script introduces the concept of writing grammars that transform into parsers, the incremental and error recovery benefits for editors, and the powerful query engine that allows asking complex questions about code structure. It showcases Tree-sitter's capabilities in enhancing editor features like highlighting, navigation, and structural editing, and its potential for broader code analysis and tooling across multiple languages.

Takeaways

  • 🌟 Treesitter is a parser generator tool that can transform a grammar into a parser, which is then used by applications for syntax analysis.
  • πŸ” Unlike LSP (Language Server Protocol), Treesitter focuses on parsing one file at a time for quick and incremental feedback, rather than understanding the whole project semantically.
  • πŸ› οΈ Treesitter is not a compiler or interpreter; it is a library for interacting with text to create a syntax tree and perform queries on it.
  • βœ‚οΈ The incremental aspect of Treesitter allows for efficient parsing as text is edited, without needing to recompute the entire syntax tree with each keystroke.
  • πŸ”„ Error recovery is a key feature of Treesitter, enabling it to handle broken code by isolating minimal errors while keeping the rest of the file functional.
  • πŸ“š The query engine in Treesitter is powerful for asking complex questions about the syntax tree, which can be used for various editor features like highlighting and structural editing.
  • πŸ“ To utilize Treesitter, one must write a grammar in a JavaScript-like DSL, which then generates a parser in C that can be compiled and used by the application.
  • πŸ”— The generated parser is a shared library that can be easily embedded into other applications, making Treesitter highly portable and efficient.
  • πŸ–ΌοΈ The visual representation of the syntax tree in the script demonstrates how Treesitter can be used for detailed code analysis and manipulation.
  • πŸ›‘ The script warns that Treesitter uses Lisp-like code for queries, which may be a point of contention for some developers but is essential for its functionality.
  • 🌐 Treesitter's wide adoption and support for many languages make it a valuable tool for building cross-language tooling for code analysis, linting, and more.

Q & A

  • What is Treesitter and how does it differ from LSP?

    -Treesitter is a parser generator tool that provides incremental parsing and querying capabilities for a single file at a time. Unlike LSP (Language Server Protocol), which focuses on understanding the whole project semantically and provides features like definitions, references, and completions, Treesitter is concerned with the text of a single file and does not know about types or packages outside of that file.

  • What are the main features of Treesitter?

    -The main features of Treesitter include its ability to generate parsers from grammars, its incremental parsing which is efficient for editing, error recovery that allows it to handle incomplete code, and a powerful query engine that allows users to ask questions about the syntax tree.

  • How does Treesitter handle incremental parsing?

    -Treesitter handles incremental parsing by updating the syntax tree as the user types, rather than recomputing the entire tree with each keystroke. This makes it efficient for providing real-time feedback while editing code.

  • What is error recovery in the context of Treesitter?

    -Error recovery in Treesitter refers to its ability to continue parsing and understanding the structure of code even when errors are present. It tries to find the minimal amount of error and encloses that, allowing the rest of the file to remain well-highlighted and functional.

  • What is the role of the query engine in Treesitter?

    -The query engine in Treesitter allows users to ask questions about the syntax tree generated from the code. It enables the retrieval of specific information from the tree, which can be used to power features in editors or other applications.

  • How is Treesitter integrated into code editors?

    -Treesitter is integrated into code editors by being embedded as a library that powers various features such as syntax highlighting, code folding, and structural editing. It is already used in editors like Neovim, Helix, Zed, and Emacs.

  • Why are incremental parsing and error recovery important in code editors?

    -Incremental parsing and error recovery are important because they allow the editor to provide immediate feedback and maintain a good editing experience even as the user types and potentially introduces errors into the code.

  • How does Treesitter generate a parser from a grammar?

    -Treesitter generates a parser from a grammar by using a JavaScript-like Domain-Specific Language (DSL). Users write a grammar in this DSL, which is then compiled into a parser using the 'tree-sitter' command-line tool, resulting in a 'parser.c' file.

  • What is the significance of the query language used in Treesitter?

    -The query language in Treesitter is significant because it allows for the selection and manipulation of specific parts of the syntax tree. It uses a Lisp-like syntax and enables complex queries that can filter and select nodes based on various criteria.

  • How can Treesitter be used for syntax highlighting in editors?

    -Treesitter can be used for syntax highlighting by writing queries that capture specific patterns or nodes in the syntax tree, such as integer literals or function declarations. The editor can then use these captures to apply different styles or highlight colors to the corresponding parts of the code.

  • What are some benefits of using Treesitter for code analysis or linting?

    -Treesitter offers benefits for code analysis or linting because it provides pre-built parsers for many languages, allowing developers to write custom queries and captures without needing to create a new parser for each language. This makes it easier to build tools that can analyze and lint code across different programming languages.

Outlines

00:00

🌲 Understanding Tree-Sitter: The Parser Generator Tool

This paragraph introduces the concept of Tree-Sitter as a parser generator tool that can demystify the process of parsing code within an editor. It clarifies that Tree-Sitter is not a compiler or interpreter and emphasizes its focus on parsing individual files incrementally for quick feedback. The paragraph explains that Tree-Sitter includes automatic incremental parsing and error recovery, which are challenging to implement in custom parsing libraries. It also introduces the powerful query engine that allows users to ask questions about the syntax tree generated from the text. The purpose of Tree-Sitter in editors is highlighted, including its adoption by various editors for its incremental parsing, error recovery, and querying capabilities.

05:00

πŸ› οΈ Building and Using Tree-Sitter Parsers

The second paragraph delves into the technical process of creating a Tree-Sitter parser. It describes how to write a grammar in a JavaScript-like DSL, which is then transformed into a C parser file through the 'tree-sitter CLI'. The resulting files, including the parser .c file, are discussed, along with their benefits such as minimal dependencies and ease of embedding in other languages. The paragraph also touches on the use of shared libraries to load grammars at runtime, allowing for dynamic language support in editors. A small Go file example is presented to illustrate how Tree-Sitter generates a syntax tree, and the introduction of a query editor is mentioned as a tool for selecting and highlighting specific elements within the code.

10:02

πŸ” The Power of Queries in Tree-Sitter

This paragraph explores the capabilities of Tree-Sitter's query system, demonstrating how it can be used to perform complex selections and manipulations within the syntax tree. It shows how queries can filter and select specific elements, such as strings on the left side of binary expressions, which would be difficult or impossible with regex. The paragraph also discusses the practical applications of queries in editors, such as syntax highlighting, language embedding, indenting, and structural editing. The potential for Tree-Sitter to enhance editor functionality with accurate and efficient parsing is emphasized, as well as its utility beyond just editors for tasks like code analysis, linting, and highlighting due to its wide language support.

Mindmap

Keywords

πŸ’‘Treesitter

Treesitter is a parser generator tool that is central to the video's theme of understanding code structure within a text editor. It allows for the creation of a grammar that is transformed into a parser, which is then used to analyze code files incrementally. The script mentions that Treesitter is not a compiler or an interpreter but rather a library for interacting with text to provide quick feedback based on the syntax tree it generates.

πŸ’‘LSP (Language Server Protocol)

LSP is mentioned to differentiate it from Treesitter. LSP is a protocol that provides semantic understanding of code across an entire project, offering features like autocompletion and definition lookup. The script clarifies that while both are useful in code editors, they serve different purposes, with Treesitter focusing on single-file parsing and incremental updates.

πŸ’‘Incremental Parsing

Incremental parsing is a concept where the parser updates its analysis as the code is being typed, without needing to re-parse the entire file. This is a key feature of Treesitter, as highlighted in the script, allowing for efficient and real-time feedback on the code structure within a file.

πŸ’‘Error Recovery

Error recovery in the context of Treesitter refers to the parser's ability to handle incomplete or incorrect code by isolating errors and continuing to provide feedback on the rest of the file. The script uses this term to illustrate Treesitter's robustness in parsing code that is being actively edited and may contain errors.

πŸ’‘Query Engine

The query engine is a powerful feature of Treesitter that allows users to ask questions about the syntax tree generated from the code. The script explains that this engine is used to retrieve specific information from the tree, enabling advanced code analysis and editor features.

πŸ’‘Syntax Tree

A syntax tree, also known as an Abstract Syntax Tree (AST) or Concrete Syntax Tree (CST), is a hierarchical representation of the code's structure. The script discusses how Treesitter generates this tree and how it can be queried to understand and interact with the code more deeply.

πŸ’‘Grammar

In the context of Treesitter, a grammar is a set of rules that define the structure of a programming language. The script mentions that users can write a grammar for Treesitter to generate a parser for that specific language, which is then used for parsing code files.

πŸ’‘Highlighting

Highlighting in the script refers to the editor's ability to visually distinguish different elements of the code, such as functions or integers, based on the syntax tree generated by Treesitter. This feature enhances code readability and understanding.

πŸ’‘Embedding

Embedding in the script refers to the process of integrating Treesitter into various code editors, such as Neovim or Helix, to power features like syntax highlighting and error recovery. It demonstrates Treesitter's versatility and adoption across different editor platforms.

πŸ’‘Foreign Function Interface (FFI)

FFI is a mechanism that allows a program written in one language to call functions written in another language. The script mentions FFI in the context of Treesitter's C-generated parsers being easily embedded into applications written in various programming languages.

πŸ’‘Capture Groups

Capture groups in the script are used in the context of queries to specify particular parts of the syntax tree that should be selected or highlighted. They are essential for creating meaningful queries that can be used to power editor features like highlighting or structural editing.

Highlights

Treesitter demystifies the process of understanding code within an editor by focusing on quick, incremental feedback from a single file.

Treesitter is distinct from LSP (Language Server Protocol), which provides semantic understanding of a whole project rather than individual files.

Treesitter operates as a parser generator tool, allowing users to write a grammar that is transformed into a parser for specific applications.

The parsers created by Treesitter come with incremental and error recovering features, enhancing the parsing process without additional coding.

A powerful aspect of Treesitter is its query engine, enabling users to ask complex questions about the syntax tree generated from the text.

Treesitter is integrated into various editors like Neovim, Helix, and Zed, enhancing their capabilities for code understanding and manipulation.

Incremental parsing by Treesitter ensures that the structure of the text is recomputed efficiently with each keystroke, optimizing performance.

Error recovery in Treesitter allows for continuous parsing even when the code is incomplete or contains errors, maintaining functionality.

Queries in Treesitter enable editors to retrieve information from the syntax tree, facilitating features like highlighting and code analysis.

Grammars for Treesitter are written in a JavaScript-like DSL, which are then compiled into C files for efficient embedding in applications.

The use of C for Treesitter's parser generation ensures minimal dependencies and broad compatibility with various development environments.

Treesitter's grammars and parsers can be dynamically loaded at runtime, allowing for flexible language support without recompiling the editor.

A demonstration of Treesitter's query editor shows how to select and filter specific elements within a code file, such as binary expressions.

Treesitter's capabilities extend beyond simple text selection, allowing for complex queries that can identify patterns within code structures.

In Neovim, Treesitter powers features like syntax highlighting, which can be customized based on user-defined queries and captures.

Treesitter enables advanced editor features such as structural editing, code folding, and navigation, all based on the syntax tree.

Beyond editors, Treesitter can be used for code analysis and linting tools across multiple languages due to its extensive grammar support.

Treesitter's focus on the current file's syntax tree allows developers to build applications on top of it for various practical coding solutions.

Transcripts

play00:00

treesitter before but you may not

play00:02

understand how it works and the whole

play00:04

process seems somewhat mystical and

play00:07

confusing and interlaced with a lot of

play00:09

different tooling that might exist

play00:10

inside your editor but today I hope that

play00:13

I can demystify that for you and show a

play00:15

few pertinent examples that really give

play00:18

a basis for understanding the power of

play00:20

what Tre sitter brings to the table but

play00:23

before we go any further we need to stop

play00:25

and if you're thinking wow I'm finally

play00:27

going to understand more stuff about LSP

play00:30

you're in the wrong video I did that

play00:32

video already in fact tritter and LSP

play00:35

are unrelated LSP is focused on

play00:38

understanding your code at a semantic

play00:40

level and what I mean by that is it

play00:42

doesn't just look at the current file

play00:44

that you're editing or even the current

play00:45

directory but it trying to understand

play00:47

your whole project it's trying to

play00:49

understand the packages that you've

play00:50

installed and everything else along

play00:52

those lines and provide definitions and

play00:55

references and completions that are

play00:58

accurate that's not the purpose of of

play01:00

treesitter treesitter is focused on one

play01:02

file at a time and getting quick and

play01:05

incremental feedback back from that file

play01:08

so along that line as well treesitter is

play01:10

not a compiler it doesn't know about the

play01:13

types it doesn't know about the pack it

play01:15

it knows nothing about the rest of those

play01:17

aspects of your project it only knows

play01:20

about the text and beyond that as well

play01:23

sometimes people sort of get this in

play01:24

their mind that tritter is like doing or

play01:26

running other things no it's not an

play01:28

interpreter it's just a library for

play01:31

interacting with this text so what is

play01:34

treesitter then the first aspect of

play01:36

treesitter is that it's a parser

play01:38

generator tool which means you have the

play01:40

ability to write a grammar and that

play01:42

grammar will be able to be transformed

play01:44

into a parser that parser is then loaded

play01:47

up by whatever application is embedding

play01:50

treesitter and then used inside of that

play01:54

application beyond that the parsers

play01:56

though automatically get this

play01:58

incremental and error recovering part of

play02:01

the grammar you don't have to write that

play02:03

extra as part of the grammar making

play02:05

process instead you get that for free

play02:08

which is generally quite difficult to do

play02:10

when you're writing a parsing library

play02:13

for a particular language and then

play02:15

lastly and probably the most powerful

play02:17

part of the whole thing is the query

play02:20

engine and in short what the query

play02:23

engine does is part of this idea of what

play02:25

tree sitter is as this framework of

play02:26

generating a syntax tree or sometimes

play02:29

called an AS or CST and then allowing

play02:31

you to use queries to ask questions

play02:35

about that tree that's sort of the high

play02:37

level thing that you need to keep in

play02:39

your mind as you're understanding

play02:40

treesitter it just cares about text

play02:44

right and it helps us get a tree from

play02:46

that text and then ask questions about

play02:49

that

play02:50

text so why tree sitter in an editor

play02:53

well you might actually already be using

play02:55

treesitter you don't know it's inside

play02:56

neovim or helix or Zed or emac and and

play02:59

some other editors as well and so why

play03:01

are all of these editors adopting

play03:03

treesitter as sort of this underlying

play03:05

library to power a bunch of different

play03:07

aspects well there's three main things

play03:10

the first one is the incremental aspect

play03:12

that I mentioned before generally when

play03:14

you're editing text you're not

play03:16

completely deleting the file and

play03:18

rewriting it on every keystroke usually

play03:20

you're adding just one or two more

play03:23

characters to the file at a time and

play03:25

what you'd like to do is you'd like the

play03:27

thing that understands the structure of

play03:29

the text to not have to recompute the

play03:32

entire tree every time you type so

play03:35

that's the incremental aspect of

play03:37

treesitter the second aspect that's

play03:39

really important is related to error

play03:42

recovery the error recovery isn't just

play03:44

about your code being broken because you

play03:46

wrote it I mean that's somewhat of a

play03:48

given the error recovery we're talking

play03:50

about here is that as you're writing a

play03:54

particular line of code it's broken all

play03:57

the way until you type the last

play03:59

semicolon or close the parentheses or

play04:02

close the end of your list right it's

play04:04

broken all the way until you're done

play04:07

editing well what would kind of suck is

play04:09

as you're typing and editing treesitter

play04:12

just says oh there's an error in the

play04:14

file I can't parse it I'm not going to

play04:16

do anything that would be really bad

play04:18

instead what treesitter does is it tries

play04:21

its best to find the minimal amount of

play04:23

error and then enclose that there and

play04:26

the rest of your file still stays well

play04:28

highlighted and working well and then

play04:31

the third and final part that's very

play04:33

important is queries and queries that's

play04:36

the part where we're able to ask

play04:38

questions to the tree and retrieve that

play04:41

information out which allows your editor

play04:43

or other application to do useful work

play04:47

with the knowledge that's in your syntax

play04:50

tree so how does this happen right we

play04:52

got to start at the beginning we have to

play04:54

write our grammar so we write a grammar

play04:57

in JavaScript and I put quotes here not

play05:00

because you know JavaScript isn't a

play05:02

language although you know an

play05:04

alternative timeline where that was the

play05:06

case would be kind of interesting no

play05:09

because what this actually is is it's

play05:11

really a JavaScript like DSL it takes

play05:14

the JavaScript and then generates a

play05:17

parser do C file based on that

play05:20

Javascript file and that happens through

play05:22

the treit or cly so you run a command

play05:24

and you take your grammar. JS and out

play05:27

comes a parser do c in fact the

play05:29

structure looks something like this

play05:30

where there's a couple Json files with

play05:32

metadata a parser doc sometimes a

play05:35

scanner. c if you had to write custom C

play05:37

code and then the parser Doh file to

play05:39

include so you're probably wondering

play05:42

whyc isn't that like outdated and

play05:45

illegal now well yes but sometimes

play05:47

projects still can use it for a good

play05:49

reason what's really nice about this is

play05:52

the only dependency you have for these

play05:54

files is a c compiler which is really

play05:57

good most places where you're building

play05:59

and using an editor have a c compiler

play06:02

available beyond that as well there's a

play06:05

really good ffi for those who don't know

play06:07

foreign function interface story with C

play06:10

for lots of different languages and what

play06:12

this means is that it's very easy to

play06:14

embed treeit inside of another language

play06:18

and directly access those bindings

play06:20

efficiently so you don't have to

play06:22

serialize everything and send it over

play06:25

some multiple different processes you

play06:27

can actually include it wholesale inside

play06:29

of your application this makes it really

play06:32

fast and really powerful as well as

play06:35

being very very portable right like I

play06:37

said if you have an editor being built

play06:40

you probably have a c compiler somewhere

play06:42

this makes it really easy to use tree

play06:44

sitter whever you're building your

play06:47

project but okay so that's what we have

play06:50

so once you've done the tree sitter clly

play06:52

and you've generated this parser doc you

play06:54

can tell whatever C compiler you like

play06:56

using hey can you please compile this

play06:59

for me

play06:59

and and sure enough it'll work just fine

play07:02

and you get out this parser doso or

play07:05

whatever file you called it and now with

play07:08

this shared Library we can load this

play07:11

into the tree sitter runtime if you will

play07:15

as part of the application that is using

play07:17

treesitter so if you're not super

play07:20

familiar with shared libraries or you

play07:21

don't know that that's okay right but

play07:23

basically what I'm saying is you can

play07:25

kind of take this later and load it

play07:26

almost like a plugin okay right you can

play07:28

take another grammar of another language

play07:31

you can load it up you can link it and

play07:33

you can use that at runtime very very

play07:35

powerful to be able to easily add or

play07:38

remove or update languages without

play07:40

recompiling your whole editor or getting

play07:42

an editor update or anything like

play07:45

that so before we do a little bit of

play07:48

exploring I do have to warn you I know

play07:49

some of you are like allergic to lisp

play07:52

code and I would say uh you're probably

play07:54

just wrong scheme's pretty cool I I know

play07:57

all the list fans are going to comment

play07:58

right now and agree with me but just as

play08:01

a warning that's what's coming up so

play08:04

let's take a quick look at a small

play08:05

example go file what we have here on the

play08:08

left of the screen is a small go file

play08:10

that just has a few expressions and some

play08:12

other stuff going on and what we have on

play08:13

the right is our tree this tree is

play08:17

generated by tree sitter okay and you

play08:20

can see that if we were to click around

play08:22

inside here when I click to a function

play08:24

declaration the entire function

play08:26

declaration is highlighted if I click on

play08:28

the identifier just the identifier of

play08:31

that function is highlighted if I click

play08:33

on the parameter list that's highlighted

play08:35

although there's no parameters in there

play08:36

right now and then I have the block

play08:38

inside as well and treeit sitter is what

play08:41

is giving us this tree okay and neovim

play08:44

knows what the tree looks like and can

play08:46

interact with it and then print this out

play08:48

for us for easy viewing and some sort of

play08:50

debugging but this is where the power

play08:53

starts to be shown what we have here now

play08:57

is the query editor and this will be

play08:58

something something that I think you'll

play09:00

be able to pick up as we go even if

play09:01

you're not super familiar with lisp so

play09:04

what we have here is let's say select

play09:05

something like an integer literal and I

play09:08

want to say that this looks like an

play09:09

integer you see that the only two things

play09:11

that are highlighted in the whole file

play09:13

are the integers we could do the same

play09:15

thing for something like an interpreted

play09:17

string literal we can call that a string

play09:20

and you'll see just the two strings are

play09:23

highlighted but that part is impressive

play09:26

but not incredible where it starts

play09:28

becoming really powerful is our ability

play09:31

to ask more complicated queries to the

play09:34

tree so for example let's say we were

play09:36

looking for all the binary expressions

play09:39

like this so you'll see we have two

play09:41

binary Expressions which in this case

play09:42

just means binary two right expression

play09:45

so that's like a left thing and a right

play09:47

thing and we're adding them together but

play09:49

we can actually ask something more

play09:51

interesting than this we can ask

play09:52

something like what about what is on the

play09:55

left side of this here and let's say we

play09:57

just say I want this to be called called

play09:59

a node well now we see we've only

play10:01

selected the left side of the binary

play10:04

expression but we can even filter this

play10:06

down more we can use the same sort of

play10:09

idea that we had here before of

play10:11

selecting strings and we can say okay

play10:13

well I want to find all the strings that

play10:15

are on the left side of a binary

play10:17

expression and we can do that just like

play10:20

this now this would

play10:23

be anywhere from very difficult to

play10:26

Impossible with Rex right I know I have

play10:28

some HTML parsing redx enjoyers in the

play10:31

audience but but this is very very

play10:35

simple and easy to do now that we're

play10:37

able to interact with the code as a tree

play10:41

okay so that's the basics of queries but

play10:43

what do we actually do with the queries

play10:45

what what is neovim going to do with the

play10:47

responses and the captures that we've

play10:49

been getting let's take a quick look if

play10:52

we go to go highlights here you can see

play10:55

that if I am going to select this file

play10:58

here this is is basically the file that

play11:00

powers the highlighting for go inside of

play11:03

neovim and if what I do is I say I

play11:05

actually want to say that int literals

play11:08

should be highlighted instead like a

play11:10

function when I save this file and

play11:12

re-edit you'll notice the changing for

play11:14

the integers changed from integer to

play11:18

function but if we do something instead

play11:21

like we say we want it to be a buil-in

play11:23

function and we open this again my

play11:25

built-in functions are highlighted

play11:26

purple and

play11:27

bold so the important bit to understand

play11:31

here is that this part of the query this

play11:34

aspect of the query the capture group

play11:36

and the name neovim is sort of providing

play11:39

meaning to these captures so we have

play11:41

different grammars which turn into

play11:43

different parsers we have to write

play11:45

multiple different queries but as long

play11:47

as those queries return the same

play11:49

captures we can use those to power

play11:53

things like

play11:57

highlighting so what is it used for in

play12:00

an Eder I just gave you an example of

play12:01

how you could do highlighting it doesn't

play12:03

just do the highlighting it can also

play12:04

manage things like finding where to

play12:06

embed other languages inside right if

play12:09

you're writing HTML and you enter a

play12:11

script tag it should embed JavaScript it

play12:14

also can do things like indenting you

play12:16

can do structural editing if you're not

play12:18

familiar with that that's things like

play12:20

being able to say daf in neovim and go

play12:22

delete around function you could select

play12:26

a particular scope or you could tell

play12:28

your editor to switch to parameters all

play12:31

of those can then instead of being

play12:32

powered by rex or best guess you can

play12:36

actually edit the tree or select from

play12:39

the tree directly which is really

play12:41

powerful and powered just by those

play12:43

queries right you would have a separate

play12:45

query to tell you which things are text

play12:47

objects you would have a separate query

play12:49

to tell you about selections you could

play12:50

do all of those different things they're

play12:53

all powered by the same mechanism of

play12:55

writing queries with a particular set of

play13:00

captures you could do things like tell

play13:02

you if you're inside of a class or

play13:03

inside of a function you can fold based

play13:06

on where functions start a lot of these

play13:09

things before were all powered just by

play13:11

reg X's or best guess efforts or naming

play13:15

conventions whereas now when you use

play13:16

tree sitter you can actually ask those

play13:18

questions of the tree itself which is

play13:22

really powerful beyond that you can use

play13:24

Tre sitter outside of editors because of

play13:27

the wide adoption that treit has been

play13:29

getting there are grammars for many many

play13:31

many different languages which lets you

play13:34

write tooling around code analysis or

play13:36

linting or highlighting because the

play13:39

grammars already exist which means you

play13:41

already have parsers for all the

play13:42

languages so you can just make up your

play13:44

own set of queries and captures and do

play13:46

something like I want to find where all

play13:49

of the Imports are in a particular file

play13:52

okay well you use the Imports you write

play13:55

a query for that and then you build this

play13:57

framework the same way that neovim is a

play13:59

framework around tree sitter and

play14:01

highlighting you could do the same thing

play14:03

for your own types of problems this is

play14:05

really great for writing stuff that you

play14:07

want to expand to a bunch of languages

play14:10

but you don't want to write a custom

play14:12

parser or custom runtime or a custom

play14:14

whatever in each of those

play14:17

languages and so that's really what tree

play14:19

sitter is about and I want to remind you

play14:20

the primary thing treesitter is dealing

play14:23

with is the code in your particular file

play14:27

that's all the information that it has

play14:28

has and it will give you a tree and let

play14:31

you ask questions of those trees but

play14:33

because we're software developers we can

play14:34

build things on top of that like

play14:36

highlighting or navigation or folding or

play14:40

whatever the particular application that

play14:41

you're looking to do but tree sitter is

play14:44

focused explicitly on that parser

play14:48

incremental compilation Air recovery and

play14:51

queries thanks everybody I hope you

play14:53

really like the video feel free to leave

play14:55

a like or subscribe or uh come hang out

play14:57

on Twitch with us bye every one

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Tree-sitterCode ParsingEditor ToolsIncremental FeedbackSyntax HighlightingLanguage GrammarError RecoveryQuery EngineCode NavigationDevelopment Tips