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

Parse error in multiline dict with equal sign #35416

Closed
Tracked by #40488
Scony opened this issue Jan 21, 2020 · 4 comments
Closed
Tracked by #40488

Parse error in multiline dict with equal sign #35416

Scony opened this issue Jan 21, 2020 · 4 comments

Comments

@Scony
Copy link
Contributor

Scony commented Jan 21, 2020

Godot version:
master @ d11d7df

OS/device including version:
Linux

Issue description:
Godot raises parse error on the code below:

var y = { name = 1 }			# fine
var x = {
	name = # parse errror
	1
}
Godot Engine v3.2.rc.custom_build.d11d7dfe3 - https://godotengine.org
 
SCRIPT ERROR: GDScript::reload: Parse Error: Error parsing expression, misplaced: '\n'
   At: res://tests/potential-godot-bugs/multiline-dict-w-eq-sign.gd:4.
ERROR: reload: Method/Function Failed, returning: ERR_PARSE_ERROR
   At: modules/gdscript/gdscript.cpp:576.
@Calinou
Copy link
Member

Calinou commented Jan 21, 2020

I think this is expected. If you want to do this, you have to add a backslash at the end of the line or wrap the expression between parentheses:

var x = {
    name = \
    1
}
var x = {
    name = (
    1)
}

This one should definitely work though:

var x = {
    name = 1
}

@Scony
Copy link
Contributor Author

Scony commented Jan 22, 2020

To me it's weird especially because

var x = {
    'name':
    1
}

is working fine. Naturally, as a consequence, the same rule should apply to =.

@bojidar-bg
Copy link
Contributor

The issue comes from a fallthrough in the dictionary parsing, which short-circuits from key to value, and fails to consume the newline at gdscript_parser.cpp:1096.
(newline is consumed at gdscript_parser.cpp:1028 after a colon, note that DICT_EXPECT_KEY/VALUE are within an else).

The best solution, apart from rewriting the dictionary parsing state machine, would be to increment/decrement parenthesis while inside the dictionary.

@KoBeWi
Copy link
Member

KoBeWi commented Dec 17, 2020

Fixed in 4.0

@KoBeWi KoBeWi closed this as completed Dec 17, 2020
@KoBeWi KoBeWi added this to the 4.0 milestone Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants