Git Product home page Git Product logo

Comments (3)

phorward avatar phorward commented on May 20, 2024

#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.

phorward avatar phorward commented on May 20, 2024

#101 is the first pull request on this topic.

from tokay.

phorward avatar phorward commented on May 20, 2024

#101 merged, issue fixed.

from tokay.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.