Ignore:
Timestamp:
Dec 27, 2017, 6:05:11 PM (7 years ago)
Author:
chronos
Message:
  • Added: Lookup tables can be defined and their usage set from grammer rules.
File:
1 edited

Legend:

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

    r136 r137  
    1616    ButtonCancel: TButton;
    1717    ButtonOk: TButton;
     18    CheckBoxLookupTable: TCheckBox;
    1819    CheckBoxAnyExcept: TCheckBox;
    1920    CheckBoxEscapedString: TCheckBox;
    2021    CheckBoxOptional: TCheckBox;
    2122    CheckBoxRepetitive: TCheckBox;
     23    ComboBoxLookupTableAction: TComboBox;
    2224    ComboBoxType: TComboBox;
    2325    EditTerminal: TEdit;
    2426    EditTerminalFrom: TEdit;
    2527    EditTerminalTo: TEdit;
     28    Label1: TLabel;
    2629    Label2: TLabel;
    2730    LabelNonTerminal: TLabel;
     
    2932    LabelTerminal1: TLabel;
    3033    LabelTerminal2: TLabel;
    31     ListBox1: TListBox;
     34    ListBoxNonTerminals: TListBox;
     35    ListBoxLookupTable: TListBox;
    3236    PageControl1: TPageControl;
    3337    TabSheetTerminalRange: TTabSheet;
     
    3539    TabSheetNonTerminal: TTabSheet;
    3640    TabSheetSubItems: TTabSheet;
     41    procedure CheckBoxLookupTableChange(Sender: TObject);
    3742    procedure ComboBoxTypeChange(Sender: TObject);
    3843    procedure EditTerminalKeyPress(Sender: TObject; var Key: char);
     
    4449    FormRuleItems: TForm;
    4550    procedure ReloadNonTerminals(Grammer: TGrammer);
     51    procedure ReloadLookupTables(Grammer: TGrammer);
    4652  public
    4753    RuleItem: TRuleItem;
     
    7076end;
    7177
     78procedure TFormRuleItem.CheckBoxLookupTableChange(Sender: TObject);
     79begin
     80  UpdateInterface;
     81end;
     82
    7283procedure TFormRuleItem.EditTerminalKeyPress(Sender: TObject; var Key: char);
    7384begin
     
    99110  case RuleItem.RuleItemType of
    100111    ritTerminal: EditTerminal.SetFocus;
    101     ritNonTerminal: ListBox1.SetFocus;
     112    ritNonTerminal: ListBoxNonTerminals.SetFocus;
    102113    ritSubItems: TFormRuleItems(FormRuleItems).ListView1.SetFocus;
    103114    ritTerminalRange: EditTerminalFrom.SetFocus;
     
    110121  Rule: TRule;
    111122begin
    112   ListBox1.Items.Clear;
     123  ListBoxNonTerminals.Items.Clear;
    113124  for Rule in Grammer.Rules do begin
    114     ListBox1.Items.AddObject(Rule.Name, Rule);
    115   end;
    116   ListBox1.Sorted := True;
     125    ListBoxNonTerminals.Items.AddObject(Rule.Name, Rule);
     126  end;
     127  ListBoxNonTerminals.Sorted := True;
     128end;
     129
     130procedure TFormRuleItem.ReloadLookupTables(Grammer: TGrammer);
     131var
     132  Item: TLookupTable;
     133begin
     134  ListBoxLookupTable.Items.Clear;
     135  for Item in Grammer.LookupTables do begin
     136    ListBoxLookupTable.Items.AddObject(Item.Name, Item);
     137  end;
     138  ListBoxLookupTable.Sorted := True;
    117139end;
    118140
     
    122144  EditTerminal.Visible := RuleItem.RuleItemType = ritTerminal;
    123145  LabelTerminal.Visible := RuleItem.RuleItemType = ritTerminal;
    124   ListBox1.Visible := RuleItem.RuleItemType = ritNonTerminal;
     146  ListBoxNonTerminals.Visible := RuleItem.RuleItemType = ritNonTerminal;
    125147  LabelNonTerminal.Visible := RuleItem.RuleItemType = ritNonTerminal;
    126148  CheckBoxOptional.Enabled := RuleItem.ParentRule.Items.RuleType = rtAnd;
     
    128150  CheckBoxEscapedString.Enabled := (RuleItem.RuleItemType = ritTerminal) or
    129151    (RuleItem.RuleItemType = ritTerminalRange);
     152  ListBoxLookupTable.Enabled := CheckBoxLookupTable.Checked;
     153  ComboBoxLookupTableAction.Enabled := CheckBoxLookupTable.Checked;
    130154end;
    131155
     
    135159  ReloadNonTerminals(RuleItem.Grammer);
    136160  ComboBoxType.ItemIndex := Integer(RuleItem.RuleItemType);
    137   ListBox1.ItemIndex := ListBox1.Items.IndexOfObject(RuleItem.NonTerminal);
     161  ListBoxNonTerminals.ItemIndex := ListBoxNonTerminals.Items.IndexOfObject(RuleItem.NonTerminal);
    138162  EditTerminal.Text := RuleItem.Terminal;
    139163  EditTerminalFrom.Text := RuleItem.TerminalFrom;
     
    144168  TFormRuleItems(FormRuleItems).LoadData(RuleItem.SubItems);
    145169  CheckBoxEscapedString.Checked := RuleItem.EscapedStrings;
     170  // Lookup table
     171  CheckBoxLookupTable.Checked := RuleItem.LookupTableUsed;
     172  ReloadLookupTables(RuleItem.Grammer);
     173  ComboBoxLookupTableAction.ItemIndex := Integer(RuleItem.LookupTableAction);
     174  ListBoxLookupTable.ItemIndex := ListBoxLookupTable.Items.IndexOfObject(RuleItem.LookupTable);
    146175  UpdateInterface;
    147176end;
     
    155184  RuleItem.TerminalFrom := EditTerminalFrom.Text;
    156185  RuleItem.TerminalTo := EditTerminalTo.Text;
    157   if ListBox1.ItemIndex <> -1 then
    158     RuleItem.NonTerminal := TRule(ListBox1.Items.Objects[ListBox1.ItemIndex])
     186  if ListBoxNonTerminals.ItemIndex <> -1 then
     187    RuleItem.NonTerminal := TRule(ListBoxNonTerminals.Items.Objects[ListBoxNonTerminals.ItemIndex])
    159188    else RuleItem.NonTerminal := nil;
    160189  RuleItem.Optional := CheckBoxOptional.Checked;
     
    162191  RuleItem.AnyExcept := CheckBoxAnyExcept.Checked;
    163192  RuleItem.EscapedStrings := CheckBoxEscapedString.Checked;
     193  // Lookup table
     194  RuleItem.LookupTableUsed := CheckBoxLookupTable.Checked;
     195  RuleItem.LookupTableAction := TLookupTableAction(ComboBoxLookupTableAction.ItemIndex);
     196  if ListBoxLookupTable.ItemIndex <> -1 then
     197    RuleItem.LookupTable := TLookupTable(ListBoxLookupTable.Items.Objects[ListBoxLookupTable.ItemIndex])
     198    else RuleItem.LookupTable := nil;
    164199end;
    165200
Note: See TracChangeset for help on using the changeset viewer.