You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Clojure
Hi all,
I was hoping that I can call
(instaparse.core/parser "my ::= 'ebnf' | 'grammar' ")
to get a parse tree of the EBNF. I'd like to convert the EBNF to a tree-sitter grammar.js.
But when I evaluate the above expression, I only see a the original EBNF input, reformatted, and without comments:
=> my = "ebnf" | "grammar"
Is there a way to get hands on the underlying structure, i.e. the parse tree?
Best, Jakob
D. Ben Knoble
unread,
Jul 17, 2021, 8:50:48 PM7/17/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Clojure
I haven't touched Clojure in a year or two, and I'm not familiar with instaparse.
I can say, from a terminology stand-point, that a grammar (such as one in EBNF) can produce a parser, which then produces parse-trees of input strings. So, perhaps you mean that you want parse-trees of strings in the grammar of EBNF? It took me a few reads to come to this conclusion—the expression "get a parse tree of the EBNF" threw me off.
It seems likely that instaparse is producing a parser, and may throw away the underlying graph (parse-tree) of the grammar.
Regardless, I have a Scala tool that parses EBNF. I'm not sure about interop, but it's all JVM, right? https://github.com/benknoble/loner
D. Ben Knoble
unread,
Jul 17, 2021, 8:52:02 PM7/17/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Clojure
Thanks Ben, you understood me correctly.
Your tool loner parses a dialect of EBNF and gives me the parse tree of that EBNF grammar file in a scala representation, as I see at your demo page. That is exactly what I need – however, instaparse has a slightly different dialect of EBNF.
I was hoping that the instaparse parser internally holds the EBNF representation but I don't know how I can see or check that. Maybe your guess is right and it throws away the parse tree... I probably have to look into the source code of instaparse... Or I transform our EBNF to match your specification and use loner...
D. Ben Knoble
unread,
Jul 18, 2021, 12:37:38 PM7/18/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to clo...@googlegroups.com
You may also be able to write an instaparse grammar for EBNF (a
grammar of grammars)—Loner contains a parser-combinator-style EBNF
parser, so it's certainly do-able.
Then you could use that parser to parse your grammar—presumably the
parsers yield trees on input-strings.
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Clojure
ben schrieb am Sonntag, 18. Juli 2021 um 18:37:38 UTC+2:
You may also be able to write an instaparse grammar for EBNF (a
grammar of grammars)—Loner contains a parser-combinator-style EBNF
parser, so it's certainly do-able.
Sure, that would work but instaparse itself already parses EBNF, so it would be kind of duplicate work.