MerlinofMines / EasyCommands

Github Repository for Ingame Scripts built by MerlinofMines. Uses MDK to Deploy to SpaceEngineerse
GNU General Public License v3.0
8 stars 3 forks source link

FR: Unary Minus #124

Closed jgersti closed 2 years ago

jgersti commented 2 years ago

The negation operator (unary -) is missing. While the workaround is simple, the bahaviour is nonetheless unexpected.

MerlinofMines commented 2 years ago

Yep, this one's been painful.

Right now "-" is only a binary operator, unless it's in front of a number (in which case it's parsed as a negative number).

I think the way to fix this is to create a new CommandParameter for "Minus".

Then, in the parsing tree, we need a branching processor to convert it to "Unary Minus" or "Binary Minus". The branching logic will then identify whether it was indented to be unary or binary based on the surrounding context.

Shouldn't be too bad to implement. we'll have to figure out exactly where to put the branch in the parsing tree to be most effective / least effective.

MerlinofMines commented 2 years ago

We might change the "negative" parsing logic too, and have "-" always be separated out and treated as a unary operator.

The unary operator we can use should be "Reverse", I believe? Whichever one currently does the ".Not()" on the value. Can't remember exactly which one atm.