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: SynHighlighterUNIXShellScript.pas, released 2001-11-13.
12 The Initial Author of this file is Stefan Ascher.
13 All Rights Reserved.
14 Portions by Jan Verhoeven (http://jansfreeware.com/jfdelphi.htm)
15 
16 Contributors to the SynEdit and mwEdit projects are listed in the
17 Contributors.txt file.
18 
19 Alternatively, the contents of this file may be used under the terms of the
20 GNU General Public License Version 2 or later (the "GPL"), in which case
21 the provisions of the GPL are applicable instead of those above.
22 If you wish to allow use of your version of this file only under the terms
23 of the GPL and not to allow others to use your version of this file
24 under the MPL, indicate your decision by deleting the provisions above and
25 replace them with the notice and other provisions required by the GPL.
26 If you do not delete the provisions above, a recipient may use your version
27 of this file under either the MPL or the GPL.
28 
29 $Id: synhighlighterunixshellscript.pas 43540 2013-12-14 13:40:04Z martin $
30 
31 You may retrieve the latest version of this file at the SynEdit home page,
32 located at http://SynEdit.SourceForge.net
33 
34 Contributors:
35 
36 Tom Lisjac <vlx@users.sourceforge.net>
37   Initially adapted for use with Lazarus and FPC - 2003-06-11
38   Changes can be found by searching for: ////TL
39 
40 Known Issues:
41 
42 -------------------------------------------------------------------------------}
43 {
44 @abstract(Provides a UNIX Shell Script highlighter for SynEdit)
45 @author(Stefan Ascher <stievie2002@yahoo.com>)
46 @created(10 November 2001)
47 The SynHighlighterUNIXShellScript unit provides SynEdit with a UNIX Shell Script highlighter.
48 }
49 
50 unit synhighlighterunixshellscript;
51 
52 {$I SynEdit.inc}
53 
54 interface
55 
56 uses
57   Graphics,
58   GraphType, /////TL 2003-06-11: Added for font attribute declaration fsBold
59   SynEditTypes,
60   SynEditHighlighter,
61   SysUtils,
62   Classes;
63 
64 type
65   TtkTokenKind = (tkComment, tkIdentifier, tkKey, tkNull, tkNumber, tkSecondKey,
66     tkSpace, tkString, tkSymbol, tkVariable, tkUnknown);
67 
68   TRangeState = (rsUnknown, rsAnsi, rsPasStyle, rsCStyle);
69 
70   TProcTableProc = procedure of object;
71 
72 type
73   TSynUNIXShellScriptSyn = class(TSynCustomHighlighter)
74   private
75     fRange: TRangeState;
76     fLine: PChar;
77     fProcTable: array[#0..#255] of TProcTableProc;
78     Run: LongInt;
79     fTokenPos: Integer;
80     FTokenID: TtkTokenKind;
81     fLineNumber: Integer;
82     fStringAttri: TSynHighlighterAttributes;
83     fSymbolAttri: TSynHighlighterAttributes;
84     fKeyAttri: TSynHighlighterAttributes;
85     fSecondKeyAttri: TSynHighlighterAttributes;
86     fNumberAttri: TSynHighlighterAttributes;
87     fCommentAttri: TSynHighlighterAttributes;
88     fSpaceAttri: TSynHighlighterAttributes;
89     fIdentifierAttri: TSynHighlighterAttributes;
90     fVarAttri: TSynHighlighterAttributes;
91     fKeyWords: TStrings;
92     fSecondKeys: TStrings;
93     procedure BraceOpenProc;
94     procedure PointCommaProc;
95     procedure CRProc;
96     procedure IdentProc;
97     procedure LFProc;
98     procedure NullProc;
99     procedure NumberProc;
100     procedure RoundOpenProc;
101     procedure SlashProc;
102     procedure SpaceProc;
103     procedure StringProc;
104     procedure UnknownProc;
105     procedure MakeMethodTables;
106     procedure AnsiProc;
107     procedure PasStyleProc;
108     procedure CStyleProc;
109     procedure DollarProc;
110     procedure DotProc;
111     procedure SetSecondKeys(const Value: TStrings);
112   protected
GetIdentCharsnull113     function GetIdentChars: TSynIdentChars; override;
114   public
GetLanguageNamenull115     class function GetLanguageName: string; override;
116   public
117     constructor Create(AOwner: TComponent); override;
118     destructor Destroy; override;
GetDefaultAttributenull119     function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
120       override;
GetEolnull121     function GetEol: Boolean; override;
GetRangenull122     function GetRange: Pointer; override;
GetTokenIDnull123     function GetTokenID: TtkTokenKind;
124     procedure SetLine(const NewValue: String; LineNumber:Integer); override; /////TL: Added 2003-06-11
IsKeywordnull125     function IsKeyword(const AKeyword: string): boolean; override;              //mh 2000-11-08
IsSecondKeyWordnull126     function IsSecondKeyWord(aToken: string): Boolean;
GetTokennull127     function GetToken: string; override;
128     procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override; /////TL: Added 2003-06-11
GetTokenAttributenull129     function GetTokenAttribute: TSynHighlighterAttributes; override;
GetTokenKindnull130     function GetTokenKind: integer; override;
GetTokenPosnull131     function GetTokenPos: Integer; override;
132     procedure Next; override;
133     procedure SetRange(Value: Pointer); override;
134     procedure ResetRange; override;
135   published
136     property CommentAttri: TSynHighlighterAttributes read fCommentAttri
137       write fCommentAttri;
138     property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
139       write fIdentifierAttri;
140     property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
141     property SecondKeyAttri: TSynHighlighterAttributes read fSecondKeyAttri
142       write fSecondKeyAttri;
143     property SecondKeyWords: TStrings read fSecondKeys write SetSecondKeys;
144     property NumberAttri: TSynHighlighterAttributes read fNumberAttri
145       write fNumberAttri;
146     property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
147       write fSpaceAttri;
148     property StringAttri: TSynHighlighterAttributes read fStringAttri
149       write fStringAttri;
150     property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
151       write fSymbolAttri;
152     property VarAttri: TSynHighlighterAttributes read fVarAttri
153       write fVarAttri;
154   end;
155 
156 implementation
157 
158 uses
159   SynEditStrConst;
160 
161 const
162   ShellScriptKeysCount = 110;
163   ShellScriptKeys: array[1..ShellScriptKeysCount] of string = (
164     'AWK', 'BANNER', 'BASENAME', 'BDIFF', 'BG', 'BREAK', 'CASE', 'CAT', 'CC',
165     'CD', 'CHDIR', 'CHGRP', 'CHMOD', 'CHOWN', 'CLEAR', 'COMPRESS', 'CONTINUE',
166     'CP', 'CPIO', 'CUT', 'DATE', 'DD', 'DIFF', 'DF', 'DO', 'DONE', 'DTPAD',
167     'ECHO', 'ELIF', 'ELSE', 'ESAC', 'EVAL', 'EXIT', 'EXPORT', 'EXPR', 'FG', 'FI',
168     'FINGER', 'FOLD', 'FOR', 'FTP', 'G++', 'GCC', 'GETOPTS', 'GREP', 'GZIP',
169     'HEAD', 'HASH', 'IF', 'IN', 'JOBS', 'KILL', 'LD', 'LOGIN', 'LN', 'LS',
170     'MAKE', 'MKDIR', 'MT', 'MV', 'NEWGRP', 'NOHUP', 'PASTE', 'PING', 'PERL',
171     'PG', 'PR', 'PS', 'PWD', 'OD', 'RCP', 'READ', 'REMSH', 'RETURN', 'RM', 'RSH',
172     'RWHO', 'SED', 'SET', 'SH', 'SHIFT', 'STOP', 'STRINGS', 'STRIP', 'SYNC',
173     'TAIL', 'TAR', 'TELNET', 'TEST', 'TIMES', 'THEN', 'TPUT', 'TRAP', 'TRUE',
174     'TTY', 'TYPE', 'ULIMIT', 'UMASK', 'UNSET', 'UNTIL', 'UUDECODE', 'UUENCODE',
175     'VI', 'WAIT', 'WC', 'WHILE', 'WHO', 'XTERN', 'ZCAT', 'ZIP');
176   ShellScriptSecondKeysCount = 23;
177   ShellScriptSecondKeys: array[1..ShellScriptSecondKeysCount] of string = (
178     'CDPATH', 'EDITOR', 'HOME', 'IFS', 'LANG', 'LC_TYPE', 'LC_MESSAGES',
179     'LD_LIBRARY_PATH', 'LOGNAME', 'MAIL', 'MAILCHECK', 'MAILPATH', 'MANPATH',
180     'PATH', 'PS1', 'PS2', 'PWD', 'SHACCT', 'SHELL', 'SHLIB_PATH', 'TERM',
181     'TERMCAP', 'TZ');
182 
183 var
184   Identifiers: array[#0..#255] of ByteBool;
185 
186 procedure MakeIdentTable;
187 var
188   I: Char;
189 begin
190   for I := #0 to #255 do
191   begin
192     case I of
193       '_', '0'..'9', 'a'..'z', 'A'..'Z':
194         Identifiers[I] := True;
195       else
196         Identifiers[I] := False;
197     end;
198   end;
199 end;
200 
IsKeywordnull201 function TSynUNIXShellScriptSyn.IsKeyword(const AKeyword: string): boolean;                //mh 2000-11-08
202 var
203   First, Last, I, Compare: Integer;
204   Token: String;
205 begin
206   First := 0;
207   Last := fKeywords.Count - 1;
208   Result := False;
209   Token := UpperCase(AKeyword);
210 
211   while First <= Last do begin
212     I := (First + Last) shr 1;
213     Compare := CompareStr(fKeywords[I], Token);
214     if Compare = 0 then begin
215       Result := True;
216       break;
217     end else
218       if Compare < 0 then First := I + 1 else Last := I - 1;
219   end;
220 end; { IsKeyWord }
221 
IsSecondKeyWordnull222 function TSynUNIXShellScriptSyn.IsSecondKeyWord(aToken: String): Boolean;
223 var
224   First, Last, I, Compare: Integer;
225   Token: String;
226 begin
227   First := 0;
228   Last := fSecondKeys.Count - 1;
229   Result := False;
230   Token := UpperCase(aToken);
231   while First <= Last do
232   begin
233     I := (First + Last) shr 1;
234     Compare := CompareStr(fSecondKeys[i], Token);
235     if Compare = 0 then
236     begin
237       Result := True;
238       break;
239     end
240     else
241       if Compare < 0 then First := I + 1 else Last := I - 1;
242   end;
243 end; { IsSecondKeyWord }
244 
245 procedure TSynUNIXShellScriptSyn.MakeMethodTables;
246 var
247   I: Char;
248 begin
249   for I := #0 to #255 do
identifiersnull250     case I of  /////TL 2003-06-11: added "@" prefix to function identifiers being assigned
251       '#': fProcTable[I] := @SlashProc{!@#$AsciiCharProc};
252       '{': fProcTable[I] := @BraceOpenProc;
253       ';': fProcTable[I] := @PointCommaProc;
254       '.': fProcTable[i] := @DotProc;
255       #13: fProcTable[I] := @CRProc;
256       'A'..'Z', 'a'..'z', '_': fProcTable[I] := @IdentProc;
257       #10: fProcTable[I] := @LFProc;
258       #0: fProcTable[I] := @NullProc;
259       '0'..'9': fProcTable[I] := @NumberProc;
260       '(': fProcTable[I] := @RoundOpenProc;
261       '/': fProcTable[I] := @SlashProc;
262       '$': fProcTable[i] := @DollarProc;
263       #1..#9, #11, #12, #14..#32: fProcTable[I] := @SpaceProc;
264       #34, #39{!@#$#39}: fProcTable[I] := @StringProc;
265       else fProcTable[I] := @UnknownProc;
266     end;
267 end;
268 
269 constructor TSynUNIXShellScriptSyn.Create(AOwner: TComponent);
270 var
271   i: integer;
272 ////TL 2003-06-11: FPC complained about local declaration... moved to the SynEditStrConst
273 ////TL resourcestring
274 ////TL  SYNS_FilterUNIXShellScript = 'UNIX Shell Scripts (*.sh)|*.sh';
275 begin
276   inherited Create(AOwner);
277   fKeyWords := TStringList.Create;
278   TStringList(fKeyWords).Sorted := True;
279   TStringList(fKeyWords).Duplicates := dupIgnore;
280   fSecondKeys := TStringList.Create;
281   TStringList(fSecondKeys).Sorted := True;
282   TStringList(fSecondKeys).Duplicates := dupIgnore;
283   if not (csDesigning in ComponentState) then begin
284     for i := 1 to ShellScriptKeysCount do
285       fKeyWords.Add(ShellScriptKeys[i]);
286     for i := 1 to ShellScriptSecondKeysCount do
287       fSecondKeys.Add(ShellScriptSecondKeys[i]);
288   end;
289 
290   fCommentAttri := TSynHighlighterAttributes.Create(@SYNS_AttrComment, SYNS_XML_AttrComment);
291   fCommentAttri.Foreground := clGreen;
292   AddAttribute(fCommentAttri);
293   fIdentifierAttri := TSynHighlighterAttributes.Create(@SYNS_AttrIdentifier, SYNS_XML_AttrIdentifier);
294   AddAttribute(fIdentifierAttri);
295   fKeyAttri := TSynHighlighterAttributes.Create(@SYNS_AttrReservedWord, SYNS_XML_AttrReservedWord);
296   fKeyAttri.Foreground := clNavy;
297   fKeyAttri.Style := [fsBold];
298   AddAttribute(fKeyAttri);
299   fSecondKeyAttri := TSynHighlighterAttributes.Create(@SYNS_AttrSecondReservedWord, SYNS_XML_AttrSecondReservedWord);
300   AddAttribute(fSecondKeyAttri);
301   fNumberAttri := TSynHighlighterAttributes.Create(@SYNS_AttrNumber, SYNS_XML_AttrNumber);
302   fNumberAttri.Foreground := clBlue;
303   AddAttribute(fNumberAttri);
304   fSpaceAttri := TSynHighlighterAttributes.Create(@SYNS_AttrSpace, SYNS_XML_AttrSpace);
305   AddAttribute(fSpaceAttri);
306   fStringAttri := TSynHighlighterAttributes.Create(@SYNS_AttrString, SYNS_XML_AttrString);
307   fStringAttri.Foreground := clMaroon;
308   AddAttribute(fStringAttri);
309   fSymbolAttri := TSynHighlighterAttributes.Create(@SYNS_AttrSymbol, SYNS_XML_AttrSymbol);
310   fSymbolAttri.Foreground := clRed;
311   AddAttribute(fSymbolAttri);
312   fVarAttri := TSynHighlighterAttributes.Create(@SYNS_AttrVariable, SYNS_XML_AttrVariable);
313   fVarAttri.Foreground := clPurple;
314   AddAttribute(fVarAttri);
315   SetAttributesOnChange(@DefHighlightChange);   ////TL 2003-06-11: added the @prefix to DefHighlightChange
316 
317   MakeMethodTables;
318   fRange := rsUnknown;
319   fDefaultFilter := SYNS_FilterUNIXShellScript;
320 end; { Create }
321 
322 ////TL 2003-06-11: Replaced existing SetLine with this one... identical except for the IFDEF
323 procedure TSynUNIXShellScriptSyn.SetLine(
324   const NewValue: String;
325   LineNumber:Integer);
326 begin
327   inherited;
328   fLine := PChar(NewValue);
329   Run := 0;
330   fLineNumber := LineNumber;
331   Next;
332 end; { SetLine }
333 
334 destructor TSynUNIXShellScriptSyn.Destroy;
335 begin
336   fKeyWords.Free;
337   fSecondKeys.Free;
338   inherited Destroy;
339 end; { Destroy }
340 
341 procedure TSynUNIXShellScriptSyn.AnsiProc;
342 begin
343   fTokenID := tkComment;
344   case FLine[Run] of
345     #0:
346       begin
347         NullProc;
348         exit;
349       end;
350     #10:
351       begin
352         LFProc;
353         exit;
354       end;
355 
356     #13:
357       begin
358         CRProc;
359         exit;
360       end;
361   end;
362 
363   while fLine[Run] <> #0 do
364     case fLine[Run] of
365       '*':
366         if fLine[Run + 1] = ')' then
367         begin
368           fRange := rsUnKnown;
369           inc(Run, 2);
370           break;
371         end else inc(Run);
372       #10: break;
373 
374       #13: break;
375     else inc(Run);
376     end;
377 end;
378 
379 procedure TSynUNIXShellScriptSyn.PasStyleProc;
380 begin
381   fTokenID := tkComment;
382   case FLine[Run] of
383     #0:
384       begin
385         NullProc;
386         exit;
387       end;
388     #10:
389       begin
390         LFProc;
391         exit;
392       end;
393 
394     #13:
395       begin
396         CRProc;
397         exit;
398       end;
399   end;
400 
401   while FLine[Run] <> #0 do
402     case FLine[Run] of
403       '}':
404         begin
405           fRange := rsUnKnown;
406           inc(Run);
407           break;
408         end;
409       #10: break;
410 
411       #13: break;
412     else inc(Run);
413     end;
414 end;
415 
416 procedure TSynUNIXShellScriptSyn.CStyleProc;
417 begin
418   case fLine[Run] of
419     #0: NullProc;
420     #10: LFProc;
421     #13: CRProc;
422   else
423     fTokenID := tkComment;
424     repeat
425       if (fLine[Run] = '*') and (fLine[Run + 1] = '/') then
426       begin
427         fRange := rsUnKnown;
428         Inc(Run, 2);
429         break;
430       end;
431       Inc(Run);
432     until fLine[Run] in [#0, #10, #13];
433   end;
434 end;
435 
436 procedure TSynUNIXShellScriptSyn.DollarProc;
437 var
438   cc: Char;
439 begin
440   inc(Run);
441   fTokenID := tkVariable;
442   if FLine[Run] = #0 then Exit;
443   cc := FLine[Run];
444   inc(Run);
445   if (cc = '{') then begin
446     // ${var}
447     while FLine[Run] in IdentChars do begin
448       case FLine[Run] of
449         #0, #10, #13: Break;
450       end;
451       inc(Run);
452     end;
453     if FLine[Run] = '}' then Inc(Run);
454   end else
455     // $var
456     while FLine[Run] in IdentChars do
457       inc(Run);
458 end;
459 
460 procedure TSynUNIXShellScriptSyn.DotProc;
TestDotnull461   function TestDot: boolean;
462   var
463     i: integer;
464   begin
465     result := false;
466     i := run;
467     inc(i);
468     while (FLine[i] in ['a'..'z', 'A'..'Z']) do
469       inc(i);
470     if i > (run + 1) then
471       result := true;
472     if result then
473       run := i;
474   end;
475 begin
476   // Don't highlight filenames like filename.zip
477   if TestDot then
478     fTokenID := tkIdentifier
479   else begin
480     inc(Run);
481     fTokenID := tkSymbol;
482   end;
483 end;
484 
485 procedure TSynUNIXShellScriptSyn.BraceOpenProc;
486 begin
487   inc(Run);
488   fTokenID := tkSymbol;
489 end;
490 
491 procedure TSynUNIXShellScriptSyn.PointCommaProc;
492 begin
493   inc(Run);
494   fTokenID := tkSymbol;
495 end;
496 
497 procedure TSynUNIXShellScriptSyn.CRProc;
498 begin
499   fTokenID := tkSpace;
500   case FLine[Run + 1] of
501     #10: inc(Run, 2);
502   else inc(Run);
503   end;
504 end;
505 
506 procedure TSynUNIXShellScriptSyn.IdentProc;
507 begin
508   while Identifiers[fLine[Run]] do inc(Run);
509   if IsKeyWord(GetToken) then begin
510     fTokenId := tkKey;
511     Exit;
512   end
513   else fTokenId := tkIdentifier;
514   if IsSecondKeyWord(GetToken)
515     then fTokenId := tkSecondKey
516     else fTokenId := tkIdentifier;
517 end;
518 
519 procedure TSynUNIXShellScriptSyn.LFProc;
520 begin
521   fTokenID := tkSpace;
522   inc(Run);
523 end;
524 
525 procedure TSynUNIXShellScriptSyn.NullProc;
526 begin
527   fTokenID := tkNull;
528 end;
529 
530 procedure TSynUNIXShellScriptSyn.NumberProc;
531 begin
532   inc(Run);
533   fTokenID := tkNumber;
534   while FLine[Run] in ['0'..'9', '.', 'e', 'E'] do
535   begin
536     case FLine[Run] of
537       '.':
538         if FLine[Run + 1] = '.' then break;
539     end;
540     inc(Run);
541   end;
542 end;
543 
544 procedure TSynUNIXShellScriptSyn.RoundOpenProc;
545 begin
546   inc(Run);
547   fTokenId := tkSymbol;
548 end;
549 
550 procedure TSynUNIXShellScriptSyn.SlashProc;
551 begin
552   if FLine[Run] = '#' then begin
553     // Perl Styled Comment
554     inc(Run);
555     fTokenID := tkComment;
556     while FLine[Run] <> #0 do
557     begin
558       case FLine[Run] of
559         #10, #13: break;
560       end;
561       inc(Run);
562     end;
563   end else begin
564 //    // C Styled Comment
565 //    case FLine[Run + 1] of
566 //      '/':
567 //        begin
568 //          inc(Run, 2);
569 //          fTokenID := tkComment;
570 //          while FLine[Run] <> #0 do
571 //          begin
572 //            case FLine[Run] of
573 //              #10, #13: break;
574 //            end;
575 //            inc(Run);
576 //          end;
577 //        end;
578 //      '*':
579 //        begin
580 //          fTokenID := tkComment;
581 //          fRange := rsCStyle;
582 //          inc(Run);
583 //          while fLine[Run] <> #0 do
584 //            case fLine[Run] of
585 //              '*':
586 //                if fLine[Run + 1] = '/' then begin
587 //                  fRange := rsUnKnown;
588 //                  inc(Run, 2);
589 //                  break;
590 //                end else
591 //                  inc(Run);
592 //              #10: break;
593 //              #13: break;
594 //            else
595 //              inc(Run);
596 //            end;
597 //        end;
598 //      else begin
599         inc(Run);
600         fTokenID := tkSymbol;
601 //      end;
602 //    end;
603   end;
604 end;
605 
606 procedure TSynUNIXShellScriptSyn.SpaceProc;
607 begin
608   inc(Run);
609   fTokenID := tkSpace;
610   while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
611 end;
612 
613 procedure TSynUNIXShellScriptSyn.StringProc;
614 var
615   QuoteChar: Char;
616 begin
617 // Single and Double Quotes.
618 
619   fTokenID := tkString;
620   QuoteChar := FLine[Run];      // either " or '
621   if (FLine[Run + 1] = QuoteChar) and (FLine[Run + 2] = QuoteChar)
622     then inc(Run, 2);
623   repeat
624     case FLine[Run] of
625       #0, #10, #13: break;
626     end;
627     inc(Run);
628   until FLine[Run] = QuoteChar;
629   if FLine[Run] <> #0 then inc(Run);
630 end;
631 
632 procedure TSynUNIXShellScriptSyn.UnknownProc;
633 begin
634   inc(Run);
635   while (fLine[Run] in [#128..#191]) OR // continued utf8 subcode
636    ((fLine[Run]<>#0) and (fProcTable[fLine[Run]] = @UnknownProc)) do inc(Run);
637   fTokenID := tkUnKnown;
638 end;
639 
640 procedure TSynUNIXShellScriptSyn.Next;
641 begin
642   fTokenPos := Run;
643   case fRange of
644     rsAnsi: AnsiProc;
645     rsPasStyle: PasStyleProc;
646     rsCStyle: CStyleProc;
647   else
648     fProcTable[fLine[Run]];
649   end;
650 end;
651 
GetDefaultAttributenull652 function TSynUNIXShellScriptSyn.GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
653 begin
654   case Index of
655     SYN_ATTR_COMMENT: Result := fCommentAttri;
656     SYN_ATTR_IDENTIFIER: Result := fIdentifierAttri;
657     SYN_ATTR_KEYWORD: Result := fKeyAttri;
658     SYN_ATTR_STRING: Result := fStringAttri;
659     SYN_ATTR_WHITESPACE: Result := fSpaceAttri;
660     SYN_ATTR_NUMBER: Result := fNumberAttri;
661     SYN_ATTR_VARIABLE: Result := fVarAttri;
662   else
663     Result := nil;
664   end;
665 end;
666 
GetEolnull667 function TSynUNIXShellScriptSyn.GetEol: Boolean;
668 begin
669   Result := False;
670   if fTokenId = tkNull then Result := True;
671 end;
672 
TSynUNIXShellScriptSyn.GetRangenull673 function TSynUNIXShellScriptSyn.GetRange: Pointer;
674 begin
675   Result := Pointer(PtrInt(fRange));
676 end;
677 
TSynUNIXShellScriptSyn.GetTokennull678 function TSynUNIXShellScriptSyn.GetToken: string;
679 var
680   Len: LongInt;
681 begin
682   Result := '';
683   Len := Run - fTokenPos;
684   SetString(Result, (FLine + fTokenPos), Len);
685 end;
686 
687 ////TL 2003-06-11: Added the following to satisfy abstract method override
688 procedure TSynUNIXShellScriptSyn.GetTokenEx(out TokenStart: PChar;
689   out TokenLength: integer);
690 begin
691   TokenLength:=Run-fTokenPos;
692   TokenStart:=FLine + fTokenPos;
693 end;
694 
GetTokenIDnull695 function TSynUNIXShellScriptSyn.GetTokenID: TtkTokenKind;
696 begin
697   Result := fTokenId;
698 end;
699 
GetTokenAttributenull700 function TSynUNIXShellScriptSyn.GetTokenAttribute: TSynHighlighterAttributes;
701 begin
702   case fTokenID of
703     tkComment: Result := fCommentAttri;
704     tkIdentifier: Result := fIdentifierAttri;
705     tkKey: Result := fKeyAttri;
706     tkSecondKey: Result := fSecondKeyAttri;
707     tkNumber: Result := fNumberAttri;
708     tkSpace: Result := fSpaceAttri;
709     tkString: Result := fStringAttri;
710     tkSymbol: Result := fSymbolAttri;
711     tkVariable: Result := fVarAttri;
712     tkUnknown: Result := fSymbolAttri;
713   else
714     Result := nil;
715   end;
716 end;
717 
GetTokenKindnull718 function TSynUNIXShellScriptSyn.GetTokenKind: integer;
719 begin
720   Result := Ord(fTokenId);
721 end;
722 
GetTokenPosnull723 function TSynUNIXShellScriptSyn.GetTokenPos: Integer;
724 begin
725   Result := fTokenPos;
726 end;
727 
728 procedure TSynUNIXShellScriptSyn.ResetRange;
729 begin
730   fRange := rsUnknown;
731 end;
732 
733 procedure TSynUNIXShellScriptSyn.SetRange(Value: Pointer);
734 begin
735   fRange := TRangeState(PtrUInt(Value));
736 end;
737 
738 procedure TSynUNIXShellScriptSyn.SetSecondKeys(const Value: TStrings);
739 var
740   i: Integer;
741 begin
742   if Value <> nil then
743     begin
744       Value.BeginUpdate;
745       for i := 0 to Value.Count - 1 do
746         Value[i] := UpperCase(Value[i]);
747       Value.EndUpdate;
748     end;
749   fSecondKeys.Assign(Value);
750   DefHighLightChange(nil);
751 end;
752 
GetIdentCharsnull753 function TSynUNIXShellScriptSyn.GetIdentChars: TSynIdentChars;
754 begin
755   Result := ['_', '0'..'9', 'a'..'z', 'A'..'Z'];
756 end;
757 
758 /////TL 11-06-2003: Moved from below
759 resourcestring
760   LangName = 'UNIX Shell Script';
761 
TSynUNIXShellScriptSyn.GetLanguageNamenull762 class function TSynUNIXShellScriptSyn.GetLanguageName: string;
763 /////TL 11-06-2003: FPC complained about local declaration... moved to the global scope
764 /////TL resourcestring
765 /////TL  LangName = 'UNIX Shell Script';
766 begin
767   Result := LangName;
768 end;
769 
770 initialization
771   MakeIdentTable;
772   RegisterPlaceableHighlighter(TSynUNIXShellScriptSyn);
773 
774 end.
775 
776