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

Add ebnf parser #3574

Closed
wants to merge 0 commits into from
Closed

Add ebnf parser #3574

wants to merge 0 commits into from

Conversation

RubixDev
Copy link
Contributor

@RubixDev RubixDev commented Oct 2, 2022

The parser is part of this repo under crates/tree-sitter-ebnf

@RubixDev
Copy link
Contributor Author

RubixDev commented Oct 4, 2022

I moved the parser to a separate repo, as it seems installation from monorepos is not supported.

@theHamsta
Copy link
Member

I moved the parser to a separate repo, as it seems installation from monorepos is not supported

It's supported. See vlang or tsx/typescript

@@ -0,0 +1,47 @@
;;;; Simple tokens ;;;;
(terminal) @string @grammar.terminal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI fails because @grammar is a undocumented new highlight type, There are a few possibilities to fix this:

  • Is @grammar needed for other languages? Then @grammar or better @grammar.punctuation should be documented in CONTRIBUTING.md and added to all languages where necessary
  • Is @grammar similar to a existing highlight group in CONTRIBUTING.md? Then, it should be changed to @XXX.grammar.nonterminal where XXXX is a documented capture. This way users will have a good default experience when their color scheme does not support @grammar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I called it @grammar and not @ebnf because there are other notations besides EBNF to express context-free grammars and they all have terminals and non-terminals, but instead of adding a new top-level @grammar I will now change them like this:

  • @grammar.terminal -> @string.grammar
  • @grammar.special -> @string.special.grammar
  • @grammar.nonterminal -> @variable.grammar

Let me know what you think of that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be ok. But I think your old @grammar categories were also ok, since they can be surely extended to other languages

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @grammar captures could also be used for ANTLR/Yacc/Bison/JFlex/CUP/etc. but none of them have TS grammars (that I know of) yet and I think existing captures can adequately describe all their tokens anyway.

Highlights can currently be customised with @string.ebnf and so on without needing a custom suffix.

@RubixDev
Copy link
Contributor Author

I moved the parser to a separate repo, as it seems installation from monorepos is not supported

It's supported. See vlang or tsx/typescript

Alright, thanks for the info, will move it back into the monorepo then

@theHamsta
Copy link
Member

Your EBNF files read nicely. Have you tried generating grammar.json nodes with it? It might be a good alternative to JS, an alternative frontend for tree-sitter CLI

@theHamsta
Copy link
Member

Ooops, closed by mistake. New PR: #3860

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

Successfully merging this pull request may close these issues.

None yet

3 participants