Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle of as a binary keyword #92

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

morganholly
Copy link
Contributor

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

only match `of` as a control keyword if it is not in an if/elif/when and is followed by a colon
@morganholly
Copy link
Contributor Author

image

this doesn't allow any closing parens before the colon, and i think it could be possible to have a that be an issue. i will work on the regex more later when i have time again
@morganholly
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@saem
Copy link
Owner

saem commented Apr 27, 2022

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
Copy link
Contributor Author

morganholly commented Apr 27, 2022

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
Copy link
Owner

saem commented Apr 27, 2022

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
Copy link
Contributor Author

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
Copy link
Owner

saem commented Apr 28, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants