robrix / Madness

Recursive Descent Into Madness
MIT License
291 stars 17 forks source link

`literal` is too noisy/verbose #15

Closed robrix closed 9 years ago

robrix commented 9 years ago

You’re trying to write a simple, obvious parser for some simple syntax, and you end up with literal everywhere clouding everything:

literal("λ") ++ variable ++ literal(".") ++ term

range is similarly noisy, and since it fits into the same category as literal I think there might be a common solution.

%"λ" ++ variable ++ %"." ++ term

A prefix operator would be one solution. We could also add overloads for bare strings but I don’t think that will work as well:

"λ" ++ variable ++ "." ++ term

is cute, but going to run into trouble as soon as there’s any ++ defined over SequenceType.

% would apply equally well to ranges (I think):

let digits = %("0"..."9")
robrix commented 9 years ago

This isn’t going to be quite so easy. Given prefix & postfix operators on the same term, postfix is applied first, i.e. %"x"* = %("x"*) which won’t compile because there’s no postfix * function defined for String.