-{
- TSakuraScriptFountain - Parser Class for SakuraScript designed for TEditor
-}
+{*******************************************************}
+{ TSakuraScriptFountain - TEditor Fountain Parser }
+{ }
+{ Copyright (c) 2003 naruto/CANO-Lab }
+{*******************************************************}
unit SakuraScriptFountain;
type
TSakuraScriptFountainParser = class(TFountainParser)
- private
protected
function GetTalkToken: char;
procedure InitMethodTable; override;
procedure TagProc;
procedure MetaProc;
- procedure SakuraSymbolProc;
+ procedure SymbolProc; override;
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;
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);
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;
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;
const
{ \83g\81[\83N\83\93\82Ì\8eí\97Þ\82ð\95\\82·\92è\90\94(\97ñ\8b\93\8c^\82¾\82Æ\82±\82¤\82â\82Á\82Ä\91\9d\82â\82¹\82È\82¢\82©\82ç\82Ë) }
- toScope0 = char(50); //\83X\83R\81[\83v1\95¶\8e\9a\97ñ
- toScope1 = char(51); //\83X\83R\81[\83v2\95¶\8e\9a\97ñ
+ toScope0 = char(50); //\83X\83R\81[\83v0\95¶\8e\9a\97ñ
+ toScope1 = char(51); //\83X\83R\81[\83v1\95¶\8e\9a\97ñ
toTag = char(52); //\83^\83O
toTagError = char(53); //\83^\83O\95\\8bL\83G\83\89\81[
toMetaWord = char(54); //\83\81\83^\95¶\8e\9a\97ñ
{ TSakuraScriptFountain }
+constructor TSakuraScriptFountain.Create(AOwner: TComponent);
+begin
+ inherited;
+ FChangeScopeByHU := true;
+ FChangeScopeBy01 := true;
+ FProcessSync := true;
+end;
+
procedure TSakuraScriptFountain.CreateFountainColors;
begin
inherited;
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
end;
procedure TSakuraScriptFountainParser.InitMethodTable;
-var C: char;
begin
inherited;
+ FMethodTable['\'] := TagProc;
+ FMethodTable['%'] := MetaProc;
+end;
- // FMethodTable\82ð\8dÄ\8f\89\8aú\89»\82·\82é\81B\8cp\8f³\8c³\82É\82 \82é\82æ\82¤\82È
- // \95¡\8eG\82È\90§\8cä\82Í\95s\95K\97v\82©\82Â\8e×\96\82\81B
- for C := #0 to #255 do
- case C of
- #0: FMethodTable[C] := EofProc;
- #9: FMethodTable[C] := TabProc;
- #10: FMethodTable[C] := LFProc;
- #13: FMethodTable[C] := CrProc;
- '\': FMethodTable[C] := TagProc;
- '%': FMethodTable[C] := MetaProc;
- else
- FMethodTable[C] := SakuraSymbolProc;
- 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;
Exit; // \82ß\82Å\82½\82\83\81\83^\95¶\8e\9a\82Æ\82µ\82Ä\89ð\90Í\8a®\97¹
end else
end;
- SakuraSymbolProc; // \92P\8f\83\82É\95¶\8e\9a\82Æ\82µ\82Ä\88µ\82¤
+ SymbolProc; // \92P\8f\83\82É\95¶\8e\9a\82Æ\82µ\82Ä\88µ\82¤
end;
function TSakuraScriptFountainParser.NextToken: Char;
begin
- Result := inherited NextToken;
+ // \82±\82Ì\83N\83\89\83X\82Ì\83L\83\82\81B
+ // toInteger\82â\82çtoDBSymbol\82â\82ç\82Ì\83g\81[\83N\83\93\82Í\95s\97v\82Å\81A
+ // \91ã\82í\82è\82É\82»\82Ì\83Z\83\8a\83t\82ª\82Ç\82¿\82ç\82Ì\83X\83R\81[\83v\82È\82Ì\82©\82ª\95K\97v\82È\82Ì\82Å\81A
+ // \83g\81[\83N\83\93\82ð\8fã\8f\91\82«\82·\82é
+ 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
- if FToken in [toSymbol] then
+ if FToken in [toSymbol..toFloat, toAnk, toDBSymbol..toKana, toHex] then
begin
if (FElementIndex and InSynchronized) > 0 then
FToken := toSynchronized
Result := FToken;
end;
-procedure TSakuraScriptFountainParser.SakuraSymbolProc;
-// '\'\82Æ'%'\88È\8aO\82Í\8d\8b\89õ\82É\93Ç\82Ý\94ò\82Î\82·\81B\97v\82ç\82È\82¢\82ñ\82¾\82à\82ñ\81B
+procedure TSakuraScriptFountainParser.SymbolProc;
+// '\'\82Æ'%'\88È\8aO\82Í\8d\8b\89õ\82É\93Ç\82Ý\94ò\82Î\82·\81B\97v\82ç\82È\82¢\81B
+// \83_\83u\83\8b\83o\83C\83g\95¶\8e\9a\82à\83V\83\93\83O\83\8b\83o\83C\83g\95¶\8e\9a\82à\95¹\82¹\82Ä\92P\82È\82é\83V\83\93\83{\83\8b\82Æ\82µ\82Ä\88µ\82¤\81B
begin
FToken := toSymbol;
- if not (FP^ in [#0, #10, #13]) then
+ if not (FP^ in [#0, #9, #10, #13, '\', '%']) then
if FP^ in LeadBytes then
Inc(FP, 2)
else
Exit;
end else if (FP^ = '\') or (FP^ = '%') then // '\\', '\%'\8c`\8e®\82Ì\83G\83X\83P\81[\83v
begin
- SakuraSymbolProc;
+ Inc(FP);
+ SymbolProc;
end else
begin
for i := 0 to SsParser.TagPattern.Count-1 do
FToken := toTagError
else
FToken := toTag;
- Exit; // \82ß\82Å\82½\82µ\82ß\82Å\82½\82µ\82Å\83p\83^\81[\83\93\83}\83b\83`\90¬\8c÷\82Ì\8fê\8d\87
+ Exit; // \82ß\82Å\82½\82\83p\83^\81[\83\93\83}\83b\83`\90¬\8c÷\82Ì\8fê\8d\87
end;
end;
// \88È\89º\82Í\83p\83^\81[\83\93\8eæ\93¾\8e¸\94s\82Ì\8fê\8d\87