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.
Location:
branches/generator/Forms
Files:
4 added
6 edited

Legend:

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

    r132 r137  
    2929      Height = 28
    3030      Top = 5
    31       Width = 169
     31      Width = 198
    3232      Align = alNone
    3333      AutoSize = True
     
    7474        Action = AGrammerSettings
    7575      end
     76      object ToolButton7: TToolButton
     77        Left = 169
     78        Top = 0
     79        Action = ALookupTables
     80      end
    7681    end
    7782  end
     
    154159    end
    155160    object MenuItem8: TMenuItem
    156       Caption = 'Tools'
     161      Caption = 'Grammer'
    157162      object MenuItem9: TMenuItem
    158163        Action = ABuildCompiler
     164      end
     165      object MenuItem3: TMenuItem
     166        Action = ALookupTables
    159167      end
    160168    end
     
    228236      OnExecute = AToolbarVisibleExecute
    229237    end
     238    object ALookupTables: TAction
     239      Caption = 'Lookup tables'
     240      ImageIndex = 8
     241      OnExecute = ALookupTablesExecute
     242    end
    230243  end
    231244  object OpenDialog1: TOpenDialog
  • branches/generator/Forms/UFormMain.pas

    r136 r137  
    1616  TFormMain = class(TForm)
    1717    ABuildCompiler: TAction;
     18    ALookupTables: TAction;
    1819    AToolbarVisible: TAction;
    1920    AProjectOpenRecent: TAction;
     
    3839    MenuItem13: TMenuItem;
    3940    MenuItem2: TMenuItem;
     41    MenuItem3: TMenuItem;
    4042    MenuItemRecent: TMenuItem;
    4143    MenuItemToolbar: TMenuItem;
     
    6062    ToolButton5: TToolButton;
    6163    ToolButton6: TToolButton;
     64    ToolButton7: TToolButton;
    6265    procedure ABuildCompilerExecute(Sender: TObject);
     66    procedure ALookupTablesExecute(Sender: TObject);
    6367    procedure AToolbarVisibleExecute(Sender: TObject);
    6468    procedure AExitExecute(Sender: TObject);
     
    96100
    97101uses
    98   UFormRules, UCore, UFormGrammer, UBuilder;
     102  UFormRules, UCore, UFormGrammer, UBuilder, UFormLookupTables;
    99103
    100104resourcestring
     
    300304end;
    301305
     306procedure TFormMain.ALookupTablesExecute(Sender: TObject);
     307var
     308  FormLookupTables: TFormLookupTables;
     309begin
     310  FormLookupTables := TFormLookupTables.Create(nil);
     311  try
     312    FormLookupTables.LookupTables := Core.Grammer.LookupTables;
     313    if FormLookupTables.ShowModal = mrOk then begin
     314
     315    end;
     316  finally
     317    FreeAndNil(FormLookupTables);
     318  end;
     319end;
     320
    302321procedure TFormMain.AToolbarVisibleExecute(Sender: TObject);
    303322begin
  • branches/generator/Forms/UFormRuleItem.lfm

    r136 r137  
    6161    Top = 88
    6262    Width = 632
    63     ActivePage = TabSheetTerminalRange
     63    ActivePage = TabSheetNonTerminal
    6464    Anchors = [akTop, akLeft, akRight, akBottom]
    6565    ShowTabs = False
    66     TabIndex = 3
     66    TabIndex = 1
    6767    TabOrder = 3
    6868    object TabSheetTerminal: TTabSheet
     
    9393      object LabelNonTerminal: TLabel
    9494        Left = 8
    95         Height = 20
    96         Top = 16
    97         Width = 92
     95        Height = 23
     96        Top = 8
     97        Width = 105
    9898        Caption = 'Non-terminal:'
    9999        ParentColor = False
    100100      end
    101       object ListBox1: TListBox
    102         Left = 128
    103         Height = 232
    104         Top = 16
    105         Width = 484
     101      object ListBoxNonTerminals: TListBox
     102        Left = 8
     103        Height = 210
     104        Top = 40
     105        Width = 304
    106106        Anchors = [akTop, akLeft, akRight, akBottom]
    107107        ItemHeight = 0
    108         ScrollWidth = 482
     108        ScrollWidth = 302
    109109        TabOrder = 0
    110110        TopIndex = -1
     111      end
     112      object CheckBoxLookupTable: TCheckBox
     113        Left = 352
     114        Height = 27
     115        Top = 8
     116        Width = 152
     117        Caption = 'Use lookup table'
     118        OnChange = CheckBoxLookupTableChange
     119        TabOrder = 1
     120      end
     121      object ListBoxLookupTable: TListBox
     122        Left = 352
     123        Height = 176
     124        Top = 40
     125        Width = 248
     126        Anchors = [akTop, akLeft, akRight, akBottom]
     127        ItemHeight = 0
     128        ScrollWidth = 246
     129        TabOrder = 2
     130        TopIndex = -1
     131      end
     132      object Label1: TLabel
     133        Left = 352
     134        Height = 23
     135        Top = 224
     136        Width = 90
     137        Caption = 'Item action:'
     138        ParentColor = False
     139      end
     140      object ComboBoxLookupTableAction: TComboBox
     141        Left = 464
     142        Height = 35
     143        Top = 224
     144        Width = 134
     145        ItemHeight = 0
     146        ItemIndex = 0
     147        Items.Strings = (
     148          'Create'
     149          'Reference'
     150        )
     151        Style = csDropDownList
     152        TabOrder = 3
     153        Text = 'Create'
    111154      end
    112155    end
  • 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
  • branches/generator/Forms/UFormRules.lfm

    r129 r137  
    77  ClientHeight = 611
    88  ClientWidth = 857
    9   DesignTimePPI = 120
    109  OnClose = FormClose
    1110  OnCreate = FormCreate
    1211  OnShow = FormShow
    13   LCLVersion = '1.8.0.6'
     12  LCLVersion = '1.8.0.4'
    1413  object CoolBar1: TCoolBar
    1514    Left = 0
     
    2827      AnchorSideTop.Control = CoolBar1
    2928      Left = 24
    30       Height = 22
     29      Height = 28
    3130      Top = 5
    32       Width = 70
     31      Width = 88
    3332      Align = alNone
    3433      AutoSize = True
     
    4847      end
    4948      object ToolButton2: TToolButton
    50         Left = 24
     49        Left = 30
    5150        Top = 0
    5251        Action = AModify
    5352      end
    5453      object ToolButton3: TToolButton
    55         Left = 47
     54        Left = 59
    5655        Top = 0
    5756        Action = ARemove
     
    9493    TabOrder = 1
    9594    ViewStyle = vsReport
    96     OnCompare = ListView1Compare
    9795    OnData = ListView1Data
    9896    OnDblClick = ListView1DblClick
  • branches/generator/Forms/UFormRules.pas

    r130 r137  
    3535    procedure FormCreate(Sender: TObject);
    3636    procedure FormShow(Sender: TObject);
    37     procedure ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
    38       Data: Integer; var Compare: Integer);
    3937    procedure ListView1Data(Sender: TObject; Item: TListItem);
    4038    procedure ListView1DblClick(Sender: TObject);
     
    7371  ReloadList;
    7472  UpdateInterface;
    75 end;
    76 
    77 procedure TFormRules.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
    78   Data: Integer; var Compare: Integer);
    79 begin
    80 
    8173end;
    8274
Note: See TracChangeset for help on using the changeset viewer.