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

improve number lexer #1646

Merged
merged 2 commits into from
Dec 31, 2018
Merged

improve number lexer #1646

merged 2 commits into from
Dec 31, 2018

Conversation

guwirth
Copy link
Collaborator

@guwirth guwirth commented Dec 29, 2018


This change is Reviewable

- reduce the number of regex rules to detect a number
- use only one channel to detect numbers
- improve #1415
@guwirth guwirth added this to the 1.2.2 milestone Dec 29, 2018
@guwirth guwirth self-assigned this Dec 29, 2018
Copy link
Contributor

@ivangalkin ivangalkin left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r1.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @guwirth, @jmecosta, and @SonarOpenCommunityAdmin)


cxx-squid/src/main/java/org/sonar/cxx/lexer/CxxLexer.java, line 45 at r1 (raw file):

  private static final String HEX_PREFIX = "0[xX]";
  private static final String EXPONENT = "([Ee][+-]?+[0-9_]([']?+[0-9_]++)*+)";

Your change is valid. However the original regexp is not really clear to me. Does it make sense to have * followed by +? Wouldn’t + be sufficient?

Copy link
Contributor

@ivangalkin ivangalkin left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @guwirth, @jmecosta, and @SonarOpenCommunityAdmin)


cxx-squid/src/main/java/org/sonar/cxx/lexer/CxxLexer.java, line 58 at r1 (raw file):

  private static final String BINDIGIT_SEQUENCE = "[01]([']?+[01]++)*+";
  private static final String POINT = "\\.";
  

Trailing whitespaces.

@ivangalkin
Copy link
Contributor

ivangalkin commented Dec 30, 2018

@guwirth Your change looks good to me (although I am not sure, that I understand it in detail). I am not available for reviews until the the 2nd week of January.

I wish you happy new year! My best wishes to all contributors too!

@guwirth
Copy link
Collaborator Author

guwirth commented Dec 30, 2018

@ivangalkin

Your change is valid. However the original regexp is not really clear to me. Does it make sense to have * followed by +? Wouldn’t + be sufficient?

Good explanation is here: https://docs.oracle.com/javase/tutorial/essential/regex/quant.html.
See also in the source code https://github.com/SonarSource/sslr/blob/master/sslr-core/src/main/java/com/sonar/sslr/impl/channel/RegexpChannelBuilder.java.

  public static String opt(String regexpPiece) {
    return regexpPiece + "?+";
  }

  public static String one2n(String regexpPiece) {
    return regexpPiece + "++";
  }

 public static String o2n(String regexpPiece) {
    return regexpPiece + "*+";
}

@guwirth guwirth removed the request for review from SonarOpenCommunityAdmin December 31, 2018 11:18
@guwirth guwirth merged commit 263f1b5 into SonarOpenCommunity:master Dec 31, 2018
@guwirth guwirth mentioned this pull request Feb 8, 2019
@guwirth guwirth deleted the optimize-lexer branch July 29, 2019 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants