1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE a_modes.inc}
19 interface
21 uses
22 Classes;
25 // ////////////////////////////////////////////////////////////////////////// //
26 type
28 public
29 const
34 //TTFloat = 3; // not yet
43 private
55 protected
59 public
84 public
91 // token start
102 // ////////////////////////////////////////////////////////////////////////// //
103 type
105 private
108 private
114 protected
117 public
124 private
128 protected
131 public
137 // ////////////////////////////////////////////////////////////////////////// //
138 type
140 protected
143 protected
146 public
159 // ////////////////////////////////////////////////////////////////////////// //
160 type
162 private
165 protected
168 public
174 implementation
176 uses
180 // ////////////////////////////////////////////////////////////////////////// //
184 // ////////////////////////////////////////////////////////////////////////// //
185 var
190 // ////////////////////////////////////////////////////////////////////////// //
192 const
194 $0402,$0403,$201A,$0453,$201E,$2026,$2020,$2021,$20AC,$2030,$0409,$2039,$040A,$040C,$040B,$040F,
195 $0452,$2018,$2019,$201C,$201D,$2022,$2013,$2014,$003F,$2122,$0459,$203A,$045A,$045C,$045B,$045F,
196 $00A0,$040E,$045E,$0408,$00A4,$0490,$00A6,$00A7,$0401,$00A9,$0404,$00AB,$00AC,$00AD,$00AE,$0407,
197 $00B0,$00B1,$0406,$0456,$0491,$00B5,$00B6,$00B7,$0451,$2116,$0454,$00BB,$0458,$0405,$0455,$0457,
198 $0410,$0411,$0412,$0413,$0414,$0415,$0416,$0417,$0418,$0419,$041A,$041B,$041C,$041D,$041E,$041F,
199 $0420,$0421,$0422,$0423,$0424,$0425,$0426,$0427,$0428,$0429,$042A,$042B,$042C,$042D,$042E,$042F,
200 $0430,$0431,$0432,$0433,$0434,$0435,$0436,$0437,$0438,$0439,$043A,$043B,$043C,$043D,$043E,$043F,
202 );
203 var
205 begin
213 // ////////////////////////////////////////////////////////////////////////// //
214 // TODO: make a hash or something
216 begin
222 // ////////////////////////////////////////////////////////////////////////// //
224 begin
240 begin
249 begin
258 begin
264 // skip CR in CR/LF
266 begin
275 var
277 begin
279 begin
281 begin
282 // single-line comment
284 begin
287 continue;
289 // multline comment
291 begin
292 // skip comment start
296 begin
298 begin
299 // skip comment end
302 break;
306 continue;
308 // nesting multline comment
310 begin
311 // skip comment start
316 begin
318 begin
319 // skip comment end
324 continue;
327 begin
328 // skip comment start
332 continue;
336 continue;
349 var
353 begin
355 begin
357 begin
361 begin
364 exit;
369 begin
377 begin
378 // skip prefix
383 // default base
389 begin
397 // check for valid number end
399 begin
401 if (curChar = '_') or ((curChar >= 'A') and (curChar <= 'Z')) or ((curChar >= 'a') and (curChar <= 'z')) or (curChar >= #128) then
402 begin
410 var
413 begin
419 begin
420 // escape
422 begin
425 // skip backslash and escape type
435 begin
440 begin
448 continue;
450 // duplicate single quote (pascal style)
452 begin
453 // skip both quotes
457 continue;
460 begin
462 break;
470 begin
477 begin
483 begin
490 begin
494 exit;
502 // number?
503 if mAllowSignedNumbers and ((curChar = '+') or (curChar = '-')) then begin parseInt(); exit; end;
506 // string?
509 // identifier?
510 if (curChar = '_') or ((curChar >= 'A') and (curChar <= 'Z')) or ((curChar >= 'a') and (curChar <= 'z')) or (curChar >= #128) then begin parseId(); exit; end;
512 // known delimiters?
527 begin
535 begin
536 if (mTokType <> TTId) or (not StrEqu(mTokStr, aid)) then raise Exception.Create('identifier '''+aid+''' expected');
542 begin
551 begin
553 if (not allowEmpty) and (Length(mTokStr) = 0) then raise Exception.Create('non-empty string expected');
560 begin
568 begin
575 begin
582 begin
583 if (mTokType <> TTDelim) then raise Exception.Create(Format('delimiter ''%s'' expected', [ch]));
590 begin
598 // ////////////////////////////////////////////////////////////////////////// //
600 begin
612 begin
624 begin
632 begin
635 begin
648 // ////////////////////////////////////////////////////////////////////////// //
650 begin
658 begin
665 begin
673 // ////////////////////////////////////////////////////////////////////////// //
675 procedure TTextWriter.put (const s: AnsiString); overload; begin if (Length(s) > 0) then putBuf((@(s[1]))^, Length(s)); end;
678 procedure TTextWriter.put (const fmt: AnsiString; args: array of const); overload; begin put(formatstrf(fmt, args)); end;
679 procedure TTextWriter.putIndent (); var f: Integer; begin for f := 1 to mIndent do put(' '); end;
684 // ////////////////////////////////////////////////////////////////////////// //
686 begin
693 begin
700 var
702 begin
704 begin
707 {
708 while (len > 0) do
709 begin
710 write(pc^);
711 Inc(pc);
712 Dec(len);
713 end;
714 }