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
117 private
121 protected
124 public
130 // ////////////////////////////////////////////////////////////////////////// //
131 type
133 protected
136 protected
139 public
152 // ////////////////////////////////////////////////////////////////////////// //
153 type
155 private
158 protected
161 public
167 implementation
169 uses
173 var
178 // ////////////////////////////////////////////////////////////////////////// //
180 const
182 $0402,$0403,$201A,$0453,$201E,$2026,$2020,$2021,$20AC,$2030,$0409,$2039,$040A,$040C,$040B,$040F,
183 $0452,$2018,$2019,$201C,$201D,$2022,$2013,$2014,$003F,$2122,$0459,$203A,$045A,$045C,$045B,$045F,
184 $00A0,$040E,$045E,$0408,$00A4,$0490,$00A6,$00A7,$0401,$00A9,$0404,$00AB,$00AC,$00AD,$00AE,$0407,
185 $00B0,$00B1,$0406,$0456,$0491,$00B5,$00B6,$00B7,$0451,$2116,$0454,$00BB,$0458,$0405,$0455,$0457,
186 $0410,$0411,$0412,$0413,$0414,$0415,$0416,$0417,$0418,$0419,$041A,$041B,$041C,$041D,$041E,$041F,
187 $0420,$0421,$0422,$0423,$0424,$0425,$0426,$0427,$0428,$0429,$042A,$042B,$042C,$042D,$042E,$042F,
188 $0430,$0431,$0432,$0433,$0434,$0435,$0436,$0437,$0438,$0439,$043A,$043B,$043C,$043D,$043E,$043F,
190 );
191 var
193 begin
201 // ////////////////////////////////////////////////////////////////////////// //
202 // TODO: make a hash or something
204 begin
210 // ////////////////////////////////////////////////////////////////////////// //
212 begin
228 begin
237 begin
246 begin
252 // skip CR in CR/LF
254 begin
263 var
265 begin
267 begin
269 begin
270 // single-line comment
272 begin
275 continue;
277 // multline comment
279 begin
280 // skip comment start
284 begin
286 begin
287 // skip comment end
290 break;
294 continue;
296 // nesting multline comment
298 begin
299 // skip comment start
304 begin
306 begin
307 // skip comment end
312 continue;
315 begin
316 // skip comment start
320 continue;
324 continue;
337 var
341 begin
343 begin
345 begin
349 begin
352 exit;
357 begin
365 begin
366 // skip prefix
371 // default base
377 begin
385 // check for valid number end
387 begin
389 if (curChar = '_') or ((curChar >= 'A') and (curChar <= 'Z')) or ((curChar >= 'a') and (curChar <= 'z')) or (curChar >= #128) then
390 begin
398 var
401 begin
407 begin
408 // escape
410 begin
413 // skip backslash and escape type
423 begin
428 begin
436 continue;
438 // duplicate single quote (pascal style)
440 begin
441 // skip both quotes
445 continue;
448 begin
450 break;
458 begin
465 begin
471 begin
478 begin
482 exit;
490 // number?
491 if mAllowSignedNumbers and ((curChar = '+') or (curChar = '-')) then begin parseInt(); exit; end;
494 // string?
497 // identifier?
498 if (curChar = '_') or ((curChar >= 'A') and (curChar <= 'Z')) or ((curChar >= 'a') and (curChar <= 'z')) or (curChar >= #128) then begin parseId(); exit; end;
500 // known delimiters?
515 begin
523 begin
524 if (mTokType <> TTId) or (CompareText(mTokStr, aid) <> 0) then raise Exception.Create('identifier '''+aid+''' expected');
530 begin
539 begin
541 if (not allowEmpty) and (Length(mTokStr) = 0) then raise Exception.Create('non-empty string expected');
548 begin
556 begin
563 begin
570 begin
571 if (mTokType <> TTDelim) then raise Exception.Create(Format('delimiter ''%s'' expected', [ch]));
578 begin
586 // ////////////////////////////////////////////////////////////////////////// //
588 begin
595 begin
602 var
604 begin
611 // ////////////////////////////////////////////////////////////////////////// //
613 begin
621 begin
628 begin
636 // ////////////////////////////////////////////////////////////////////////// //
638 procedure TTextWriter.put (const s: AnsiString); overload; begin if (Length(s) > 0) then putBuf((@(s[1]))^, Length(s)); end;
641 procedure TTextWriter.put (const fmt: AnsiString; args: array of const); overload; begin put(formatstrf(fmt, args)); end;
642 procedure TTextWriter.putIndent (); var f: Integer; begin for f := 1 to mIndent do put(' '); end;
647 // ////////////////////////////////////////////////////////////////////////// //
649 begin
656 begin
663 var
665 begin
667 begin
670 {
671 while (len > 0) do
672 begin
673 write(pc^);
674 Inc(pc);
675 Dec(len);
676 end;
677 }