unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Christian Johansson <christian@cvj.se>
Cc: "Eli Zaretskii" <eliz@gnu.org>,
	"Daniel Martín" <mardani29@yahoo.es>,
	monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re: New package emacs-parser-generator
Date: Mon, 29 Nov 2021 11:22:49 -0800	[thread overview]
Message-ID: <8ECC2C6B-9BB0-442F-98A5-39AB88E2AC12@gmail.com> (raw)
In-Reply-To: <B58DD8E6-5088-487E-934E-652D928493A1@cvj.se>

The tree-sitter integration doesn’t provide anything to define a grammar nor generating a parser. It merely uses pre-defined grammar (written by tree-sitter community) to parse buffers and produce an AST.

To write an tree-sitter grammar definition you need to write the grammar in JavaScript and pass it to tree-sitter’s parser generator. The generator spits out a grammar definition encoded in a C source file (in the form of a C struct). To use this grammar definition, we compile it to a library, load it at runtime, pass the struct to tree-sitter library, and tree-sitter can now parse according to this grammar definition.

The tree-sitter integration provides 1) Lisp wrappers for tree-sitter’s C API; 2) some convenient functions built on the C API; 3) integration with font-lock and indentation. I didn’t add any “common API”, I simply used existing frameworks in Emacs: for font-lock I used font-lock-fontify-region-function, for indent I used indent-line-function. If in the future a common API for parses is desirable, tree-sitter can easily comply.

IOW, this is what tree-sitter integration currently does:

font-lock                                indent
      |                                     |
font-lock-fontify-region-function        indent-line-function
      |                                     |
      |                                     |
tree-sitter-font-lock-fontify-region     tree-sitter-indent-function

This is what could happen if we want a common API:

font-lock                                indent
      |                                     |
font-lock-fontify-region-function        indent-line-function
      |                                     |
      |                                     |
     common  API  --------------------------+
     /         \
    /           \
   /             \
tree-sitter    other parser

Yuan


  reply	other threads:[~2021-11-29 19:22 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-27 21:40 New package emacs-parser-generator Christian Johansson
2021-11-28  7:01 ` Eli Zaretskii
2021-11-28  7:22   ` Christian Johansson
2021-11-28 13:24     ` Stefan Monnier
2021-11-28 13:45       ` Christian Johansson
2021-11-28 23:46         ` Daniel Martín
2021-11-29 12:30           ` Eli Zaretskii
2021-11-29 13:09             ` Christian Johansson
2021-11-29 19:22               ` Yuan Fu [this message]
2021-12-01  7:52                 ` Christian Johansson
2021-12-01  8:39                   ` Yuan Fu
2021-12-01  8:51                     ` Christian Johansson
2021-12-01 13:45                       ` Stefan Monnier
2021-12-01 14:10                         ` Christian Johansson
2021-12-01 19:25                       ` Yuan Fu
2021-12-01 19:44                         ` Christian Johansson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ECC2C6B-9BB0-442F-98A5-39AB88E2AC12@gmail.com \
    --to=casouri@gmail.com \
    --cc=christian@cvj.se \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=mardani29@yahoo.es \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).