Ignore:
Timestamp:
Nov 27, 2017, 1:09:38 PM (7 years ago)
Author:
chronos
Message:
  • Added: Rule can be set as optional or repetitive.
  • Added: Support for nested rule item sublist.
Location:
branches/generator
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/generator

    • Property svn:ignore
      •  

        old new  
        22generator.lps
        33lib
         4heaptrclog.trc
  • branches/generator/Forms/UFormMain.lfm

    r115 r117  
    11object FormMain: TFormMain
    2   Left = 620
     2  Left = 382
    33  Height = 678
    4   Top = 427
     4  Top = 195
    55  Width = 1050
    66  Caption = 'Language generator'
  • branches/generator/Forms/UFormMain.pas

    r114 r117  
    5959
    6060procedure TFormMain.ARulesExecute(Sender: TObject);
     61var
     62  FormRules: TFormRules;
    6163begin
     64  FormRules := TFormRules.Create(nil);
    6265  FormRules.Rules := Core.Grammer.Rules;
    6366  FormRules.ShowModal;
    6467  MemoBNF.Lines.Text := Core.Grammer.GetBNF;
     68  FreeAndNil(FormRules);
    6569end;
    6670
  • branches/generator/Forms/UFormRule.lfm

    r116 r117  
    99  ClientWidth = 663
    1010  OnCreate = FormCreate
     11  OnDestroy = FormDestroy
    1112  OnShow = FormShow
    1213  LCLVersion = '1.6.4.0'
  • branches/generator/Forms/UFormRule.pas

    r116 r117  
    2222    TabSheet2: TTabSheet;
    2323    procedure FormCreate(Sender: TObject);
     24    procedure FormDestroy(Sender: TObject);
    2425    procedure FormShow(Sender: TObject);
    2526  private
     
    3940{$R *.lfm}
    4041
    41 uses
    42   UFormRuleItem;
    43 
    4442{ TFormRule }
    4543
     
    5553  FormRuleItems.Align := alClient;
    5654  FormRuleItems.Show;
     55end;
     56
     57procedure TFormRule.FormDestroy(Sender: TObject);
     58begin
     59  FreeAndNil(FormRuleItems);
    5760end;
    5861
  • branches/generator/Forms/UFormRuleItem.lfm

    r114 r117  
    11object FormRuleItem: TFormRuleItem
    22  Left = 474
    3   Height = 278
     3  Height = 400
    44  Top = 386
    55  Width = 656
    6   ActiveControl = EditName
    76  Caption = 'Rule item'
    8   ClientHeight = 278
     7  ClientHeight = 400
    98  ClientWidth = 656
     9  OnClose = FormClose
     10  OnCreate = FormCreate
     11  OnDestroy = FormDestroy
     12  OnShow = FormShow
    1013  LCLVersion = '1.6.4.0'
    11   object LabelTerminal: TLabel
    12     Left = 16
    13     Height = 20
    14     Top = 64
    15     Width = 61
    16     Caption = 'Terminal:'
    17     ParentColor = False
    18   end
    19   object EditName: TEdit
    20     Left = 160
    21     Height = 28
    22     Top = 64
    23     Width = 400
     14  object ButtonCancel: TButton
     15    Left = 176
     16    Height = 25
     17    Top = 362
     18    Width = 75
     19    Anchors = [akLeft, akBottom]
     20    Caption = 'Cancel'
     21    ModalResult = 2
    2422    TabOrder = 0
    2523  end
    26   object ButtonCancel: TButton
    27     Left = 232
     24  object ButtonOk: TButton
     25    Left = 352
    2826    Height = 25
    29     Top = 208
     27    Top = 362
    3028    Width = 75
    31     Caption = 'Cancel'
    32     ModalResult = 2
    33     TabOrder = 1
    34   end
    35   object ButtonOk: TButton
    36     Left = 408
    37     Height = 25
    38     Top = 208
    39     Width = 75
     29    Anchors = [akLeft, akBottom]
    4030    Caption = 'Ok'
    4131    ModalResult = 1
    42     TabOrder = 2
     32    TabOrder = 1
    4333  end
    4434  object ComboBoxType: TComboBox
     
    5141      'Terminal'
    5242      'Non-terminal'
     43      'Subitems'
    5344    )
    5445    OnChange = ComboBoxTypeChange
    5546    Style = csDropDownList
    56     TabOrder = 3
     47    TabOrder = 2
    5748  end
    5849  object Label2: TLabel
     
    6455    ParentColor = False
    6556  end
    66   object LabelNonTerminal: TLabel
     57  object PageControl1: TPageControl
    6758    Left = 16
    68     Height = 20
    69     Top = 112
    70     Width = 92
    71     Caption = 'Non-terminal:'
    72     ParentColor = False
     59    Height = 266
     60    Top = 88
     61    Width = 632
     62    ActivePage = TabSheetSubItems
     63    Anchors = [akTop, akLeft, akRight, akBottom]
     64    ShowTabs = False
     65    TabIndex = 2
     66    TabOrder = 3
     67    object TabSheetTerminal: TTabSheet
     68      Caption = 'Terminal'
     69      ClientHeight = 168
     70      ClientWidth = 624
     71      object EditName: TEdit
     72        Left = 152
     73        Height = 28
     74        Top = 16
     75        Width = 400
     76        TabOrder = 0
     77      end
     78      object LabelTerminal: TLabel
     79        Left = 8
     80        Height = 20
     81        Top = 24
     82        Width = 61
     83        Caption = 'Terminal:'
     84        ParentColor = False
     85      end
     86    end
     87    object TabSheetNonTerminal: TTabSheet
     88      Caption = 'NonTerminal'
     89      ClientHeight = 168
     90      ClientWidth = 624
     91      object ComboBoxNonTerminal: TComboBox
     92        Left = 152
     93        Height = 28
     94        Top = 16
     95        Width = 404
     96        ItemHeight = 20
     97        Style = csDropDownList
     98        TabOrder = 0
     99      end
     100      object LabelNonTerminal: TLabel
     101        Left = 8
     102        Height = 20
     103        Top = 24
     104        Width = 92
     105        Caption = 'Non-terminal:'
     106        ParentColor = False
     107      end
     108    end
     109    object TabSheetSubItems: TTabSheet
     110      Caption = 'SubItems'
     111    end
    73112  end
    74   object ComboBoxNonTerminal: TComboBox
    75     Left = 160
    76     Height = 28
    77     Top = 104
    78     Width = 404
    79     ItemHeight = 20
    80     Style = csDropDownList
     113  object CheckBoxOptional: TCheckBox
     114    Left = 16
     115    Height = 24
     116    Top = 56
     117    Width = 82
     118    Caption = 'Optional'
    81119    TabOrder = 4
    82120  end
     121  object CheckBoxRepetitive: TCheckBox
     122    Left = 336
     123    Height = 24
     124    Top = 56
     125    Width = 91
     126    Caption = 'Repetitive'
     127    TabOrder = 5
     128  end
    83129end
  • branches/generator/Forms/UFormRuleItem.pas

    r111 r117  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   URules;
     9  ComCtrls, URules;
    1010
    1111type
     
    1616    ButtonCancel: TButton;
    1717    ButtonOk: TButton;
     18    CheckBoxOptional: TCheckBox;
     19    CheckBoxRepetitive: TCheckBox;
     20    ComboBoxNonTerminal: TComboBox;
    1821    ComboBoxType: TComboBox;
    19     ComboBoxNonTerminal: TComboBox;
    2022    EditName: TEdit;
    21     LabelTerminal: TLabel;
    2223    Label2: TLabel;
    2324    LabelNonTerminal: TLabel;
     25    LabelTerminal: TLabel;
     26    PageControl1: TPageControl;
     27    TabSheetTerminal: TTabSheet;
     28    TabSheetNonTerminal: TTabSheet;
     29    TabSheetSubItems: TTabSheet;
    2430    procedure ComboBoxTypeChange(Sender: TObject);
     31    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     32    procedure FormCreate(Sender: TObject);
     33    procedure FormDestroy(Sender: TObject);
     34    procedure FormShow(Sender: TObject);
    2535  private
     36    FormRuleItems: TForm;
    2637    procedure ReloadNonTerminals(Grammer: TGrammer);
    2738  public
     
    3546  FormRuleItem: TFormRuleItem;
    3647
     48
    3749implementation
     50
     51uses
     52  UCore, UFormRuleItems;
    3853
    3954{$R *.lfm}
     
    4560  RuleItem.RuleItemType := TRuleItemType(ComboBoxType.ItemIndex);
    4661  UpdateInterface;
     62end;
     63
     64procedure TFormRuleItem.FormClose(Sender: TObject; var CloseAction: TCloseAction
     65  );
     66begin
     67  Core.PersistentForm1.Save(Self);
     68end;
     69
     70procedure TFormRuleItem.FormCreate(Sender: TObject);
     71begin
     72  FormRuleItems := TFormRuleItems.Create(nil);
     73  FormRuleItems.ManualDock(TabSheetSubItems);
     74  FormRuleItems.Align := alClient;
     75  FormRuleItems.Show;
     76end;
     77
     78procedure TFormRuleItem.FormDestroy(Sender: TObject);
     79begin
     80  FreeAndNil(FormRuleItems);
     81end;
     82
     83procedure TFormRuleItem.FormShow(Sender: TObject);
     84begin
     85  Core.PersistentForm1.Load(Self);
    4786end;
    4887
     
    5998procedure TFormRuleItem.UpdateInterface;
    6099begin
     100  PageControl1.PageIndex := Integer(RuleItem.RuleItemType);
    61101  EditName.Visible := RuleItem.RuleItemType = ritTerminal;
    62102  LabelTerminal.Visible := RuleItem.RuleItemType = ritTerminal;
     
    72112  ComboBoxNonTerminal.ItemIndex := ComboBoxNonTerminal.Items.IndexOfObject(RuleItem.NonTerminal);
    73113  EditName.Text := RuleItem.Terminal;
     114  CheckBoxOptional.Checked := RuleItem.Optional;
     115  CheckBoxRepetitive.Checked := RuleItem.Repetitive;
     116  TFormRuleItems(FormRuleItems).LoadData(RuleItem.SubItems);
    74117  UpdateInterface;
    75118end;
     
    77120procedure TFormRuleItem.SaveData(RuleItem: TRuleItem);
    78121begin
     122  TFormRuleItems(FormRuleItems).SaveData(RuleItem.SubItems);
    79123  RuleItem.RuleItemType := TRuleItemType(ComboBoxType.ItemIndex);
    80124  if RuleItem.RuleItemType = ritTerminal then RuleItem.Terminal := EditName.Text
    81125  else if RuleItem.RuleItemType = ritNonTerminal then
    82126    RuleItem.NonTerminal := TRule(ComboBoxNonTerminal.Items.Objects[ComboBoxNonTerminal.ItemIndex]);
     127  RuleItem.Optional := CheckBoxOptional.Checked;
     128  RuleItem.Repetitive := CheckBoxRepetitive.Checked;
    83129end;
    84130
  • branches/generator/Forms/UFormRuleItems.pas

    r116 r117  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    9   Menus, ActnList, StdCtrls, URules;
     9  Menus, ActnList, StdCtrls, URules, UFormRuleItem;
    1010
    1111type
     
    4848      Selected: Boolean);
    4949  private
    50     { private declarations }
     50    FormRuleItem: TFormRuleItem;
    5151  public
    5252    RuleItems: TRuleItems;
     
    6363implementation
    6464
    65 uses
    66   UFormRuleItem;
    6765
    6866{$R *.lfm}
     
    8482  NewRuleItem := TRuleItem.Create;
    8583  NewRuleItem.Grammer := RuleItems.Grammer;
     84  FormRuleItem := TFormRuleItem.Create(nil);
    8685  FormRuleItem.LoadData(NewRuleItem);
    8786  if FormRuleItem.ShowModal = mrOk then begin
     
    9190    ReloadList;
    9291  end else FreeAndNil(NewRuleItem);
     92  FreeAndNil(FormRuleItem);
    9393end;
    9494
     
    9898begin
    9999  RuleItem := TRuleItem(ListView.Selected.Data);
     100  FormRuleItem := TFormRuleItem.Create(nil);
    100101  FormRuleItem.LoadData(RuleItem);
    101102  if FormRuleItem.ShowModal = mrOk then begin
     
    103104    ReloadList;
    104105  end;
     106  FreeAndNil(FormRuleItem);
    105107end;
    106108
  • branches/generator/Forms/UFormRules.pas

    r116 r117  
    7373  NewRule := TRule.Create;
    7474  NewRule.Grammer := Rules.Grammer;
     75  FormRule := TFormRule.Create(nil);
    7576  FormRule.LoadData(NewRule);
    7677  if FormRule.ShowModal = mrOk then begin
     
    7980    ReloadList;
    8081  end else FreeAndNil(NewRule);
     82  FreeAndNil(FormRule);
    8183end;
    8284
     
    8486var
    8587  Rule: TRule;
     88  FormRule: TFormRule;
    8689begin
    8790  Rule := TRule(ListView1.Selected.Data);
     91  FormRule := TFormRule.Create(nil);
    8892  FormRule.LoadData(Rule);
    8993  if FormRule.ShowModal = mrOk then begin
     
    9195    ReloadList;
    9296  end;
     97  FreeAndNil(FormRule);
    9398end;
    9499
     
    118123    Item.Caption := Rules[Item.Index].Name;
    119124    Item.Data := Rules[Item.Index];
    120     Item.SubItems.Add(Rules[Item.Index].Items.GetBNF(Rules[Item.Index].Items.RuleType));
     125    Item.SubItems.Add(Rules[Item.Index].Items.GetBNF);
    121126  end;
    122127end;
Note: See TracChangeset for help on using the changeset viewer.