CraftTweaker

CraftTweaker

151M Downloads

Subtractions vs negation caused by spaces: `1 - 1` vs `1-1`

nerdywhiteguy opened this issue · 1 comments

commented

Issue description

A script containing only the line

println( 1 - 1 );

works without problem, producing the following line in the log:
[20:18:34.462][DONE][CLIENT][INFO] 0
Meanwhile,

println( 1-1 );

produces the error

[20:20:44.932][DONE][CLIENT][ERROR] Parser Exception @ subtraction_vs_negation.zs:1:10 : ) expected
org.openzen.zenscript.lexer.ParseException: subtraction_vs_negation.zs:1:10: ) expected
	at org.openzen.zenscript.lexer.LLParserTokenStream.required(LLParserTokenStream.java:96)
	at org.openzen.zenscript.parser.expression.ParsedCallArguments.parse(ParsedCallArguments.java:47)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readPostfixExpression(ParsedExpression.java:389)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readUnaryExpression(ParsedExpression.java:349)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readMulExpression(ParsedExpression.java:278)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readAddExpression(ParsedExpression.java:258)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readShiftExpression(ParsedExpression.java:237)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readCompareExpression(ParsedExpression.java:166)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readAndExpression(ParsedExpression.java:156)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readXorExpression(ParsedExpression.java:146)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readOrExpression(ParsedExpression.java:136)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readAndAndExpression(ParsedExpression.java:126)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readOrOrExpression(ParsedExpression.java:110)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readConditionalExpression(ParsedExpression.java:97)
	at org.openzen.zenscript.parser.expression.ParsedExpression.readAssignExpression(ParsedExpression.java:49)
	at org.openzen.zenscript.parser.expression.ParsedExpression.parse(ParsedExpression.java:40)
	at org.openzen.zenscript.parser.statements.ParsedStatement.parse(ParsedStatement.java:299)
	at org.openzen.zenscript.parser.statements.ParsedStatement.parse(ParsedStatement.java:81)
	at org.openzen.zenscript.parser.ParsedFile.parse(ParsedFile.java:215)
	at org.openzen.zenscript.parser.ParsedFile.parse(ParsedFile.java:158)
…

I suspect this is an order of operations error. With spaces, it is parsed as one, subtract, one, as is expected. Without the spaces, I suspect it's getting parsed as one, negative one, and so it's throwing an error because there isn't an operation between the two tokens.
I could be wrong, however, as both

println( 1 * -1 );

and

println( 1 * - 1 );

produce no errors and print [20:41:47.319][DONE][CLIENT][INFO] -1 as expected.

Steps to reproduce

No response

Script used

https://gist.github.com/nerdywhiteguy/ebad0302b0d6eb9736ed3f8fce9a618c#file-subtraction_vs_negation_bugged-zs

The crafttweaker.log file

https://gist.github.com/nerdywhiteguy/ebad0302b0d6eb9736ed3f8fce9a618c#file-crafttweaker-log

Minecraft version

1.16

Forge version

36.1.10

CraftTweaker version

7.1.0.371

Other relevant information

There are plenty of other mods and scripts loaded, as I'm in the process of creating a modpack, so you'll see plenty of excess nonsense if you dive into my logs. None of that should effect something so basic as an operator, though.

The latest.log file

https://gist.github.com/nerdywhiteguy/ebad0302b0d6eb9736ed3f8fce9a618c#latest-log

commented

Looking at Issue #892, this seems to have been present in the version for Minecraft 1.12.2, but never actually fixed. The issue was only "solved" by having the user be sure to include spaces between the dash and the number after it.
Oh, I forgot to mention:
1- 1 works fine, but 1 -1 does not.
The key is the space between the dash and the digit after it. And, in particular, this only effects digits immediately after a dash.

var x = 1;
println( 1-x );

This works just fine. It's only an issue with numerical literals, and base doesn't matter: 1-0x1 throws the same error.