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

Nolol multiline if's do not allow $ after end #125

Open
Firestar99 opened this issue Jul 28, 2022 · 4 comments
Open

Nolol multiline if's do not allow $ after end #125

Firestar99 opened this issue Jul 28, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@Firestar99
Copy link

Firestar99 commented Jul 28, 2022

Describe the bug
Nolol multiline if's do not allow $ after end erroring out with Expected newline. Found Token: '$'(Symbol), although it works just fine with single line ifs. This makes it hard to describe behaviour where after a multiline if a line break ($) is required followed by time sensitive code which should execute exactly 1 tick later later. Inserting the $ into a new line after the if inserts an empty line and thus 2 ticks of latency.

I my use-case (well known number parser ported to nolol) I can use the workaround described below: a useless statement followed by a $.

Example Code/Screenshots

if c=="-" then //if needs to be multiline due to multiple exprs in body
    :a=1
    :b=42 //Putting $ here: Does nothing
    //Putting $ here: same as bottom $
end //Putting $ here: Expected newline. Found Token: '$'(Symbol)
    // ^^ this works on single line ifs
//Putting $ here: inserts an extra empty line, 2 newlines -> 0.4s latency
//Workaround: "c=c $" using pointless expression to allow $

:a=0 //:a needs to be set back to 0 after exactly 0.2s, requiring a SINGLE $ in the line above

Platform:

  • OS: windows
  • yodk 0.1.13
@Firestar99 Firestar99 added the bug Something isn't working label Jul 28, 2022
@dbaumgarten
Copy link
Owner

dbaumgarten commented Jul 29, 2022

Not really a bug, but rather a consequence of how nolol is structured. A nolol-ast consist of differen things. There are mainly Elements (include, define etc.), NestableElements (if, for) and StatementLines.
StatementLines are effectively the plain-old yolol. Just a list of 0 or more statements (with some optional modifiers).
Things like $, jumplabels and comments are features of StatementLines. MultiLine-Ifs are no StatementLines and can therefore not have these.

A line that only contains a $ results in an empty line, by design.

The correct way to do what you are trying to is to add the $ either at the end of the last line inside the if-block, or at the beginning of the first (non empty) line after the if-block.

If one of that does not work, then it definitely a bug.

I cant test this myself right now, but does one of this work for you?

if c=="-" then 
    :a=1
    :b=42 $
end
:a=0
if c=="-" then 
    :a=1
    :b=42
end
$ :a=0

@Firestar99
Copy link
Author

if c=="-" then 
    :a=1
    :b=42 $
end
:a=0

As already described in the opening comment the dollar here does nothing.

if c=="-" then 
    :a=1
    :b=42
end
$ :a=0

This version however works! I was not aware that prepending a $ is allowed.

@dbaumgarten
Copy link
Owner

Ok, then the first one is a bug. I will have to see when I find the time to look into this.
But I am glad that there is a working workaround

@Firestar99
Copy link
Author

Feel free to take your time, this is just something I've noticed and don't even have a usecase for it currently :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants