lydell / frappe

JavaScript with some nice fluff on top of it.
7 stars 1 forks source link

Token disabiguation regarding short arrow syntax #4

Closed forivall closed 8 years ago

forivall commented 8 years ago

Since | is already used for bitwise operators, it would be tough for the parser to figure out if it's reading a list of arguments or a bitwise OR. There are two possible solutions for this:

  1. Use the same mechanism used by regular expressions. (I don't fully understand it, but it's implemented in a number of parsers). Basically, this figures out if the previous token would allow a binary operator as the next token, and then act accordingly.
  2. Use a different character or set of characters
    • It's your language, so I don't know what kind of feel you would want. I would go with |>x> x*x or ||x>x*x (the second one makes sense if you wanted a plugin for my project, which is completely replacing || with or)
lydell commented 8 years ago

If an expression is followed by a pipe, treat the pipe as the bitwise operator no matter what. Wouldn't that work?

forivall commented 8 years ago

Yup, that's what regexp parsing does. I actually only remembered about regexp parsing when I started writing this issue, but it's still worthwhile to document somewhere.

lydell commented 8 years ago

@forivall FYI, I decided to change |> into #> (which looks more like => and shouldn’t be as ambigous).

lydell commented 8 years ago

FYI, I changed it again to a syntax inspired by Elm: \=>, \arg =>, \{a, b} =>.