pratt
pratt copied to clipboard
How to define a sequence?
I came across a special syntax where a space between two Primary expressions indicates a special connection.
For example:
"a" "b"
// equivalent to
"a" + "b"
In the current situation, two consecutive Primary expressions will cause the following expressions to disappear directly.
Is there any suitable patch hacking?
Hi, that is an interesting point. I will try to find a fix, it might require some additions to the API. This page gives some ideas about how to support the juxtaposition operator in a pratt parser. In our case, I think we need to modify the lbp
and led
to do something when encountering a prefix and nilfix (primary) expression.
@oovm do you possibly have an example grammar to test?
@segeljakt
I created a test case here, the content after juxtaposition will be discarded.
https://github.com/oovm/wolfram-parser/blob/1d848b9f763da50b5a3712d0a930a591ea3259c8/projects/wolfram-parser/tests/main.rs#L10-L41
This is the implementation part of pratt parser:
https://github.com/oovm/wolfram-parser/blob/1d848b9f763da50b5a3712d0a930a591ea3259c8/projects/wolfram-parser/src/parser/from_str/parse_expr/mod.rs#L22-L87
There is another problem.
In regular language, prefix +
and infix +
can be distinguished by this expression:
Expr : Term (Infix Term)*
Term : Prefix* Factor Suffix*
But in languages with juxtaposition, only expressions like this can be used
Expr :
| Prefix
| Infix
| Factor
| Suffix
At this time infix +
will be overwritten by prefix +
.
Is there any way to mark such polymorphic operators?
This problem also exists with the prefix !
(not) and the suffix !
(factorial).
eg: x^5!y
-> x^(5!)*y
In the lexer stage, I have no way of knowing whether the previous expression terminates.
Hi, I'm sorry for the late response. I am currently working towards a deadline so I haven't had time to take a look. I will return as soon as possible.