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

Project Converter: Do not convert lines that start with a comment #74193

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

Maran23
Copy link
Contributor

@Maran23 Maran23 commented Mar 1, 2023

Partially fixes: - #66061
Partially fixes: - #70983

This PR adds detection of lines that start with a comment.
Those lines are ignored so that the text inside the comments remains untouched.
E.g. # Reference is not converted to # RefCounted.
Lines that do not start with a comment, e.g. func _ready(): # Reference will still be converted.

Same applies to C# comments: // Reference

@Maran23 Maran23 force-pushed the project-converter-comments branch 2 times, most recently from dc8f07b to 964add1 Compare March 1, 2023 22:35
@YeldhamDev YeldhamDev added this to the 4.1 milestone Mar 2, 2023
@akien-mga
Copy link
Member

Would it be too risky / lead to false positives to make the regex handle inline comments?

At least for GDScript, I think it might be safe to assume that # always starts a comment unless it's:

  • In a string (i.e. enclosed with " or two ')
  • In a comment (but that doesn't matter I guess)

Might be a bit hard to make fully reliable as strings are messy, so maybe we could just match:

  • Lines starting with a comment (this PR)
  • Inline comments with no " or ' character after #
    • Would break on words like "it's" but it's maybe better than nothing. Otherwise the regex would need to check for " on both sides of #, with an uneven number of " on the left side, or... I don't know, sounds like a complex problem which should have been solved already for matching comments in Python code :P

@Maran23
Copy link
Contributor Author

Maran23 commented Mar 2, 2023

Would it be too risky / lead to false positives to make the regex handle inline comments?

There is a little risk, as you also wrote.
But there is also a little more work involved when converting/overwriting the files.
The logic introduced in this PR is simple: if the line is a comment, it will be ignored during conversion.

If we want to support inline comments, the logic needs to be further improved to separate the line into a code and a comment part.
Then ONLY the code part should be converted and after that both parts should be put back together again.
E.g. func _ready(): # Reference must be tokenized into func _ready(): and # Reference.
Only func _ready(): is converted and then # Reference should be added again.

@Maran23 Maran23 force-pushed the project-converter-comments branch from 964add1 to 3eb7976 Compare March 6, 2023 08:05
@Maran23 Maran23 force-pushed the project-converter-comments branch from 3eb7976 to 5669590 Compare March 6, 2023 08:09
@Maran23 Maran23 force-pushed the project-converter-comments branch from 5669590 to 8cf7ac3 Compare March 6, 2023 08:13
@akien-mga akien-mga merged commit cf1739f into godotengine:master Mar 6, 2023
@akien-mga
Copy link
Member

Thanks!

@YuriSizov
Copy link
Contributor

Cherry-picked for 4.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants