added bash scripts highlighter from Tom Lisjac

git-svn-id: trunk@4259 -
This commit is contained in:
mattias 2003-06-11 22:56:09 +00:00
parent 524f94c628
commit 4d558ca95e
7 changed files with 855 additions and 9 deletions

1
.gitattributes vendored
View File

@ -109,6 +109,7 @@ components/synedit/synhighlightermulti.pas svneol=native#text/pascal
components/synedit/synhighlighterpas.pp svneol=native#text/pascal
components/synedit/synhighlighterperl.pas svneol=native#text/pascal
components/synedit/synhighlighterposition.pas svneol=native#text/pascal
components/synedit/synhighlighterunixshellscript.pas svneol=native#text/pascal
components/synedit/synhighlighterxml.pas svneol=native#text/pascal
components/synedit/synmacrorecorder.pas svneol=native#text/pascal
components/synedit/synmemo.pas svneol=native#text/pascal

View File

@ -21,6 +21,7 @@ uses
SynHighlighterLFM, SynHighlighterPerl, SynHighlighterMulti, SynRegExpr,
SynEditExport, SynExportHTML, SynMemo, SynMacroRecorder, SynEditPlugins,
SynEditRegexSearch, SynHighlighterPosition, SynHighlighterJava,
SynHighlighterUNIXShellScript,
SynEditLazDsgn;
implementation
@ -30,6 +31,9 @@ end.
{ =============================================================================
$Log$
Revision 1.17 2003/06/11 22:56:09 mattias
added bash scripts highlighter from Tom Lisjac
Revision 1.16 2003/02/20 00:44:01 mattias
added synedit to component palette

View File

@ -212,6 +212,7 @@ resourcestring
SYNS_FilterXML = 'XML Document (*.xml,*.xsd,*.xsl,*.xslt,*.dtd)|*.xml;*.xsd;*.xsl;*.xslt;*.dtd';
SYNS_FilterGWS = 'GW-TEL Script Files (*.gws)|*.gws';
SYNS_FilterSynGenMsgfiles = 'Msg files (*.msg)|*.msg';
SYNS_FilterUNIXShellScript = 'UNIX Shell Scripts (*.sh)|*.sh';
{$IFDEF SYN_LAZARUS}
// Currently the language names are used to identify the language

View File

@ -0,0 +1,796 @@
{-------------------------------------------------------------------------------
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$
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.
}
{$IFNDEF QSYNHIGHLIGHTERUNIXSHELLSCRIPT}
unit synhighlighterunixshellscript;
{$ENDIF}
{$I SynEdit.inc}
interface
uses
{$IFDEF SYN_CLX}
QGraphics,
QSynEditTypes,
QSynEditHighlighter,
{$ELSE}
Graphics,
{$IFDEF SYN_LAZARUS}
GraphType, /////TL 2003-06-11: Added for font attribute declaration fsBold
{$ENDIF}
SynEditTypes,
SynEditHighlighter,
{$ENDIF}
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);
public
{$IFNDEF SYN_CPPB_1} class {$ENDIF}
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({$IFDEF FPC}const {$ENDIF}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;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(var TokenStart: PChar; var TokenLength: integer); override; /////TL: Added 2003-06-11
{$ENDIF}
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;
procedure Register;
implementation
uses
{$IFDEF SYN_CLX}
QSynEditStrConst;
{$ELSE}
SynEditStrConst;
{$ENDIF}
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;
mHashTable: array[#0..#255] of Integer;
procedure MakeIdentTable;
var
I, J: 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;
J := UpCase(I);
case I in ['_', 'a'..'z', 'A'..'Z'] of
True: mHashTable[I] := Ord(J) - 64
else mHashTable[I] := 0;
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] := {$IFDEF SYN_LAZARUS}@{$ENDIF}SlashProc{!@#$AsciiCharProc};
'{': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}BraceOpenProc;
';': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}PointCommaProc;
'.': fProcTable[i] := {$IFDEF SYN_LAZARUS}@{$ENDIF}DotProc;
#13: fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}CRProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}IdentProc;
#10: fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}LFProc;
#0: fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}NullProc;
'0'..'9': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}NumberProc;
'(': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}RoundOpenProc;
'/': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}SlashProc;
'$': fProcTable[i] := {$IFDEF SYN_LAZARUS}@{$ENDIF}DollarProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}SpaceProc;
#34, #39{!@#$#39}: fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}StringProc;
else fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}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);
fCommentAttri.Foreground := clGreen;
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Foreground := clNavy;
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fSecondKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrSecondReservedWord);
AddAttribute(fSecondKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
fNumberAttri.Foreground := clBlue;
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
fStringAttri.Foreground := clMaroon;
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
fSymbolAttri.Foreground := clRed;
AddAttribute(fSymbolAttri);
fVarAttri := TSynHighlighterAttributes.Create(SYNS_AttrVariable);
fVarAttri.Foreground := clPurple;
AddAttribute(fVarAttri);
SetAttributesOnChange({$IFDEF SYN_LAZARUS}@{$ENDIF}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(
{$IFDEF FPC}const {$ENDIF}NewValue: String;
LineNumber:Integer);
begin
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);
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;
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(fRange);
end;
function TSynUNIXShellScriptSyn.GetToken: string;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
////TL 2003-06-11: Added the following to satisfy abstract method override
{$IFDEF SYN_LAZARUS}
procedure TSynUNIXShellScriptSyn.GetTokenEx(var TokenStart: PChar;
var TokenLength: integer);
begin
TokenLength:=Run-fTokenPos;
TokenStart:=FLine + fTokenPos;
end;
{$ENDIF}
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(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;
/////TL 11-06-2003: Moved from below
resourcestring
LangName = 'UNIX Shell Script';
{$IFNDEF SYN_CPPB_1} class {$ENDIF}
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;
procedure Register;
begin
RegisterComponents('SynEdit', [TSynUNIXShellScriptSyn]);
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSynUNIXShellScriptSyn);
{$ENDIF}
end.

View File

@ -28,9 +28,7 @@
Currently only for TSynEdit.
ToDo:
- Code template adding does not scroll listbox
- key mapping schemes
- SetSynEditSettings
- nicer TColorButton
}
unit EditorOptions;
@ -46,6 +44,7 @@ uses
SynEdit, SynEditHighlighter, SynEditAutoComplete, SynEditKeyCmds,
SynHighlighterPas, SynHighlighterHTML, SynHighlighterCPP, SynHighlighterXML,
SynHighlighterLFM, SynHighlighterPerl, SynHighlighterJava,
SynHighlighterUNIXShellScript,
Laz_XMLCfg, CodeTemplateDialog, KeyMapping, InputHistory, IDEOptionDefs,
LazarusIDEStrConsts;
@ -58,7 +57,7 @@ type
TLazSyntaxHighlighter =
(lshNone, lshText, lshFreePascal, lshDelphi, lshLFM, lshXML, lshHTML,
lshCPP, lshPerl, lshJava);
lshCPP, lshPerl, lshJava, lshBash);
TAdditionalHilightAttribute = (ahaNone, ahaTextBlock, ahaExecutionPoint,
ahaEnabledBreakpoint, ahaDisabledBreakpoint,
@ -82,7 +81,7 @@ const
LazSyntaxHighlighterClasses: array[TLazSyntaxHighlighter] of TCustomSynClass =
( nil, nil, TSynPasSyn, TSynPasSyn, TSynLFMSyn, TSynXMLSyn, TSynHTMLSyn,
TSynCPPSyn, TSynPerlSyn, TSynJavaSyn);
TSynCPPSyn, TSynPerlSyn, TSynJavaSyn, TSynUNIXShellScriptSyn);
{ Comments }
@ -97,7 +96,8 @@ const
comtHtml, // lshHTML
comtCPP, // lshCPP
comtPerl, // lshPerl
comtCPP // lshJava
comtCPP, // lshJava
comtPerl // lshBash
);
const
@ -537,7 +537,8 @@ const
'HTML',
'C++',
'Perl',
'Java'
'Java',
'Bash'
);
var
@ -562,7 +563,7 @@ const
CompatibleLazSyntaxHilighter:
array[TLazSyntaxHighlighter] of TLazSyntaxHighlighter= (
lshNone, lshText, lshFreePascal, lshFreePascal, lshLFM, lshXML, lshHTML,
lshCPP, lshPerl, lshJava
lshCPP, lshPerl, lshJava, lshBash
);
DefaultColorScheme = 'Default';
@ -951,7 +952,7 @@ begin
end;
Add(NewInfo);
// create info for Perl
// create info for Java
NewInfo:=TEditOptLanguageInfo.Create;
with NewInfo do begin
TheType:=CompatibleLazSyntaxHilighter[lshJava];
@ -986,6 +987,40 @@ begin
end;
end;
Add(NewInfo);
// create info for Bash
NewInfo:=TEditOptLanguageInfo.Create;
with NewInfo do begin
TheType:=CompatibleLazSyntaxHilighter[lshBash];
DefaultCommentType:=DefaultCommentTypes[TheType];
SynClass:=LazSyntaxHighlighterClasses[TheType];
FileExtensions:='sh';
SampleSource:=
'#!/bin/bash'#13#13+
'# Bash syntax highlighting'#13#10 +
'set -x'#13#10 +
'set -e'#13#10 +
'Usage="Usage: $0 devel|stable"'#13#10 +
'FPCVersion=$1'#13#10 +
'for ver in devel stable; do'#13#10 +
' if [ "x$FPCVersion" = "x$ver" ]; then'#13#10 +
' fi'#13#10 +
'done'#13#10 +
'# Text Block'#13#10+
#13#10;
AddAttrSampleLines[ahaTextBlock]:=12;
MappedAttributes:=TStringList.Create;
with MappedAttributes do begin
Add('Comment=Comment');
Add('Variable=Identifier');
Add('Key=Reserved_word');
Add('Number=Number');
Add('Space=Space');
Add('String=String');
Add('Symbol=Symbol');
end;
end;
Add(NewInfo);
end;
destructor TEditOptLangList.Destroy;

View File

@ -930,6 +930,8 @@ begin
AddFile('synhighlighterhtml.pp','SynHighlighterHTML',pftUnit,[],cpBase);
AddFile('synhighlighterxml.pas','SynHighlighterXML',pftUnit,[],cpBase);
AddFile('synhighlighterlfm.pas','SynHighlighterLFM',pftUnit,[],cpBase);
AddFile('synhighlighterunixshellscript.pas','SynHighlighterUNIXShellScript',
pftUnit,[],cpBase);
AddFile('synhighlightermulti.pas','SynHighlighterMulti',pftUnit,[],cpBase);
// add unit paths

View File

@ -42,7 +42,7 @@ uses
SynEditLazDsgn, SynEdit, SynCompletion, SynExportHTML, SynMacroRecorder,
SynMemo, SynHighlighterPas, SynHighlighterCPP, SynHighlighterJava,
SynHighlighterPerl, SynHighlighterHTML, SynHighlighterXML,
SynHighlighterLFM, SynHighlighterMulti,
SynHighlighterLFM, SynHighlighterMulti, SynHighlighterUNIXShellScript,
LazarusPackageIntf, LazarusIDEStrConsts;
procedure Register;
@ -109,6 +109,11 @@ begin
RegisterComponents('SynEdit',[TSynLFMSyn]);
end;
procedure RegisterSynHighlighterUNIXShellScript;
begin
RegisterComponents('SynEdit',[TSynUNIXShellScriptSyn]);
end;
procedure RegisterSynHighlighterMulti;
begin
RegisterComponents('SynEdit',[TSynMultiSyn]);
@ -128,6 +133,8 @@ begin
RegisterUnit('SynHighlighterHTML',@RegisterSynHighlighterHTML);
RegisterUnit('SynHighlighterXML',@RegisterSynHighlighterXML);
RegisterUnit('SynHighlighterLFM',@RegisterSynHighlighterLFM);
RegisterUnit('SynHighlighterUNIXShellScript',
@RegisterSynHighlighterUNIXShellScript);
RegisterUnit('SynHighlighterMulti',@RegisterSynHighlighterMulti);
end;