1 {*******************************************************}
2 { TSakuraScriptFountain - TEditor Fountain Parser }
4 { Copyright (c) 2003 naruto/CANO-Lab }
5 {*******************************************************}
7 unit SakuraScriptFountain;
12 SysUtils, Classes, heClasses, heFountain, heRaStrings, SsParser;
15 TSakuraScriptFountainParser = class(TFountainParser)
17 function GetTalkToken: char;
18 procedure InitMethodTable; override;
21 procedure SymbolProc; override;
22 function SsParser: TSsParser;
23 function IsScope0ChangeTag(const Tag: String): boolean; virtual;
24 function IsScope1ChangeTag(const Tag: String): boolean; virtual;
26 function NextToken: Char; override;
27 function TokenToFountainColor: TFountainColor; override;
30 TSakuraScriptFountain = class(TFountain)
32 FScope0Color: TFountainColor;
33 FScope1Color: TFountainColor;
34 FTagColor: TFountainColor;
35 FMetaWordColor: TFountainColor;
36 FTagErrorColor: TFountainColor;
37 FSynchronizedColor: TFountainColor;
38 FSakuraScriptParser: TSsParser;
39 FProcessSync: boolean;
40 FChangeScopeByHU: boolean;
41 FChangeScopeBy01: boolean;
42 procedure SetMetaWordColor(const Value: TFountainColor);
43 procedure SetScope0Color(const Value: TFountainColor);
44 procedure SetScope1Color(const Value: TFountainColor);
45 procedure SetTagColor(const Value: TFountainColor);
46 procedure SetTagErrorColor(const Value: TFountainColor);
47 procedure SetSynchronizedColor(const Value: TFountainColor);
48 procedure SetSakuraScriptParser(const Value: TSsParser);
49 procedure SetChangeScopeBy01(const Value: boolean);
50 procedure SetChangeScopeByHU(const Value: boolean);
51 procedure SetProcessSync(const Value: boolean);
54 { Protected
\90é
\8c¾ }
55 procedure CreateFountainColors; override;
56 function GetParserClass: TFountainParserClass; override;
58 constructor Create(AOwner: TComponent); override;
59 destructor Destroy; override;
61 property Scope0Color: TFountainColor read FScope0Color write SetScope0Color;
62 property Scope1Color: TFountainColor read FScope1Color write SetScope1Color;
63 property TagColor: TFountainColor read FTagColor write SetTagColor;
64 property TagErrorColor: TFountainColor read FTagErrorColor write SetTagErrorColor;
65 property MetaWordColor: TFountainColor read FMetaWordColor write SetMetaWordColor;
66 property SynchronizedColor: TFountainColor read FSynchronizedColor write SetSynchronizedColor;
67 property SakuraScriptParser: TSsParser read FSakuraScriptParser write SetSakuraScriptParser;
68 property ChangeScopeBy01: boolean read FChangeScopeBy01 write SetChangeScopeBy01 default true;
69 property ChangeScopeByHU: boolean read FChangeScopeByHU write SetChangeScopeByHU default true;
70 property ProcessSync: boolean read FProcessSync write SetProcessSync default true;
72 { Published
\90é
\8c¾ }
80 {
\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Ë) }
81 toScope0 = char(50); //
\83X
\83R
\81[
\83v0
\95¶
\8e\9a\97ñ
82 toScope1 = char(51); //
\83X
\83R
\81[
\83v1
\95¶
\8e\9a\97ñ
83 toTag = char(52); //
\83^
\83O
84 toTagError = char(53); //
\83^
\83O
\95\
\8bL
\83G
\83\89\81[
85 toMetaWord = char(54); //
\83\81\83^
\95¶
\8e\9a\97ñ
86 toSynchronized = char(55); //
\83V
\83\93\83N
\83\8d\83i
\83C
\83Y
\83h
\83Z
\83b
\83V
\83\87\83\93
91 { TSakuraScriptFountain }
93 constructor TSakuraScriptFountain.Create(AOwner: TComponent);
96 FChangeScopeByHU := true;
97 FChangeScopeBy01 := true;
101 procedure TSakuraScriptFountain.CreateFountainColors;
104 FScope0Color := CreateFountainColor;
105 FScope1Color := CreateFountainColor;
106 FTagColor := CreateFountainColor;
107 FTagErrorColor := CreateFountainColor;
108 FMetaWordColor := CreateFountainColor;
109 FSynchronizedColor := CreateFountainColor;
112 destructor TSakuraScriptFountain.Destroy;
119 FSynchronizedColor.Free;
123 function TSakuraScriptFountain.GetParserClass: TFountainParserClass;
125 Result := TSakuraScriptFountainParser;
128 procedure TSakuraScriptFountain.SetChangeScopeBy01(const Value: boolean);
130 FChangeScopeBy01 := Value;
133 procedure TSakuraScriptFountain.SetChangeScopeByHU(const Value: boolean);
135 FChangeScopeByHU := Value;
138 procedure TSakuraScriptFountain.SetMetaWordColor(
139 const Value: TFountainColor);
141 FMetaWordColor.Assign(Value);
144 procedure TSakuraScriptFountain.SetProcessSync(const Value: boolean);
146 FProcessSync := Value;
149 procedure TSakuraScriptFountain.SetSakuraScriptParser(
150 const Value: TSsParser);
152 FSakuraScriptParser := Value;
155 procedure TSakuraScriptFountain.SetScope0Color(
156 const Value: TFountainColor);
158 FScope0Color.Assign(Value);
161 procedure TSakuraScriptFountain.SetScope1Color(
162 const Value: TFountainColor);
164 FScope1Color.Assign(Value);
167 procedure TSakuraScriptFountain.SetSynchronizedColor(
168 const Value: TFountainColor);
170 FSynchronizedColor.Assign(Value);
173 procedure TSakuraScriptFountain.SetTagColor(const Value: TFountainColor);
175 FTagColor.Assign(Value);
178 procedure TSakuraScriptFountain.SetTagErrorColor(
179 const Value: TFountainColor);
181 FTagErrorColor.Assign(Value);
184 { TSakuraScriptFountainParser }
186 function TSakuraScriptFountainParser.GetTalkToken: char;
188 if (FElementIndex or InSynchronized) > 0 then
189 Result := toSynchronized
190 else if (FElementIndex or InScope1) > 0 then
196 procedure TSakuraScriptFountainParser.InitMethodTable;
199 FMethodTable['\'] := TagProc;
200 FMethodTable['%'] := MetaProc;
204 function TSakuraScriptFountainParser.IsScope0ChangeTag(
205 const Tag: String): boolean;
208 if (Self.FFountain as TSakuraScriptFountain).ChangeScopeBy01 then
211 if (Self.FFountain as TSakuraScriptFountain).ChangeScopeByHU then
216 function TSakuraScriptFountainParser.IsScope1ChangeTag(
217 const Tag: String): boolean;
220 if (Self.FFountain as TSakuraScriptFountain).ChangeScopeBy01 then
223 if (Self.FFountain as TSakuraScriptFountain).ChangeScopeByHU then
228 procedure TSakuraScriptFountainParser.MetaProc;
232 for i := 0 to SsParser.MetaPattern.Count-1 do
234 Le := SsParser.MatchP(FP, PChar(SsParser.MetaPattern[i]));
237 FToken := toMetaWord;
239 Exit; //
\82ß
\82Å
\82½
\82
\83\81\83^
\95¶
\8e\9a\82Æ
\82µ
\82Ä
\89ð
\90Í
\8a®
\97¹
242 SymbolProc; //
\92P
\8f\83\82É
\95¶
\8e\9a\82Æ
\82µ
\82Ä
\88µ
\82¤
245 function TSakuraScriptFountainParser.NextToken: Char;
247 //
\82±
\82Ì
\83N
\83\89\83X
\82Ì
\83L
\83\82\81B
248 // toInteger
\82â
\82çtoDBSymbol
\82â
\82ç
\82Ì
\83g
\81[
\83N
\83\93\82Í
\95s
\97v
\82Å
\81A
249 //
\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
250 //
\83g
\81[
\83N
\83\93\82ð
\8fã
\8f\91\82«
\82·
\82é
252 if FToken = toTag then
254 if IsScope1ChangeTag(TokenString) then
255 FElementIndex := FElementIndex or InScope1
256 else if IsScope0ChangeTag(TokenString) then
257 FElementIndex := FElementIndex and not InScope1
258 else if (FFountain as TSakuraScriptFountain).ProcessSync and
259 (TokenString = '\_s') then
260 FElementIndex := FElementIndex xor InSynchronized;
263 if FToken in [toSymbol..toFloat, toAnk, toDBSymbol..toKana, toHex] then
265 if (FElementIndex and InSynchronized) > 0 then
266 FToken := toSynchronized
267 else if (FElementIndex and InScope1) > 0 then
276 procedure TSakuraScriptFountainParser.SymbolProc;
277 // '\'
\82Æ'%'
\88È
\8aO
\82Í
\8d\8b\89õ
\82É
\93Ç
\82Ý
\94ò
\82Î
\82·
\81B
\97v
\82ç
\82È
\82¢
\81B
278 //
\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
281 if not (FP^ in [#0, #9, #10, #13, '\', '%']) then
282 if FP^ in LeadBytes then
288 function TSakuraScriptFountainParser.SsParser: TSsParser;
290 Result := (FFountain as TSakuraScriptFountain).SakuraScriptParser;
291 if Result = nil then raise Exception.Create('SakuraScriptParser property is nil');
294 procedure TSakuraScriptFountainParser.TagProc;
300 if (FP^ in [#0, #13, #10]) then
302 FToken := toTagError;
304 end else if (FP^ = '\') or (FP^ = '%') then // '\\', '\%'
\8c`
\8e®
\82Ì
\83G
\83X
\83P
\81[
\83v
310 for i := 0 to SsParser.TagPattern.Count-1 do
312 Pat := SsParser.TagPattern[i];
313 if Length(Pat) < 2 then Continue;
314 IsErr := Pat[1] = '!';
315 Le := SsParser.MatchP(FP, @Pat[2]);
323 Exit; //
\82ß
\82Å
\82½
\82
\83p
\83^
\81[
\83\93\83}
\83b
\83`
\90¬
\8c÷
\82Ì
\8fê
\8d\87
326 //
\88È
\89º
\82Í
\83p
\83^
\81[
\83\93\8eæ
\93¾
\8e¸
\94s
\82Ì
\8fê
\8d\87
327 FToken := toTagError;
328 if FP^ in LeadBytes then
335 function TSakuraScriptFountainParser.TokenToFountainColor: TFountainColor;
337 with TSakuraScriptFountain(FFountain) do
340 Result := FScope0Color;
342 Result := FScope1Color;
346 Result := FTagErrorColor;
348 Result := FMetaWordColor;
350 Result := FSynchronizedColor;
358 RegisterComponents('TEditor', [TSakuraScriptFountain]);