Closed Axiomatic-Mind closed 1 year ago
Hey @Axiomatic-Mind ๐ as to your first question, whether parse_input
returns a list of parse trees or not is mostly up to your grammar, and things like grammars for programming languages usually shouldn't have ambiguous ways to interpret a sentence. But grammars for natural language can be full of ambiguities that can lead to multiple parse trees. My personal favorite example of the kind of sentence that would lead a parser like this to return multiple trees is "Time flies like an arrow". Where we're either talking about the concept of time moving quickly, or something more like a plot line from Doctor Who, i.e. "Time flies like an arrow. Fruit flies like a banana."
As to your second question, it's a great point! ParseTreeNode probably needs to be exposed!
Thanks! Embarrassingly, I was trying to get that information by calling format!(โ{:?}โ, foo)
on the output of the parse_input
function and using regular expressions to parse it. The lengths to which one will go!
Thanks so much for #106! I've published version 0.4.1 to crates.io now so you should be able to use your changes
Thanks for noticing this issue @Axiomatic-Mind ! totally just an oversight. And double thanks for opening a PR ๐
My pleasure๐
Why does
Grammar::parse_input
have a return type ofimpl Iterator<Item = ParseTree>
and not ofOption<ParseTree>
orResult<ParseTree, Error>
? Is there any circumstance in whichGrammar::parse_input
could parse to multipleParseTree
s?I know that I can access the data in a
ParseTree
by callingParseTree::rhs_iter
to get something of typeParseTreeIter
, which implementsIterator<Item = &ParseTreeNode>
. I can then iterate through this to get items of type&ParseTreeNode
, but how can I get the data out from this?src/lib.rs
only publicly exportsGrammar
andParseTree
fromsrc/grammar.rs
, and I cannot construct the variants of the externally privateParseTreeNode
necessary to matchParseTreeNode
s and access the data stored within.