Debian Codegraph @

components/synunihighlighter/source/SynUniHighlighter.pas

raw
1 {
2 The contents of this file are subject to the Mozilla Public License
3 Version 1.1 (the "License"); you may not use this file except in compliance
4 with the License. You may obtain a copy of the License at
5 http://www.mozilla.org/MPL/
6
7 Software distributed under the License is distributed on an "AS IS" basis,
8 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9 the specific language governing rights and limitations under the License.
10
11 The Original Code is: SynUniHighlighter.pas, released 2003-01
12 All Rights Reserved.
13
14 Alternatively, the contents of this file may be used under the terms of the
15 GNU General Public License Version 2 or later (the "GPL"), in which case
16 the provisions of the GPL are applicable instead of those above.
17 If you wish to allow use of your version of this file only under the terms
18 of the GPL and not to allow others to use your version of this file
19 under the MPL, indicate your decision by deleting the provisions above and
20 replace them with the notice and other provisions required by the GPL.
21 If you do not delete the provisions above, a recipient may use your version
22 of this file under either the MPL or the GPL.
23
24 }{
25 @abstract(Provides a universal highlighter for SynEdit)
26 @authors(Fantasist [[email protected]], Vit [[email protected]],
27 Vitalik [[email protected]])
28 @created(2003)
29 @lastmod(2004-05-12)
30 }
31
32 (******************************************************************************
33 Authors: Fantasist (Kirill Burtsev [email protected])
34 Vit (Vitaly Nevzorov [email protected])
35 Vitalik (Vitaly Lyapota [email protected])
36 Official Site: www.delphist.com
37 With all questions, please visit www.delphist.com/forum
38 ******************************************************************************)
39
40 unit SynUniHighlighter;
41
42 {$mode delphi}
43
44 interface
45
46 uses
47 SysUtils, Classes, Graphics,
48 SynEditTypes, SynEditHighlighter, SynUniClasses, SynUniRules, Laz2_DOM;
49
50 Const
51 _Root = 'Root';
52 _New = 'New';
53
54 type
55
56 { TSynUniSyn }
57
58 TSynUniSyn = class(TSynCustomHighlighter)
59 private
60 FFileName: String;
61
62 protected
63 fMainRules: TSynRange;
64 fEol: boolean;
65 fPrEol: boolean;
66 fLine: PChar;
67 fTrueLine: String;
68 fLineNumber: Integer;
69 Run: LongInt;
70 fTokenPos: Integer;
71 fCurrToken: TSynSymbol;
72 fCurrentRule: TSynRange;
73 SymbolList: array[char] of TAbstractSymbol; //???
74 fPrepared: boolean;
75
76 fSchemes: TStringList;
77 fSchemeIndex: integer;
78
79 function GetIdentChars: TSynIdentChars; override;
80 function GetSampleSource: string; override;
81 procedure SetSampleSource(Value: string); override;
82 function GetDefaultFilter: string; override;
83 procedure SetDefaultFilter(Value: string); override;
84 public
85 class function GetLanguageName: string; override;
86 public
87 constructor Create(AOwner: TComponent); overload; override;
88 destructor Destroy; override;
89 function GetHashCode: PtrInt; override;
90 procedure Assign(Source: TPersistent); override;
91 function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
92 override; {Abstract}
93 function GetEol: Boolean; override; {Abstract}
94 function GetRange: Pointer; override;
95 function GetToken: string; override; {Abstract}
96 procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override; {Abstract}
97 function GetTokenAttribute: TSynHighlighterAttributes; override; {Abstract}
98 function GetTokenKind: integer; override; {Abstract}
99 function GetTokenPos: Integer; override; {Abstract}
100 function IsKeyword(const AKeyword: string): boolean; override;
101 procedure Next; override; {Abstract}
102 procedure ResetRange; override;
103 procedure SetLine(const NewValue: string; LineNumber: Integer); override; {Abstract}
104 procedure SetRange(Value: Pointer); override;
105 procedure Reset;
106 procedure Clear;
107 procedure Prepare;
108 procedure CreateStandardRules;
109
110 procedure ReadSchemes(xml: TDOMNode);
111 procedure ReadInfo(xml: TDOMNode);
112 procedure LoadHglFromXml(xml: TDOMNode);
113 procedure LoadHglFromStream(Stream: TStream);
114 procedure LoadHglFromFile(FileName: string);
115
116 procedure SaveHglToStream(Stream: TStream);
117 procedure SaveHglToFile(FileName: string);
118
119 procedure LoadFromXml(xml: TDOMNode);
120 procedure LoadFromStream(Stream: TStream; FreeStream: boolean = True);
121 procedure LoadFromFile(FileName: string);
122
123 function GetAsStream: TMemoryStream;
124 procedure SaveToStream(Stream: TStream; Rule: TSynRule = nil);
125 procedure SaveToFile(FileName: string; Rule: TSynRule = nil);
126
127 public
128 Info: TSynInfo;
129 Styles: TSynUniStyles;
130 SchemeFileName: string;
131 SchemeName: string;
132 property FileName: String read FFileName;
133 property MainRules: TSynRange read fMainRules;
134 property SchemesList: TStringList read fSchemes write fSchemes;
135 property SchemeIndex: integer read fSchemeIndex write fSchemeIndex;
136 end;
137
138 implementation
139
140 uses
141 CRC, Laz2_XMLRead;
142
143 //==== TSynUniSyn ============================================================
144 constructor TSynUniSyn.Create(AOwner: TComponent);
145 begin
146 inherited Create(AOwner);
147 Info := TSynInfo.Create;
148 Info.History := TStringList.Create;
149 Info.Sample := TStringList.Create;
150 fPrepared := False;
151
152 fSchemes := TStringList.Create;
153 fSchemeIndex := -1;
154
155 fMainRules := TSynRange.Create;
156 MainRules.Name := _Root;
157 fEol := False;
158 fPrEol := False;
159 fCurrentRule := MainRules;
160 end;
161
162 destructor TSynUniSyn.Destroy;
163 //: Destructor of TSynUniSyn
164 begin
165 MainRules.Free;
166 Info.History.Free;
167 Info.Sample.Free;
168 Info.Free;
169 fSchemes.Free;
170 inherited;
171 end;
172
173 function TSynUniSyn.GetHashCode: PtrInt;
174
175 function Update(ACrc: PtrInt; ARule: TSynRule): PtrInt;
176 var
177 Index: Integer;
178 AValue: Cardinal;
179 begin
180 AValue:= Cardinal(ARule.Attribs.GetHashCode);
181 Result:= PtrInt(CRC32(Cardinal(ACrc), @AValue, SizeOf(AValue)));
182
183 if ARule is TSynRange then
184 begin
185 with TSynRange(ARule) do
186 begin
187 for Index := 0 to SetCount - 1 do
188 Result:= Update(Result, Sets[Index]);
189 for Index := 0 to RangeCount - 1 do
190 Result:= Update(Result, Ranges[Index]);
191 for Index := 0 to KeyListCount - 1 do
192 Result:= Update(Result, KeyLists[Index]);
193 end;
194 end;
195 end;
196
197 begin
198 Result:= Update(0, MainRules);
199 end;
200
201 procedure TSynUniSyn.Assign(Source: TPersistent);
202 var
203 AStream: TMemoryStream;
204 begin
205 inherited Assign(Source);
206 if (Source is TSynUniSyn) then
207 begin
208 if GetHashCode <> Source.GetHashCode then
209 begin
210 AStream:= TMemoryStream.Create;
211 try
212 Tag:= -1;
213 TSynUniSyn(Source).SaveToStream(AStream);
214 AStream.Seek(0, soBeginning);
215 LoadFromStream(AStream, False);
216 Self.Info.Version.ReleaseDate:= Now;
217 finally
218 AStream.Free;
219 end;
220 end;
221 end;
222 end;
223
224 procedure TSynUniSyn.SetLine(const NewValue: string; LineNumber: Integer);
225 //: Set current line in SynEdit for highlighting
226 function HaveNodeAnyStart(Node: TSymbolNode): boolean;
227 var
228 i: integer;
229 begin
230 Result := False;
231 if Node.StartType = stAny then
232 begin
233 Result := True;
234 Exit;
235 end;
236 for i := 0 to Node.NextSymbs.Count-1 do
237 if (Node.NextSymbs.Nodes[i].StartType = stAny) or HaveNodeAnyStart(Node.NextSymbs.Nodes[i]) then
238 begin
239 Result := True;
240 Exit;
241 end
242 end;
243
244 var i: integer;
245 begin
246 if LineNumber = 1 then begin
247 MainRules.ResetParents(MainRules);
248 MainRules.ClearParsingFields();
249 end;
250 if not fCurrentRule.Prepared then begin //: If current Range isn't prepared,
251 Prepare; //: then prepare it and its sub-ranges
252 (*{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
253 !!!!!!! Это я писал и это зачем-то нужно !!!!!!!!!!!!!!!!!!!!!!!!*)
254 for i := 0 to 255 do
255 if (SymbolList[char(i)] <> nil) {temp}and (TSymbols(SymbolList[char(i)]).HeadNode <> nil){/temp} then
256 fCurrentRule.HasNodeAnyStart[char(i)] := HaveNodeAnyStart(TSymbols(SymbolList[fCurrentRule.CaseFunct(char(i))]).HeadNode);
257 (*}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}*)
258 end;
259
260 fTrueLine := NewValue;
261 fLine := PChar(NewValue); //: Current string of SynEdit
262
263 Run := 0; //: Set Position of "parser" at the first char of string
264 fTokenPos := 0; //: Set Position of current token at the first char of string
265 fLineNumber := LineNumber; //: Number of current line in SynEdit
266 fEol := False; //: ???
267 fPrEol := False; //: ???
268 Next; //: Find first token in the line
269 end;
270
271 procedure TSynUniSyn.Next;
272 //: Goes to the next token and open/close ranges
273 var
274 ParentCycle, CurrentParent: TSynRange;
275 RangeLink: TSynRangeLink;
276 isFindSame: boolean;
277 begin
278 if fPrEol then //: if it was end of line then
279 begin //: if current range close on end of line then
280 if (fCurrentRule.fRule.fCloseOnEol) or (fCurrentRule.fRule.fCloseOnTerm) then begin
281 if fCurrentRule.OpenCount > 0 then
282 fCurrentRule.OpenCount := fCurrentRule.OpenCount - 1
283 else
284 if fCurrentRule.ParentBackup <> nil then
285 fCurrentRule.Parent := fCurrentRule.ParentBackup;
286 if fCurrentRule.fRule.fAllowPredClose then begin
287 fCurrentRule := fCurrentRule.Parent;
288 while (fCurrentRule.fRule.fCloseOnEol) or (fCurrentRule.fRule.fCloseOnTerm) do
289 fCurrentRule := fCurrentRule.Parent;
290 end else
291 fCurrentRule := fCurrentRule.Parent;
292 end;
293 fEol := True; //: ???
294 Exit;
295 end;
296
297 fTokenPos := Run; //: Start of cf current token is end of previsious
298 //: if current range close on delimeter and current symbol is delimeter then
299 if (fCurrentRule.fRule.fCloseOnTerm) and (fLine[Run] in fCurrentRule.fTermSymbols) then begin
300 if fCurrentRule.OpenCount > 0 then
301 fCurrentRule.OpenCount := fCurrentRule.OpenCount - 1
302 else
303 if fCurrentRule.ParentBackup <> nil then
304 fCurrentRule.Parent := fCurrentRule.ParentBackup;
305 if fCurrentRule.fRule.fAllowPredClose then begin
306 fCurrentRule := fCurrentRule.Parent;
307 while (fCurrentRule.fRule.fCloseOnTerm) do
308 fCurrentRule := fCurrentRule.Parent;
309 end
310 else
311 fCurrentRule := fCurrentRule.Parent;
312 end;
313
314 //: if we can't find token from current position:
315 if not fCurrentRule.SymbolList[fCurrentRule.CaseFunct(fLine[Run])].GetToken(fCurrentRule, fLine, Run, fCurrToken) then
316 begin
317 fCurrToken := fCurrentRule.fDefaultSynSymbol; //: Current token is just default symbol
318 while not ((fLine[Run] in fCurrentRule.fTermSymbols) or fCurrentRule.HasNodeAnyStart[fCurrentRule.CaseFunct(fLine[Run])]) do
319 inc(Run); //: goes to the first non-delimeter symbol
320 end
321 else //: else (we find token!)
322 if (fCurrentRule.fClosingSymbol = fCurrToken) then begin //: if current token close current range
323 // if (fCurrentRule.fClosingSymbol <> nil) and (fCurrentRule.fClosingSymbol.Symbol = fCurrToken.Symbol) then
324 if fCurrentRule.OpenCount > 0 then
325 fCurrentRule.OpenCount := fCurrentRule.OpenCount - 1
326 else
327 if fCurrentRule.ParentBackup <> nil then
328 fCurrentRule.Parent := fCurrentRule.ParentBackup;
329 if fCurrentRule.fRule.fAllowPredClose then begin
330 fCurrentRule := fCurrentRule.Parent;
331 while (fCurrentRule.fClosingSymbol <> nil) and (fCurrentRule.fClosingSymbol.Symbol = fCurrToken.Symbol) do
332 fCurrentRule := fCurrentRule.Parent;
333 end else
334 fCurrentRule := fCurrentRule.Parent
335 end else
336 if fCurrToken.fOpenRule <> nil then begin //: else if current token open range then
337 CurrentParent := fCurrentRule;
338 if fCurrToken.fOpenRule is TSynRangeLink then begin
339 RangeLink := TSynRangeLink(fCurrToken.fOpenRule);
340 fCurrentRule := RangeLink.Range;
341 ParentCycle := CurrentParent;
342 isFindSame := False;
343 while ParentCycle <> nil do begin // Ищем есть ли у тек. правила такой же родитель
344 if ParentCycle = fCurrentRule then begin
345 if RangeLink.Range.OpenCount = 0 then begin // Первое открытие вложенного в себя правила.
346 fCurrentRule.ParentBackup := RangeLink.Range.Parent;
347 fCurrentRule.Parent := CurrentParent;
348 RangeLink.Range.OpenCount := 1;
349 end else begin
350 RangeLink.Range.OpenCount := RangeLink.Range.OpenCount + 1;
351 end;
352 isFindSame := True;
353 break;
354 end;
355 ParentCycle := ParentCycle.Parent;
356 end;
357 if not isFindSame then begin
358 { fCurrentRule.ParentBackup := RangeLink.Range.Parent;
359 fCurrentRule.Parent := CurrentParent;
360 RangeLink.Range.OpenCount := 1;
361 // fCurrentRule.Parent := RangeLink.Parent;}
362 end
363 end
364 else if fCurrToken.fOpenRule is TSynRange then begin
365 fCurrentRule := TSynRange(fCurrToken.fOpenRule); //: open range
366 fCurrentRule.Parent := CurrentParent;
367 end;
368 end;
369
370 if fLine[Run] = #0 then //: If end of line
371 fPrEol := True; //: ???
372
373 end;
374
375 function TSynUniSyn.IsKeyword(const AKeyword: string): boolean;
376 //! Never used!!!! ??? SSS
377 begin
378 // Result := fSymbols.FindSymbol(aKeyword) <> nil;
379 end;
380
381 function TSynUniSyn.GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
382 //: Returns default attribute
383 //: Неопнятно зачем это нужно, но функция предка - абстрактная (может что-нить с ней сделать...)
384 begin
385 case Index of
386 SYN_ATTR_COMMENT: Result := fCurrentRule.Attribs;
387 SYN_ATTR_IDENTIFIER: Result := fCurrentRule.Attribs;
388 SYN_ATTR_KEYWORD: Result := fCurrentRule.Attribs;
389 SYN_ATTR_STRING: Result := fCurrentRule.Attribs;
390 SYN_ATTR_WHITESPACE: Result := fCurrentRule.Attribs;
391 else
392 Result := nil;
393 end;
394 end;
395
396 function TSynUniSyn.GetEol: Boolean;
397 begin
398 Result := fEol;
399 end;
400
401 function TSynUniSyn.GetRange: Pointer;
402 //: Returns current Range
403 begin
404 Result := fCurrentRule;
405 end;
406
407 function TSynUniSyn.GetToken: string;
408 //: Returns current token (string from fTokenPos to Run)
409 var
410 Len: LongInt;
411 begin
412 Len := Run - fTokenPos;
413 Setstring(Result, (fLine + fTokenPos), Len);
414 end;
415
416 procedure TSynUniSyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
417 begin
418 TokenLength := Run - fTokenPos;
419 TokenStart := PAnsiChar(fTrueLine) + fTokenPos;
420 end;
421
422 function TSynUniSyn.GetTokenAttribute: TSynHighlighterAttributes;
423 //: Returns attribute of current token
424 begin
425 Result := fCurrToken.Attributes;
426 end;
427
428 function TSynUniSyn.GetTokenKind: integer;
429 //~ Можно в Kind у токена fCurrToken хранить что это ?: слово или Range или Set
430 begin
431 Result := 1; //# CODE_REVIEW fCurrToken.ID;
432 end;
433
434 function TSynUniSyn.GetTokenPos: Integer;
435 //: Returns position of current token
436 begin
437 Result := fTokenPos;
438 end;
439
440 procedure TSynUniSyn.ResetRange;
441 //: Reset current range to MainRules
442 begin
443 fCurrentRule := MainRules;
444 end;
445
446 procedure TSynUniSyn.SetRange(Value: Pointer);
447 //: Set current range
448 begin
449 fCurrentRule := TSynRange(Value);
450 end;
451
452 class function TSynUniSyn.GetLanguageName: string;
453 begin
454 Result := 'UniLanguage';
455 end;
456
457 procedure TSynUniSyn.Clear;
458 begin
459 MainRules.Clear;
460 Info.Clear;
461 end;
462
463 procedure TSynUniSyn.CreateStandardRules;
464 //: Create sample rools
465 var r: TSynRange;
466 kw: TSynKeyList;
467 begin
468 self.MainRules.Clear;
469 self.MainRules.Attribs.Foreground := clBlack;
470 self.MainRules.Attribs.Background := clWhite;
471 self.MainRules.CaseSensitive := False;
472
473 r := TSynRange.Create('''', '''');
474 r.Name := 'Strings ''..''';
475 r.Attribs.Foreground := clRed;
476 r.Attribs.Background := clWhite;
477 r.CaseSensitive := False;
478 r.fRule.fOpenSymbol.BrakeType := btAny;
479 self.MainRules.AddRange(r);
480
481 r := TSynRange.Create('"', '"');
482 r.Name := 'Strings ".."';
483 r.Attribs.Foreground := clRed;
484 r.Attribs.Background := clWhite;
485 r.CaseSensitive := False;
486 r.fRule.fOpenSymbol.BrakeType := btAny;
487 self.MainRules.AddRange(r);
488
489 r := TSynRange.Create('{', '}');
490 r.Name := 'Remarks {..}';
491 r.Attribs.Foreground := clNavy;
492 r.Attribs.Background := clWhite;
493 r.CaseSensitive := False;
494 r.fRule.fOpenSymbol.BrakeType := btAny;
495 self.MainRules.AddRange(r);
496
497 r := TSynRange.Create('(*', '*)');
498 r.Name := 'Remarks (*..*)';
499 r.Attribs.Foreground := clNavy;
500 r.Attribs.Background := clWhite;
501 r.CaseSensitive := False;
502 r.fRule.fOpenSymbol.BrakeType := btAny;
503 self.MainRules.AddRange(r);
504
505 r := TSynRange.Create('/*', '*/');
506 r.Name := 'Remarks /*..*/';
507 r.Attribs.Foreground := clNavy;
508 r.Attribs.Background := clWhite;
509 r.CaseSensitive := False;
510 r.fRule.fOpenSymbol.BrakeType := btAny;
511 self.MainRules.AddRange(r);
512
513 kw := TSynKeyList.Create('');
514 kw.Name := 'Key words';
515 kw.Attribs.Foreground := clGreen;
516 kw.Attribs.Background := clWhite;
517 self.MainRules.AddKeyList(kw);
518 end;
519
520 procedure TSynUniSyn.Prepare;
521 //: Prepare of SynUniSyn is Prepare of SynUniSyn.fMailRules
522 function HaveNodeAnyStart(Node: TSymbolNode): boolean;
523 var
524 i: integer;
525 begin
526 Result := False;
527 if Node.StartType = stAny then
528 begin
529 Result := True;
530 Exit;
531 end;
532 for i := 0 to Node.NextSymbs.Count-1 do
533 if (Node.NextSymbs.Nodes[i].StartType = stAny) or HaveNodeAnyStart(Node.NextSymbs.Nodes[i]) then
534 begin
535 Result := True;
536 Exit;
537 end
538 end;
539
540 var i: integer;
541 begin
542 MainRules.Prepare(MainRules);
543 // for i := 0 to 255 do
544 // if (MainRules.SymbolList[char(i)] <> MainRules.fDefaultTermSymbol) and (MainRules.SymbolList[char(i)] <> MainRules.fDefaultSymbols) then
545 // MessageBox(0,PChar(TSymbols(MainRules.SymbolList[char(i)]).HeadNode.tkSynSymbol.Symbol),'1',0);
546 for i := 0 to 255 do
547 // if (MainRules.SymbolList[char(i)] <> nil) {temp}and (TSymbols(MainRules.SymbolList[char(i)]).HeadNode <> nil){/temp} then
548 if (MainRules.SymbolList[char(i)] <> MainRules.fDefaultTermSymbol) and (MainRules.SymbolList[char(i)] <> MainRules.fDefaultSymbols) and (TSymbols(MainRules.SymbolList[char(i)]).HeadNode <> nil) then
549 MainRules.HasNodeAnyStart[char(i)] := HaveNodeAnyStart(TSymbols(MainRules.SymbolList[MainRules.CaseFunct(char(i))]).HeadNode);
550 end;
551
552 procedure TSynUniSyn.Reset;
553 //: Reset of SynUniSyn is Reset of SynUniSyn.MainRules
554 begin
555 MainRules.Reset;
556 end;
557
558 function TSynUniSyn.GetIdentChars: TSynIdentChars;
559 //: Return IdentChars - hmm... What for ??? word selection?
560 begin
561 Result := [#32..#255] - fCurrentRule.TermSymbols;
562 end;
563
564 function TSynUniSyn.GetSampleSource: string;
565 //: Get sample text
566 begin
567 Result := Info.Sample.Text;
568 end;
569
570 procedure TSynUniSyn.SetSampleSource(Value: string);
571 //: Set sample text
572 begin
573 Info.Sample.Text := Value;
574 end;
575
576 function TSynUniSyn.GetDefaultFilter: string;
577 var
578 S: String;
579 begin
580 Result:= EmptyStr;
581 for S in Info.General.Extensions.Split([' ', ',']) do
582 begin
583 Result+= '*.' + S + ';';
584 end;
585 if Length(Result) > 0 then Result:= Info.General.Name + '|' + Copy(Result, 1, Length(Result) - 1);
586 end;
587
588 procedure TSynUniSyn.SetDefaultFilter(Value: string);
589 var
590 S: String;
591 Result: String;
592 begin
593 Result:= EmptyStr;
594 Value:= Copy(Value, Pos('|', Value) + 1, MaxInt);
595 for S in Value.Split([';']) do
596 begin
597 Result+= StringReplace(S, '*.', '', []) + ',';
598 end;
599 if Length(Result) = 0 then
600 Info.General.Extensions:= EmptyStr
601 else
602 Info.General.Extensions:= Copy(Result, 1, Length(Result) - 1);
603 end;
604
605 procedure TSynUniSyn.LoadFromXml(xml: TDOMNode);
606 var
607 i, J, K: integer;
608 ChildNode1,
609 ChildNode2: TDOMNode;
610 Key, Value: string;
611 begin
612 Clear;
613 for J := 0 to Int32(xml.ChildNodes.Count) - 1 do
614 begin
615 ChildNode1:= xml.ChildNodes.Item[J];
616 if SameText(ChildNode1.NodeName, 'UniHighlighter') then
617 if ChildNode1.Attributes.Length = 0 then
618 begin
619 LoadHglFromXml(ChildNode1);
620 Exit;
621 end
622 else begin
623 for I := 0 to Int32(ChildNode1.ChildNodes.Count) - 1 do
624 begin
625 ChildNode2:= ChildNode1.ChildNodes.Item[I];
626 if SameText(ChildNode2.NodeName, 'Info') then
627 Info.LoadFromXml(ChildNode2)
628 else
629 if SameText(ChildNode2.NodeName, 'Scheme') then begin
630 SchemeFileName := ''; SchemeName := '';
631 for K := 0 to Int32(ChildNode2.Attributes.Length) - 1 do begin
632 Key := ChildNode2.Attributes[K].NodeName;
633 Value := ChildNode2.Attributes[K].NodeValue;
634 if SameText('File', Key) then SchemeFileName := Value else
635 if SameText('Name', Key) then SchemeName := Value;
636 end;
637 if FileExists(SchemeFileName) then begin
638 if Styles <> nil then
639 Styles.Free;
640 Styles := TSynUniStyles.Create;
641 Styles.FileName := SchemeFileName;
642 Styles.Load;
643 end;
644 end else
645 if SameText(ChildNode2.NodeName, 'Range') then begin
646 // fMainRules.SetStyles(fStyles);
647 fMainRules.Styles := Styles;
648 fMainRules.LoadFromXml(ChildNode2);
649 Break;
650 end
651 end;
652 end;
653 end
654 end;
655
656 procedure TSynUniSyn.LoadFromStream(Stream: TStream; FreeStream: boolean);
657 var
658 Len: Integer;
659 Temp: PAnsiChar;
660 Target: PAnsiChar;
661 Source: PAnsiChar;
662 Finish: PAnsiChar;
663 Memory: PAnsiChar;
664 Xml: TXMLDocument;
665 TargetStream: TMemoryStream;
666 begin
667 TargetStream:= TMemoryStream.Create;
668 try
669 Len:= Stream.Size;
670 Source:= GetMem(Len);
671 TargetStream.SetSize(Len * 2);
672 Stream.ReadBuffer(Source^, Len);
673 Temp:= Source;
674 Memory:= Source;
675 Finish:= Temp + Len - 4;
676 Target:= TargetStream.Memory;
677 // Convert '&qt;' to '&quot;'
678 while (Temp < Finish) do
679 begin
680 if (Temp^ <> '&') then
681 Inc(Temp, 1)
682 else if ((Temp + 1)^ <> 'q') then
683 Inc(Temp, 2)
684 else if ((Temp + 2)^ <> 't') then
685 Inc(Temp, 3)
686 else begin
687 Len:= (Temp - Source) + 2;
688 Move(Source^, Target^, Len);
689 Inc(Temp, 4);
690 Inc(Target, Len);
691 Move('uot;', Target^, 4);
692 Inc(Target, 4);
693 Source:= Temp;
694 end;
695 end;
696 Len:= (Temp - Source) + 4;
697 Move(Source^, Target^, Len);
698 Inc(Target, Len);
699 TargetStream.SetSize(Target - TargetStream.Memory);
700 try
701 TargetStream.Position:= 0;
702 ReadXMLFile(Xml, TargetStream, [xrfPreserveWhiteSpace]);
703 try
704 LoadFromXml(Xml);
705 finally
706 Xml.Free;
707 end;
708 finally
709 DefHighlightChange(Self);
710 end;
711 finally
712 TargetStream.Free;
713 if FreeStream then Stream.Free;
714 if (Memory <> nil) then FreeMem(Memory);
715 end;
716 end;
717
718 procedure TSynUniSyn.LoadFromFile(FileName: string);
719 begin
720 FFileName:= FileName;
721 LoadFromStream(TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone));
722 end;
723
724 procedure TSynUniSyn.SaveToStream(Stream: TStream; Rule: TSynRule);
725 var
726 StreamWriter: TStreamWriter;
727 begin
728 StreamWriter := TStreamWriter.Create(Stream);
729 with StreamWriter do begin
730 WriteTag(0, 'UniHighlighter');
731 WriteParam('version', '1.8', CloseStartTag);
732 Info.SaveToStream(StreamWriter, 2);
733 WriteTag(2, 'Scheme');
734 WriteParam('File', SchemeFileName);
735 WriteParam('Name', SchemeName, CloseEmptyTag);
736 if Rule = nil then
737 MainRules.SaveToStream(StreamWriter, 2)
738 else
739 Rule.SaveToStream(StreamWriter, 2);
740 WriteTag(0, '/UniHighlighter', True);
741 end;
742 StreamWriter.Free;
743 end;
744
745 function TSynUniSyn.GetAsStream: TMemoryStream;
746 begin
747 Result := TMemoryStream.Create;
748 SaveToStream(Result);
749 end;
750
751 procedure TSynUniSyn.SaveToFile(FileName: string; Rule: TSynRule);
752 var
753 F: TFileStream;
754 begin
755 if FileName = '' then
756 raise exception.Create(ClassName + '.SaveToFile - FileName is empty');
757 F := TFileStream.Create(FileName, fmCreate);
758 try
759 SaveToStream(F, Rule)
760 finally
761 F.Free;
762 end;
763 end;
764
765 function ReadValue(ANode: TDOMNode): String;
766 begin
767 if Assigned(ANode.FirstChild) then
768 Result:= ANode.FirstChild.NodeValue
769 else
770 Result:= EmptyStr;
771 end;
772
773 procedure TSynUniSyn.SaveHglToStream(Stream: TStream);
774 //: Save Highlighter to stream
775 procedure WriteString(const aStr: string);
776 begin
777 Stream.Write( aStr[1], Length(aStr) );
778 Stream.Write( #10#13, 1 );
779 end;
780
781 function Indent(i: integer): string;
782 begin
783 SetLength( Result, i );
784 FillChar( Result[1], i, #32 );
785 end;
786
787 function GetValidValue(Value: string): string;
788 begin
789 Value := StringReplace(Value, '&', '&amp;', [rfReplaceAll, rfIgnoreCase]);
790 Value := StringReplace(Value, '<', '&lt;', [rfReplaceAll, rfIgnoreCase]);
791 Value := StringReplace(Value, '"', '&quot;', [rfReplaceAll, rfIgnoreCase]);
792 Result := StringReplace(Value, '>', '&gt;', [rfReplaceAll, rfIgnoreCase]);
793 end;
794
795 procedure InsertTag(Ind: integer; Name: string; Value: string);
796 begin
797 WriteString( Format('%s<%s>%s</%s>', [Indent(Ind), Name, GetValidValue(Value), Name]) );
798 end;
799
800 procedure OpenTag(Ind: integer; Name: string; Param: string = ''; ParamValue: string = '');
801 begin
802 if Param = '' then
803 WriteString(Format('%s<%s>', [Indent(Ind), Name]))
804 else
805 WriteString(Format('%s<%s %s="%s">', [Indent(Ind), Name, Param, GetValidValue(ParamValue)]));
806 end;
807
808 procedure SaveColor(MainTag: string; Ind, Fore, Back: integer; Style: TFontStyles; PFore, PBack: boolean);
809 procedure InsertTagBool(Ind: integer; Name: string; Value: Boolean);
810 begin
811 if Value then
812 WriteString(Format('%s<%s>True</%s>', [Indent(Ind), Name, Name]))
813 else
814 WriteString(Format('%s<%s>False</%s>', [Indent(Ind), Name, Name]))
815 end;
816 begin
817 OpenTag(Ind, MainTag);
818 InsertTag(Ind+1, 'Back', Inttostr(Back));
819 InsertTag(Ind+1, 'Fore', Inttostr(Fore));
820 InsertTag(Ind+1, 'Style', FontStyleToStr(Style));
821 InsertTagBool(Ind+1, 'ParentForeground', PFore);
822 InsertTagBool(Ind+1, 'ParentBackground', PBack);
823 OpenTag(Ind, '/'+MainTag);
824 end;
825
826 procedure SaveKWGroup(Ind: integer; G: TSynKeyList);
827 var i: integer;
828 procedure InsertTagBool(Ind: integer; Name: string; Value: Boolean);
829 begin
830 if Value then
831 WriteString(Format('%s<%s>True</%s>', [Indent(Ind), Name, Name]))
832 else
833 WriteString(Format('%s<%s>False</%s>', [Indent(Ind), Name, Name]))
834 end;
835 begin
836 OpenTag(Ind, 'KW', 'Name', G.Name);
837 for i := 0 to fSchemes.Count-1 do begin
838 G.ind := i;
839 SaveColor('Attri', Ind+1, G.Attribs.Foreground, G.Attribs.Background, G.Attribs.Style, G.Attribs.ParentForeground, G.Attribs.ParentBackground);
840 end;
841 G.ind := fSchemeIndex;
842 InsertTagBool(Ind+1, 'Enabled', G.Enabled);
843 For i := 0 to G.KeyList.Count-1 do InsertTag(Ind+1, 'W', G.KeyList[i]);
844 OpenTag(Ind, '/KW');
845 end;
846
847 procedure SaveSet(Ind: integer; S: TSynSet);
848 var i: integer;
849 procedure InsertTagBool(Ind: integer; Name: string; Value: Boolean);
850 begin
851 if Value then
852 WriteString(Format('%s<%s>True</%s>', [Indent(Ind), Name, Name]))
853 else
854 WriteString(Format('%s<%s>False</%s>', [Indent(Ind), Name, Name]))
855 end;
856 begin
857 OpenTag(Ind, 'Set', 'Name', S.Name);
858 for i := 0 to fSchemes.Count-1 do begin
859 S.ind := i;
860 SaveColor('Attri', Ind+1, S.Attribs.Foreground, S.Attribs.Background, S.Attribs.Style, S.Attribs.ParentForeground, S.Attribs.ParentBackground);
861 end;
862 S.ind := fSchemeIndex;
863 InsertTagBool(Ind+1, 'Enabled', S.Enabled);
864 { if S.StartType = stAny then
865 if S.BrakeType = btAny then
866 InsertTag(Ind+1, 'SymbolSetPartOfTerm', 'True')
867 else
868 InsertTag(Ind+1, 'SymbolSetPartOfTerm', 'Left')
869 else
870 if S.BrakeType = btAny then
871 InsertTag(Ind+1, 'SymbolSetPartOfTerm', 'Right')
872 else
873 InsertTag(Ind+1, 'SymbolSetPartOfTerm', 'False');}
874
875 InsertTag(Ind+1, 'S', SetToStr(S.SymbSet));
876 OpenTag(Ind, '/Set');
877 end;
878
879 procedure SaveRange(Ind: integer; R: TSynRange);
880 var i: integer;
881 procedure InsertTagBool(Ind: integer; Name: string; Value: Boolean);
882 begin
883 if Value then
884 WriteString(Format('%s<%s>True</%s>', [Indent(Ind), Name, Name]))
885 else
886 WriteString(Format('%s<%s>False</%s>', [Indent(Ind), Name, Name]))
887 end;
888
889 begin
890 OpenTag(Ind, 'Range', 'Name', R.Name);
891 for i := 0 to fSchemes.Count-1 do begin
892 R.ind := i;
893 SaveColor('Attri', Ind, R.Attribs.Foreground, R.Attribs.Background, R.Attribs.Style, R.Attribs.ParentForeground, R.Attribs.ParentBackground);
894 end;
895 R.ind := fSchemeIndex;
896 InsertTagBool(Ind, 'Enabled', R.Enabled);
897 if (Length(R.fRule.fOpenSymbol.Symbol) > 0) and (R.fRule.fOpenSymbol.Symbol[Length(R.fRule.fOpenSymbol.Symbol)] = #0) then begin
898 InsertTag(Ind, 'OpenSymbol', copy(R.fRule.fOpenSymbol.Symbol,1,Length(R.fRule.fOpenSymbol.Symbol)-1));
899 InsertTagBool(Ind, 'OpenSymbolFinishOnEol', true);
900 end else begin
901 InsertTag(Ind, 'OpenSymbol', R.fRule.fOpenSymbol.Symbol);
902 InsertTagBool(Ind, 'OpenSymbolFinishOnEol', false);
903 end;
904
905 if (Length(R.fRule.fCloseSymbol.Symbol) > 0) and (R.fRule.fCloseSymbol.Symbol[Length(R.fRule.fCloseSymbol.Symbol)] = #0) then begin
906 InsertTag(Ind, 'CloseSymbol', copy(R.fRule.fCloseSymbol.Symbol,1,Length(R.fRule.fCloseSymbol.Symbol)-1));
907 InsertTagBool(Ind, 'CloseSymbolFinishOnEol', true);
908 end else begin
909 InsertTag(Ind, 'CloseSymbol', R.fRule.fCloseSymbol.Symbol);
910 InsertTagBool(Ind, 'CloseSymbolFinishOnEol', false);
911 end;
912 if R.fRule.fOpenSymbol.StartLine = slFirst then
913 InsertTag(Ind, 'OpenSymbolStartLine', 'True')
914 else if R.fRule.fOpenSymbol.StartLine = slFirstNonSpace then
915 InsertTag(Ind, 'OpenSymbolStartLine', 'NonSpace')
916 else
917 InsertTag(Ind, 'OpenSymbolStartLine', 'False');
918 if R.fRule.fCloseSymbol.StartLine = slFirst then
919 InsertTag(Ind, 'CloseSymbolStartLine', 'True')
920 else if R.fRule.fCloseSymbol.StartLine = slFirstNonSpace then
921 InsertTag(Ind, 'CloseSymbolStartLine', 'NonSpace')
922 else
923 InsertTag(Ind, 'CloseSymbolStartLine', 'False');
924 InsertTag(Ind, 'DelimiterChars', SetToStr(R.TermSymbols));
925
926 if R.fRule.fOpenSymbol.StartType = stAny then
927 if R.fRule.fOpenSymbol.BrakeType = btAny then
928 InsertTag(Ind, 'OpenSymbolPartOfTerm', 'True')
929 else
930 InsertTag(Ind, 'OpenSymbolPartOfTerm', 'Left')
931 else
932 if R.fRule.fOpenSymbol.BrakeType = btAny then
933 InsertTag(Ind, 'OpenSymbolPartOfTerm', 'Right')
934 else
935 InsertTag(Ind, 'OpenSymbolPartOfTerm', 'False');
936 if R.fRule.fCloseSymbol.StartType = stAny then
937 if R.fRule.fCloseSymbol.BrakeType = btAny then
938 InsertTag(Ind, 'CloseSymbolPartOfTerm', 'True')
939 else
940 InsertTag(Ind, 'CloseSymbolPartOfTerm', 'Left')
941 else
942 if R.fRule.fCloseSymbol.BrakeType = btAny then
943 InsertTag(Ind, 'CloseSymbolPartOfTerm', 'Right')
944 else
945 InsertTag(Ind, 'CloseSymbolPartOfTerm', 'False');
946
947 InsertTagBool(Ind, 'CloseOnTerm', R.fRule.fCloseOnTerm);
948 InsertTagBool(Ind, 'CloseOnEol', R.fRule.fCloseOnEol);
949 InsertTagBool(Ind, 'AllowPredClose', R.fRule.fAllowPredClose);
950 InsertTagBool(Ind, 'CaseSensitive', R.CaseSensitive);
951 For i := 0 to R.KeyListCount-1 do SaveKWGroup(Ind, R.KeyLists[i]);
952 For i := 0 to R.SetCount-1 do SaveSet(Ind, R.Sets[i]);
953 For i := 0 to R.RangeCount-1 do SaveRange(Ind+1, R.Ranges[i]);
954 OpenTag(Ind, '/Range');
955 end;
956
957 procedure SaveInfo;
958 var i: integer;
959 begin
960 OpenTag(1, 'Info');
961
962 OpenTag(2, 'General');
963 InsertTag(3, 'Name', info.General.Name);
964 InsertTag(3, 'FileTypeName', info.General.Extensions);
965 // InsertTag(3, 'Layout', info.General.Layout);
966 OpenTag(2, '/General');
967
968 OpenTag(2, 'Author');
969 InsertTag(3, 'Name', Info.Author.Name);
970 InsertTag(3, 'Email', Info.Author.Email);
971 InsertTag(3, 'Web', Info.Author.Web);
972 InsertTag(3, 'Copyright', Info.Author.Copyright);
973 InsertTag(3, 'Company', Info.Author.Company);
974 InsertTag(3, 'Remark', Info.Author.Remark);
975 OpenTag(2, '/Author');
976
977 OpenTag(2, 'Version');
978 InsertTag(3, 'Version', IntToStr(Info.Version.Version));
979 InsertTag(3, 'Revision', IntToStr(Info.Version.Revision));
980 InsertTag(3, 'Date', FloatToStr(Info.Version.ReleaseDate));
981 case Info.Version.VersionType of
982 vtInternalTest: InsertTag(3, 'Type', 'Internal Test');
983 vtBeta: InsertTag(3, 'Type', 'Beta');
984 vtRelease: InsertTag(3, 'Type', 'Release');
985 end;
986 OpenTag(2, '/Version');
987
988 OpenTag(2, 'History');
989 for i := 0 to Info.history.count-1 do InsertTag(3, 'H', Info.history[i]);
990 OpenTag(2, '/History');
991
992 OpenTag(2, 'Sample');
993 for i := 0 to Info.Sample.count-1 do InsertTag(3, 'S', Info.Sample[i]);
994 OpenTag(2, '/Sample');
995
996 OpenTag(1, '/Info');
997 end;
998
999 procedure SaveSchemes;
1000 var
1001 i: integer;
1002 begin
1003 InsertTag(1, 'SchemeIndex', IntToStr(fSchemeIndex));
1004 OpenTag(1, 'Schemes');
1005 for i := 0 to self.SchemesList.Count-1 do
1006 InsertTag(2, 'S', fSchemes.Strings[i]);
1007 OpenTag(1, '/Schemes');
1008 end;
1009
1010 begin
1011 OpenTag(0, 'UniHighlighter');
1012 OpenTag(1, 'ImportantInfo');
1013 WriteString(Indent(2)+'******* Please read carefully *************************');
1014 WriteString(Indent(2)+'* Please, make any changes in this file very carefuly!*');
1015 WriteString(Indent(2)+'* It is much more convenient to use native designer! *');
1016 WriteString(Indent(2)+'*******************************************************');
1017 OpenTag(1, '/ImportantInfo');
1018 SaveInfo;
1019 SaveSchemes;
1020 SaveRange(1, self.MainRules);
1021 OpenTag(0, '/UniHighlighter');
1022 end;
1023
1024 procedure TSynUniSyn.LoadHglFromXml(xml: TDOMNode);
1025 var
1026 J: Integer;
1027 ChildNode: TDOMNode;
1028 begin
1029 Clear;
1030 SchemeIndex := 0;
1031 for J := 0 to Int32(xml.ChildNodes.Count) - 1 do
1032 begin
1033 ChildNode:= xml.ChildNodes.Item[J];
1034 if SameText(ChildNode.NodeName, 'Info') then
1035 ReadInfo(ChildNode)
1036 else if SameText(ChildNode.NodeName, 'SchemeIndex') then
1037 SchemeIndex := StrToInt(ReadValue(ChildNode))
1038 else if SameText(ChildNode.NodeName, 'Schemes') then
1039 ReadSchemes(ChildNode)
1040 else if SameText(ChildNode.NodeName, 'Range') then
1041 begin
1042 fMainRules.LoadHglFromXml(ChildNode, fSchemes.Count, SchemeIndex);
1043 end
1044 end
1045 end;
1046
1047 procedure TSynUniSyn.ReadInfo(xml: TDOMNode);
1048 var
1049 I, J: Integer;
1050 ChildNode1, ChildNode2: TDOMNode;
1051 AFormatSettings: TFormatSettings;
1052 begin
1053 for J := 0 to Int32(xml.ChildNodes.Count) - 1 do
1054 begin
1055 ChildNode1:= xml.ChildNodes.Item[J];
1056 if ChildNode1.NodeName = 'General' then
1057 begin
1058 for I:= 0 to Int32(ChildNode1.ChildNodes.Count) - 1 do
1059 begin
1060 ChildNode2 := ChildNode1.ChildNodes.Item[I];
1061 if ChildNode2.NodeName = 'Name' then Info.General.Name:= ReadValue(ChildNode2)
1062 else if ChildNode2.NodeName = 'FileTypeName' then Info.General.Extensions := ReadValue(ChildNode2)
1063 // else if ChildNode2.NodeName = 'Layout' then Info.General.Layout := ReadValue(ChildNode2);
1064 end;
1065 end
1066 else if ChildNode1.NodeName = 'Author' then
1067 begin
1068 for I:= 0 to Int32(ChildNode1.ChildNodes.Count) - 1 do
1069 begin
1070 ChildNode2 := ChildNode1.ChildNodes.Item[I];
1071 if ChildNode2.NodeName = 'Name' then Info.Author.Name:= ReadValue(ChildNode2)
1072 else if ChildNode2.NodeName = 'Email' then Info.Author.Email:= ReadValue(ChildNode2)
1073 else if ChildNode2.NodeName = 'Web' then Info.Author.Web:= ReadValue(ChildNode2)
1074 else if ChildNode2.NodeName = 'Copyright' then Info.Author.Copyright:= ReadValue(ChildNode2)
1075 else if ChildNode2.NodeName = 'Company' then Info.Author.Company:= ReadValue(ChildNode2)
1076 else if ChildNode2.NodeName = 'Remark' then Info.Author.Remark:= ReadValue(ChildNode2)
1077 end;
1078 end
1079 else if ChildNode1.NodeName = 'Version' then
1080 begin
1081 for I:= 0 to Int32(ChildNode1.ChildNodes.Count) - 1 do
1082 begin
1083 ChildNode2 := ChildNode1.ChildNodes.Item[I];
1084 if ChildNode2.NodeName = 'Version' then Info.Version.Version := StrToIntDef(ReadValue(ChildNode2), 0)
1085 else if ChildNode2.NodeName = 'Revision' then Info.Version.Revision := StrToIntDef(ReadValue(ChildNode2), 0)
1086 else if ChildNode2.NodeName = 'Date' then
1087 {
1088 try
1089 AFormatSettings:= DefaultFormatSettings;
1090 Info.Version.ReleaseDate := StrToFloat(ReadValue(ChildNode2), AFormatSettings);
1091 except
1092 AFormatSettings.DecimalSeparator := '.';
1093 try
1094 Info.Version.ReleaseDate := StrToFloat(ReadValue(ChildNode2), AFormatSettings);
1095 except
1096 // Ignore
1097 end;
1098 end
1099 }
1100 else if ChildNode2.NodeName = 'Type' then
1101 begin
1102 if ReadValue(ChildNode2) = 'Beta' then Info.Version.VersionType := vtBeta
1103 else if ReadValue(ChildNode2) = 'Release' then Info.Version.VersionType := vtRelease
1104 else Info.Version.VersionType := vtInternalTest
1105 end
1106 end;
1107 end
1108 else if ChildNode1.NodeName = 'History' then
1109 begin
1110 Info.History.Clear;
1111 for I:= 0 to Int32(ChildNode1.ChildNodes.Count) - 1 do
1112 begin
1113 ChildNode2 := ChildNode1.ChildNodes.Item[I];
1114 if ChildNode2.NodeName = 'H' then
1115 Info.History.Add(ReadValue(ChildNode2));
1116 end;
1117 end
1118 else if ChildNode1.NodeName = 'Sample' then
1119 begin
1120 Info.Sample.Clear;
1121 for I:= 0 to Int32(ChildNode1.ChildNodes.Count) - 1 do
1122 begin
1123 ChildNode2 := ChildNode1.ChildNodes.Item[I];
1124 if ChildNode2.NodeName = 'S' then
1125 Info.Sample.Add(ReadValue(ChildNode2));
1126 end;
1127 end;
1128 end;
1129 end;
1130
1131 procedure TSynUniSyn.ReadSchemes(xml: TDOMNode);
1132 var
1133 J: Integer;
1134 ChildNode: TDOMNode;
1135 begin
1136 if fSchemes <> nil then begin
1137 fSchemes.Clear();
1138 //MainRules.ClearAttributes();
1139 end
1140 else
1141 raise Exception.Create(ClassName + '.ReadSchemes - property Schemes not initialized.');
1142
1143 for J := 0 to Int32(xml.ChildNodes.Count) - 1 do
1144 begin
1145 ChildNode:= xml.ChildNodes.Item[J];
1146 if ChildNode.NodeName = 'S' then
1147 fSchemes.Add(ReadValue(ChildNode));
1148 end;
1149 end;
1150
1151 procedure TSynUniSyn.LoadHglFromFile(FileName: string);
1152 //: Load Highlighter'a from file
1153 var
1154 F: TFileStream;
1155 begin
1156 if not FileExists(FileName) then
1157 raise Exception.Create(ClassName + '.LoadHglFromFile - "'+FileName+'" does not exists.');
1158 F := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
1159 try
1160 LoadHglFromStream( F );
1161 finally
1162 F.Free;
1163 end;
1164 end;
1165
1166 procedure TSynUniSyn.SaveHglToFile(FileName: string);
1167 //: Save Highlighter to file
1168 var
1169 F: TFileStream;
1170 begin
1171 if FileName = '' then
1172 raise exception.Create(ClassName + '.SaveHglToFile - FileName is empty');
1173 F := TFileStream.Create(FileName, fmCreate);
1174 try
1175 SaveHglToStream( F );
1176 finally
1177 F.Free;
1178 end;
1179 end;
1180
1181 procedure TSynUniSyn.LoadHglFromStream(Stream: TStream);
1182 var
1183 xml: TXMLDocument = nil;
1184 begin
1185 try
1186 ReadXMLFile(xml, Stream);
1187 LoadHglFromXml(xml);
1188 finally
1189 xml.Free;
1190 end;
1191 DefHighlightChange( Self );
1192 end;
1193
1194 initialization
1195 {$IFNDEF SYN_CPPB_1}
1196 RegisterPlaceableHighlighter(TSynUniSyn);
1197 {$ENDIF}
1198
1199 end.