unit REMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ecSyntDlg, StdCtrls, ExtCtrls, ComCtrls, ecSyntMemo, ecZRegExpr,
  ecSyntAnal;

type
  TRegExprTest = class(TForm)
    TreeView1: TTreeView;
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Panel2: TPanel;
    SyntaxMemo1: TSyntaxMemo;
    SyntaxMemo2: TSyntaxMemo;
    Label1: TLabel;
    Label2: TLabel;
    SyntAnalyzer1: TSyntAnalyzer;
    Splitter1: TSplitter;
    Splitter2: TSplitter;
    Label3: TLabel;
    Splitter3: TSplitter;
    SyntaxMemo3: TSyntaxMemo;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    procedure LogStr(const S: string);
  public
    { Public declarations }
  end;

var
  RegExprTest: TRegExprTest;

implementation

{$R *.dfm}

procedure TRegExprTest.Button2Click(Sender: TObject);
var Re: TecRegExpr;
    p: integer;
begin
  SyntaxMemo3.Clear;
  REDebugOnMatchProc := LogStr;
  Re := TecRegExpr.Create;
  try
    Re.Expression := SyntaxMemo1.Text;
    Re.Compile;
    REDebugCompiledBuildTree(RE, TreeView1);
    p := 1;
    if Re.Match(SyntaxMemo2.Lines.FText, p) then
//      SyntaxMemo2.Lines.Text := Re.Substitute(SyntaxMemo2.Lines.Text, '\2');
      SyntaxMemo2.SetSelection(0, p - 1);
  finally
    Re.Free;
    REDebugOnMatchProc := nil;
  end;
end;

procedure TRegExprTest.Button1Click(Sender: TObject);
var Re: TecRegExpr;
begin
  Re := TecRegExpr.Create;
  try
    Re.Expression := SyntaxMemo1.Text;
    Re.Compile;
    REDebugCompiledBuildTree(RE, TreeView1);
  finally
    Re.Free;
  end;
end;

procedure TRegExprTest.LogStr(const S: string);
begin
  SyntaxMemo3.Lines.Add(S);
end;

end.
