Open virtualritz opened 4 years ago
There may be other ways to tackle this, and I am not all that familiar with the notation, but the grammar is likely to be recursive, so you may end up with a nested token tree, then you could evaluate it, bottom up, through recursion, very loosely (and not real rust!)
eval(t) => if t is primitive then t, else apply t as an operator to eval(t.child)
Recursive evaluation is usually quite concise for prefix forms
-- Andy Philpotts
On Wed, Oct 7, 2020 at 12:31 PM Moritz Moeller notifications@github.com wrote:
For example, a grammar for Conway polyhedron notation https://en.wikipedia.org/wiki/Conway_polyhedron_notation requires reversing the order of symbols at the top level of the resulting token tree.
In this grammar the string mt3nD https://levskaya.github.io/polyhedronisme/?recipe=mt3nD will be executed back to front as:
Create a Dodecahedron needle truncate all vertices of degree 3 meta
Ideally I'd like to be able to just express this like so:
let token_tree = MyParser::parse(Rule:foo, input);for token in token_tree.reverse() { ... }
P.S.: kindly pardon me if this is already possible. I'm new to pest.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pest-parser/pest/issues/478, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABXP5RPRDN2MNC7XLKE5OF3SJSJUZANCNFSM4SHT6FUA .
For recursive evaluation I'd have to make a whole new API for the crate that executes the geometric operations. It uses the builder pattern which mirrors how people think about these operations.
What I currently do is simply this:
// Reverse notation and skip end-of-input token now at the beginning
// (EOI)
conway_notation_token_tree.rev().skip(1).for_each(|pair| {
let token = pair.clone().into_inner();
match pair.as_rule() {
...
}
}
But the result, token_tree
, cannot be used with pest_consume
, unless I miss something.
So I do all the consumption using my own code.
Implementation is public in polyhedron_ops::Polyhedron::try_from<&str>()
.
Source is here.
For example, a grammar for Conway polyhedron notation requires reversing the order of symbols at the top level of the resulting token tree.
In this grammar the string
mt3nD
will be executed back to front as:Ideally I'd like to be able to just express this like so:
P.S.: kindly pardon me if this is already possible. I'm new to
pest
.