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

Grammar doesn't allow nesting of conditionals through second argument #1035

Open
1 task done
verytactical opened this issue Nov 13, 2024 · 1 comment
Open
1 task done
Assignees
Labels
discussion Ideas that are not fully formed and require discussion scope: parser
Milestone

Comments

@verytactical
Copy link
Contributor

Are you using the latest released (or pre-released, a.k.a. "next") version?

  • I'm using the latest Tact version

Tact source code

const a: Int = 2;
const counter: Int = a == 0 ? a == 1 ? a : a : a;

Relevant Tact/build system log output

Parse error: expected ":", ".", "!!", "-", "+", "%", "/", "*", "<=", "<", ">=", ">", ">>", "<<", "&", "==", "!=", "|", "^", "||", or "&&" 
 
Line 2, col 38: 
  1 | const a: Int = 2; 
> 2 | const counter: Int = a == 0 ? a == 1 ? a : a : a; 
                                           ^

What happened?

Grammar disallows nesting conditionals through second argument

What did you expect?

Grammar allows nesting conditionals through second argument, as in pretty much any other C-like language

Steps to reproduce

No response

How do you run Tact?

Other

Anything else?

No response

@verytactical verytactical added the bug Something isn't working or isn't right label Nov 13, 2024
@anton-trunov anton-trunov added this to the v1.6.0 milestone Nov 14, 2024
@anton-trunov
Copy link
Member

A summary of our discussion elsewhere:

We should forbid a == 0 ? a == 1 ? a : a : a as it's done now, because this syntax is really hard to read, so we want to be JS-like but not allow everything if it hurts readability. For instance, a / 2 / b should also be forbidden if there are not parentheses.

To do that, we might introduce a separate linter-like pass into the compiler.

There are might be many other cases, so we should turn to existing academic research on common mistakes people make because of confusing syntax and draw from industrial best practices.

@anton-trunov anton-trunov added discussion Ideas that are not fully formed and require discussion and removed bug Something isn't working or isn't right labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Ideas that are not fully formed and require discussion scope: parser
Projects
None yet
Development

No branches or pull requests

2 participants