1 | unit UFormRuleItem;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
9 | ComCtrls, UGrammer;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TFormRuleItem }
|
---|
14 |
|
---|
15 | TFormRuleItem = class(TForm)
|
---|
16 | ButtonCancel: TButton;
|
---|
17 | ButtonOk: TButton;
|
---|
18 | CheckBoxLookupTable: TCheckBox;
|
---|
19 | CheckBoxAnyExcept: TCheckBox;
|
---|
20 | CheckBoxEscapedString: TCheckBox;
|
---|
21 | CheckBoxOptional: TCheckBox;
|
---|
22 | CheckBoxRepetitive: TCheckBox;
|
---|
23 | ComboBoxLookupTableAction: TComboBox;
|
---|
24 | ComboBoxType: TComboBox;
|
---|
25 | EditTerminal: TEdit;
|
---|
26 | EditTerminalFrom: TEdit;
|
---|
27 | EditTerminalTo: TEdit;
|
---|
28 | Label1: TLabel;
|
---|
29 | Label2: TLabel;
|
---|
30 | LabelNonTerminal: TLabel;
|
---|
31 | LabelTerminal: TLabel;
|
---|
32 | LabelTerminal1: TLabel;
|
---|
33 | LabelTerminal2: TLabel;
|
---|
34 | ListBoxNonTerminals: TListBox;
|
---|
35 | ListBoxLookupTable: TListBox;
|
---|
36 | PageControl1: TPageControl;
|
---|
37 | TabSheetTerminalRange: TTabSheet;
|
---|
38 | TabSheetTerminal: TTabSheet;
|
---|
39 | TabSheetNonTerminal: TTabSheet;
|
---|
40 | TabSheetSubItems: TTabSheet;
|
---|
41 | procedure CheckBoxLookupTableChange(Sender: TObject);
|
---|
42 | procedure ComboBoxTypeChange(Sender: TObject);
|
---|
43 | procedure EditTerminalKeyPress(Sender: TObject; var Key: char);
|
---|
44 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
45 | procedure FormCreate(Sender: TObject);
|
---|
46 | procedure FormDestroy(Sender: TObject);
|
---|
47 | procedure FormShow(Sender: TObject);
|
---|
48 | private
|
---|
49 | FormRuleItems: TForm;
|
---|
50 | procedure ReloadNonTerminals(Grammer: TGrammer);
|
---|
51 | procedure ReloadLookupTables(Grammer: TGrammer);
|
---|
52 | public
|
---|
53 | RuleItem: TRuleItem;
|
---|
54 | procedure UpdateInterface;
|
---|
55 | procedure LoadData(RuleItem: TRuleItem);
|
---|
56 | procedure SaveData(RuleItem: TRuleItem);
|
---|
57 | end;
|
---|
58 |
|
---|
59 | var
|
---|
60 | FormRuleItem: TFormRuleItem;
|
---|
61 |
|
---|
62 |
|
---|
63 | implementation
|
---|
64 |
|
---|
65 | uses
|
---|
66 | UCore, UFormRuleItems;
|
---|
67 |
|
---|
68 | {$R *.lfm}
|
---|
69 |
|
---|
70 | { TFormRuleItem }
|
---|
71 |
|
---|
72 | procedure TFormRuleItem.ComboBoxTypeChange(Sender: TObject);
|
---|
73 | begin
|
---|
74 | RuleItem.RuleItemType := TRuleItemType(ComboBoxType.ItemIndex);
|
---|
75 | UpdateInterface;
|
---|
76 | end;
|
---|
77 |
|
---|
78 | procedure TFormRuleItem.CheckBoxLookupTableChange(Sender: TObject);
|
---|
79 | begin
|
---|
80 | UpdateInterface;
|
---|
81 | end;
|
---|
82 |
|
---|
83 | procedure TFormRuleItem.EditTerminalKeyPress(Sender: TObject; var Key: char);
|
---|
84 | begin
|
---|
85 | if Key = #13 then ButtonOk.Click;
|
---|
86 | end;
|
---|
87 |
|
---|
88 | procedure TFormRuleItem.FormClose(Sender: TObject; var CloseAction: TCloseAction
|
---|
89 | );
|
---|
90 | begin
|
---|
91 | Core.PersistentForm1.Save(Self);
|
---|
92 | end;
|
---|
93 |
|
---|
94 | procedure TFormRuleItem.FormCreate(Sender: TObject);
|
---|
95 | begin
|
---|
96 | Core.CoolTranslator1.TranslateComponentRecursive(Self);
|
---|
97 | FormRuleItems := TFormRuleItems.Create(nil);
|
---|
98 | FormRuleItems.ManualDock(TabSheetSubItems);
|
---|
99 | FormRuleItems.Align := alClient;
|
---|
100 | FormRuleItems.Show;
|
---|
101 | end;
|
---|
102 |
|
---|
103 | procedure TFormRuleItem.FormDestroy(Sender: TObject);
|
---|
104 | begin
|
---|
105 | FreeAndNil(FormRuleItems);
|
---|
106 | end;
|
---|
107 |
|
---|
108 | procedure TFormRuleItem.FormShow(Sender: TObject);
|
---|
109 | begin
|
---|
110 | Core.PersistentForm1.Load(Self);
|
---|
111 | case RuleItem.RuleItemType of
|
---|
112 | ritTerminal: EditTerminal.SetFocus;
|
---|
113 | ritNonTerminal: ListBoxNonTerminals.SetFocus;
|
---|
114 | ritSubItems: TFormRuleItems(FormRuleItems).ListView1.SetFocus;
|
---|
115 | ritTerminalRange: EditTerminalFrom.SetFocus;
|
---|
116 | end;
|
---|
117 | end;
|
---|
118 |
|
---|
119 |
|
---|
120 | procedure TFormRuleItem.ReloadNonTerminals(Grammer: TGrammer);
|
---|
121 | var
|
---|
122 | Rule: TRule;
|
---|
123 | begin
|
---|
124 | ListBoxNonTerminals.Items.Clear;
|
---|
125 | for Rule in Grammer.Rules do begin
|
---|
126 | ListBoxNonTerminals.Items.AddObject(Rule.Name, Rule);
|
---|
127 | end;
|
---|
128 | ListBoxNonTerminals.Sorted := True;
|
---|
129 | end;
|
---|
130 |
|
---|
131 | procedure TFormRuleItem.ReloadLookupTables(Grammer: TGrammer);
|
---|
132 | var
|
---|
133 | Item: TLookupTable;
|
---|
134 | begin
|
---|
135 | ListBoxLookupTable.Items.Clear;
|
---|
136 | for Item in Grammer.LookupTables do begin
|
---|
137 | ListBoxLookupTable.Items.AddObject(Item.Name, Item);
|
---|
138 | end;
|
---|
139 | ListBoxLookupTable.Sorted := True;
|
---|
140 | end;
|
---|
141 |
|
---|
142 | procedure TFormRuleItem.UpdateInterface;
|
---|
143 | begin
|
---|
144 | PageControl1.PageIndex := Integer(RuleItem.RuleItemType);
|
---|
145 | EditTerminal.Visible := RuleItem.RuleItemType = ritTerminal;
|
---|
146 | LabelTerminal.Visible := RuleItem.RuleItemType = ritTerminal;
|
---|
147 | ListBoxNonTerminals.Visible := RuleItem.RuleItemType = ritNonTerminal;
|
---|
148 | LabelNonTerminal.Visible := RuleItem.RuleItemType = ritNonTerminal;
|
---|
149 | CheckBoxOptional.Enabled := RuleItem.ParentRule.Items.RuleType = rtAnd;
|
---|
150 | CheckBoxRepetitive.Enabled := RuleItem.ParentRule.Items.RuleType = rtAnd;
|
---|
151 | CheckBoxEscapedString.Enabled := (RuleItem.RuleItemType = ritTerminal) or
|
---|
152 | (RuleItem.RuleItemType = ritTerminalRange);
|
---|
153 | ListBoxLookupTable.Enabled := CheckBoxLookupTable.Checked;
|
---|
154 | ComboBoxLookupTableAction.Enabled := CheckBoxLookupTable.Checked;
|
---|
155 | end;
|
---|
156 |
|
---|
157 | procedure TFormRuleItem.LoadData(RuleItem: TRuleItem);
|
---|
158 | begin
|
---|
159 | Self.RuleItem := RuleItem;
|
---|
160 | ReloadNonTerminals(RuleItem.Grammer);
|
---|
161 | ComboBoxType.ItemIndex := Integer(RuleItem.RuleItemType);
|
---|
162 | ListBoxNonTerminals.ItemIndex := ListBoxNonTerminals.Items.IndexOfObject(RuleItem.NonTerminal);
|
---|
163 | EditTerminal.Text := RuleItem.Terminal;
|
---|
164 | EditTerminalFrom.Text := RuleItem.TerminalFrom;
|
---|
165 | EditTerminalTo.Text := RuleItem.TerminalTo;
|
---|
166 | CheckBoxOptional.Checked := RuleItem.Optional;
|
---|
167 | CheckBoxRepetitive.Checked := RuleItem.Repetitive;
|
---|
168 | CheckBoxAnyExcept.Checked := RuleItem.AnyExcept;
|
---|
169 | TFormRuleItems(FormRuleItems).LoadData(RuleItem.SubItems);
|
---|
170 | CheckBoxEscapedString.Checked := RuleItem.EscapedStrings;
|
---|
171 | // Lookup table
|
---|
172 | CheckBoxLookupTable.Checked := RuleItem.LookupTableUsed;
|
---|
173 | ReloadLookupTables(RuleItem.Grammer);
|
---|
174 | ComboBoxLookupTableAction.ItemIndex := Integer(RuleItem.LookupTableAction);
|
---|
175 | ListBoxLookupTable.ItemIndex := ListBoxLookupTable.Items.IndexOfObject(RuleItem.LookupTable);
|
---|
176 | UpdateInterface;
|
---|
177 | end;
|
---|
178 |
|
---|
179 | procedure TFormRuleItem.SaveData(RuleItem: TRuleItem);
|
---|
180 | begin
|
---|
181 | RuleItem.Grammer.Modified := True;
|
---|
182 | TFormRuleItems(FormRuleItems).SaveData(RuleItem.SubItems);
|
---|
183 | RuleItem.RuleItemType := TRuleItemType(ComboBoxType.ItemIndex);
|
---|
184 | RuleItem.Terminal := EditTerminal.Text;
|
---|
185 | RuleItem.TerminalFrom := EditTerminalFrom.Text;
|
---|
186 | RuleItem.TerminalTo := EditTerminalTo.Text;
|
---|
187 | if ListBoxNonTerminals.ItemIndex <> -1 then
|
---|
188 | RuleItem.NonTerminal := TRule(ListBoxNonTerminals.Items.Objects[ListBoxNonTerminals.ItemIndex])
|
---|
189 | else RuleItem.NonTerminal := nil;
|
---|
190 | RuleItem.Optional := CheckBoxOptional.Checked;
|
---|
191 | RuleItem.Repetitive := CheckBoxRepetitive.Checked;
|
---|
192 | RuleItem.AnyExcept := CheckBoxAnyExcept.Checked;
|
---|
193 | RuleItem.EscapedStrings := CheckBoxEscapedString.Checked;
|
---|
194 | // Lookup table
|
---|
195 | RuleItem.LookupTableUsed := CheckBoxLookupTable.Checked;
|
---|
196 | RuleItem.LookupTableAction := TLookupTableAction(ComboBoxLookupTableAction.ItemIndex);
|
---|
197 | if ListBoxLookupTable.ItemIndex <> -1 then
|
---|
198 | RuleItem.LookupTable := TLookupTable(ListBoxLookupTable.Items.Objects[ListBoxLookupTable.ItemIndex])
|
---|
199 | else RuleItem.LookupTable := nil;
|
---|
200 | end;
|
---|
201 |
|
---|
202 | end.
|
---|
203 |
|
---|