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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.