summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarco <marco@3ad0048d-3df7-0310-abae-a5850022a9f2>2010-08-06 13:31:17 +0000
committermarco <marco@3ad0048d-3df7-0310-abae-a5850022a9f2>2010-08-06 13:31:17 +0000
commit9fd65ae6e59b0153d8ecce506a45ecdf4fb0c6f6 (patch)
treed9901aa4306e4954e24a43f26c65f29e153e6a27
parent495c0f99fa178d67ae71c244d8b8eef5a5772872 (diff)
downloadfpc-9fd65ae6e59b0153d8ecce506a45ecdf4fb0c6f6.tar.gz
* Patch from Dmitry for #$ef#$ab styled literals. Mantis 17110
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@15725 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--packages/fcl-passrc/src/pscanner.pp124
1 files changed, 67 insertions, 57 deletions
diff --git a/packages/fcl-passrc/src/pscanner.pp b/packages/fcl-passrc/src/pscanner.pp
index 90ed2a959e..d9a5601539 100644
--- a/packages/fcl-passrc/src/pscanner.pp
+++ b/packages/fcl-passrc/src/pscanner.pp
@@ -185,6 +185,8 @@ type
TPOptions = (po_delphi);
+ { TPascalScanner }
+
TPascalScanner = class
private
FFileResolver: TFileResolver;
@@ -209,6 +211,7 @@ type
protected
procedure Error(const Msg: string);overload;
procedure Error(const Msg: string; Args: array of Const);overload;
+ function DoFetchTextToken: TToken;
function DoFetchToken: TToken;
public
Options : set of TPOptions;
@@ -569,6 +572,68 @@ begin
raise EScannerError.CreateFmt(Msg, Args);
end;
+function TPascalScanner.DoFetchTextToken:TToken;
+var
+ OldLength : Integer;
+ TokenStart : PChar;
+ SectionLength : Integer;
+begin
+ Result:=tkEOF;
+ OldLength:=0;
+ FCurTokenString := '';
+
+ while TokenStr[0] in ['#', ''''] do
+ begin
+ case TokenStr[0] of
+ '#':
+ begin
+ TokenStart := TokenStr;
+ Inc(TokenStr);
+ if TokenStr[0] = '$' then
+ begin
+ Inc(TokenStr);
+ repeat
+ Inc(TokenStr);
+ until not (TokenStr[0] in ['0'..'9', 'A'..'F', 'a'..'f']);
+ end else
+ repeat
+ Inc(TokenStr);
+ until not (TokenStr[0] in ['0'..'9']);
+ if Result=tkEOF then Result := tkChar else Result:=tkString;
+ end;
+ '''':
+ begin
+ TokenStart := TokenStr;
+ Inc(TokenStr);
+
+ while true do
+ begin
+ if TokenStr[0] = '''' then
+ if TokenStr[1] = '''' then
+ Inc(TokenStr)
+ else
+ break;
+
+ if TokenStr[0] = #0 then
+ Error(SErrOpenString);
+
+ Inc(TokenStr);
+ end;
+ Inc(TokenStr);
+ Result := tkString;
+ end;
+ else
+ Break;
+ end;
+ SectionLength := TokenStr - TokenStart;
+ SetLength(FCurTokenString, OldLength + SectionLength);
+ if SectionLength > 0 then
+ Move(TokenStart^, FCurTokenString[OldLength + 1], SectionLength);
+ Inc(OldLength, SectionLength);
+ end;
+
+end;
+
function TPascalScanner.DoFetchToken: TToken;
function FetchLine: Boolean;
@@ -623,27 +688,8 @@ begin
end;
until not (TokenStr[0] in [#9, ' ']);
end;
- '#':
- begin
- TokenStart := TokenStr;
- Inc(TokenStr);
- if TokenStr[0] = '$' then
- begin
- Inc(TokenStr);
- repeat
- Inc(TokenStr);
- until not (TokenStr[0] in ['0'..'9', 'A'..'F', 'a'..'f']);
- end else
- repeat
- Inc(TokenStr);
- until not (TokenStr[0] in ['0'..'9']);
-
- SectionLength := TokenStr - TokenStart;
- SetLength(FCurTokenString, SectionLength);
- if SectionLength > 0 then
- Move(TokenStart^, FCurTokenString[1], SectionLength);
- Result := tkChar;
- end;
+ '#', '''':
+ Result:=DoFetchTextToken;
'&':
begin
TokenStart := TokenStr;
@@ -680,42 +726,6 @@ begin
Move(TokenStart^, FCurTokenString[1], SectionLength);
Result := tkNumber;
end;
- '''':
- begin
- Inc(TokenStr);
- TokenStart := TokenStr;
- OldLength := 0;
- FCurTokenString := '';
-
- while true do
- begin
- if TokenStr[0] = '''' then
- if TokenStr[1] = '''' then
- begin
- SectionLength := TokenStr - TokenStart + 1;
- SetLength(FCurTokenString, OldLength + SectionLength);
- if SectionLength > 0 then
- Move(TokenStart^, FCurTokenString[OldLength + 1], SectionLength);
- Inc(OldLength, SectionLength);
- Inc(TokenStr);
- TokenStart := TokenStr+1;
- end else
- break;
-
- if TokenStr[0] = #0 then
- Error(SErrOpenString);
-
- Inc(TokenStr);
- end;
-
- SectionLength := TokenStr - TokenStart;
- SetLength(FCurTokenString, OldLength + SectionLength);
- if SectionLength > 0 then
- Move(TokenStart^, FCurTokenString[OldLength + 1], SectionLength);
-
- Inc(TokenStr);
- Result := tkString;
- end;
'(':
begin
Inc(TokenStr);