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