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

Allow java comment after yylexthrow #794

Merged
merged 10 commits into from
Jan 24, 2021
Merged

Conversation

regisd
Copy link
Member

@regisd regisd commented Dec 13, 2020

Currently the %lexthrow keyword can only be followed by identifiers

"%yylexthrow"{WSP}+ {QUIL} {WSP}*  {...}

This change allows the identifier of the exception to be followed by a comment.

"%yylexthrow"{WSP}+ {QUIL} {WSP}* {JavaComment}? {...}

However, the emitter must also be adapter to emit one exception per line, otherwise the comment of the first might hide all the following declarations.

Also refactor the AbstractLexScan.lexThrown field from String to List<String>, and let the emitter handle the formatting.

Add an integration test.

```
INFO: Found 2 targets...
ERROR: /Users/regisd/Projects/jflex/javatests/jflex/testcase/yylexthrow_comment/BUILD.bazel:3:6: jflex javatests/jflex/testcase/yylexthrow_comment/Yylexthrow.java failed (Exit 1) jflex_bin failed: error executing command bazel-out/host/bin/jflex/jflex_bin -d bazel-out/darwin-fastbuild/bin/javatests/jflex/testcase/yylexthrow_comment javatests/jflex/testcase/yylexthrow_comment/yylexthrow.flex

Use --sandbox_debug to see verbose messages from the sandbox
Reading "javatests/jflex/testcase/yylexthrow_comment/yylexthrow.flex"

Error in file "javatests/jflex/testcase/yylexthrow_comment/yylexthrow.flex" (line 9):
%yylexthrow needs a list of (qualified) identifiers
%yylexthrow Exception // comment on same line allowed
```
@regisd regisd requested a review from lsf37 as a code owner December 13, 2020 13:41
@regisd regisd added the bug Not working as intended label Dec 13, 2020
@regisd regisd added this to the 1.9.0 milestone Dec 13, 2020
@regisd regisd linked an issue Dec 13, 2020 that may be closed by this pull request
@regisd regisd self-assigned this Dec 13, 2020
- Add the comment after the exception
- Change type of AbstractLexer.lexThrown from String to List<String>
  Let the emitter do the formatting, instead of concatenating the exceptions in the flex file
@regisd
Copy link
Member Author

regisd commented Dec 13, 2020

@lsf37 I think this fixes the described bug. I'm not sure whether {JavaComment} is actually the desired macro.

There might be other ways, such as dropping the comment and only keep the identifier.

Also, there might be other keywords to fix.

What do you think?

@regisd
Copy link
Member Author

regisd commented Jan 21, 2021

@lsf37 Can you have a look at this PR? It's not very complex, but it's changing jflex core and I don't want to submit without review.

@lsf37
Copy link
Member

lsf37 commented Jan 21, 2021

Thanks for doing this, I can look at it tomorrow and finish it off (if there is anything to be changed, which there probably isn't)

@regisd
Copy link
Member Author

regisd commented Jan 23, 2021

My knownledge of the jflex grammar is not great.
Maybe there is a more elegant way, and follow yylexthrow by a JFlexComment rather than a JavaComment

Copy link
Member

@lsf37 lsf37 left a comment

Choose a reason for hiding this comment

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

This looks good. I can't think of a nicer way to include the comments, at least not without a major refactor (the whole section should probably be more in the parser and less in the lexer, but that's for another time).

Happy for you to merge!

jflex/src/main/jflex/LexScan.flex Show resolved Hide resolved
@regisd regisd merged commit 7afb932 into jflex-de:master Jan 24, 2021
@regisd regisd deleted the yylexthrow_comment branch January 24, 2021 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not working as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

%yylexthrow doesn't allow comments on the same line
2 participants