yodk icon indicating copy to clipboard operation
yodk copied to clipboard

Nolol multiline if's do not allow $ after end

Open Firestar99 opened this issue 1 year ago • 4 comments

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 avatar Jul 28 '22 23:07 Firestar99

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

dbaumgarten avatar Jul 29 '22 08:07 dbaumgarten

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.

Firestar99 avatar Jul 29 '22 11:07 Firestar99

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

dbaumgarten avatar Jul 29 '22 12:07 dbaumgarten

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

Firestar99 avatar Jul 29 '22 13:07 Firestar99