OSDN Git Service

Added ChangeScopeBy** properties and ProcessSync property
authornaru <bottle@mikage.to>
Tue, 22 Apr 2003 08:23:50 +0000 (08:23 +0000)
committernaru <bottle@mikage.to>
Tue, 22 Apr 2003 08:23:50 +0000 (08:23 +0000)
Minor Optimization

sakurasuite/SakuraScriptFountain.pas

index b0e5c53..bc4af01 100644 (file)
@@ -13,7 +13,6 @@ uses
 
 type
   TSakuraScriptFountainParser = class(TFountainParser)
-  private
   protected
     function GetTalkToken: char;
     procedure InitMethodTable; override;
@@ -21,6 +20,8 @@ type
     procedure MetaProc;
     procedure SakuraSymbolProc;
     function SsParser: TSsParser;
+    function IsScope0ChangeTag(const Tag: String): boolean; virtual;
+    function IsScope1ChangeTag(const Tag: String): boolean; virtual;
   public
     function NextToken: Char; override;
     function TokenToFountainColor: TFountainColor; override;
@@ -35,6 +36,9 @@ type
     FTagErrorColor: TFountainColor;
     FSynchronizedColor: TFountainColor;
     FSakuraScriptParser: TSsParser;
+    FProcessSync: boolean;
+    FChangeScopeByHU: boolean;
+    FChangeScopeBy01: boolean;
     procedure SetMetaWordColor(const Value: TFountainColor);
     procedure SetScope0Color(const Value: TFountainColor);
     procedure SetScope1Color(const Value: TFountainColor);
@@ -42,12 +46,16 @@ type
     procedure SetTagErrorColor(const Value: TFountainColor);
     procedure SetSynchronizedColor(const Value: TFountainColor);
     procedure SetSakuraScriptParser(const Value: TSsParser);
+    procedure SetChangeScopeBy01(const Value: boolean);
+    procedure SetChangeScopeByHU(const Value: boolean);
+    procedure SetProcessSync(const Value: boolean);
     { Private \90é\8c¾ }
   protected
     { Protected \90é\8c¾ }
     procedure CreateFountainColors; override;
     function GetParserClass: TFountainParserClass; override;
   public
+    constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
   published
     property Scope0Color: TFountainColor read FScope0Color write SetScope0Color;
@@ -57,6 +65,9 @@ type
     property MetaWordColor: TFountainColor read FMetaWordColor write SetMetaWordColor;
     property SynchronizedColor: TFountainColor read FSynchronizedColor write SetSynchronizedColor;
     property SakuraScriptParser: TSsParser read FSakuraScriptParser write SetSakuraScriptParser;
+    property ChangeScopeBy01: boolean read FChangeScopeBy01 write SetChangeScopeBy01 default true;
+    property ChangeScopeByHU: boolean read FChangeScopeByHU write SetChangeScopeByHU default true;
+    property ProcessSync: boolean read FProcessSync write SetProcessSync default true;
   published
     { Published \90é\8c¾ }
   end;
@@ -79,6 +90,14 @@ const
 
 { TSakuraScriptFountain }
 
+constructor TSakuraScriptFountain.Create(AOwner: TComponent);
+begin
+  inherited;
+  FChangeScopeByHU := true;
+  FChangeScopeBy01 := true;
+  FProcessSync := true;
+end;
+
 procedure TSakuraScriptFountain.CreateFountainColors;
 begin
   inherited;
@@ -106,12 +125,27 @@ begin
   Result := TSakuraScriptFountainParser;
 end;
 
+procedure TSakuraScriptFountain.SetChangeScopeBy01(const Value: boolean);
+begin
+  FChangeScopeBy01 := Value;
+end;
+
+procedure TSakuraScriptFountain.SetChangeScopeByHU(const Value: boolean);
+begin
+  FChangeScopeByHU := Value;
+end;
+
 procedure TSakuraScriptFountain.SetMetaWordColor(
   const Value: TFountainColor);
 begin
   FMetaWordColor.Assign(Value);
 end;
 
+procedure TSakuraScriptFountain.SetProcessSync(const Value: boolean);
+begin
+  FProcessSync := Value;
+end;
+
 procedure TSakuraScriptFountain.SetSakuraScriptParser(
   const Value: TSsParser);
 begin
@@ -180,6 +214,30 @@ begin
 end;
 
 
+function TSakuraScriptFountainParser.IsScope0ChangeTag(
+  const Tag: String): boolean;
+begin
+  Result := false;
+  if (Self.FFountain as TSakuraScriptFountain).ChangeScopeBy01 then
+    if Tag = '\0' then
+      Result := true;
+  if (Self.FFountain as TSakuraScriptFountain).ChangeScopeByHU then
+    if Tag = '\h' then
+      Result := true;
+end;
+
+function TSakuraScriptFountainParser.IsScope1ChangeTag(
+  const Tag: String): boolean;
+begin
+  Result := false;
+  if (Self.FFountain as TSakuraScriptFountain).ChangeScopeBy01 then
+    if Tag = '\1' then
+      Result := true;
+  if (Self.FFountain as TSakuraScriptFountain).ChangeScopeByHU then
+    if Tag = '\u' then
+      Result := true;
+end;
+
 procedure TSakuraScriptFountainParser.MetaProc;
 var i, Le: integer;
 begin
@@ -202,11 +260,12 @@ begin
   inherited NextToken;
   if FToken = toTag then
   begin
-    if TokenString = '\u' then
-      FElementIndex := FElementIndex or InScope1;
-    if TokenString = '\h' then
-      FElementIndex := FElementIndex and not InScope1;
-    if TokenString = '\_s' then
+    if IsScope1ChangeTag(TokenString) then
+      FElementIndex := FElementIndex or InScope1
+    else if IsScope0ChangeTag(TokenString) then
+      FElementIndex := FElementIndex and not InScope1
+    else if (FFountain as TSakuraScriptFountain).ProcessSync and
+      (TokenString = '\_s') then
       FElementIndex := FElementIndex xor InSynchronized;
   end else
   begin