Having a tree-sitter parser for cppfront #1031
Replies: 5 comments 10 replies
-
Thanks! I've written this on the sister threads @gregmarr mentioned: Without rewriting the grammar, are there any blockers right now to mechanically generate EBNF/PEG/Tree-sitter from the |
Beta Was this translation helpful? Give feedback.
-
I started writing the parser and encountered this grammar
which is saying that some syntax like the following is valid
I know it's invalid, but it seems like the grammar is not very accurate also. |
Beta Was this translation helpful? Give feedback.
-
Thanks! Good question. The grammar is intentionally general, and I think it's as intended in this case. There are semantic rules that make some grammatical programs not valid. It could be that I'm using semantic restrictions for grammar subsetting more than in other languages. One reason for having all declarations be
I could restrict this case now, but it's possible I could want to allow that in the future, for example to have a metafunction that takes a type or namespace as a non-template parameter. If the goal is to write something like a syntax highlighter, I don't know of a reason to special-case this and restrict it arbitrarily? It can just highlight the general grammar attractively, and cppfront will reject some cases today if they're not yet legal. That also makes the syntax highlighter more future-proof as Cpp2 supports more uses of the general grammar. Does that help? |
Beta Was this translation helpful? Give feedback.
-
I wrote a tree-sitter here: https://github.com/tsoj/tree-sitter-cpp2 |
Beta Was this translation helpful? Give feedback.
-
For those who do not know, tree-sitter is a parser generator that is designed for highlighting code. Since cppfront's grammar is stable (discussion for numbered release is going on), I'd like to have a discussion regarding having a tree-sitter parser for cppfront (I'm planning to start it). I've tried to look but I don't think there is something like BNF specification for the syntax yet.
Beta Was this translation helpful? Give feedback.
All reactions