search: barebones frontend recursive descent parser (draft for comments)
Created by: rvantonder
This implements the barebones recursive descent parsing that ensures operator precedence. I am intentionally leaving out complexity to make this easier for feedback/comments. I don't have TypeScript savvy, I'm sure this can be improved and eager to get comments. It does closely model the initial Go PR.
Simplifying decisions I'm not addressing in this PR:
- Just
leaf
for arbitrary leaf nodes. This will be patterns/filters later. - No parens for grouping here
- A type for errors, but no real error handling
- No range info yet
- Assumes just single space for whitespace-separated tokens
There are some notable differences I'm thinking about wrt frontend parser and backend. E.g., in the Go PR it's very reasonable to normalize nested statements like:
a or b or c or d
=> (or a b c d)
. This is useful when evaluating nodes, no need for those additional or
s in that context. Note that this normalization is part and parcel of parsing in the Go parser (cf. reduce
) to avoid doing extra passes.
One frontend concern is highlighting, and so with the normalization above ^ we would effectively throw away any additional or
tokens, the output doesn't expose that information for highlighting the concrete syntax. The implication is, this is probably not a normalization we want to apply in the frontend in the interest of highlighting, since we'd like to communicate those or
tokens to Monaco.
Edit: to be clear, there are ways around this, expanding out or
infix tokens again, and so on. But it could get icky. So I'm still thinking about this, and the idea right now is to just deal with a parse tree that's close(r) to the original syntax.