Skip to content

Commit

Permalink
fix: Update number regex for Java
Browse files Browse the repository at this point in the history
Reference:
https://docs.oracle.com/javase/specs/jls/se6/html/lexical.html#48272

Draft:

DecimalNumeral: 0|[1-9][0-9]*
HexNumeral: 0x[0-9a-f]+
OctalNumeral: 0[0-7]+

IntegerLiteral: 0|[1-9][0-9]*|0x[0-9a-f]+|0[0-7]+

ExponentPart: e[+-]?[0-9]+

DecimalFloatingPointLiteral:

1. [0-9]+\.[0-9]*(?:e[+-]?[0-9]+)?[fd]?
2. \.[0-9]+(?:e[+-]?[0-9]+)?[fd]?
3. [0-9]+(?:e[+-]?[0-9]+)[fd]?
4. [0-9]+(?:e[+-]?[0-9]+)?[fd]

HexadecimalFloatingPointLiteral:
(?:0x[0-9a-f]+\.?|0x[0-9a-f]*\.[0-9a-f]+)p[+-]?[0-9]+[fd]?

Number:
(?<=\b|\s|^)(?i)(?:(?:[0-9]+\.[0-9]*(?:e[+-]?[0-9]+)?[fd]?)|(?:\.[0-9]+(?:e[+-]?[0-9]+)?[fd]?)|(?:[0-9]+(?:e[+-]?[0-9]+)[fd]?)|(?:[0-9]+(?:e[+-]?[0-9]+)?[fd])|(?:(?:(?:0x[0-9a-f]+\.?)|(?:0x[0-9a-f]*\.[0-9a-f]+))p[+-]?[0-9]+[fd]?)|(?:0)|(?:[1-9][0-9]*)|(?:0x[0-9a-f]+)|(?:0[0-7]+))(?=\b|\s|$)
  • Loading branch information
ouuan committed Feb 22, 2020
1 parent 9e276cf commit 11f5647
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/internal/QJavaHighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ QJavaHighlighter::QJavaHighlighter(QTextDocument* document) :

// Numbers
m_highlightRules.append({
QRegularExpression(R"((?<=\b|\s|^)(?i)(?:(?:(?:(?:(?:\d+(?:'\d+)*)?\.(?:\d+(?:'\d+)*)(?:e[+-]?(?:\d+(?:'\d+)*))?)|(?:(?:\d+(?:'\d+)*)\.(?:e[+-]?(?:\d+(?:'\d+)*))?)|(?:(?:\d+(?:'\d+)*)(?:e[+-]?(?:\d+(?:'\d+)*)))|(?:0x(?:[0-9a-f]+(?:'[0-9a-f]+)*)?\.(?:[0-9a-f]+(?:'[0-9a-f]+)*)(?:p[+-]?(?:\d+(?:'\d+)*)))|(?:0x(?:[0-9a-f]+(?:'[0-9a-f]+)*)\.?(?:p[+-]?(?:\d+(?:'\d+)*))))[lf]?)|(?:(?:(?:[1-9]\d*(?:'\d+)*)|(?:0[0-7]*(?:'[0-7]+)*)|(?:0x[0-9a-f]+(?:'[0-9a-f]+)*)|(?:0b[01]+(?:'[01]+)*))(?:u?l{0,2}|l{0,2}u?)))(?=\b|\s|$))"),
QRegularExpression(R"((?<=\b|\s|^)(?i)(?:(?:[0-9]+\.[0-9]*(?:e[+-]?[0-9]+)?[fd]?)|(?:\.[0-9]+(?:e[+-]?[0-9]+)?[fd]?)|(?:[0-9]+(?:e[+-]?[0-9]+)[fd]?)|(?:[0-9]+(?:e[+-]?[0-9]+)?[fd])|(?:(?:(?:0x[0-9a-f]+\.?)|(?:0x[0-9a-f]*\.[0-9a-f]+))p[+-]?[0-9]+[fd]?)|(?:0)|(?:[1-9][0-9]*)|(?:0x[0-9a-f]+)|(?:0[0-7]+))(?=\b|\s|$))"),
"Number"
});

Expand Down

0 comments on commit 11f5647

Please sign in to comment.