~ubuntu-branches/ubuntu/lucid/fpc/lucid-proposed

« back to all changes in this revision

Viewing changes to fpcsrc/rtl/objpas/classes/parser.inc

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-10-09 23:29:00 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081009232900-553f61m37jkp6upv
Tags: 2.2.2-4
[ Torsten Werner ]
* Update ABI version in fpc-depends automatically.
* Remove empty directories from binary package fpc-source.

[ Mazen Neifer ]
* Removed leading path when calling update-alternatives to remove a Linitian
  error.
* Fixed clean target.
* Improved description of packages. (Closes: #498882)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
{
2
2
    This file is part of the Free Component Library (FCL)
3
 
    Copyright (c) 1999-2000 by the Free Pascal development team
 
3
    Copyright (c) 1999-2007 by the Free Pascal development team
4
4
 
5
5
    See the file COPYING.FPC, included in this distribution,
6
6
    for details about the copyright.
17
17
 
18
18
const
19
19
  ParseBufSize     = 4096;
20
 
 
21
 
procedure TParser.ReadBuffer;
 
20
  LastSpecialToken = 5;
 
21
 
 
22
  TokNames : array[0..LastSpecialToken] of string =
 
23
  (
 
24
    'EOF',
 
25
    'Symbol',
 
26
    'String',
 
27
    'Integer',
 
28
    'Float',
 
29
    'WideString'
 
30
  );
 
31
 
 
32
function TParser.GetTokenName(aTok: char): string;
 
33
begin
 
34
  if ord(aTok) <= LastSpecialToken then
 
35
    Result:=TokNames[ord(aTok)]
 
36
  else Result:=aTok;
 
37
end;
 
38
 
 
39
procedure TParser.LoadBuffer;
 
40
var toread : integer;
 
41
begin
 
42
  toread:=fStream.Size-fStream.Position;
 
43
  if toread>ParseBufSize then toread:=ParseBufSize;
 
44
  if toread=0 then
 
45
  begin
 
46
    fEofReached:=true;
 
47
    exit;
 
48
  end;
 
49
  fStream.ReadBuffer(fBuf[0],toread);
 
50
  fBuf[toread]:=#0;
 
51
  inc(fDeltaPos,fPos);
 
52
  fPos:=0;
 
53
  fBufLen:=toread;
 
54
end;
 
55
 
 
56
procedure TParser.CheckLoadBuffer; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
 
57
begin
 
58
  if fBuf[fPos]=#0 then LoadBuffer;
 
59
end;
 
60
 
 
61
procedure TParser.ProcessChar; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
 
62
begin
 
63
  fLastTokenStr:=fLastTokenStr+fBuf[fPos];
 
64
  inc(fPos);
 
65
  CheckLoadBuffer;
 
66
end;
 
67
 
 
68
function TParser.IsNumber: boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
 
69
begin
 
70
  Result:=fBuf[fPos] in ['0'..'9'];
 
71
end;
 
72
 
 
73
function TParser.IsHexNum: boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
 
74
begin
 
75
  Result:=fBuf[fPos] in ['0'..'9','A'..'F','a'..'f'];
 
76
end;
 
77
 
 
78
function TParser.IsAlpha: boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
 
79
begin
 
80
  Result:=fBuf[fPos] in ['_','A'..'Z','a'..'z'];
 
81
end;
 
82
 
 
83
function TParser.IsAlphaNum: boolean; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
 
84
begin
 
85
  Result:=IsAlpha or IsNumber;
 
86
end;
 
87
 
 
88
function TParser.GetHexValue(c: char): byte; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
 
89
begin
 
90
  case c of
 
91
    '0'..'9' : Result:=ord(c)-$30;
 
92
    'A'..'F' : Result:=ord(c)-$37; //-$41+$0A
 
93
    'a'..'f' : Result:=ord(c)-$57; //-$61+$0A
 
94
  end;
 
95
end;
 
96
 
 
97
function TParser.GetAlphaNum: string;
 
98
begin
 
99
  if not IsAlpha then
 
100
    ErrorFmt(SParExpected,[GetTokenName(toSymbol)]);
 
101
  Result:='';
 
102
  while IsAlphaNum do
 
103
  begin
 
104
    Result:=Result+fBuf[fPos];
 
105
    inc(fPos);
 
106
    CheckLoadBuffer;
 
107
  end;
 
108
end;
 
109
 
 
110
procedure TParser.HandleNewLine;
 
111
begin
 
112
  if fBuf[fPos]=#13 then //CR
 
113
  begin
 
114
    inc(fPos);
 
115
    CheckLoadBuffer;
 
116
    if fBuf[fPos]=#10 then inc(fPos); //CR LF
 
117
  end
 
118
  else inc(fPos); //LF
 
119
  inc(fSourceLine);
 
120
  fDeltaPos:=-(fPos-1);
 
121
end;
 
122
 
 
123
procedure TParser.SkipSpaces;
 
124
begin
 
125
  while fBuf[fPos] in [' ',#9] do
 
126
    inc(fPos);
 
127
end;
 
128
 
 
129
procedure TParser.SkipWhitespace;
 
130
begin
 
131
  while true do
 
132
  begin
 
133
    CheckLoadBuffer;
 
134
    case fBuf[fPos] of
 
135
      ' ',#9  : SkipSpaces;
 
136
      #10,#13 : HandleNewLine
 
137
      else break;
 
138
    end;
 
139
  end;
 
140
end;
 
141
 
 
142
procedure TParser.HandleEof;
 
143
begin
 
144
  fToken:=toEOF;
 
145
  fLastTokenStr:='';
 
146
end;
 
147
 
 
148
procedure TParser.HandleAlphaNum;
 
149
begin
 
150
  fLastTokenStr:=GetAlphaNum;
 
151
  fToken:=toSymbol;
 
152
end;
 
153
 
 
154
procedure TParser.HandleNumber;
 
155
type
 
156
  floatPunct = (fpDot,fpE);
 
157
  floatPuncts = set of floatPunct;
22
158
var
23
 
  Count            : Integer;
 
159
  allowed : floatPuncts;
24
160
begin
25
 
  Inc(FOrigin, FSourcePtr - FBuffer);
26
 
 
27
 
  FSourceEnd[0] := FSaveChar;
28
 
  Count         := FBufPtr - FSourcePtr;
29
 
  if Count <> 0 then
30
 
  begin
31
 
    Move(FSourcePtr[0], FBuffer[0], Count);
32
 
  end;
33
 
 
34
 
  FBufPtr := FBuffer + Count;
35
 
  Inc(FBufPtr, FStream.Read(FBufPtr[0], FBufEnd - FBufPtr));
36
 
 
37
 
  FSourcePtr := FBuffer;
38
 
  FSourceEnd := FBufPtr;
39
 
  if (FSourceEnd = FBufEnd) then
40
 
  begin
41
 
    FSourceEnd := LineStart(FBuffer, FSourceEnd - 1);
42
 
    if FSourceEnd = FBuffer then
 
161
  fLastTokenStr:='';
 
162
  while IsNumber do
 
163
    ProcessChar;
 
164
  fToken:=toInteger;
 
165
  if (fBuf[fPos] in ['.','e','E']) then
 
166
  begin
 
167
    fToken:=toFloat;
 
168
    allowed:=[fpDot,fpE];
 
169
    while (fBuf[fPos] in ['.','e','E','0'..'9']) do
43
170
    begin
44
 
      Error(SLineTooLong);
45
 
    end;
46
 
  end;
47
 
  FSaveChar := FSourceEnd[0];
48
 
  FSourceEnd[0] := #0;
49
 
end;
50
 
 
51
 
procedure TParser.SkipBlanks;
52
 
begin
53
 
  while FSourcePtr^ < #33 do begin
54
 
    if FSourcePtr^ = #0 then begin
55
 
      ReadBuffer;
56
 
      if FSourcePtr^ = #0 then exit;
57
 
      continue;
58
 
    end else if FSourcePtr^ = #10 then Inc(FSourceLine);
59
 
    Inc(FSourcePtr);
60
 
  end;
 
171
      case fBuf[fPos] of
 
172
        '.'     : if fpDot in allowed then Exclude(allowed,fpDot) else break;
 
173
        'E','e' : if fpE in allowed then
 
174
                  begin
 
175
                    allowed:=[];
 
176
                    ProcessChar;
 
177
                    if (fBuf[fPos] in ['+','-']) then ProcessChar;
 
178
                    if not (fBuf[fPos] in ['0'..'9']) then
 
179
                      ErrorFmt(SParInvalidFloat,[fLastTokenStr+fBuf[fPos]]);
 
180
                  end
 
181
                  else break;
 
182
      end;
 
183
      ProcessChar;
 
184
    end;
 
185
  end;
 
186
  if (fBuf[fPos] in ['s','S','d','D','c','C']) then //single, date, currency
 
187
  begin
 
188
    fFloatType:=fBuf[fPos];
 
189
    inc(fPos);
 
190
    fToken:=toFloat;
 
191
  end
 
192
  else fFloatType:=#0;
 
193
end;
 
194
 
 
195
procedure TParser.HandleHexNumber;
 
196
var valid : boolean;
 
197
begin
 
198
  fLastTokenStr:='$';
 
199
  inc(fPos);
 
200
  CheckLoadBuffer;
 
201
  valid:=false;
 
202
  while IsHexNum do
 
203
  begin
 
204
    valid:=true;
 
205
    ProcessChar;
 
206
  end;
 
207
  if not valid then
 
208
    ErrorFmt(SParInvalidInteger,[fLastTokenStr]);
 
209
  fToken:=toInteger;
 
210
end;
 
211
 
 
212
function TParser.HandleQuotedString: string;
 
213
begin
 
214
  Result:='';
 
215
  inc(fPos);
 
216
  CheckLoadBuffer;
 
217
  while true do
 
218
  begin
 
219
    case fBuf[fPos] of
 
220
      #0     : ErrorStr(SParUnterminatedString);
 
221
      #13,#10 : ErrorStr(SParUnterminatedString);
 
222
      ''''   : begin
 
223
                 inc(fPos);
 
224
                 CheckLoadBuffer;
 
225
                 if fBuf[fPos]<>'''' then exit;
 
226
               end;
 
227
    end;
 
228
    Result:=Result+fBuf[fPos];
 
229
    inc(fPos);
 
230
    CheckLoadBuffer;
 
231
  end;
 
232
end;
 
233
 
 
234
function TParser.HandleDecimalString(var ascii : boolean): widestring;
 
235
var i : integer;
 
236
begin
 
237
  Result:='';
 
238
  inc(fPos);
 
239
  CheckLoadBuffer;
 
240
  while IsNumber do
 
241
  begin
 
242
    Result:=Result+fBuf[fPos];
 
243
    inc(fPos);
 
244
    CheckLoadBuffer;
 
245
  end;
 
246
  if not TryStrToInt(Result,i) then
 
247
  i:=0;
 
248
  if i>127 then ascii:=false;
 
249
  setlength(Result,1);
 
250
  Result[1]:=widechar(word(i));
 
251
end;
 
252
 
 
253
procedure TParser.HandleString;
 
254
var ascii : boolean;
 
255
begin
 
256
  fLastTokenWStr:='';
 
257
  ascii:=true;
 
258
  while true do
 
259
    case fBuf[fPos] of
 
260
      '''' : fLastTokenWStr:=fLastTokenWStr+HandleQuotedString;
 
261
      '#'  : fLastTokenWStr:=fLastTokenWStr+HandleDecimalString(ascii)
 
262
      else break;
 
263
    end;
 
264
  if ascii then
 
265
    fToken:=toString
 
266
  else
 
267
    fToken:=toWString;
 
268
  fLastTokenStr:=fLastTokenWStr;
 
269
end;
 
270
 
 
271
procedure TParser.HandleMinus;
 
272
begin
 
273
  inc(fPos);
 
274
  CheckLoadBuffer;
 
275
  if IsNumber then
 
276
  begin
 
277
    HandleNumber;
 
278
    fLastTokenStr:='-'+fLastTokenStr;
 
279
  end
 
280
  else
 
281
  begin
 
282
    fToken:='-';
 
283
    fLastTokenStr:=fToken;
 
284
  end;
 
285
end;
 
286
 
 
287
procedure TParser.HandleUnknown;
 
288
begin
 
289
  fToken:=fBuf[fPos];
 
290
  fLastTokenStr:=fToken;
 
291
  inc(fPos);
61
292
end;
62
293
 
63
294
constructor TParser.Create(Stream: TStream);
64
295
begin
65
 
  inherited Create;
66
 
 
67
 
  FStream := Stream;
68
 
  GetMem(FBuffer, ParseBufSize);
69
 
 
70
 
  FBuffer[0]  := #0;
71
 
  FBufPtr     := FBuffer;
72
 
  FBufEnd     := FBuffer + ParseBufSize;
73
 
  FSourcePtr  := FBuffer;
74
 
  FSourceEnd  := FBuffer;
75
 
  FTokenPtr   := FBuffer;
76
 
  FSourceLine := 1;
77
 
 
 
296
  fStream:=Stream;
 
297
  fBuf:=GetMem(ParseBufSize+1);
 
298
  fBufLen:=0;
 
299
  fPos:=0;
 
300
  fDeltaPos:=1;
 
301
  fSourceLine:=1;
 
302
  fEofReached:=false;
 
303
  fLastTokenStr:='';
 
304
  fLastTokenWStr:='';
 
305
  fFloatType:=#0;
 
306
  fToken:=#0;
 
307
  LoadBuffer;
78
308
  NextToken;
79
309
end;
80
310
 
81
 
 
82
311
destructor TParser.Destroy;
83
312
begin
84
 
  if Assigned(FBuffer) then
85
 
  begin
86
 
    FStream.Seek(PtrInt(FTokenPtr) - PtrInt(FBufPtr), 1);
87
 
    FreeMem(FBuffer, ParseBufSize);
88
 
  end;
89
 
 
90
 
  inherited Destroy;
 
313
  fStream.Position:=SourcePos;
 
314
  FreeMem(fBuf);
91
315
end;
92
316
 
93
 
procedure TParser.CheckToken(T : Char);
 
317
procedure TParser.CheckToken(T: Char);
94
318
begin
95
 
  if Token <> T then
96
 
  begin
97
 
    case T of
98
 
      toSymbol:
99
 
        Error(SIdentifierExpected);
100
 
      toString:
101
 
        Error(SStringExpected);
102
 
      toInteger, toFloat:
103
 
        Error(SNumberExpected);
104
 
    else
105
 
      ErrorFmt(SCharExpected, [T]);
106
 
    end;
107
 
  end;
 
319
  if fToken<>T then
 
320
    ErrorFmt(SParWrongTokenType,[GetTokenName(T),GetTokenName(fToken)]);
108
321
end;
109
322
 
110
323
procedure TParser.CheckTokenSymbol(const S: string);
111
324
begin
112
 
  if not TokenSymbolIs(S) then
113
 
    ErrorFmt(SSymbolExpected, [S]);
 
325
  CheckToken(toSymbol);
 
326
  if CompareText(fLastTokenStr,S)<>0 then
 
327
    ErrorFmt(SParWrongTokenSymbol,[s,fLastTokenStr]);
114
328
end;
115
329
 
116
 
Procedure TParser.Error(const Ident: string);
 
330
procedure TParser.Error(const Ident: string);
117
331
begin
118
332
  ErrorStr(Ident);
119
333
end;
120
334
 
121
 
Procedure TParser.ErrorFmt(const Ident: string; const Args: array of const);
122
 
begin
123
 
  ErrorStr(Format(Ident, Args));
124
 
end;
125
 
 
126
 
Procedure TParser.ErrorStr(const Message: string);
127
 
begin
128
 
  raise EParserError.CreateFmt(SParseError, [Message, FSourceLine]);
129
 
end;
130
 
 
 
335
procedure TParser.ErrorFmt(const Ident: string; const Args: array of const);
 
336
begin
 
337
  ErrorStr(Format(Ident,Args));
 
338
end;
 
339
 
 
340
procedure TParser.ErrorStr(const Message: string);
 
341
begin
 
342
  raise EParserError.CreateFmt(Message+SParLocInfo,[SourceLine,fPos+fDeltaPos,SourcePos]);
 
343
end;
131
344
 
132
345
procedure TParser.HexToBinary(Stream: TStream);
133
 
 
134
 
  function HexDigitToInt(c: Char): Integer;
 
346
var outbuf : array[0..ParseBufSize-1] of byte;
 
347
    b : byte;
 
348
    i : integer;
 
349
begin
 
350
  i:=0;
 
351
  SkipWhitespace;
 
352
  while IsHexNum do
135
353
  begin
136
 
    if (c >= '0') and (c <= '9') then Result := Ord(c) - Ord('0')
137
 
    else if (c >= 'A') and (c <= 'F') then Result := Ord(c) - Ord('A') + 10
138
 
    else if (c >= 'a') and (c <= 'f') then Result := Ord(c) - Ord('a') + 10
139
 
    else Result := -1;
140
 
  end;
141
 
 
142
 
var
143
 
  buf: array[0..255] of Byte;
144
 
  digit1: Integer;
145
 
  bytes: Integer;
146
 
begin
147
 
  SkipBlanks;
148
 
  while FSourcePtr^ <> '}' do begin
149
 
    bytes := 0;
150
 
    while True do begin
151
 
      digit1 := HexDigitToInt(FSourcePtr[0]);
152
 
      if digit1 < 0 then break;
153
 
      buf[bytes] := digit1 shl 4 or HexDigitToInt(FSourcePtr[1]);
154
 
      Inc(FSourcePtr, 2);
155
 
      Inc(bytes);
 
354
    b:=(GetHexValue(fBuf[fPos]) shl 4);
 
355
    inc(fPos);
 
356
    CheckLoadBuffer;
 
357
    if not IsHexNum then
 
358
      Error(SParUnterminatedBinValue);
 
359
    b:=b or GetHexValue(fBuf[fPos]);
 
360
    inc(fPos);
 
361
    outbuf[i]:=b;
 
362
    inc(i);
 
363
    if i>=ParseBufSize then
 
364
    begin
 
365
      Stream.WriteBuffer(outbuf[0],i);
 
366
      i:=0;
156
367
    end;
157
 
    if bytes = 0 then Error(SInvalidBinary);
158
 
    Stream.Write(buf, bytes);
159
 
    SkipBlanks;
 
368
    SkipWhitespace;
160
369
  end;
 
370
  if i>0 then
 
371
    Stream.WriteBuffer(outbuf[0],i);
161
372
  NextToken;
162
373
end;
163
374
 
 
375
function TParser.NextToken: Char;
164
376
 
165
 
Function TParser.NextToken: Char;
166
 
var
167
 
  CharCount         : Integer;
168
 
 
169
 
  procedure PutChar(achar: Word);
170
 
  begin
171
 
    inc(CharCount);
172
 
    if length(fString) < CharCount then begin
173
 
     setlength(fString,length(fString) + length(fString) div 4 + 64);
174
 
    end;
175
 
    fString[CharCount]:= WideChar(achar);
176
 
  end;
177
 
 
178
 
var
179
 
  I                : Integer;
180
 
  P                : PChar;
181
377
begin
182
 
  SkipBlanks;
183
 
  P := FSourcePtr;
184
 
  FTokenPtr := P;
185
 
  case P^ of
186
 
    'A'..'Z', 'a'..'z', '_':
187
 
      begin
188
 
        Inc(P);
189
 
        while P^ in ['A'..'Z', 'a'..'z', '0'..'9', '_'] do Inc(P);
190
 
        Result := toSymbol;
191
 
      end;
192
 
    '#', '''':
193
 
      begin
194
 
        CharCount:= 0;
195
 
        while True do
196
 
          case P^ of
197
 
            '#':
198
 
              begin
199
 
                Inc(P);
200
 
                I := 0;
201
 
                while P^ in ['0'..'9'] do
202
 
                begin
203
 
                  I := I * 10 + (Ord(P^) - Ord('0'));
204
 
                  Inc(P);
205
 
                end;
206
 
                PutChar(I)
207
 
              end;
208
 
            '''':
209
 
              begin
210
 
                Inc(P);
211
 
                while True do
212
 
                begin
213
 
                  case P^ of
214
 
                    #0, #10, #13:
215
 
                      Error(SInvalidString);
216
 
                    '''':
217
 
                      begin
218
 
                        Inc(P);
219
 
                        if P^ <> '''' then Break;
220
 
                      end;
221
 
                  end;
222
 
                  PutChar(Word(P^));
223
 
                  Inc(P);
224
 
                end;
225
 
              end;
226
 
          else
227
 
            Break;
228
 
          end;
229
 
        setlength(fString,CharCount);
230
 
        Result := toString;
231
 
      end;
232
 
    '$':
233
 
      begin
234
 
        Inc(P);
235
 
        while P^ in ['0'..'9', 'A'..'F', 'a'..'f'] do Inc(P);
236
 
        Result := toInteger;
237
 
      end;
238
 
    '-', '0'..'9':
239
 
      begin
240
 
        Inc(P);
241
 
        while P^ in ['0'..'9'] do Inc(P);
242
 
        Result := toInteger;
243
 
        while (P^ in ['0'..'9', '.', 'e', 'E', '+', '-']) and not
244
 
          ((P[0] = '.') and not (P[1] in ['0'..'9', 'e', 'E'])) do
245
 
        begin
246
 
          Inc(P);
247
 
          Result := toFloat;
248
 
        end;
249
 
      end;
 
378
  SkipWhiteSpace;
 
379
  if fEofReached then
 
380
    HandleEof
250
381
  else
251
 
    Result := P^;
252
 
    if Result <> toEOF then Inc(P);
253
 
  end;
254
 
  FSourcePtr := P;
255
 
  FToken := Result;
256
 
end;
257
 
 
258
 
Function TParser.SourcePos: Longint;
259
 
begin
260
 
  Result := FOrigin + (FTokenPtr - FBuffer);
261
 
end;
262
 
 
263
 
 
264
 
Function TParser.TokenComponentIdent: String;
265
 
var
266
 
  P                : PChar;
267
 
begin
268
 
  CheckToken(toSymbol);
269
 
 
270
 
  P := FSourcePtr;
271
 
  while P^ = '.' do
 
382
    case fBuf[fPos] of
 
383
      '_','A'..'Z','a'..'z' : HandleAlphaNum;
 
384
      '$'                   : HandleHexNumber;
 
385
      '-'                   : HandleMinus;
 
386
      '0'..'9'              : HandleNumber;
 
387
      '''','#'              : HandleString
 
388
      else
 
389
        HandleUnknown;
 
390
    end;
 
391
  Result:=fToken;
 
392
end;
 
393
 
 
394
function TParser.SourcePos: Longint;
 
395
begin
 
396
  Result:=fStream.Position-fBufLen+fPos;
 
397
end;
 
398
 
 
399
function TParser.TokenComponentIdent: string;
 
400
begin
 
401
  if fToken<>toSymbol then
 
402
    ErrorFmt(SParExpected,[GetTokenName(toSymbol)]);
 
403
  CheckLoadBuffer;
 
404
  while fBuf[fPos]='.' do
272
405
  begin
273
 
    Inc(P);
274
 
    if not (P^ in ['A'..'Z', 'a'..'z', '_']) then
275
 
      Error(SIdentifierExpected);
276
 
    repeat
277
 
      Inc(P)
278
 
    until not (P^ in ['A'..'Z', 'a'..'z', '0'..'9', '_']);
 
406
    ProcessChar;
 
407
    fLastTokenStr:=fLastTokenStr+GetAlphaNum;
279
408
  end;
280
 
  FSourcePtr := P;
281
 
  Result := TokenString;
 
409
  Result:=fLastTokenStr;
282
410
end;
283
411
 
284
412
Function TParser.TokenFloat: Extended;
285
 
var
286
 
  I,FloatError       : Integer;
287
 
  Back             : Real;
288
 
  S                : String;
289
 
  
290
 
begin
291
 
  Result   := 0;
292
 
  S:=TokenString;
293
 
  // Convert , decimal separator to ., handle backwards compatibility streams.
294
 
  for I:=1 to Length(S) do
295
 
    if (S[i]=',') then
296
 
      S[i]:='.';
297
 
  Val(S, Back, FloatError);
298
 
  Result := Back;
299
 
end;
300
 
 
301
 
Function TParser.TokenInt: Longint;
302
 
begin
303
 
  Result := StrToInt(TokenString);
304
 
end;
305
 
 
306
 
Function TParser.TokenString: string;
307
 
var
308
 
  L                : Integer;
309
 
begin
310
 
  if FToken = toString then begin
311
 
    result:= fString;
312
 
  end else begin
313
 
    L := FSourcePtr - FTokenPtr;
314
 
    SetLength(Result,L);
315
 
    If (L>0) then
316
 
      Move(FTokenPtr^,Result[1],L);
 
413
 
 
414
var errcode : word;
 
415
 
 
416
begin
 
417
  Val(fLastTokenStr,Result,errcode);
 
418
  if errcode<>0 then
 
419
    ErrorFmt(SParInvalidFloat,[fLastTokenStr]);
 
420
end;
 
421
 
 
422
Function TParser.TokenInt: Int64;
 
423
begin
 
424
  if not TryStrToInt64(fLastTokenStr,Result) then
 
425
    Result:=Int64(StrToQWord(fLastTokenStr)); //second chance for malformed files
 
426
end;
 
427
 
 
428
function TParser.TokenString: string;
 
429
begin
 
430
  case fToken of
 
431
    toWString : Result:=fLastTokenWStr;
 
432
    toFloat : if fFloatType<>#0 then
 
433
                Result:=fLastTokenStr+fFloatType
 
434
              else Result:=fLastTokenStr
 
435
    else
 
436
      Result:=fLastTokenStr;
317
437
  end;
318
438
end;
319
439
 
320
 
Function TParser.TokenWideString: widestring;
 
440
function TParser.TokenWideString: WideString;
321
441
begin
322
 
  if FToken = toString then
323
 
    result:= fString
 
442
  if fToken=toWString then
 
443
    Result:=fLastTokenWStr
324
444
  else
325
 
    result:= TokenString
 
445
    Result:=fLastTokenStr;
326
446
end;
327
447
 
328
 
 
329
 
Function TParser.TokenSymbolIs(const S: string): Boolean;
 
448
function TParser.TokenSymbolIs(const S: string): Boolean;
330
449
begin
331
 
  Result := (Token = toSymbol) and (CompareText(S, TokenString) = 0);
 
450
  Result:=(fToken=toSymbol) and (CompareText(fLastTokenStr,S)=0);
332
451
end;
 
452