- Timestamp:
- Aug 8, 2017, 11:15:41 PM (7 years ago)
- Location:
- branches/generator
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generator/Forms/UFormMain.lfm
r109 r110 5 5 Width = 1050 6 6 Caption = 'Language generator' 7 ClientHeight = 646 8 ClientWidth = 1050 7 9 Menu = MainMenu1 10 OnShow = FormShow 8 11 LCLVersion = '1.6.4.0' 12 object MemoBNF: TMemo 13 Left = 0 14 Height = 646 15 Top = 0 16 Width = 1050 17 Align = alClient 18 TabOrder = 0 19 end 9 20 object MainMenu1: TMainMenu 10 21 left = 240 -
branches/generator/Forms/UFormMain.pas
r109 r110 20 20 ActionList1: TActionList; 21 21 MainMenu1: TMainMenu; 22 MemoBNF: TMemo; 22 23 MenuItem1: TMenuItem; 23 24 MenuItem2: TMenuItem; … … 33 34 procedure ARulesExecute(Sender: TObject); 34 35 procedure ASaveAsExecute(Sender: TObject); 36 procedure FormShow(Sender: TObject); 35 37 private 36 38 { private declarations } … … 55 57 begin 56 58 FormRules.Rules := Core.Rules; 57 FormRules.Show; 59 FormRules.ShowModal; 60 MemoBNF.Lines.Text := Core.Rules.GetBNF; 58 61 end; 59 62 60 63 procedure TFormMain.ASaveAsExecute(Sender: TObject); 61 64 begin 65 SaveDialog1.FileName := Core.Rules.FileName; 62 66 if SaveDialog1.Execute then begin 63 67 Core.Rules.SaveToXmlFile(SaveDialog1.FileName); 64 68 end; 69 end; 70 71 procedure TFormMain.FormShow(Sender: TObject); 72 begin 73 MemoBNF.Lines.Text := Core.Rules.GetBNF; 65 74 end; 66 75 … … 72 81 procedure TFormMain.AOpenExecute(Sender: TObject); 73 82 begin 83 OpenDialog1.FileName := Core.Rules.FileName; 74 84 if OpenDialog1.Execute then begin 75 85 Core.Rules.LoadFromXmlFile(OpenDialog1.FileName); -
branches/generator/Forms/UFormRule.lfm
r109 r110 13 13 Left = 376 14 14 Height = 25 15 Top = 3 2815 Top = 360 16 16 Width = 75 17 Anchors = [akLeft, akBottom] 17 18 Caption = 'Ok' 18 19 ModalResult = 1 … … 20 21 end 21 22 object ButtonCancel: TButton 22 Left = 1 7623 Left = 168 23 24 Height = 25 24 Top = 3 2825 Top = 360 25 26 Width = 75 27 Anchors = [akLeft, akBottom] 26 28 Caption = 'Cancel' 27 29 ModalResult = 2 … … 43 45 TabOrder = 2 44 46 end 47 object ListView: TListView 48 Left = 16 49 Height = 264 50 Top = 80 51 Width = 624 52 Anchors = [akTop, akLeft, akBottom] 53 Columns = < 54 item 55 Caption = 'Name' 56 Width = 604 57 end> 58 MultiSelect = True 59 OwnerData = True 60 PopupMenu = PopupMenu1 61 ReadOnly = True 62 RowSelect = True 63 TabOrder = 3 64 ViewStyle = vsReport 65 OnData = ListViewData 66 OnDblClick = ListViewDblClick 67 OnKeyPress = ListViewKeyPress 68 OnSelectItem = ListViewSelectItem 69 end 70 object ActionList1: TActionList 71 left = 347 72 top = 187 73 object AAdd: TAction 74 Caption = 'Add' 75 OnExecute = AAddExecute 76 end 77 object AModify: TAction 78 Caption = 'Modify' 79 OnExecute = AModifyExecute 80 end 81 object ARemove: TAction 82 Caption = 'Remove' 83 OnExecute = ARemoveExecute 84 end 85 end 86 object PopupMenu1: TPopupMenu 87 left = 118 88 top = 185 89 object MenuItem1: TMenuItem 90 Action = AAdd 91 end 92 object MenuItem2: TMenuItem 93 Action = AModify 94 end 95 object MenuItem3: TMenuItem 96 Action = ARemove 97 end 98 end 45 99 end -
branches/generator/Forms/UFormRule.pas
r109 r110 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 URules;9 ComCtrls, ActnList, Menus, URules; 10 10 11 11 type … … 14 14 15 15 TFormRule = class(TForm) 16 AAdd: TAction; 17 AModify: TAction; 18 ARemove: TAction; 19 ActionList1: TActionList; 16 20 ButtonOk: TButton; 17 21 ButtonCancel: TButton; 18 22 EditName: TEdit; 19 23 Label1: TLabel; 24 ListView: TListView; 25 MenuItem1: TMenuItem; 26 MenuItem2: TMenuItem; 27 MenuItem3: TMenuItem; 28 PopupMenu1: TPopupMenu; 29 procedure AAddExecute(Sender: TObject); 30 procedure AModifyExecute(Sender: TObject); 31 procedure ARemoveExecute(Sender: TObject); 20 32 procedure FormShow(Sender: TObject); 33 procedure ListViewData(Sender: TObject; Item: TListItem); 34 procedure ListViewDblClick(Sender: TObject); 35 procedure ListViewKeyPress(Sender: TObject; var Key: char); 36 procedure ListViewSelectItem(Sender: TObject; Item: TListItem; 37 Selected: Boolean); 21 38 private 22 39 { private declarations } 23 40 public 41 RuleItems: TRuleItems; 42 procedure UpdateInterface; 43 procedure ReloadList; 24 44 procedure LoadData(Rule: TRule); 25 45 procedure SaveData(Rule: TRule); … … 29 49 FormRule: TFormRule; 30 50 51 31 52 implementation 32 53 33 54 {$R *.lfm} 55 56 uses 57 UFormRuleItem; 34 58 35 59 { TFormRule } … … 38 62 begin 39 63 EditName.SetFocus; 64 ReloadList; 65 UpdateInterface; 66 end; 67 68 procedure TFormRule.ListViewData(Sender: TObject; Item: TListItem); 69 begin 70 if (Item.Index >= 0) and (Item.Index < RuleItems.Count) then begin 71 Item.Caption := RuleItems[Item.Index].Name; 72 Item.Data := RuleItems[Item.Index]; 73 end; 74 end; 75 76 procedure TFormRule.ListViewDblClick(Sender: TObject); 77 begin 78 AModify.Execute; 79 end; 80 81 procedure TFormRule.ListViewKeyPress(Sender: TObject; var Key: char); 82 begin 83 if Key = #13 then AModify.Execute; 84 end; 85 86 procedure TFormRule.ListViewSelectItem(Sender: TObject; Item: TListItem; 87 Selected: Boolean); 88 begin 89 UpdateInterface; 90 end; 91 92 procedure TFormRule.AAddExecute(Sender: TObject); 93 var 94 NewRuleItem: TRuleItem; 95 begin 96 NewRuleItem := TRuleItem.Create; 97 FormRuleItem.LoadData(NewRuleItem); 98 if FormRuleItem.ShowModal = mrOk then begin 99 FormRuleItem.SaveData(NewRuleItem); 100 RuleItems.Add(NewRuleItem); 101 ReloadList; 102 end else FreeAndNil(NewRuleItem); 103 end; 104 105 procedure TFormRule.AModifyExecute(Sender: TObject); 106 var 107 RuleItem: TRuleItem; 108 begin 109 RuleItem := TRuleItem(ListView.Selected.Data); 110 FormRuleItem.LoadData(RuleItem); 111 if FormRuleItem.ShowModal = mrOk then begin 112 FormRuleItem.SaveData(RuleItem); 113 ReloadList; 114 end; 115 end; 116 117 procedure TFormRule.ARemoveExecute(Sender: TObject); 118 var 119 Item: TListItem; 120 begin 121 for Item in ListView.Items do 122 if Item.Selected then 123 RuleItems.Remove(TRuleItem(Item.Data)); 124 ReloadList; 125 end; 126 127 procedure TFormRule.UpdateInterface; 128 begin 129 AModify.Enabled := Assigned(ListView.Selected); 130 ARemove.Enabled := Assigned(ListView.Selected); 131 end; 132 133 procedure TFormRule.ReloadList; 134 begin 135 ListView.Items.Count := RuleItems.Count; 136 ListView.Refresh; 40 137 end; 41 138 … … 43 140 begin 44 141 EditName.Text := Rule.Name; 142 RuleItems := Rule.Items; 45 143 end; 46 144 -
branches/generator/URules.pas
r109 r110 10 10 type 11 11 12 { TRuleItem } 13 14 TRuleItem = class 15 Name: string; 16 procedure LoadFromXmlNode(Node: TDOMNode); 17 procedure SaveToXmlNode(Node: TDOMNode); 18 end; 19 20 { TRuleItems } 21 22 TRuleItems = class(TFPGObjectList<TRuleItem>) 23 procedure LoadFromXmlNode(Node: TDOMNode); 24 procedure SaveToXmlNode(Node: TDOMNode); 25 end; 26 12 27 { TRule } 13 28 14 29 TRule = class 15 30 Name: string; 16 procedure SaveToXmlNode(Node: TDOMNode); 17 procedure LoadFromXmlNode(Node: TDOMNode); 31 Items: TRuleItems; 32 constructor Create; 33 destructor Destroy; override; 34 procedure LoadFromXmlNode(Node: TDOMNode); 35 procedure SaveToXmlNode(Node: TDOMNode); 36 function GetBNF: string; 18 37 end; 19 38 … … 21 40 22 41 TRules = class(TFPGObjectList<TRule>) 42 FileName: string; 43 procedure LoadFromXmlNode(Node: TDOMNode); 44 procedure SaveToXmlNode(Node: TDOMNode); 23 45 procedure LoadFromXmlFile(FileName: string); 24 46 procedure SaveToXmlFile(FileName: string); 47 function GetBNF: string; 25 48 end; 26 49 27 50 implementation 28 51 52 { TRuleItem } 53 54 procedure TRuleItem.SaveToXmlNode(Node: TDOMNode); 55 begin 56 WriteString(Node, 'Name', Name); 57 end; 58 59 procedure TRuleItem.LoadFromXmlNode(Node: TDOMNode); 60 begin 61 Name := ReadString(Node, 'Name', ''); 62 end; 63 64 { TRuleItems } 65 66 procedure TRuleItems.SaveToXmlNode(Node: TDOMNode); 67 var 68 RuleItem: TRuleItem; 69 RuleItemNode: TDOMNode; 70 begin 71 for RuleItem in Self do begin 72 RuleItemNode := Node.OwnerDocument.CreateElement('RuleItem'); 73 RuleItem.SaveToXmlNode(RuleItemNode); 74 Node.AppendChild(RuleItemNode); 75 end; 76 end; 77 78 procedure TRuleItems.LoadFromXmlNode(Node: TDOMNode); 79 var 80 RuleItemNode: TDOMNode; 81 RuleItem: TRuleItem; 82 begin 83 RuleItemNode := Node.FirstChild; 84 while Assigned(RuleItemNode) do begin 85 if RuleItemNode.NodeName = 'RuleItem' then begin 86 RuleItem := TRuleItem.Create; 87 RuleItem.LoadFromXmlNode(RuleItemNode); 88 Add(RuleItem); 89 end; 90 RuleItemNode := RuleItemNode.NextSibling; 91 end; 92 end; 93 29 94 { TRule } 30 95 31 96 procedure TRule.SaveToXmlNode(Node: TDOMNode); 97 var 98 RuleItemsNode: TDOMNode; 32 99 begin 33 100 WriteString(Node, 'Name', Name); 101 102 RuleItemsNode := Node.OwnerDocument.CreateElement('RuleItems'); 103 Node.AppendChild(RuleItemsNode); 104 Items.SaveToXmlNode(RuleItemsNode); 105 end; 106 107 function TRule.GetBNF: string; 108 var 109 Item: TRuleItem; 110 begin 111 Result := Name + ' ::='; 112 for Item in Items do begin 113 Result := Result + ' ' + Item.Name; 114 end; 115 end; 116 117 constructor TRule.Create; 118 begin 119 Items := TRuleItems.Create; 120 end; 121 122 destructor TRule.Destroy; 123 begin 124 FreeAndNil(Items); 125 inherited Destroy; 34 126 end; 35 127 36 128 procedure TRule.LoadFromXmlNode(Node: TDOMNode); 129 var 130 ItemsNode: TDOMNode; 37 131 begin 38 132 Name := ReadString(Node, 'Name', ''); 133 134 ItemsNode := Node.FindNode('RuleItems'); 135 if Assigned(ItemsNode) then begin 136 Items.LoadFromXmlNode(ItemsNode); 137 end; 39 138 end; 40 139 41 140 { TRules } 141 142 procedure TRules.SaveToXmlNode(Node: TDOMNode); 143 var 144 Rule: TRule; 145 RuleNode: TDOMNode; 146 begin 147 for Rule in Self do begin 148 RuleNode := Node.OwnerDocument.CreateElement('Rule'); 149 Rule.SaveToXmlNode(RuleNode); 150 Node.AppendChild(RuleNode); 151 end; 152 end; 153 154 procedure TRules.LoadFromXmlNode(Node: TDOMNode); 155 var 156 RuleNode: TDOMNode; 157 Rule: TRule; 158 begin 159 RuleNode := Node.FirstChild; 160 while Assigned(RuleNode) do begin 161 if RuleNode.NodeName = 'Rule' then begin 162 Rule := TRule.Create; 163 Rule.LoadFromXmlNode(RuleNode); 164 Add(Rule); 165 end; 166 RuleNode := RuleNode.NextSibling; 167 end; 168 end; 42 169 43 170 procedure TRules.LoadFromXmlFile(FileName: string); … … 46 173 RootNode: TDOMNode; 47 174 RulesNode: TDOMNode; 48 RuleNode: TDOMNode; 49 Rule: TRule; 50 begin 175 begin 176 Self.FileName := FileName; 51 177 Clear; 52 178 try … … 57 183 RulesNode := RootNode.FindNode('Rules'); 58 184 if Assigned(RulesNode) then begin 59 RuleNode := RulesNode.FirstChild; 60 while Assigned(RuleNode) do begin 61 if RuleNode.NodeName = 'Rule' then begin 62 Rule := TRule.Create; 63 Rule.LoadFromXmlNode(RuleNode); 64 Add(Rule); 65 end; 66 RuleNode := RuleNode.NextSibling; 67 end; 185 LoadFromXmlNode(RulesNode); 68 186 end; 69 187 end; … … 78 196 RootNode: TDOMNode; 79 197 RulesNode: TDOMNode; 80 RuleNode: TDOMNode; 81 Rule: TRule; 82 begin 198 begin 199 Self.FileName := FileName; 83 200 Doc := TXMLDocument.Create; 84 201 try … … 88 205 RulesNode := Doc.CreateElement('Rules'); 89 206 RootNode.AppendChild(RulesNode); 90 91 for Rule in Self do begin 92 RuleNode := Doc.CreateElement('Rule'); 93 Rule.SaveToXmlNode(RuleNode); 94 RulesNode.AppendChild(RuleNode); 95 end; 207 SaveToXmlNode(RulesNode); 96 208 97 209 WriteXMLFile(Doc, FileName); … … 101 213 end; 102 214 215 function TRules.GetBNF: string; 216 var 217 Rule: TRule; 218 begin 219 Result := ''; 220 for Rule in Self do begin 221 Result := Result + Rule.GetBNF + LineEnding; 222 end; 223 end; 224 103 225 end. 104 226 -
branches/generator/generator.lpi
r109 r110 33 33 </Item1> 34 34 </RequiredPackages> 35 <Units Count=" 7">35 <Units Count="8"> 36 36 <Unit0> 37 37 <Filename Value="generator.lpr"/> … … 39 39 </Unit0> 40 40 <Unit1> 41 <Filename Value="UFormMain.pas"/> 41 <Filename Value="UCore.pas"/> 42 <IsPartOfProject Value="True"/> 43 <ComponentName Value="Core"/> 44 <HasResources Value="True"/> 45 <ResourceBaseClass Value="DataModule"/> 46 </Unit1> 47 <Unit2> 48 <Filename Value="URules.pas"/> 49 <IsPartOfProject Value="True"/> 50 </Unit2> 51 <Unit3> 52 <Filename Value="Forms/UFormRule.pas"/> 53 <IsPartOfProject Value="True"/> 54 <ComponentName Value="FormRule"/> 55 <HasResources Value="True"/> 56 <ResourceBaseClass Value="Form"/> 57 </Unit3> 58 <Unit4> 59 <Filename Value="UXMLUtils.pas"/> 60 <IsPartOfProject Value="True"/> 61 </Unit4> 62 <Unit5> 63 <Filename Value="Forms/UFormMain.pas"/> 42 64 <IsPartOfProject Value="True"/> 43 65 <ComponentName Value="FormMain"/> 44 66 <HasResources Value="True"/> 45 67 <ResourceBaseClass Value="Form"/> 46 </Unit 1>47 <Unit 2>48 <Filename Value=" UFormRules.pas"/>68 </Unit5> 69 <Unit6> 70 <Filename Value="Forms/UFormRules.pas"/> 49 71 <IsPartOfProject Value="True"/> 50 72 <ComponentName Value="FormRules"/> 73 <HasResources Value="True"/> 51 74 <ResourceBaseClass Value="Form"/> 52 </Unit 2>53 <Unit 3>54 <Filename Value=" UCore.pas"/>75 </Unit6> 76 <Unit7> 77 <Filename Value="Forms/UFormRuleItem.pas"/> 55 78 <IsPartOfProject Value="True"/> 56 <ComponentName Value="Core"/> 57 <ResourceBaseClass Value="DataModule"/> 58 </Unit3> 59 <Unit4> 60 <Filename Value="URules.pas"/> 61 <IsPartOfProject Value="True"/> 62 </Unit4> 63 <Unit5> 64 <Filename Value="Forms/UFormRule.pas"/> 65 <IsPartOfProject Value="True"/> 66 <ComponentName Value="FormRule"/> 79 <ComponentName Value="FormRuleItem"/> 67 80 <ResourceBaseClass Value="Form"/> 68 </Unit5> 69 <Unit6> 70 <Filename Value="UXMLUtils.pas"/> 71 <IsPartOfProject Value="True"/> 72 </Unit6> 81 </Unit7> 73 82 </Units> 74 83 </ProjectOptions> -
branches/generator/generator.lpr
r109 r110 8 8 {$ENDIF}{$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, U FormMain, UFormRules, UCore, URules, UFormRule10 Forms, UCore, URules, UFormRule, UFormMain, UFormRules, UFormRuleItem 11 11 { you can add units after this }; 12 12 … … 14 14 15 15 begin 16 RequireDerivedFormResource :=True;16 RequireDerivedFormResource := True; 17 17 Application.Initialize; 18 Application.CreateForm(TCore, Core); 18 19 Application.CreateForm(TFormMain, FormMain); 20 Application.CreateForm(TFormRule, FormRule); 19 21 Application.CreateForm(TFormRules, FormRules); 20 Application.CreateForm(TCore, Core); 21 Application.CreateForm(TFormRule, FormRule); 22 Application.CreateForm(TFormRuleItem, FormRuleItem); 22 23 Application.Run; 23 24 end. -
branches/generator/pascal.grm
r109 r110 4 4 <Rule> 5 5 <Name>BeginEnd</Name> 6 <RuleItems> 7 <RuleItem> 8 <Name>begin</Name> 9 </RuleItem> 10 <RuleItem> 11 <Name>command</Name> 12 </RuleItem> 13 <RuleItem> 14 <Name>end</Name> 15 </RuleItem> 16 </RuleItems> 6 17 </Rule> 7 18 <Rule> 8 19 <Name>IfThenElse</Name> 20 <RuleItems/> 9 21 </Rule> 10 22 <Rule> 11 23 <Name>WhileDo</Name> 24 <RuleItems/> 12 25 </Rule> 13 26 <Rule> 14 27 <Name>RepeatUntil</Name> 28 <RuleItems/> 15 29 </Rule> 16 30 <Rule> 17 31 <Name>ForToDo</Name> 32 <RuleItems/> 18 33 </Rule> 19 34 <Rule> 20 35 <Name>WithDo</Name> 36 <RuleItems/> 21 37 </Rule> 22 38 <Rule> 23 39 <Name>CaseOf</Name> 40 <RuleItems/> 24 41 </Rule> 25 42 <Rule> 26 43 <Name>Assignment</Name> 44 <RuleItems/> 45 </Rule> 46 <Rule> 47 <Name>Command</Name> 48 <RuleItems/> 27 49 </Rule> 28 50 </Rules>
Note:
See TracChangeset
for help on using the changeset viewer.