saem / vscode-nim

Other
180 stars 23 forks source link

handle `of` as a binary keyword #92

Open morganholly opened 2 years ago

morganholly commented 2 years ago

only match of as a control keyword if it is not in an if/elif/when and is followed by a colon. additionally reorder keyword.control.nim match|multiple|strings to be (hopefully) alphabetical order

see #91, #90, #86

morganholly commented 2 years ago
image
morganholly commented 2 years ago

ok added a small change. this doesn't allow any closing parens before the colon, and i think it could be possible to have a that be an issue. so i will work on the regex more later when i have time again

morganholly commented 2 years ago

i will likely need to figure out a regex to match balancing parens so that only a following unbalanced paren stops the match

saem commented 2 years ago

This makes me nervous, gonna read it over a few times, but the grammar doesn't feel right.

The keyword of doesn't feel like it's being classified correctly, I think we should revise the approach. It's effectively a form of equality in each case. 🤔

Thoughts?

morganholly commented 2 years ago

it seems to me, someone a bit new to nim, that of for case is directing program flow, while in a type comparison, it’s a boolean operator. like in java, switch case and instanceof seem to me to be analogous to nim’s case of and of. two different things, in one language they have two different names, in another they have the same name

saem commented 2 years ago

For the case case 😁, of is saying the thing left of the case is equal to/in the lhs of the of. Hence more equality. So if we started with case foo, it's copy pasting if/elif foo of ..., where of us replaced with equal or in.

Which makes it effectively like a binary operator again.

morganholly commented 2 years ago

but of as an operator doesn't check equality, it checks whether a variable is of a specific type. for a case/of, you can't just stick a variable in the case and the type in the of, nim complains about the case and of being different types, even if you use the type of the variable. T vs typedesc[T]

saem commented 2 years ago

Not exactly equality, but it feels more like an operator than control flow in both cases.

This is fuzzy stuff, it's classify syntax to a language agnostic set of categories without much semantic information.