?? synhighlighterinno.pas
字號:
{-------------------------------------------------------------------------------
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: SynHighlighterInno.pas, released 2000-05-01.
The Initial Author of this file is Satya.
Portions created by Satya are Copyright 2000 Satya.
All Rights Reserved.
Contributors to the SynEdit project 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.
$jrsoftware: issrc/Components/SynHighlighterInno.pas,v 1.44 2004/11/07 20:25:58 jr Exp $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
Known Issues:
-------------------------------------------------------------------------------}
{
@abstract(Provides an Inno script file highlighter for SynEdit)
@author(Satya)
@created(2000-05-01)
@lastmod(2001-01-23)
The SynHighlighterInno unit provides an Inno script file highlighter for SynEdit.
Check out http://www.jrsoftware.org for the free Inno Setup program,
and http://isx.wintax.nl/ for My Inno Setup Extensions.
}
unit SynHighlighterInno;
{$I SynEdit.inc}
interface
uses
SysUtils, Classes,
{$IFDEF SYN_CLX}
Qt, QControls, QGraphics,
{$ELSE}
Windows, Messages, Controls, Graphics, Registry,
{$ENDIF}
SynEditTypes, SynEditHighlighter, SynHighlighterHashEntries;
type
TtkTokenKind = (tkComment, tkConstant, tkIdentifier, tkKey, tkKeyOrParameter, //mh 2001-02-07
tkNull, tkNumber, tkParameter, tkSection, tkSpace, tkString, tkSymbol,
tkUnknown, tkDirective);
TProcTableProc = procedure of object;
TSynInnoSyn = class(TSynCustomHighlighter)
private
fLine: PChar;
fLineNumber: integer;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fStringLen: Integer;
fToIdent: PChar;
fTokenPos: Integer;
fTokenID: TtkTokenKind;
fConstantAttri: TSynHighlighterAttributes;
fCommentAttri: TSynHighlighterAttributes;
fSectionAttri: TSynHighlighterAttributes;
fParamAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fInvalidAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
fDirectiveAttri: TSynHighlighterAttributes;
fKeywords: TSynHashEntryList;
function KeyHash(ToHash: PChar): integer;
function KeyComp(const aKey: string): Boolean;
procedure SymbolProc;
procedure CRProc;
procedure IdentProc;
procedure LFProc;
procedure NullProc;
procedure NumberProc;
procedure SectionProc;
procedure SpaceProc;
procedure EqualProc;
procedure ConstantProc;
procedure SemiColonProc;
procedure StringProc;
procedure UnknownProc;
procedure DoAddKeyword(AKeyword: string; AKind: integer);
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
protected
function GetIdentChars: TSynIdentChars; override;
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 GetToken: string; override;
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenID: TtkTokenKind;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
procedure SetLine(NewValue: string; LineNumber:Integer); override;
published
property ConstantAttri: TSynHighlighterAttributes read fConstantAttri
write fConstantAttri;
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
property DirectiveAttri: TSynHighlighterAttributes read fDirectiveAttri
write fDirectiveAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
write fIdentifierAttri;
property InvalidAttri: TSynHighlighterAttributes read fInvalidAttri
write fInvalidAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property NumberAttri: TSynHighlighterAttributes read fNumberAttri
write fNumberAttri;
property ParameterAttri: TSynHighlighterAttributes read fParamAttri
write fParamAttri;
property SectionAttri: TSynHighlighterAttributes read fSectionAttri
write fSectionAttri;
property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
write fSpaceAttri;
property StringAttri: TSynHighlighterAttributes read fStringAttri
write fStringAttri;
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
write fSymbolAttri;
end;
implementation
uses
SynEditStrConst;
var
Identifiers: array[#0..#255] of ByteBool;
mHashTable: array[#0..#255] of Integer;
const
{Note: new 'Section names' and the new 'Constants' need not be added
as they are highlighted automatically}
{Ref: Keywords and Parameters are updated as they last appeared in
Inno Setup / ISX version 1.3.26}
{begin} //satya 2001-01-23
Keywords: string =
'AdminPrivilegesRequired,AfterInstall,AllowCancelDuringInstall,AllowNoIcons,AllowRootDirectory,AllowUNCPath,' +
'AlwaysRestart,AlwaysShowComponentsList,' +
'AlwaysShowDirOnReadyPage,AlwaysShowGroupOnReadyPage,' +
'AlwaysUsePersonalGroup,AppComments,AppContact,AppCopyright,AppendDefaultDirName,' +
'AppendDefaultGroupName,AppId,AppModifyPath,AppMutex,AppName,AppPublisher,' +
'AppPublisherURL,AppReadmeFile,AppSupportURL,AppUpdatesURL,AppVerName,AppVersion,' +
'Attribs,BackColor,BackColor2,BackColorDirection,BackSolid,BeforeInstall,' +
'ChangesAssociations,ChangesEnvironment,Check,CodeFile,Comment,Components,Compression,CopyMode,'+
'CreateAppDir,CreateUninstallRegKey,DefaultDirName,DefaultGroupName,' +
'DefaultUserInfoName,DefaultUserInfoOrg,DefaultUserInfoSerial,' +
'Description,DestDir,DestName,DirExistsWarning,' +
'DisableDirPage,DisableFinishedPage,' +
'DisableProgramGroupPage,DisableReadyMemo,DisableReadyPage,' +
'DisableStartupPrompt,DiskClusterSize,DiskSliceSize,DiskSpaceMBLabel,' +
'DiskSpanning,DontMergeDuplicateFiles,EnableDirDoesntExistWarning,Encryption,' +
'Excludes,ExtraDiskSpaceRequired,Filename,Flags,FlatComponentsList,FontInstall,' +
'GroupDescription,HotKey,IconFilename,IconIndex,InfoAfterFile,InfoBeforeFile,' +
'InternalCompressLevel,Key,LanguageDetectionMethod,Languages,' +
'LicenseFile,MergeDuplicateFiles,MessagesFile,MinVersion,Name,' +
'OnlyBelowVersion,OutputBaseFilename,OutputManifestFile,OutputDir,' +
'Parameters,Password,Permissions,PrivilegesRequired,ReserveBytes,' +
'RestartIfNeededByRun,Root,RunOnceId,Section,SetupIconFile,' +
'ShowComponentSizes,ShowLanguageDialog,ShowTasksTreeLines,SlicesPerDisk,' +
'SolidCompression,Source,SourceDir,StatusMsg,Subkey,Tasks, ' +
'TimeStampRounding,TimeStampsInUTC,TouchDate,TouchTime,Type,Types,' +
'UninstallDisplayIcon,UninstallDisplayName,UninstallFilesDir,UninstallIconFile,' +
'UninstallLogMode,UninstallRestartComputer,UninstallStyle,Uninstallable,' +
'UpdateUninstallLogAppName,UsePreviousAppDir,UsePreviousGroup,' +
'UsePreviousTasks,UsePreviousSetupType,UsePreviousUserInfo,' +
'UserInfoPage,UseSetupLdr,ValueData,ValueName,ValueType,' +
'VersionInfoVersion,VersionInfoCompany,VersionInfoDescription,VersionInfoTextVersion,' +
'WindowResizable,WindowShowCaption,WindowStartMaximized,' +
'WindowVisible,WizardImageBackColor,WizardImageFile,WizardImageStretch,WizardSmallImageBackColor,' +
'WizardSmallImageFile,WizardStyle,WorkingDir';
Parameters: string =
'HKCC,HKCR,HKCU,HKLM,HKU,alwaysoverwrite,alwaysskipifsameorolder,append,' +
'binary,classic,closeonexit,comparetimestamp,confirmoverwrite,' +
'createkeyifdoesntexist,createonlyiffileexists,createvalueifdoesntexist,' +
'deleteafterinstall,deletekey,deletevalue,dirifempty,dontcloseonexit,' +
'dontcopy,dontcreatekey,disablenouninstallwarning,dword,exclusive,expandsz,' +
'external,files,filesandordirs,fixed,fontisnttruetype,ignoreversion,iscustom,isreadme,' +
'modern,multisz,new,noerror,none,normal,nowait,onlyifdestfileexists,' +
'onlyifdoesntexist,onlyifnewer,overwrite,overwritereadonly,postinstall,' +
'preservestringtype,promptifolder,regserver,regtypelib,restart,restartreplace,' +
'runhidden,runmaximized,runminimized,sharedfile,shellexec,showcheckbox,' +
'skipifnotsilent,skipifsilent,silent,skipifdoesntexist,' +
'skipifsourcedoesntexist,sortfilesbyextension,unchecked,uninsalwaysuninstall,' +
'uninsclearvalue,uninsdeleteentry,uninsdeletekey,uninsdeletekeyifempty,' +
'uninsdeletesection,uninsdeletesectionifempty,uninsdeletevalue,' +
'uninsneveruninstall,useapppaths,verysilent,waituntilidle';
{end} //satya 2001-01-23
KeyOrParameter: string = 'string'; //mh 2001-02-07
procedure MakeIdentTable;
var
c: char;
begin
FillChar(Identifiers, SizeOf(Identifiers), 0);
for c := 'a' to 'z' do
Identifiers[c] := TRUE;
for c := 'A' to 'Z' do
Identifiers[c] := TRUE;
for c := '0' to '9' do
Identifiers[c] := TRUE;
Identifiers['_'] := TRUE;
FillChar(mHashTable, SizeOf(mHashTable), 0);
mHashTable['_'] := 1;
for c := 'a' to 'z' do
mHashTable[c] := 2 + Ord(c) - Ord('a');
for c := 'A' to 'Z' do
mHashTable[c] := 2 + Ord(c) - Ord('A');
end;
function TSynInnoSyn.KeyHash(ToHash: PChar): integer;
begin
Result := 0;
while Identifiers[ToHash^] do begin
{$IFOPT Q-}
Result := 7 * Result + mHashTable[ToHash^];
{$ELSE}
Result := (7 * Result + mHashTable[ToHash^]) and $FFFFFF;
{$ENDIF}
inc(ToHash);
end;
Result := Result and $1FF; // 511
fStringLen := ToHash - fToIdent;
end;
function TSynInnoSyn.KeyComp(const aKey: string): Boolean;
var
i: integer;
pKey1, pKey2: PChar;
begin
pKey1 := fToIdent;
// Note: fStringLen is always > 0 !
pKey2 := pointer(aKey);
for i := 1 to fStringLen do
begin
if mHashTable[pKey1^] <> mHashTable[pKey2^] then
begin
Result := FALSE;
exit;
end;
Inc(pKey1);
Inc(pKey2);
end;
Result := TRUE;
end;
function TSynInnoSyn.IdentKind(MayBe: PChar): TtkTokenKind;
var
Entry: TSynHashEntry;
begin
fToIdent := MayBe;
Entry := fKeywords[KeyHash(MayBe)];
while Assigned(Entry) do begin
if Entry.KeywordLen > fStringLen then
break
else if Entry.KeywordLen = fStringLen then
if KeyComp(Entry.Keyword) then begin
Result := TtkTokenKind(Entry.Kind);
exit;
end;
Entry := Entry.Next;
end;
Result := tkIdentifier;
end;
procedure TSynInnoSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
#13: fProcTable[I] := CRProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := IdentProc;
#10: fProcTable[I] := LFProc;
#0: fProcTable[I] := NullProc;
'0'..'9': fProcTable[I] := NumberProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := SpaceProc;
#59 {';'}: fProcTable[I] := SemiColonProc;
#61 {=} : fProcTable[I] := EqualProc;
#34: fProcTable[I] := StringProc;
'#', ':', ',', '(', ')': fProcTable[I] := SymbolProc;
'{': fProcTable[I] := ConstantProc;
#91 {[} : fProcTable[i] := SectionProc;
else
fProcTable[I] := UnknownProc;
end;
end;
constructor TSynInnoSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fKeywords := TSynHashEntryList.Create;
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style := [fsItalic];
fCommentAttri.Foreground := clGray;
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fInvalidAttri := TSynHighlighterAttributes.Create(SYNS_AttrIllegalChar);
AddAttribute(fInvalidAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
fKeyAttri.Foreground := clNavy;
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
fNumberAttri.Foreground := clMaroon;
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -