Skip to content

FIX: parsing of string literals that contains //, closes #442 #444

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

Conversation

filipsajdak
Copy link
Contributor

In the following code:

main: () = {
	{ std::cout << "//456"; } //error

	:()->_ = { return "//Error"; };

	b:="/* error even without {} block";
}
error: (x) -> _ = { return "//"; }

// and /* inside string literals are parsed as the beginning of comments.

Current change solves that. This FIX does not handle the handling of raw string literals.

Closes #442

@filipsajdak filipsajdak changed the title Fix parsing of string literals that contains //, closes #442 FIX: parsing of string literals that contains //, closes #442 May 9, 2023
In the following code:
```cpp
main: () = {
	{ std::cout << "//456"; } //error

	:()->_ = { return "//Error"; };

	b:="/* error even without {} block";
}
error: (x) -> _ = { return "//"; }
```
`//` and `/*` inside string literals are parsed as begining of comments.

Current change solves that. The missing is handling of raw string literals.

Closes hsutter#442
@JohelEGP
Copy link
Contributor

JohelEGP commented May 9, 2023

This FIX does not handle the handling of raw string literals.

I thought #69 did that.

@filipsajdak
Copy link
Contributor Author

filipsajdak commented May 9, 2023

Herb changed the parsing stages. There is a new simpler one that did not cover string literals not raw string literals.

@hsutter
Copy link
Owner

hsutter commented May 20, 2023

Herb changed the parsing stages. There is a new simpler one that did not cover string literals not raw string literals.

Could you remind me / elaborate?

@hsutter hsutter merged commit 6f85448 into hsutter:main May 20, 2023
@filipsajdak
Copy link
Contributor Author

Herb changed the parsing stages. There is a new simpler one that did not cover string literals not raw string literals.

Could you remind me / elaborate?

Hmmm... I made a mistake with this statement. I mistakenly treat a switch that is in the process_cpp2_line() function (in the io.h file) with the switch that is in the lex_line() function (in the lex.h file). I could not see parts that take into account raw string literals, and I thought that it was somehow lost during refactoring... my mistake.

Now I see that the process_cpp2_line stage was there all the time... I need to add support for raw string literals as well.

@hsutter
Copy link
Owner

hsutter commented May 21, 2023

OK, thanks -- for now I've reopened #442 to track this part too, and the issue will then be re-closed via the coming new PR to apply the fix to raw strings.

Again, thanks!

@filipsajdak filipsajdak deleted the fsajdak-fix-comment-in-string-literals-inside-braces branch May 31, 2023 21:27
zaucy pushed a commit to zaucy/cppfront that referenced this pull request Dec 5, 2023
…sutter#444)

In the following code:
```cpp
main: () = {
	{ std::cout << "//456"; } //error

	:()->_ = { return "//Error"; };

	b:="/* error even without {} block";
}
error: (x) -> _ = { return "//"; }
```
`//` and `/*` inside string literals are parsed as begining of comments.

Current change solves that. The missing is handling of raw string literals.

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

Successfully merging this pull request may close these issues.

[BUG] "//" "/*" inside string literal treated as real comment and doesn't compile
3 participants