Comments (3)
#90 and d1f2f80 show up general problems with Tokay's parentheses-less syntax attempt.
The syntax of for-loops is currently a stopgap and trade-off between C/awk-style, Rust/Python-style and Tokay's own syntactic specialities. The iterator-part can only be a Statement, not a Sequence, as expressed in tokay.tok
:
Atomic : @{
# ...
'for' _SeparatedIdentifier (Sequence | Nop) ';' _ (Sequence | Nop) ';' _ Statement _ Block ast("op_for")
'for' _SeparatedIdentifier (Sequence | Nop) ';' _ (Sequence | Nop) ';' _ Nop _ Block ast("op_for")
# ...
}
This allows for simple
for i = 0; i < 10; i++ { print(i) }
but it's getting stuck here
for i = 0, j= 100; i < 10; i++, j-- { print(i, j) }
which will throw a syntax error with d1f2f80. Note, that previously, even less was possible, though!
Anyway, the syntax error is because Statement
is used rather than Sequence
on the iterator part, and a block is part of a Sequence
, so this even more causes a syntax error.
The syntax is disambiguating here, and
for i = 0, j= 100; i < 10; (i++, j--) { print(i, j) }
is an acceptable, but not nice workaround.
Also, generally adding parentheses to the syntax would solve the problem.
Atomic : @{
# ...
'for' _ '(' _ (Sequence | Nop) ';' _ (Sequence | Nop) ';' _ (Sequence | Nop) ')' _ Block ast("op_for")
# ...
}
would enforce the original C/awk-style syntax
for (i = 0, j= 100; i < 10; i++, j--) { print(i, j) }
but this isn't wanted due personal preference, and Tokay's "different" syntax from existing syntax.
Generally, maybe its better to reinforced for...in
and use this as the one-and-only-for
syntax.
from tokay.
#101 is the first pull request on this topic.
from tokay.
#101 merged, issue fixed.
from tokay.
Related Issues (20)
- Misleading error message on undefined constant `I: X` HOT 1
- `cargo install tokay` fails with Rust toolchain >= 1.68 HOT 2
- `print(Int ast("int"))` causes `assertion failed: n <= tos - self.frame0().capture_start` HOT 3
- Alternative keyword syntax for `parselet` and `function` definitions
- Remove build-dependency on `tokay = "0.4"` for `build.rs` HOT 2
- Run program once over all provided files or in parallel HOT 1
- `"x".upper.replace("y")` throws `"Method 'method_replace' not found"`
- bug: Assign of consumable to variable should call (like an expression)
- Turn `Capture` into object HOT 1
- `1(2+3)`: The value Int(1) is generally not callable! - hint for user? HOT 1
- `Context::collect()` collects everything, even severity 0
- Requirement for inlined parselets
- Implement builtin `Keyword<P>` HOT 2
- Capture access should downgrade captured items
- Bug with `Repeat<P>`: Match in `Pos<P>` sequence fails without severity
- Function call with multiple, same arguments should be rejected
- Compile-time `static : void` should unregister static HOT 1
- Implement indirect left-recursion HOT 1
- Implement parselet capture variable `$` as a dict HOT 1
- Improving `testmode:repl` facilities
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tokay.