Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace RegEx based syntax with external AST parser #300

Open
3 tasks
alerque opened this issue Oct 29, 2019 · 4 comments
Open
3 tasks

Replace RegEx based syntax with external AST parser #300

alerque opened this issue Oct 29, 2019 · 4 comments

Comments

@alerque
Copy link
Member

alerque commented Oct 29, 2019

We keep mentioning this in various places, but apparently we don't have an issue to track it. Lets try to collect links to relevant tools and discussions to help move towards a syntax highlighter that actually understands Markdown instead of trying to fudge with Regular Expressions.

  1. Neovim has an API for quickly replacing lots of highlights via an asynchronous background job. To date I don't think VIM has anything on par with this feature. Are we okay with a Neovim only improvement? Personally I'm okay with this because I exclusively use Neovim anyway. Since this might be a lot easier to implement with direct API access and VIM support could be added later, I'm totaly okay with putting my own time into Neovim only features. Of course the RegEx could be a fall-back, I wouldn't neuter the plugin for VIM users, only have a less nice set of features.

  2. What, if any, plugin language should we use? Pure VimL might be ideal, but I am not as comfortable with it as Lua or Python, and it's likely much slower. Personally I think if we can make this work in Lua that should be our way forward.

  3. What external parser should be actually use? Ideally this would be Pandoc of course, but it does not currently provide position information in its AST. Until this is implemented or CommonMark-hs is up to speed I don't think we have a practical way forward. I'm not enough of a Haskell ninja to even help on CommonMark yet. The best Lua based Markdown parser I know of is LuaMark (from the same author as Pandoc). Another option might be a filter that takes the Pandoc AST and walks it against the source to inject position information.

With those decisions made, here is a running to-do list of things I think we need to get there:

  • Add a feature flag to toggle the new syntax highlighter so people can use the RegEx ones either by preference or because they don't have the tools. Note this will also make development easier as we can start hacking on it without an expectation of it working yet.
  • Figure out the basic tooling for getting an external AST with source data injected into the syntax highlight system.
  • ...
@alerque
Copy link
Member Author

alerque commented Oct 29, 2019

Other related references:

@fmoralesc
Copy link
Member

Just some quick thoughts:

  • I think creating an nvim only implementation of this might be the best shot, although vim 8 probably could do something similar also (I also use neovim exclusively, so that's my bias). I think the upcoming extended marks feature could be useful for this purpose as well. I had been waiting for this to look more into this problem.
  • I am more comfortable in python than in lua, but both languages would be fine to move forward.
  • If we plan to do this incrementally, we could start by creating a custom parser to detect blocks first (that could be reused by vim-pandoc for autoformatting already). We could then generalize it in a way that could be used for sile and other things as well.

Obviously, the ideal solution would be to use pandoc's full AST, but the metadata we need is still missing.

@alerque
Copy link
Member Author

alerque commented May 12, 2020

It looks like the tree-sitter branch still waiting merge into Neovim is what will largely enable this possibility on the editor side. See [https://github.com/neovim/neovim/issues/1767]. Of course we still need the other side of that too, but it does look like it is key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants