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 protected
111 public
118 private
122 protected
125 public
131 // ////////////////////////////////////////////////////////////////////////// //
132 type
134 protected
137 protected
140 public
153 // ////////////////////////////////////////////////////////////////////////// //
154 type
156 private
159 protected
162 public
168 implementation
170 uses
174 var
179 // ////////////////////////////////////////////////////////////////////////// //
181 const
183 $0402,$0403,$201A,$0453,$201E,$2026,$2020,$2021,$20AC,$2030,$0409,$2039,$040A,$040C,$040B,$040F,
184 $0452,$2018,$2019,$201C,$201D,$2022,$2013,$2014,$003F,$2122,$0459,$203A,$045A,$045C,$045B,$045F,
185 $00A0,$040E,$045E,$0408,$00A4,$0490,$00A6,$00A7,$0401,$00A9,$0404,$00AB,$00AC,$00AD,$00AE,$0407,
186 $00B0,$00B1,$0406,$0456,$0491,$00B5,$00B6,$00B7,$0451,$2116,$0454,$00BB,$0458,$0405,$0455,$0457,
187 $0410,$0411,$0412,$0413,$0414,$0415,$0416,$0417,$0418,$0419,$041A,$041B,$041C,$041D,$041E,$041F,
188 $0420,$0421,$0422,$0423,$0424,$0425,$0426,$0427,$0428,$0429,$042A,$042B,$042C,$042D,$042E,$042F,
189 $0430,$0431,$0432,$0433,$0434,$0435,$0436,$0437,$0438,$0439,$043A,$043B,$043C,$043D,$043E,$043F,
191 );
192 var
194 begin
202 // ////////////////////////////////////////////////////////////////////////// //
203 // TODO: make a hash or something
205 begin
211 // ////////////////////////////////////////////////////////////////////////// //
213 begin
229 begin
238 begin
247 begin
253 // skip CR in CR/LF
255 begin
264 var
266 begin
268 begin
270 begin
271 // single-line comment
273 begin
276 continue;
278 // multline comment
280 begin
281 // skip comment start
285 begin
287 begin
288 // skip comment end
291 break;
295 continue;
297 // nesting multline comment
299 begin
300 // skip comment start
305 begin
307 begin
308 // skip comment end
313 continue;
316 begin
317 // skip comment start
321 continue;
325 continue;
338 var
342 begin
344 begin
346 begin
350 begin
353 exit;
358 begin
366 begin
367 // skip prefix
372 // default base
378 begin
386 // check for valid number end
388 begin
390 if (curChar = '_') or ((curChar >= 'A') and (curChar <= 'Z')) or ((curChar >= 'a') and (curChar <= 'z')) or (curChar >= #128) then
391 begin
399 var
402 begin
408 begin
409 // escape
411 begin
414 // skip backslash and escape type
424 begin
429 begin
437 continue;
439 // duplicate single quote (pascal style)
441 begin
442 // skip both quotes
446 continue;
449 begin
451 break;
459 begin
466 begin
472 begin
479 begin
483 exit;
491 // number?
492 if mAllowSignedNumbers and ((curChar = '+') or (curChar = '-')) then begin parseInt(); exit; end;
495 // string?
498 // identifier?
499 if (curChar = '_') or ((curChar >= 'A') and (curChar <= 'Z')) or ((curChar >= 'a') and (curChar <= 'z')) or (curChar >= #128) then begin parseId(); exit; end;
501 // known delimiters?
516 begin
524 begin
525 if (mTokType <> TTId) or (CompareText(mTokStr, aid) <> 0) then raise Exception.Create('identifier '''+aid+''' expected');
531 begin
540 begin
542 if (not allowEmpty) and (Length(mTokStr) = 0) then raise Exception.Create('non-empty string expected');
549 begin
557 begin
564 begin
571 begin
572 if (mTokType <> TTDelim) then raise Exception.Create(Format('delimiter ''%s'' expected', [ch]));
579 begin
587 // ////////////////////////////////////////////////////////////////////////// //
589 begin
596 begin
604 begin
611 var
613 begin
620 // ////////////////////////////////////////////////////////////////////////// //
622 begin
630 begin
637 begin
645 // ////////////////////////////////////////////////////////////////////////// //
647 procedure TTextWriter.put (const s: AnsiString); overload; begin if (Length(s) > 0) then putBuf((@(s[1]))^, Length(s)); end;
650 procedure TTextWriter.put (const fmt: AnsiString; args: array of const); overload; begin put(formatstrf(fmt, args)); end;
651 procedure TTextWriter.putIndent (); var f: Integer; begin for f := 1 to mIndent do put(' '); end;
656 // ////////////////////////////////////////////////////////////////////////// //
658 begin
665 begin
672 var
674 begin
676 begin
679 {
680 while (len > 0) do
681 begin
682 write(pc^);
683 Inc(pc);
684 Dec(len);
685 end;
686 }