Code Monkey home page Code Monkey logo

Comments (11)

ayushnix avatar ayushnix commented on June 16, 2024 1

I'd like to point out that this treesitter repository for commonmark is now recommended for use over the repository linked before.

from djot.

ayushnix avatar ayushnix commented on June 16, 2024 1

This would be 100% accurate (but not incremental, which might be an issue on large files).

One of the reasons I'm really interested in djot is because editing CommonMark documents becomes a pain when the documents become fairly large. It'd be awesome if editing djot documents doesn't feel that way as well. 😅

from djot.

jgm avatar jgm commented on June 16, 2024

I don't know anything about tree-sitter, but this would be a great project for someone who does.

from djot.

jgm avatar jgm commented on June 16, 2024

Made a start on this in the tree-sitter directory.

from djot.

jgm avatar jgm commented on June 16, 2024

OK, it looks like we'd need to define some external scanners to make this work, since the regexes tree-sitter allows don't include any assertions. (We won't be able to distinguish open- and close-emph delimiters, for example.) But tree-sitter does allow you to define external scanners in C, so maybe we could do this.

from djot.

jgm avatar jgm commented on June 16, 2024

https://tree-sitter.github.io/tree-sitter/creating-parsers#external-scanners

from djot.

jgm avatar jgm commented on June 16, 2024

Oh, thanks, that one is much easier to understand!

from djot.

jgm avatar jgm commented on June 16, 2024

An interesting option for nvim would be to use the djot lua library itself to do the lexing, and call https://neovim.io/doc/user/api.html#nvim_buf_add_highlight()
directly to add the highlighting. (nvim has a Lua api.)
This would be 100% accurate (but not incremental, which might be an issue on large files).

from djot.

jgm avatar jgm commented on June 16, 2024

That function wants to have (line, column) locations, but column is byte indexed. We could convert our current byte offsets to (line, column-byte) pairs by counting newlines. Perhaps we should change the Lua library so that it can efficiently produce this output as well as absolute byte offsets.

from djot.

jgm avatar jgm commented on June 16, 2024

Interesting. Well, we could try the thing I suggest above and see how it works. The parser is very fast, so maybe it will be okay. It would require a few changes in the Lua library, but then it should be fairly straightforward.

from djot.

prncss-xyz avatar prncss-xyz commented on June 16, 2024

While using the lua engine directly might be a good solution for highlighting, having a treesitter grammar has other advantages. In neovim, treesitter is also used for editing (selecting, deleting etc.) and navigation. Basically, as a common language abstraction, it makes integration between arbitrary plugins and arbitrary languages easier, resulting in a more homogeneous/higher level experience. So that would be a pro for a treesitter solution. Also, treesitter is supported by many editors (emerging ones like helix and zed), while a lua solution would need some integration code for each editor. (Pretty excited by the future of djot btw.)

from djot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.