-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Improve readabillity of multiline string blocks #5794
Comments
Now you can use func _run() -> void:
print("""
<html>
<body>
<p>Hello, world</p>
</body>
</html>
""".dedent()) We could add a special literal, for example d-strings (dedent), like f-strings and r-strings: func _run() -> void:
print(d"""
<html>
<body>
<p>Hello, world</p>
</body>
</html>
""") But there is a question: how should the initial and final line breaks be handled? |
hi Try this: func _run() -> void:
print("""<html>
<body>
<p>Hello, world</p>
</body>
</html>
""".dedent()) The linked document descripes in detail how it should work. my current workaround is to use |
|
Yes sure, but is would be nice to have this as standard :) |
I also have doubts about how useful it would be. I would never format my strings like this personally, and I'd assume the same for most people. |
sorry you like more to write this func foo() -> void:
var message = """
This is a message.
With multi lines.
"""
prints(message) instead of a good formatted code like this? func foo() -> void:
var message = """
This is a message.
With multi lines.
"""
prints(message) |
True that it's better-formatted, but again I'd just The idea of changing the standard is almost out of the question now, as it would be a compat-breaking change. It'd be a method, and I can't think of any way to make a useful method for this. |
Describe the project you are working on
GdUnit3/4 a unit test framework
Describe the problem or limitation you are having in your project
I have an internal test coverage for generated assert error messages.
These error messages can be quite complex, to test them I use multiline strings as references but the formatting is very bad.
The text block should strip the incidental white spaces to allow better code readabillity.
For better visualisation (using dots to visualize spaces:)
Should be parsed as (using | to visualize margins:)
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Text blocks should follow the same rules as described here https://docs.oracle.com/en/java/javase/15/text-blocks/index.html
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
This improvement allows you to write better formatted code
If this enhancement will not be used often, can it be worked around with a few lines of script?
no workaround exists, would be a core fature
Is there a reason why this should be core and not an add-on in the asset library?
it is not possible because is part of the core GdScript parser
The text was updated successfully, but these errors were encountered: