Ignore:
Timestamp:
Aug 9, 2017, 12:09:47 AM (7 years ago)
Author:
chronos
Message:
  • Added: RuleItem can be selected as terminal or non-terminal node.
Location:
branches/generator/Forms
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/generator/Forms/UFormMain.pas

    r110 r111  
    5656procedure TFormMain.ARulesExecute(Sender: TObject);
    5757begin
    58   FormRules.Rules := Core.Rules;
     58  FormRules.Rules := Core.Grammer.Rules;
    5959  FormRules.ShowModal;
    60   MemoBNF.Lines.Text := Core.Rules.GetBNF;
     60  MemoBNF.Lines.Text := Core.Grammer.GetBNF;
    6161end;
    6262
    6363procedure TFormMain.ASaveAsExecute(Sender: TObject);
    6464begin
    65   SaveDialog1.FileName := Core.Rules.FileName;
     65  SaveDialog1.FileName := Core.Grammer.FileName;
    6666  if SaveDialog1.Execute then begin
    67     Core.Rules.SaveToXmlFile(SaveDialog1.FileName);
     67    Core.Grammer.SaveToXmlFile(SaveDialog1.FileName);
    6868  end;
    6969end;
     
    7171procedure TFormMain.FormShow(Sender: TObject);
    7272begin
    73   MemoBNF.Lines.Text := Core.Rules.GetBNF;
     73  MemoBNF.Lines.Text := Core.Grammer.GetBNF;
    7474end;
    7575
     
    8181procedure TFormMain.AOpenExecute(Sender: TObject);
    8282begin
    83   OpenDialog1.FileName := Core.Rules.FileName;
     83  OpenDialog1.FileName := Core.Grammer.FileName;
    8484  if OpenDialog1.Execute then begin
    85     Core.Rules.LoadFromXmlFile(OpenDialog1.FileName);
     85    Core.Grammer.LoadFromXmlFile(OpenDialog1.FileName);
    8686  end;
    8787end;
  • branches/generator/Forms/UFormRule.lfm

    r110 r111  
    4747  object ListView: TListView
    4848    Left = 16
    49     Height = 264
    50     Top = 80
     49    Height = 232
     50    Top = 112
    5151    Width = 624
    5252    Anchors = [akTop, akLeft, akBottom]
     
    6767    OnKeyPress = ListViewKeyPress
    6868    OnSelectItem = ListViewSelectItem
     69  end
     70  object Label2: TLabel
     71    Left = 24
     72    Height = 24
     73    Top = 64
     74    Width = 82
     75    Caption = 'Operator:'
     76    ParentColor = False
     77  end
     78  object ComboBox1: TComboBox
     79    Left = 186
     80    Height = 36
     81    Top = 61
     82    Width = 390
     83    ItemHeight = 0
     84    Items.Strings = (
     85      'And'
     86      'Or'
     87    )
     88    Style = csDropDownList
     89    TabOrder = 4
    6990  end
    7091  object ActionList1: TActionList
  • branches/generator/Forms/UFormRule.pas

    r110 r111  
    2020    ButtonOk: TButton;
    2121    ButtonCancel: TButton;
     22    ComboBox1: TComboBox;
    2223    EditName: TEdit;
    2324    Label1: TLabel;
     25    Label2: TLabel;
    2426    ListView: TListView;
    2527    MenuItem1: TMenuItem;
     
    3941    { private declarations }
    4042  public
    41     RuleItems: TRuleItems;
     43    Rule: TRule;
    4244    procedure UpdateInterface;
    4345    procedure ReloadList;
     
    6870procedure TFormRule.ListViewData(Sender: TObject; Item: TListItem);
    6971begin
    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];
     72  if (Item.Index >= 0) and (Item.Index < Rule.Items.Count) then begin
     73    Item.Caption := Rule.Items[Item.Index].GetBNF;
     74    Item.Data := Rule.Items[Item.Index];
    7375  end;
    7476end;
     
    9597begin
    9698  NewRuleItem := TRuleItem.Create;
     99  NewRuleItem.Grammer := Rule.Grammer;
    97100  FormRuleItem.LoadData(NewRuleItem);
    98101  if FormRuleItem.ShowModal = mrOk then begin
    99102    FormRuleItem.SaveData(NewRuleItem);
    100     RuleItems.Add(NewRuleItem);
     103    NewRuleItem.ParentRule := Rule;
     104    Rule.Items.Add(NewRuleItem);
    101105    ReloadList;
    102106  end else FreeAndNil(NewRuleItem);
     
    121125  for Item in ListView.Items do
    122126  if Item.Selected then
    123     RuleItems.Remove(TRuleItem(Item.Data));
     127    Rule.Items.Remove(TRuleItem(Item.Data));
    124128  ReloadList;
    125129end;
     
    133137procedure TFormRule.ReloadList;
    134138begin
    135   ListView.Items.Count := RuleItems.Count;
     139  ListView.Items.Count := Rule.Items.Count;
    136140  ListView.Refresh;
    137141end;
     
    139143procedure TFormRule.LoadData(Rule: TRule);
    140144begin
     145  Self.Rule := Rule;
     146  ComboBox1.ItemIndex := Integer(Rule.RuleType);
    141147  EditName.Text := Rule.Name;
    142   RuleItems := Rule.Items;
     148  Rule.Items := Rule.Items;
    143149end;
    144150
    145151procedure TFormRule.SaveData(Rule: TRule);
    146152begin
     153  Rule.RuleType := TRuleType(ComboBox1.ItemIndex);
    147154  Rule.Name := EditName.Text;
    148155end;
  • branches/generator/Forms/UFormRuleItem.lfm

    r110 r111  
    99  ClientWidth = 656
    1010  LCLVersion = '1.6.4.0'
    11   object Label1: TLabel
    12     Left = 24
     11  object LabelTerminal: TLabel
     12    Left = 16
    1313    Height = 24
    14     Top = 24
    15     Width = 56
    16     Caption = 'Name:'
     14    Top = 64
     15    Width = 79
     16    Caption = 'Terminal:'
    1717    ParentColor = False
    1818  end
    1919  object EditName: TEdit
    20     Left = 132
     20    Left = 160
    2121    Height = 34
    22     Top = 19
    23     Width = 428
     22    Top = 64
     23    Width = 400
    2424    TabOrder = 0
    2525  end
     
    4242    TabOrder = 2
    4343  end
     44  object ComboBoxType: TComboBox
     45    Left = 160
     46    Height = 34
     47    Top = 16
     48    Width = 400
     49    ItemHeight = 0
     50    Items.Strings = (
     51      'Terminal'
     52      'Non-terminal'
     53    )
     54    OnChange = ComboBoxTypeChange
     55    Style = csDropDownList
     56    TabOrder = 3
     57  end
     58  object Label2: TLabel
     59    Left = 16
     60    Height = 24
     61    Top = 24
     62    Width = 45
     63    Caption = 'Type:'
     64    ParentColor = False
     65  end
     66  object LabelNonTerminal: TLabel
     67    Left = 16
     68    Height = 24
     69    Top = 112
     70    Width = 119
     71    Caption = 'Non-terminal:'
     72    ParentColor = False
     73  end
     74  object ComboBoxNonTerminal: TComboBox
     75    Left = 160
     76    Height = 36
     77    Top = 104
     78    Width = 404
     79    ItemHeight = 0
     80    Style = csDropDownList
     81    TabOrder = 4
     82  end
    4483end
  • branches/generator/Forms/UFormRuleItem.pas

    r110 r111  
    1616    ButtonCancel: TButton;
    1717    ButtonOk: TButton;
     18    ComboBoxType: TComboBox;
     19    ComboBoxNonTerminal: TComboBox;
    1820    EditName: TEdit;
    19     Label1: TLabel;
     21    LabelTerminal: TLabel;
     22    Label2: TLabel;
     23    LabelNonTerminal: TLabel;
     24    procedure ComboBoxTypeChange(Sender: TObject);
    2025  private
    21     { private declarations }
     26    procedure ReloadNonTerminals(Grammer: TGrammer);
    2227  public
     28    RuleItem: TRuleItem;
     29    procedure UpdateInterface;
    2330    procedure LoadData(RuleItem: TRuleItem);
    2431    procedure SaveData(RuleItem: TRuleItem);
     
    3441{ TFormRuleItem }
    3542
     43procedure TFormRuleItem.ComboBoxTypeChange(Sender: TObject);
     44begin
     45  RuleItem.RuleItemType := TRuleItemType(ComboBoxType.ItemIndex);
     46  UpdateInterface;
     47end;
     48
     49procedure TFormRuleItem.ReloadNonTerminals(Grammer: TGrammer);
     50var
     51  Rule: TRule;
     52begin
     53  ComboBoxNonTerminal.Items.Clear;
     54  for Rule in Grammer.Rules do begin
     55    ComboBoxNonTerminal.Items.AddObject(Rule.Name, Rule);
     56  end;
     57end;
     58
     59procedure TFormRuleItem.UpdateInterface;
     60begin
     61  EditName.Visible := RuleItem.RuleItemType = ritTerminal;
     62  LabelTerminal.Visible := RuleItem.RuleItemType = ritTerminal;
     63  ComboBoxNonTerminal.Visible := RuleItem.RuleItemType = ritNonTerminal;
     64  LabelNonTerminal.Visible := RuleItem.RuleItemType = ritNonTerminal;
     65end;
     66
    3667procedure TFormRuleItem.LoadData(RuleItem: TRuleItem);
    3768begin
    38   EditName.Text := RuleItem.Name;
     69  Self.RuleItem := RuleItem;
     70  ReloadNonTerminals(RuleItem.Grammer);
     71  ComboBoxType.ItemIndex := Integer(RuleItem.RuleItemType);
     72  ComboBoxNonTerminal.ItemIndex := ComboBoxNonTerminal.Items.IndexOfObject(RuleItem.NonTerminal);
     73  EditName.Text := RuleItem.Terminal;
     74  UpdateInterface;
    3975end;
    4076
    4177procedure TFormRuleItem.SaveData(RuleItem: TRuleItem);
    4278begin
    43   RuleItem.Name := EditName.Text;
     79  RuleItem.RuleItemType := TRuleItemType(ComboBoxType.ItemIndex);
     80  if RuleItem.RuleItemType = ritTerminal then RuleItem.Terminal := EditName.Text
     81  else if RuleItem.RuleItemType = ritNonTerminal then
     82    RuleItem.NonTerminal := TRule(ComboBoxNonTerminal.Items.Objects[ComboBoxNonTerminal.ItemIndex]);
    4483end;
    4584
  • branches/generator/Forms/UFormRules.lfm

    r109 r111  
    2727      Height = 24
    2828      Top = 5
    29       Width = 70
     29      Width = 150
    3030      Align = alNone
    3131      AutoSize = True
  • branches/generator/Forms/UFormRules.pas

    r109 r111  
    6969begin
    7070  NewRule := TRule.Create;
     71  NewRule.Grammer := Rules.Grammer;
    7172  FormRule.LoadData(NewRule);
    7273  if FormRule.ShowModal = mrOk then begin
Note: See TracChangeset for help on using the changeset viewer.