Skip to content

Commit

Permalink
Correctly parse various unusual integer literals
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneduffield committed Oct 6, 2023
1 parent ae9c752 commit edd79d7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `add` is no longer colorized as a keyword in the SonarQube web interface.
- `remove` is no longer colorized as a keyword in the SonarQube web interface.
- `variant` is no longer colorized as a keyword in the SonarQube web interface.
- Parsing errors for unusual escaped character, hex integer, and binary integer literals.

## [0.40.0] - 2023-01-10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1201,9 +1201,9 @@ TkIntNumber : DigitSeq (
)?
)?
;
TkHexNumber : '$' HexDigitSeq
TkHexNumber : '$' ('_' | HexDigit)*
;
TkBinaryNumber : '%' BinaryDigitSeq
TkBinaryNumber : '%' ('_' | BinaryDigit)*
;
TkAsmId : { asmMode }? => '@' '@'? (Alpha | '_' | Digit)+
;
Expand All @@ -1213,9 +1213,9 @@ TkQuotedString : '\'' ('\'\'' | ~('\''))* '\''
;
TkAsmDoubleQuotedString : { asmMode }? => '"' (~('\"'))* '"'
;
TkCharacterEscapeCode : '#' DigitSeq
| '#' '$' HexDigitSeq
| '#' '%' BinaryDigitSeq
TkCharacterEscapeCode : '#' ('_' | Digit)+
| '#' '$' ('_' | HexDigit)+
| '#' '%' ('_' | BinaryDigit)+
;
//----------------------------------------------------------------------------
// Fragments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,9 @@ void testEmptyFileShouldThrow() {
DelphiFileUtils.mockConfig()))
.isInstanceOf(DelphiFileConstructionException.class);
}

@Test
void testUnusualIntegerLiterals() {
parseFile("UnusualIntegerLiterals.pas");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
unit UnusualIntegerLiterals;

interface

const
HexWithoutDigits = $;
BinaryWithoutDigits = %;
HexStartingWithUnderscore = $_;
BinaryStartingWithUnderscore = %_;
HexStartingWithManyUnderscores = $__;
BinaryStartingWithManyUnderscores = %__;

CharHexStartingWithUnderscore = #$_;
CharBinaryStartingWithUnderscore = #%_;
CharHexStartingWithManyUnderscores = #$__;
CharBinaryStartingWithManyUnderscores = #%__;

CharDecimalStartingWithUnderscore = #_;
CharDecimalStartingWithManyUnderscores = #__;

implementation

end.

0 comments on commit edd79d7

Please # to comment.