|
1 | 1 | (******************************************************************************)
|
2 | 2 | (* upascallexer 19.04.2023 *)
|
3 | 3 | (* *)
|
4 |
| -(* Version : 0.05 *) |
| 4 | +(* Version : 0.06 *) |
5 | 5 | (* *)
|
6 | 6 | (* Author : Uwe Schächterle (Corpsman) *)
|
7 | 7 | (* *)
|
|
27 | 27 | (* 0.03 - Start with unittests, fix "invalid" ( * Parsing *)
|
28 | 28 | (* 0.04 - Berücksichtigen von {$I ...} *)
|
29 | 29 | (* 0.05 - Fix Linecounting von {$I ...} *)
|
| 30 | +(* 0.06 - Support recursive includes *) |
30 | 31 | (* *)
|
31 | 32 | (******************************************************************************)
|
32 | 33 | Unit upascallexer;
|
|
357 | 358 | Procedure TPascalLexer.DoLex(Const Stream: TStream);
|
358 | 359 |
|
359 | 360 | Var
|
360 |
| - BlockLineCounting: Boolean; // Wenn True, dann werden die ZeilenNummern nicht "Erhöht" wenn CRT gelesen wird. |
| 361 | + BlockLineCounting: integer; // Wenn True, dann werden die ZeilenNummern nicht "Erhöht" wenn CRT gelesen wird. |
361 | 362 |
|
362 | 363 | Procedure HToken(); //Inline;
|
363 | 364 | Begin
|
364 | 365 | If atoken = '~DisableLineCounter~' Then Begin
|
365 |
| - BlockLineCounting := true; |
| 366 | + inc(BlockLineCounting); |
366 | 367 | atoken := '';
|
367 | 368 | exit;
|
368 | 369 | End;
|
369 | 370 | If atoken = '~EnableLineCounter~' Then Begin
|
370 |
| - BlockLineCounting := false; |
| 371 | + dec(BlockLineCounting); |
| 372 | + If BlockLineCounting < 0 Then BlockLineCounting := 0; |
371 | 373 | atoken := '';
|
372 | 374 | exit;
|
373 | 375 | End;
|
|
404 | 406 | i, mSize: Int64;
|
405 | 407 | Begin
|
406 | 408 | aToken := '';
|
407 |
| - BlockLineCounting := false; |
| 409 | + BlockLineCounting := 0; |
408 | 410 | State := sCollectToken;
|
409 | 411 | CommentDetphCounter := 0;
|
410 | 412 | pc := #0;
|
|
672 | 674 | inc(aEmptyLine);
|
673 | 675 | End;
|
674 | 676 | If (c = LB) Then Begin
|
675 |
| - If (Not BlockLineCounting) Then Begin |
| 677 | + If (BlockLineCounting = 0) Then Begin |
676 | 678 | inc(aLine);
|
677 | 679 | End;
|
678 | 680 | inc(aParsedLine);
|
|
690 | 692 | End;
|
691 | 693 |
|
692 | 694 | Procedure TPascalLexer.LexFile(Const Filename: String);
|
693 |
| -Var |
694 |
| - m: TMemoryStream; |
695 |
| - sl2, sl: TStringList; |
696 |
| - i: integer; |
697 |
| - s, t: String; |
698 |
| -Begin |
699 |
| - sl := TStringList.Create; |
700 |
| - Try |
701 |
| - sl.LoadFromFile(Filename); |
702 |
| - // Auflösen der Includierten Dateien, ja das ist ein Böser Hack .. |
703 |
| - If assigned(OnResolveFileRequest) And (pos('{$I ', sl.text) <> 0) Then Begin |
704 |
| - For i := 0 To sl.Count - 1 Do Begin |
705 |
| - If pos('{$I ', sl[i]) <> 0 Then Begin |
706 |
| - s := sl[i]; |
| 695 | + Procedure IncludeIncludes(Const Content: TStringList); |
| 696 | + Var |
| 697 | + sl2: TStringList; |
| 698 | + i: integer; |
| 699 | + s, t: String; |
| 700 | + Begin |
| 701 | + If (pos('{$I ', content.text) <> 0) Then Begin |
| 702 | + For i := content.Count - 1 Downto 0 Do Begin |
| 703 | + If pos('{$I ', content[i]) <> 0 Then Begin |
| 704 | + s := content[i]; |
707 | 705 | s := copy(s, pos('{$I ', s) + 4, length(s));
|
708 | 706 | t := copy(s, pos('}', s) + 1, length(s)); // Retten dessen was nach dem Include kommt.
|
709 | 707 | s := copy(s, 1, pos('}', s) - 1);
|
|
712 | 710 | If s <> '' Then Begin
|
713 | 711 | sl2 := TStringList.Create;
|
714 | 712 | sl2.LoadFromFile(s);
|
715 |
| - sl[i] := ' ~DisableLineCounter~ ' + sl2.Text + ' ~EnableLineCounter~ ' + t; |
| 713 | + IncludeIncludes(sl2); // Falls includes, includes machen .. |
| 714 | + content[i] := ' ~DisableLineCounter~ ' + sl2.Text + ' ~EnableLineCounter~ ' + t; |
716 | 715 | sl2.free;
|
717 | 716 | End;
|
718 | 717 | End;
|
719 | 718 | End;
|
720 | 719 | End;
|
| 720 | + End; |
| 721 | + |
| 722 | +Var |
| 723 | + m: TMemoryStream; |
| 724 | + sl: TStringList; |
| 725 | + |
| 726 | +Begin |
| 727 | + sl := TStringList.Create; |
| 728 | + Try |
| 729 | + sl.LoadFromFile(Filename); |
| 730 | + // Rekursives Auflösen der Includierten Dateien |
| 731 | + If assigned(OnResolveFileRequest) Then Begin |
| 732 | + IncludeIncludes(sl); |
| 733 | + End; |
721 | 734 | m := TMemoryStream.Create;
|
722 | 735 | sl.SaveToStream(m);
|
723 | 736 | Try
|
|
0 commit comments