mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-18 04:49:43 +02:00
JCF2: Support octal numbers. Issue #31876, patch from CCRDude.
git-svn-id: trunk@55028 -
This commit is contained in:
parent
f0a4e67894
commit
3ea7d0a0f9
@ -30,6 +30,7 @@ unit BuildTokenList;
|
||||
This is the lexical analysis phase of the parsing
|
||||
|
||||
2014.11.02 ~bk Added lexing of binary constants (ex. -> const a=%101001;)
|
||||
2017.05.17 ~pktv Added lexing of octal constants (ex. -> const a=&777;)
|
||||
}
|
||||
|
||||
{$I JcfGlobal.inc}
|
||||
@ -42,6 +43,8 @@ uses
|
||||
|
||||
type
|
||||
|
||||
{ TBuildTokenList }
|
||||
|
||||
TBuildTokenList = class(TObject)
|
||||
private
|
||||
{ property implementation }
|
||||
@ -75,6 +78,7 @@ type
|
||||
function TryNumber(const pcToken: TSourceToken): boolean;
|
||||
function TryHexNumber(const pcToken: TSourceToken): boolean;
|
||||
function TryBinNumber(const pcToken: TSourceToken): boolean; // ~bk 14.11.01
|
||||
function TryOctNumber(const pcToken: TSourceToken): boolean; // ~pktv 17.05.19
|
||||
|
||||
function TryDots(const pcToken: TSourceToken): boolean;
|
||||
|
||||
@ -171,6 +175,8 @@ var
|
||||
exit;
|
||||
if TryBinNumber(lcNewToken) then // ~bk 2014.11.01
|
||||
exit;
|
||||
if TryOctNumber(lcNewToken) then // ~pktv 2017.05.19
|
||||
exit;
|
||||
|
||||
if TryDots(lcNewToken) then
|
||||
exit;
|
||||
@ -659,6 +665,36 @@ begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
{ ~pktb 2017.05.19 - Oct numbers are prefixed with & }
|
||||
function TBuildTokenList.TryOctNumber(const pcToken: TSourceToken): boolean;
|
||||
function CharIsOctDigit(const c: Char): Boolean;
|
||||
const
|
||||
OctDigits: set of AnsiChar = [
|
||||
'0', '1', '2', '3', '4', '5', '6', '7'];
|
||||
begin
|
||||
Result := (c in OctDigits);
|
||||
end;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
{ starts with a & }
|
||||
if Current <> '&' then
|
||||
exit;
|
||||
|
||||
pcToken.TokenType := ttNumber;
|
||||
pcToken.SourceCode := Current;
|
||||
Consume;
|
||||
|
||||
{ concat any subsequent binary chars }
|
||||
while CharIsOctDigit(Current) do
|
||||
begin
|
||||
pcToken.SourceCode := pcToken.SourceCode + Current;
|
||||
Consume;
|
||||
end;
|
||||
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
{ try the range '..' operator and object access '.' operator }
|
||||
function TBuildTokenList.TryDots(const pcToken: TSourceToken): boolean;
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user