Open 39555 opened 1 week ago
Well, the example is complete and all the features are there! I assume with #618 it would be the same. I may check it later.
@39555 I have to say, I am thoroughly impressed with the dedication you have put to this investigation, having
An example of the usage of the
Pratt
parser for parsing a weird cexpr.The result of the parsing is a nicely formatted ast and the expression in prefix notation.
1 + 2 + 3
:Parser Problems
[x] Parsing any complex postfix operator
a ? b : c
,foo()
,foo(1 + 2)
,a[1 + 2]
cannot be done without parsing it inside theoperand
parser (which means breaking the prefix precedence). Maybe the api should provide the input inside the operator closures.But I'm having strange lifetime troubles with it for nowEDIT: I made it by switching all callbacks to function pointers
fn() ->
. I had completely forgotten about it. Now the input is a first argument in closures.[x] Maybe closures should return an error instead of plain value to allow validation of the input e.g dereferencing the literal
1->foo
or handling unbalanced delimiter in complex postfixes.EDIT: all closures now return
PResult
. Looks quite ugly..[x] Concept of
neither
associativity.I don't know yet how it works but the parser could potentially reject.a == b == c
somehowEDIT: added
Assoc::Neither
and tests. This should fail:a == b == c
,a < b < c
.