sonar-delphi
sonar-delphi copied to clipboard
Parsing error on caret-escaped special characters
Prerequisites
- [X] This bug is in SonarDelphi, not SonarQube or my Delphi code.
- [X] This bug has not already been reported.
SonarDelphi version
1.0.0
SonarQube version
No response
Issue description
An undocumented Delphi feature (carried forward from TurboPascal) are escaped 'control characters'.
For example
const
CtrlC = ^C;
While it may be intended for use with visible characters, it's valid to escape any ~single-byte~ ascii character with this technique.
const
Space = ^ ;
Comment = ^{;
Plus = ^+;
The relevant section of the grammar in SonarDelphi currently has a few problems
escapedCharacter : TkCharacterEscapeCode
| '^' (TkIdentifier | TkIntNumber | TkAnyChar) -> ^({changeTokenType(TkEscapedCharacter)})
- It's not valid to accept any identifier or integer after the
^
; only one (~single-byte~ ascii) character may be escaped - Whitespace and the comment-starting
{
are handled by the 'hidden' channel and never make it to this section
For more info about the caret-escaped characters, see:
- https://stackoverflow.com/a/4916503/21058101
- http://www.delphibasics.co.uk/RTL.php?Name=Char
Steps to reproduce
Run SonarDelphi on the following program
program Test;
const A = ^ '';
begin
end.
observe the error
no viable alternative at input 'A'
Minimal Delphi code exhibiting the issue
No response