Ignore:
Timestamp:
Nov 29, 2017, 1:21:22 PM (7 years ago)
Author:
chronos
Message:
  • Added: Show "Used by" rules in rule edit window.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/generator/URules.pas

    r119 r120  
    7676  TRule = class
    7777  private
    78     function GetGrammer: TGrammer;
     78    FGrammer: TGrammer;
    7979    procedure SetGrammer(AValue: TGrammer);
    8080  public
     
    8383    Items: TRuleItems;
    8484    Links: TRuleLinks;
    85     property Grammer: TGrammer read GetGrammer write SetGrammer;
    8685    constructor Create;
    8786    destructor Destroy; override;
     87    procedure GetUsedByRule(RefRule: TRule; UsedByRules: TStrings);
    8888    procedure LoadFromXmlNode(Node: TDOMNode);
    8989    procedure SaveToXmlNode(Node: TDOMNode);
    9090    function GetString: string;
     91    property Grammer: TGrammer read FGrammer write SetGrammer;
    9192  end;
    9293
     
    117118    destructor Destroy; override;
    118119    procedure BuildCompiler;
     120    procedure GetUsedByRule(RefRule: TRule; UsedByRules: TStrings);
    119121    function GetString: string;
    120122    property Modified: Boolean read FModified write SetModified;
     
    308310end;
    309311
     312procedure TGrammer.GetUsedByRule(RefRule: TRule; UsedByRules: TStrings);
     313var
     314  Rule: TRule;
     315begin
     316  UsedByRules.Clear;
     317  for Rule in Rules do
     318    Rule.GetUsedByRule(RefRule, UsedByRules);
     319end;
     320
    310321function TGrammer.GetString: string;
    311322begin
     
    498509end;
    499510
    500 function TRule.GetGrammer: TGrammer;
    501 begin
    502   Result := Items.Grammer;
    503 end;
    504 
    505511procedure TRule.SetGrammer(AValue: TGrammer);
    506512begin
     513  if FGrammer = AValue then Exit;
     514  FGrammer := AValue;
    507515  Items.Grammer := AValue;
    508516end;
     
    520528  FreeAndNil(Items);
    521529  inherited Destroy;
     530end;
     531
     532procedure TRule.GetUsedByRule(RefRule: TRule; UsedByRules: TStrings);
     533var
     534  Item: TRuleItem;
     535begin
     536  for Item in Items do
     537    if (Item.RuleItemType = ritNonTerminal) and
     538      (Item.NonTerminal = RefRule) and
     539      (UsedByRules.IndexOf(Item.ParentRule.Name) = -1) then
     540      UsedByRules.AddObject(Item.ParentRule.Name, Item.ParentRule);
    522541end;
    523542
Note: See TracChangeset for help on using the changeset viewer.