(module (function_definition (identifier) # ← ここに関数名「sample_func」が含まれます (parameters) (block (expression_statement (call (identifier) (argument_list (string)))))) (expression_statement (call (identifier) (argument_list)))) ノードが色々取れましたが、「function_definition」が関数、その子である「identifier」が関数名を表すため、 function_definition == 子ノード ==> identifier となっている箇所を探索すれば抽出できます(関数ではあっても「lambda」など異なる場合もあります)。 今回は上記のようにTree-si
こちらはPostgreSQL Advent Calendar 2022 カレンダー2枚目・15日目の投稿となります。 前回は、@hmatsu47さんのSupabase で TCE(透過的列暗号化)を軽く試してみたでした。 はじめにこんにちは、フューチャーでアルバイトをしている齋藤です。以前は同社のインターンでSQLフォーマッタを作成していました(記事)。現在はインターン中に作成していたSQLフォーマッタをPostgreSQLの構文に対応させる作業に取り組んでいます。 このフォーマッタではSQLパーサにtree-sitter-sqlを利用していますが、対応していない構文がいくつか存在します。本記事では、未対応の構文であるBETWEEN述語を例に、tree-sitterの構文拡張の手順を紹介します。開発中のSQLフォーマッタはOSS公開予定ですので、ぜひ仲間を増やしたいという思いから記事にしま
This article was discussed on Hacker News. This is a continuation of my last post on how to write a tree-sitter grammar in an afternoon. Building on the grammar we wrote, now we’re going to write a linter for Imp, and it’s even easier! The final result clocks in less than 60 SLOC and can be found here. Recall that tree-sitter is an incremental parser generator. That is, you give it a description o
皆さん型書いてますか?私はそもそもRubyを書いていません! とはいえ、最近Kaigi on RailsやRubyWorldとカンファレンスが続いていたので、ちょっとやる気を出してrbsを書くためのエコシステムに貢献しようと思い、rbs用のtree-sitterパーサを書いてみました。パーサ流行ってますからね。 github.com READMEにしたがってnvim-treesitterでパーサをインストールし、このリポジトリをneovimプラグインとしてインストールすれば、rbsのシンタックスハイライトがイカした感じになります。 しかし、しかしながらですね、これ半年ぐらい前に調べた時には誰も書いてなかったんですが、8割ぐらい書いた所で、既に別のtree-sitter-rbsがあることに気付いたんですよね……。 github.com まあ、せっかく作ったんで完全に同じ車輪の再発明だろうが、
Vim 使いの「ブイ」(仮名)です。Vim のすゝめ改では、現代のテキストエディタについてのあらゆる話題をテーマに Vim の視点から見た話を行います。 今回のテーマは「Tree-sitter」です。 1 Tree-sitter とは? https://tree-sitter.github.io/tree-sitter/ Tree-sitter は Atom のシンタックスハイライトとしても使用されている技術であり、最近になって neovim にも Tree-sitter によるシンタックスハイライトが導入されました。 https://github.blog/2018-10-31-atoms-new-parsing-system/ https://github.com/neovim/neovim/pull/11113 従来、テキストエディタの汎用的なシンタックスハイライトには正規表現が使わ
Have you ever wanted to execute code from inside Zed? Run tests, or a linter, or the compiler, or maybe a script, or a shell one-liner? Watch: What you just saw was me using Zed Tasks to execute a Go test from inside Zed, passing the name of the current function to the go test command. Tasks, as a new feature, first landed in Zed all the way back in February, in v0.124.7. But since then they've be
Emacs 29以降の設定方法 Emacs 29以降の設定方法は こちら の記事で説明しています! Tree-sitterとは Tree-sitter自体はパーサ生成ツールと、かつそれを利用して作成された様々な言語のパーサのセットのようです。 Tree-sitterのパーサを利用することで高速かつ正確なシンタックスハイライトを適用することができます。 AtomではTree-sitterをベースにしたシンタックスハイライトシステムを使用しているようです。 emacsではELisp Tree-sitterというEmacs Lispバインディングパッケージを通じてシンタックスハイライトを適用できます。 Tree-sitterそのものについての解説は下記の記事がわかりやすかったです。 インストール インストール手順に則ってElisp Tree-sitterパッケージを追加します。 併せて、tree
Let’s Write a Tree-Sitter Major Mode Creating a standard programming major mode presents significant challenges, with the intricate tasks of establishing proper indentation and font highlighting being among the two hardest things to get right. It's painstaking work, and it'll quickly descend into a brawl between the font lock engine and your desire for correctness. Tree-sitter makes writing many m
はじめに 大量のファイルがあるコードベースの中から関数やクラスの定義を抽出できるとそれをLLMのコンテキストに埋め込んでコード生成や読解、ドキュメント生成などに利用できます。 この記事では、Tree-sitterを使用してPHPコードから関数定義を抽出する方法を紹介します。 Tree-sitterとは Tree-sitterは高速な構文解析ライブラリで、多くのプログラミング言語に対応しています。Zedなどの多くのモダンエディタでも採用されている技術です。 実装例 Tree-sitterは各言語から呼び出せるバインディングが用意されています。 以下のNode.jsスクリプトは、指定されたディレクトリ内のPHPファイルから関数とクラスの定義を抽出します: 使い方 必要なパッケージのインストール:
Yet another entry for tree-sitter. For those new here, I have blogged previously about using tree-sitter here and here. Here is another installment of how I use tree-sitter to simplify/speed up things for me. In this installment we are going to see how we can use tree-sitter to easily navigate around config files. When having to navigate through huge config files there are two problems that I usua
A few years ago I blogged about custom tree-sitter-based syntax highlighting in emacs. I started out with highlighting certain keywords in red. I wanted to show the keywords that interrupt control flow: Screenshot showing syntax highlighting of keywords in black or red I highlight regular keywords (while, if) in bold. I highlight control flow interrupting keywords (return, continue) in red. That's
Emacsでtsxを編集するときのいい設定がないなあないなあと思って、長年いろいろ模索 (typescript-mode に rjsx-minor-mode を併用して (define-derived-mode typescript-tsx-mode typescript-mode "TSX") して (typescript-tsx-mode-map ("<" . rjsx-electric-lt) (">" . rjsx-electric-gt)) したり)やっていたんですが、どうもインデントとかがおかしくなりがちでした。 ここにきて Emacs 29からならtree-sitterで設定できそう だとわかったのでメモします。 手順 まずmacOSでHomebrewを使っている場合は tree-sitter を次でインストールしておきます。
Tree-sitterというソフトウェアがある。CとRustメインで書かれているパーサジェネレータとそれをとりまくツールである。 tree-sitter.github.io これを利用して、コードをもとにシンタックスハイライトを効かせたHTMLを生成できたのでその紹介をする。 追記(2023-05-16T10:43+09:00) Tree-sitterのアーキテクチャ Rust製CLIツール 事前準備(CLIツール) 事前準備(文法) シンタックスハイライト HTMLに出力する(その1)(追記) HTMLに出力する(その2) まとめ あわせて読みたい 追記(2023-05-16T10:43+09:00) tree-sitter単体でもHTMLを出力できたのでその旨追記した。 Tree-sitterのアーキテクチャ Tree-sitterはコアとなるソフトウェアと、各言語ごとの文法ファイル、
I have added syntax highlighting to my blog using tree-sitter. Here are some notes about what I learned, with some complaining. static site generator markdown ingestion highlighting incompatible?! highlight names class names styling code results future work frontmatter templates feed style highlight quality static site generator I moved my blog to my own web site a few years ago. It is produced us
One of my favorite features in Neovim is the Tree-sitter integration. It allows for fast syntax highlighting that works well even in an error state (often the case when you’re editing code), and it has additional semantics (you can differentiate between function parameters and local variables). With nvim-treesitter-textobjects you can also jump between nodes (such as ]c to jump to next class) or t
Tree Sitter and the Complications of Parsing Languages I talk about tree sitter, CEDET, and Combobulate – my "paredit-style" package that's designed to work with most programming languages. You might be surprised to hear when you visit a file in Emacs that the syntax highlighting you are shown on your screen is – most likely – a potpourri of regular expressions with a dash of functions and syntax
How to Get Started with Tree-Sitter Emacs 29 introduces tree-sitter support, a powerful parsing library that enhances its understanding of source code. With this integration, Emacs gains features like precise syntax highlighting, accurate indentation and easier extensibility. Here's how you install and configure Emacs with tree-sitter support. I think it’s time to talk about how you can start usin
Press ← or → to navigate between chapters Press S or / to search in the book Press ? to show this help Press Esc to hide this help Using Parsers This guide covers the fundamental concepts of using Tree-sitter, which is applicable across all programming languages. Although we'll explore some C-specific details that are valuable for direct C API usage or creating new language bindings, the core conc
Combobulate: Structured Movement and Editing with Tree-Sitter Combobulate is a package that adds advanced structured editing and movement to many programming modes in Emacs. Here's how it works, and how it can enrich your editing experience in Emacs. About a year ago I released an alpha – prototype, really – version of a tool I call Combobulate. I’d been using it personally for a while before I le
This article was discussed on Hacker News. Every passing decade, it seems as if the task of implementing a new programming language becomes easier. Parser generators take the pain out of parsing, and can give us informative error messages. Expressive type systems in the host language let us pattern-match over a recursive syntax tree with ease, letting us know if we’ve forgotten a case. Property-ba
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く