jesopo / scpl

simple compact pattern language
MIT License
1 stars 0 forks source link

regex unary heuristic doesn't account for parenthesis #1

Open jesopo opened 2 years ago

jesopo commented 2 years ago
✨ ~/src/jess/scpl main % python3 -m scpl.parser "(/a/)"
tokens  : [Parenthesis((), Operator(/), Word(a), Operator(/), Parenthesis())]

(/a/)
 ^
parse error: invalid unary operator
jesopo commented 2 years ago

I feel like a better way to do this is to have a unary operator token that does the heuristics and then introduce a way for a token to say "scrap all other unfinished tokens" so it takes priority. that way only the unary operator token needs to know what a unary operator is and the unfinished regex token will just fall away

jesopo commented 2 years ago

additional to the above, we could use that same priority system to prevent this

✨ ~/src/jess/scpl main % python3 -m scpl.parser ".1 + .1"
tokens  : [Regex(.1 + .), Number(1)]

.1 + .1
      ^
parse error: missing operator

the gist of it being that a regex shouldn't know what its delimiters can't be because that list will get very long, but other tokens should be able to know what they individually get priority over