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 var
185 // ////////////////////////////////////////////////////////////////////////// //
187 const
189 $0402,$0403,$201A,$0453,$201E,$2026,$2020,$2021,$20AC,$2030,$0409,$2039,$040A,$040C,$040B,$040F,
190 $0452,$2018,$2019,$201C,$201D,$2022,$2013,$2014,$003F,$2122,$0459,$203A,$045A,$045C,$045B,$045F,
191 $00A0,$040E,$045E,$0408,$00A4,$0490,$00A6,$00A7,$0401,$00A9,$0404,$00AB,$00AC,$00AD,$00AE,$0407,
192 $00B0,$00B1,$0406,$0456,$0491,$00B5,$00B6,$00B7,$0451,$2116,$0454,$00BB,$0458,$0405,$0455,$0457,
193 $0410,$0411,$0412,$0413,$0414,$0415,$0416,$0417,$0418,$0419,$041A,$041B,$041C,$041D,$041E,$041F,
194 $0420,$0421,$0422,$0423,$0424,$0425,$0426,$0427,$0428,$0429,$042A,$042B,$042C,$042D,$042E,$042F,
195 $0430,$0431,$0432,$0433,$0434,$0435,$0436,$0437,$0438,$0439,$043A,$043B,$043C,$043D,$043E,$043F,
197 );
198 var
200 begin
208 // ////////////////////////////////////////////////////////////////////////// //
209 // TODO: make a hash or something
211 begin
217 // ////////////////////////////////////////////////////////////////////////// //
219 begin
235 begin
244 begin
253 begin
259 // skip CR in CR/LF
261 begin
270 var
272 begin
274 begin
276 begin
277 // single-line comment
279 begin
282 continue;
284 // multline comment
286 begin
287 // skip comment start
291 begin
293 begin
294 // skip comment end
297 break;
301 continue;
303 // nesting multline comment
305 begin
306 // skip comment start
311 begin
313 begin
314 // skip comment end
319 continue;
322 begin
323 // skip comment start
327 continue;
331 continue;
344 var
348 begin
350 begin
352 begin
356 begin
359 exit;
364 begin
372 begin
373 // skip prefix
378 // default base
384 begin
392 // check for valid number end
394 begin
396 if (curChar = '_') or ((curChar >= 'A') and (curChar <= 'Z')) or ((curChar >= 'a') and (curChar <= 'z')) or (curChar >= #128) then
397 begin
405 var
408 begin
414 begin
415 // escape
417 begin
420 // skip backslash and escape type
430 begin
435 begin
443 continue;
445 // duplicate single quote (pascal style)
447 begin
448 // skip both quotes
452 continue;
455 begin
457 break;
465 begin
472 begin
478 begin
485 begin
489 exit;
497 // number?
498 if mAllowSignedNumbers and ((curChar = '+') or (curChar = '-')) then begin parseInt(); exit; end;
501 // string?
504 // identifier?
505 if (curChar = '_') or ((curChar >= 'A') and (curChar <= 'Z')) or ((curChar >= 'a') and (curChar <= 'z')) or (curChar >= #128) then begin parseId(); exit; end;
507 // known delimiters?
522 begin
530 begin
531 if (mTokType <> TTId) or (CompareText(mTokStr, aid) <> 0) then raise Exception.Create('identifier '''+aid+''' expected');
537 begin
546 begin
548 if (not allowEmpty) and (Length(mTokStr) = 0) then raise Exception.Create('non-empty string expected');
555 begin
563 begin
570 begin
577 begin
578 if (mTokType <> TTDelim) then raise Exception.Create(Format('delimiter ''%s'' expected', [ch]));
585 begin
593 // ////////////////////////////////////////////////////////////////////////// //
595 begin
607 begin
619 begin
627 begin
630 begin
643 // ////////////////////////////////////////////////////////////////////////// //
645 begin
653 begin
660 begin
668 // ////////////////////////////////////////////////////////////////////////// //
670 procedure TTextWriter.put (const s: AnsiString); overload; begin if (Length(s) > 0) then putBuf((@(s[1]))^, Length(s)); end;
673 procedure TTextWriter.put (const fmt: AnsiString; args: array of const); overload; begin put(formatstrf(fmt, args)); end;
674 procedure TTextWriter.putIndent (); var f: Integer; begin for f := 1 to mIndent do put(' '); end;
679 // ////////////////////////////////////////////////////////////////////////// //
681 begin
688 begin
695 var
697 begin
699 begin
702 {
703 while (len > 0) do
704 begin
705 write(pc^);
706 Inc(pc);
707 Dec(len);
708 end;
709 }