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

unify grammars #1

Open
FreddieGilbraith opened this issue Mar 7, 2025 · 6 comments
Open

unify grammars #1

FreddieGilbraith opened this issue Mar 7, 2025 · 6 comments

Comments

@FreddieGilbraith
Copy link

Looks like great minds think alike! https://github.com/little-bonsai/tree-sitter-ink

I've been working on this as well for the last few months. It would be great if we could find a way to unify into a single grammar, that we could perhaps donate to the inkle github org? I think there are strengths to both our approaches (you have better support for identifiers in weave labels and better highlighting; I think my grammar has more in-depth handling of code sections), so it would be good to preserve work from both.

Let me know if you'd be interested in coming together on this :)

@rhizoome
Copy link
Owner

rhizoome commented Mar 7, 2025

This is very interesting. First, I want to emphasize that any differences I point out are not meant as value judgements. My parser grew very organically from a few priorities I chose, but I could have chosen differently. I treated building the parser like coloring mandalas. I choose colors and let my choices guide me. Here are some of the choices I made:

  • Think of Ink as a line-based language, similar to Python.
    • Therefore scanner.c identifies line start and line end.
    • This has the nice side effect that parse errors are always recovered after "\n".
  • Try very hard to avoid conflicts, use scanner.c to resolve conflicts.
  • If it is not about conflicts, try to have a minimal scanner.c.
  • Have full unicode support with minimal unicode knowledge in scanner.c, so scanner.c only knows unicode whitespaces.
  • Prioritize features that are important for highlighting and an auto-completion language server.
    • It knows all about knots, knits, stitches and diversions, so we can autocomplete them.
    • It has a production for "vocabulary", so we can autocomplete vocabulary like inky does.
    • Make the parsing more flexible than the ink language, so we can do lints in the language server.

In particular, treating ink as a line-based language leads to a very different approach. It seems you needed more complexity in scanner.c, while my grammer.js is much more verbose and repetitive. Also I haven't bothered to build the complete grammar.

It seems you found out about this project when you wanted to submit the highlighting to Helix, which must be frustrating. I am really sorry about that.

I suppose it is the same for you, once you have built a piece of software in a certain way, you start to like it. Mainly because you understand what you have built and it is difficult to understand someone else's thought process. So what can we do? Some ideas:

  • Design a new parser that takes the best of both projects
  • Work on the language server together, I have only very minimal rust code at the moment

I see you also worked on LSPs in rust, so that might be interesting. Just so you know, if we can't find a way to work together and your project turns out to be better maintained than mine, I won't stand in the way of switching Helix to yours.

I’d really like to collaborate on software, though I’ve mostly either worked alone or contributed small changes to larger projects. Maybe this could be an opportunity? What do you think? And what are the design principles of your parser?

@FreddieGilbraith
Copy link
Author

FreddieGilbraith commented Mar 12, 2025

Thank you for your polite and thoughtful response!

I treated building the parser like coloring mandalas. I choose colors and let my choices guide me.

What a wonderful philosophy!

My approach when building the grammar was to go through in ink tutorial in order, and add new language constructs as they appeared in the tutorial. I hoped that this would lead to a grammar that was structured to prioritise language features in order of importance, as more important features would be introduced first.

I also wanted to avoid having a complex scanner, but eventually realised it was impossible to correctly parse ink with only a context-free-grammar.

Prompted by some of the points you’ve made, I’ve made some major simplifications and improvements to my grammar & scanner. I have also added you as a contributor, and would love to hear any further ideas you might have for improvements. I know there are still a few things in TheIntercept that cause parsing errors, so there’s still more work to be done.

Regarding LSPs, my main priority at the moment is to write an LSP that supports spell-checking, as my spelling is very poor, but I would also be interested in working with you on a LSP that uses Treesitter to parse and analyse ink projects.

Let me know what you think about all the above, and I’m looking forward to working with you :)

@rhizoome
Copy link
Owner

rhizoome commented Mar 13, 2025 via email

@rhizoome
Copy link
Owner

rhizoome commented Apr 3, 2025

@FreddieGilbraith we are getting built-in word-completion in helix: helix-editor/helix#13206, the contributor usually gets things done. :-)

@FreddieGilbraith
Copy link
Author

Sorry it's taken me so long to reply. I don't have a lot of time for open source stuff at the moment as I've just had my first child. For that reason I probably don't have enough time for a discord call or similar, but would like to continue working with you when I get time :)

@rhizoome
Copy link
Owner

rhizoome commented Apr 8, 2025

Congratulations! It is a beautiful and sometimes bumpy journey to support a new life in this world. I may be spending a lot of time on open source over the next months. So if you think: "Let's fix some errors in tree-sitter-ink to get a change from changing diapers." - just ping me and I might spontaneously find the time.

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

No branches or pull requests

2 participants