Ignore:
Timestamp:
Nov 29, 2017, 2:03:17 PM (7 years ago)
Author:
chronos
Message:
  • Added: New rule item type "Terminal range" to hold interval of characters.
  • Fixed: Removel of selected items in a list was not working correctly.
File:
1 edited

Legend:

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

    r118 r122  
    1818    CheckBoxOptional: TCheckBox;
    1919    CheckBoxRepetitive: TCheckBox;
    20     ComboBoxNonTerminal: TComboBox;
    2120    ComboBoxType: TComboBox;
    22     EditName: TEdit;
     21    EditTerminal: TEdit;
     22    EditTerminalFrom: TEdit;
     23    EditTerminalTo: TEdit;
    2324    Label2: TLabel;
    2425    LabelNonTerminal: TLabel;
    2526    LabelTerminal: TLabel;
     27    LabelTerminal1: TLabel;
     28    LabelTerminal2: TLabel;
     29    ListBox1: TListBox;
    2630    PageControl1: TPageControl;
     31    TabSheetTerminalRange: TTabSheet;
    2732    TabSheetTerminal: TTabSheet;
    2833    TabSheetNonTerminal: TTabSheet;
    2934    TabSheetSubItems: TTabSheet;
    3035    procedure ComboBoxTypeChange(Sender: TObject);
     36    procedure EditTerminalKeyPress(Sender: TObject; var Key: char);
    3137    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    3238    procedure FormCreate(Sender: TObject);
     
    6268end;
    6369
     70procedure TFormRuleItem.EditTerminalKeyPress(Sender: TObject; var Key: char);
     71begin
     72  if Key = #13 then ButtonOk.Click;
     73end;
     74
    6475procedure TFormRuleItem.FormClose(Sender: TObject; var CloseAction: TCloseAction
    6576  );
     
    8495begin
    8596  Core.PersistentForm1.Load(Self);
     97  case RuleItem.RuleItemType of
     98    ritTerminal: EditTerminal.SetFocus;
     99    ritNonTerminal: ListBox1.SetFocus;
     100    ritSubItems: TFormRuleItems(FormRuleItems).ListView1.SetFocus;
     101  end;
    86102end;
     103
    87104
    88105procedure TFormRuleItem.ReloadNonTerminals(Grammer: TGrammer);
     
    90107  Rule: TRule;
    91108begin
    92   ComboBoxNonTerminal.Items.Clear;
     109  ListBox1.Items.Clear;
    93110  for Rule in Grammer.Rules do begin
    94     ComboBoxNonTerminal.Items.AddObject(Rule.Name, Rule);
     111    ListBox1.Items.AddObject(Rule.Name, Rule);
    95112  end;
    96   ComboBoxNonTerminal.Sorted := True;
     113  ListBox1.Sorted := True;
    97114end;
    98115
     
    100117begin
    101118  PageControl1.PageIndex := Integer(RuleItem.RuleItemType);
    102   EditName.Visible := RuleItem.RuleItemType = ritTerminal;
     119  EditTerminal.Visible := RuleItem.RuleItemType = ritTerminal;
    103120  LabelTerminal.Visible := RuleItem.RuleItemType = ritTerminal;
    104   ComboBoxNonTerminal.Visible := RuleItem.RuleItemType = ritNonTerminal;
     121  ListBox1.Visible := RuleItem.RuleItemType = ritNonTerminal;
    105122  LabelNonTerminal.Visible := RuleItem.RuleItemType = ritNonTerminal;
    106123end;
     
    111128  ReloadNonTerminals(RuleItem.Grammer);
    112129  ComboBoxType.ItemIndex := Integer(RuleItem.RuleItemType);
    113   ComboBoxNonTerminal.ItemIndex := ComboBoxNonTerminal.Items.IndexOfObject(RuleItem.NonTerminal);
    114   EditName.Text := RuleItem.Terminal;
     130  ListBox1.ItemIndex := ListBox1.Items.IndexOfObject(RuleItem.NonTerminal);
     131  EditTerminal.Text := RuleItem.Terminal;
     132  EditTerminalFrom.Text := RuleItem.TerminalFrom;
     133  EditTerminalTo.Text := RuleItem.TerminalTo;
    115134  CheckBoxOptional.Checked := RuleItem.Optional;
    116135  CheckBoxRepetitive.Checked := RuleItem.Repetitive;
     
    123142  TFormRuleItems(FormRuleItems).SaveData(RuleItem.SubItems);
    124143  RuleItem.RuleItemType := TRuleItemType(ComboBoxType.ItemIndex);
    125   if RuleItem.RuleItemType = ritTerminal then RuleItem.Terminal := EditName.Text
    126   else if RuleItem.RuleItemType = ritNonTerminal then
    127     RuleItem.NonTerminal := TRule(ComboBoxNonTerminal.Items.Objects[ComboBoxNonTerminal.ItemIndex]);
     144  RuleItem.Terminal := EditTerminal.Text;
     145  RuleItem.TerminalFrom := EditTerminalFrom.Text;
     146  RuleItem.TerminalTo := EditTerminalTo.Text;
     147  if ListBox1.ItemIndex <> -1 then
     148    RuleItem.NonTerminal := TRule(ListBox1.Items.Objects[ListBox1.ItemIndex])
     149    else RuleItem.NonTerminal := nil;
    128150  RuleItem.Optional := CheckBoxOptional.Checked;
    129151  RuleItem.Repetitive := CheckBoxRepetitive.Checked;
Note: See TracChangeset for help on using the changeset viewer.