OSDN Git Service

1つのSsParserインスタンスで複数の処理が出来るように変更。
authornaru <bottle@mikage.to>
Tue, 11 Apr 2006 01:02:04 +0000 (01:02 +0000)
committernaru <bottle@mikage.to>
Tue, 11 Apr 2006 01:02:04 +0000 (01:02 +0000)
スレッドセーフにするためには、
EscapeInvalidMeta/LeaveEscapeの保存処理を少しいじればいけるかも

sakurasuite/SsParser.pas

index 7f06e3d..720a1ce 100644 (file)
@@ -59,14 +59,14 @@ type
     function GetStr(Index: Integer): string;
     procedure SetExtra(Index: Integer; const Value: string);
     function GetItem(Index: Integer): TSsMarkUp;
+    procedure Clear;
+    procedure Add(Pos: Integer; MarkUpType: TSsMarkUpType; Str: string;
+      Extra: string = '');
   protected
     property Item[Index: Integer]: TSsMarkUp read GetItem;
   public
     constructor Create(const InputString: string);
     destructor Destroy; override;
-    procedure Clear;
-    procedure Add(Pos: Integer; MarkUpType: TSsMarkUpType; Str: string;
-      Extra: string = '');
     function MarkUpAt(const Pos: Integer): Integer;
     property Count: Integer read GetCount;
     property MarkUpType[Index: Integer]: TSsMarkUpType read GetMarkUpType;
@@ -76,7 +76,12 @@ type
     property InputString: string read FInputString; // Cannot Write
   end;
 
- TSsParser = class(TComponent)
+  // Notes to user:
+  // This class has been modified so that it can handle multiple parsing
+  // results, but this class is NOT thread-safe.
+  // If you want to parse scripts within more than one thread,
+  // separate parser instance should be prepared for each thread.
+  TSsParser = class(TComponent)
   private
     FTagPattern: TStrings;  //SakuraScript tag pattern string
     FMetaPattern: TStrings; //SakuraScript meta expression pattern string
@@ -114,6 +119,8 @@ type
     function EscapeParam(const Param: string): string;
     function MarkUpAt(const Pos: integer): integer;
 
+    function Parse(const Script: string): TSsParseResult;
+
     { These properties are deprecated. }
     property Count: integer read GetCount;
     property MarkUpType[Index: integer]: TSsMarkUpType read GetMarkUpType;
@@ -682,6 +689,12 @@ begin
   if not Matched then Result := 0;
 end;
 
+function TSsParser.Parse(const Script: string): TSsParseResult;
+begin
+  Result := TSsParseResult.Create(Script);
+  BeginParse(Result);
+end;
+
 procedure TSsParser.SetExtra(Index: integer; const Value: string);
 begin
   FBuffList.Extra[Index] := Value;