1 | unit Generator;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, strutils, Source;
|
---|
7 |
|
---|
8 | type
|
---|
9 |
|
---|
10 | { TGenerator }
|
---|
11 |
|
---|
12 | TGenerator = class
|
---|
13 | private
|
---|
14 | FIndent: Integer;
|
---|
15 | procedure SetIndent(AValue: Integer);
|
---|
16 | public
|
---|
17 | Name: string;
|
---|
18 | FileExt: string;
|
---|
19 | Output: string;
|
---|
20 | Prog: TProgram;
|
---|
21 | procedure AddText(Text: string);
|
---|
22 | procedure AddTextLine(Text: string = '');
|
---|
23 | procedure Generate; virtual;
|
---|
24 | constructor Create; virtual;
|
---|
25 | destructor Destroy; override;
|
---|
26 | property Indent: Integer read FIndent write SetIndent;
|
---|
27 | end;
|
---|
28 |
|
---|
29 | TGeneratorClass = class of TGenerator;
|
---|
30 |
|
---|
31 |
|
---|
32 | implementation
|
---|
33 |
|
---|
34 | procedure TGenerator.SetIndent(AValue: Integer);
|
---|
35 | var
|
---|
36 | ToRemove: string;
|
---|
37 | RemoveIndex: Integer;
|
---|
38 | begin
|
---|
39 | if FIndent = AValue then Exit;
|
---|
40 | if AValue > FIndent then begin
|
---|
41 | Output := Output + DupeString(' ', AValue - FIndent);
|
---|
42 | end else
|
---|
43 | if AValue < FIndent then begin
|
---|
44 | RemoveIndex := Length(Output) - (FIndent - AValue) * 2;
|
---|
45 | ToRemove := Copy(Output, RemoveIndex + 1, MaxInt);
|
---|
46 | if ToRemove = DupeString(' ', FIndent - AValue) then
|
---|
47 | Output := Copy(Output, 1, RemoveIndex);
|
---|
48 | end;
|
---|
49 | FIndent := AValue;
|
---|
50 | end;
|
---|
51 |
|
---|
52 | procedure TGenerator.AddText(Text: string);
|
---|
53 | begin
|
---|
54 | Output := Output + Text;
|
---|
55 | end;
|
---|
56 |
|
---|
57 | procedure TGenerator.AddTextLine(Text: string);
|
---|
58 | begin
|
---|
59 | AddText(Text + LineEnding + DupeString(' ', Indent));
|
---|
60 | end;
|
---|
61 |
|
---|
62 | procedure TGenerator.Generate;
|
---|
63 | begin
|
---|
64 | end;
|
---|
65 |
|
---|
66 | constructor TGenerator.Create;
|
---|
67 | begin
|
---|
68 | end;
|
---|
69 |
|
---|
70 | destructor TGenerator.Destroy;
|
---|
71 | begin
|
---|
72 | inherited;
|
---|
73 | end;
|
---|
74 |
|
---|
75 | end.
|
---|
76 |
|
---|