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

Block comment ignores strings #58

Open
PavelVozenilek opened this issue Apr 14, 2020 · 3 comments
Open

Block comment ignores strings #58

PavelVozenilek opened this issue Apr 14, 2020 · 3 comments

Comments

@PavelVozenilek
Copy link

This failed:

/*
void main() {
    println("Hello /* world"); // <<< open block comment in a string
}
*/

void main() {
    println("Hello world");
}

with error:

main.delta:1:1: error: unterminated block comment
/*
^

I noticed, that in file parser/lex.cpp the function Lexer::readBlockComment doesn't handle strings.

@emlai
Copy link
Member

emlai commented Apr 15, 2020

Good catch. But I don't this is feasible to implement, because comments may contain arbitrary text, making it nearly impossible to reliably detect if the /* is inside a "string" or not. For example:

/* Some explanation here.
var c = '"'; /* The ascii value of `"` is 34.
                More explanation. */
*/

Here the /* is enclosed between two " characters on the same line, but it's actually part of a nested block comment, and therefore should not be ignored.

I tested with Swift, which also has nested comments, and it doesn't seem to handle strings inside block comments in a special way either.

@PavelVozenilek
Copy link
Author

I noticed it when reading lexer'code. One way would be to lex everything first (including comments start/stop), and then to filter comments away.

@emlai
Copy link
Member

emlai commented Apr 17, 2020

That wouldn't work because comments can contain text that doesn't lex properly. For example the text "\" is valid in a comment, but lexing would treat is as an unterminated string literal (since the last quote is escaped).

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

No branches or pull requests

2 participants