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

Fix line vs. block comment interaction in the saw-script lexer #2191

Merged
merged 4 commits into from
Jan 23, 2025

Conversation

sauclovian-g
Copy link
Contributor

Prompted by #1225 (which is about the saw-core lexer); closes #2181.

Don't have the lexer match //.*; just match the // part, and extend
the same logic that handles dropping the bits between /* and */ to
also handle dropping the bits between // and EOL.

This requires materializing EOL tokens instead of treating them as
whitespace, but that costs ~nothing.

Also fix it so we generate explicit messages when there are unclosed
comments. A // comment that doesn't have an EOL before EOF generates a
warning; a /* comment without a matching */ generates an error. The
position for this error is the comment start.

(The previous behavior was that unclosed comments commented out the
EOF token and that would cause a non-specific "parse error".)

Update the lexer call sites to post the messages. There should not be
four separate lexer call sites, but that's a problem for a future
branch.

Add some tests. This includes a new test_parse_errors area akin to
the existing test_type_errors.
(interactions of comments and Cryptol blocks)

Note: these reflect the current behavior, which as discussed in the
issue is not particularly desirable. They should be updated when/if
the behavior is improved.
Copy link
Contributor

@RyanGlScott RyanGlScott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach used here looks plausible to me, although I'd like for some of this to be documented further.

src/SAWScript/Token.hs Show resolved Hide resolved
src/SAWScript/Lexer.x Outdated Show resolved Hide resolved
src/SAWScript/Lexer.x Outdated Show resolved Hide resolved
src/SAWScript/Lexer.x Show resolved Hide resolved
src/SAWScript/Lexer.x Show resolved Hide resolved
Comment on lines 38 to 39
-- EOL End of line
-- EOF End of file/input
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- EOL End of line
-- EOF End of file/input
-- TEOL End of line
-- TEOF End of file/input

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oy. Fixed...

@sauclovian-g sauclovian-g merged commit 97bcdf4 into master Jan 23, 2025
32 of 34 checks passed
@sauclovian-g sauclovian-g deleted the 2181-comments branch January 23, 2025 00:05
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.

It should not be possible to comment out comment delimiters
2 participants