-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Editor: @for loop custom step size #401
Editor: @for loop custom step size #401
Conversation
…loops Allows for the following syntax: ``` @for (0 through 4 in steps of 2) { For.i; } ``` Printing: ``` 0; 2; 4; ```
Since this operator uses spaces, I also had to change `customOperators` from a word set to a regular expression.
…ng a @for loop with a custom step size Use the "to"/"through" as a delimiter for where we should check. If to the left there is no "from", then warn the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! It's a bit overkill since you can just do For.i * x
, but it's also kinda fun, so why not! I did have a couple of nitpicks though
@@ -58,6 +58,7 @@ function tokenBase(stream, state) { | |||
if (stream.match(hexadecimal)) return "number" | |||
if (stream.match(decimal)) return "number" | |||
if (stream.match(customKeywords)) return "atom" | |||
if (stream.match(customOperators)) return "atom" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully it wasn't down below for a reason :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was just leeching off the identifier
regex.
Yes, but that means outputting For simple cases I also found you can do a mixin like the one below, though its less readable/more verbose.
|
This PR adds an optional step size to @for loops (instead of the default:
1
), active when using thein steps of
operator.Example
Renders: