extrasyn: initial commit (additional synedit highlighters from https://bugs.freepascal.org/view.php?id=18248)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6219 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2018-03-04 09:33:24 +00:00
parent f78d780b5f
commit 3391d5813f
131 changed files with 52806 additions and 0 deletions

View File

@ -0,0 +1,551 @@
{-------------------------------------------------------------------------------
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: SynHighlighter8051.pas, the Initial
Author of this file is Zhou Kan.
All Rights Reserved.
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: SynHighlighter8051.pas,v 1.00 2005/01/24 17:58:27 Kan 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 a 8051 Assembler highlighter for SynEdit)
@author(Zhou Kan [textrush@tom.com])
@created(June 2004)
@lastmod(2005-01-24)
The SynHighlighter8051 unit provides SynEdit with a 8051 Assembler (*.a51;*.asm;*.s03) highlighter.
The highlighter formats 8051 source code highlighting keywords, strings, numbers and characters.
}
unit SynHighlighter8051;
//SynEdit.inc is the synedit.inc from laz 1.2.0 synedit package source if it has changed
//in newer version you might need to copy it again. Remember to redclare the syn_lazarus define.
{$I synedit.inc}
interface
uses
SysUtils, Classes, Graphics, SynEditHighlighter, SynEditTypes,
SynEditStrConst, SynHighlighterHashEntries;
type
TtkTokenKind = (tkComment, tkDirective, tkIdentifier, tkKey, tkNull,
tkNumber, tkRegister, tkSpace, tkString, tkSymbol, tkUnknown); //Kan
TProcTableProc = procedure of object;
type
TSyn8051Syn = class(TSynCustomHighlighter)
private
fLine: PChar;
fLineNumber: Integer;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fStringLen: Integer;
fToIdent: PChar;
fTokenPos: Integer;
fTokenID: TtkTokenKind;
fCommentAttri: TSynHighlighterAttributes;
fDirectiveAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fRegisterAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
fKeywords: TSynHashEntryList;
function KeyHash(ToHash: PChar): Integer;
function KeyComp(const aKey: String): Boolean;
procedure CommentProc;
procedure CRProc;
procedure GreaterProc;
procedure IdentProc;
procedure LFProc;
procedure LowerProc;
procedure NullProc;
procedure NumberProc;
procedure SlashProc;
procedure SpaceProc;
procedure StringProc;
procedure SingleQuoteStringProc;
procedure SymbolProc;
procedure UnknownProc;
procedure DoAddKeyword(AKeyword: string; AKind: integer);
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
protected
function GetIdentChars: TSynIdentChars; override;
function IsFilterStored :boolean; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
override;
function GetEol: Boolean; override;
function GetTokenID: TtkTokenKind;
procedure SetLine(const NewValue: String; LineNumber:Integer); override;
function GetToken: String; override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
class function GetLanguageName :string; override;
published
property CommentAttri: TSynHighlighterAttributes read fCommentAttri write fCommentAttri;
property DirectiveAttri: TSynHighlighterAttributes read fDirectiveAttri write fDirectiveAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri write fIdentifierAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property NumberAttri: TSynHighlighterAttributes read fNumberAttri write fNumberAttri;
property RegisterAttri: TSynHighlighterAttributes read fRegisterAttri write fRegisterAttri;
property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri write fSpaceAttri;
property StringAttri: TSynHighlighterAttributes read fStringAttri write fStringAttri;
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri write fSymbolAttri;
end;
implementation
uses
SynEditStrConstExtra;
var
Identifiers: array[#0..#255] of ByteBool;
mHashTable: array[#0..#255] of Integer;
//Keywords
const
OpCodes: string =
'acall,add,addc,ajmp,anl,call,cjne,clr,cpl,da,dec,div,djnz,inc,jb,jbc,jc,jmp,' +
'jnc,jnb,jnz,jz,lcall,ljmp,mov,movc,movx,mul,nop,orl,pop,push,ret,reti,rl,rlc,' +
'rr,rrc,setb,sjmp,subb,swap,xch,xrl';
RegCodes: string =
'a,ab,acc,b,c,dph,dpl,dptr,r0,r1,r2,r3,r4,r5,r6,r7,sp,psw';
DirectCodes: string =
'aseg,bseg,common,cseg,db,dbit,ds,dseg,dw,end,endif,endmod,else,equ,extern,' +
'extrn,high,iseg,low,lstpag,module,name,org,page,pagsiz,public,rseg,segment,' +
'set,titel,titl,using,xseg';
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);
for c := 'a' to 'z' do
mHashTable[c] := 1 + Ord(c) - Ord('a');
for c := 'A' to 'Z' do
mHashTable[c] := 1 + Ord(c) - Ord('A');
for c := '0' to '9' do
mHashTable[c] := 27 + Ord(c) - Ord('0');
end;
function TSyn8051Syn.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 $3FF;
fStringLen := ToHash - fToIdent;
end;
function TSyn8051Syn.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;
procedure TSyn8051Syn.DoAddKeyword(AKeyword: string; AKind: integer);
var
HashValue: integer;
begin
HashValue := KeyHash(PChar(AKeyword));
fKeywords[HashValue] := TSynHashEntry.Create(AKeyword, AKind);
end;
function TSyn8051Syn.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 TSyn8051Syn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
#0 : fProcTable[I] := {$IFDEF FPC}@{$ENDIF}NullProc;
#10 : fProcTable[I] := {$IFDEF FPC}@{$ENDIF}LFProc;
#13 : fProcTable[I] := {$IFDEF FPC}@{$ENDIF}CRProc;
#34 : fProcTable[I] := {$IFDEF FPC}@{$ENDIF}StringProc;
#39 : fProcTable[I] := {$IFDEF FPC}@{$ENDIF}SingleQuoteStringProc;
'>' : fProcTable[I] := {$IFDEF FPC}@{$ENDIF}GreaterProc;
'<' : fProcTable[I] := {$IFDEF FPC}@{$ENDIF}LowerProc;
'/' : fProcTable[I] := {$IFDEF FPC}@{$ENDIF}SlashProc;
'A'..'Z', 'a'..'z', '_':
fProcTable[I] := {$IFDEF FPC}@{$ENDIF}IdentProc;
'0'..'9':
fProcTable[I] := {$IFDEF FPC}@{$ENDIF}NumberProc;
#1..#9, #11, #12, #14..#32:
fProcTable[I] := {$IFDEF FPC}@{$ENDIF}SpaceProc;
';':
fProcTable[I] := {$IFDEF FPC}@{$ENDIF}CommentProc;
'.', ':', '&', '{', '}', '=', '^', '-', '+', '(', ')', '*', '#':
fProcTable[I] := {$IFDEF FPC}@{$ENDIF}SymbolProc;
else
fProcTable[I] := {$IFDEF FPC}@{$ENDIF}UnknownProc;
end;
end;
constructor TSyn8051Syn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fKeywords := TSynHashEntryList.Create;
fCommentAttri := TSynHighLighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Foreground := clGreen;
AddAttribute(fCommentAttri);
fDirectiveAttri := TSynHighLighterAttributes.Create(SYNS_AttrDirective);
fDirectiveAttri.Foreground := $00A00000;
AddAttribute(fDirectiveAttri);
fIdentifierAttri := TSynHighLighterAttributes.Create(SYNS_AttrIdentifier);
fIdentifierAttri.Foreground := clWindowText;
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighLighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Foreground := clBlue;
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighLighterAttributes.Create(SYNS_AttrNumber);
fNumberAttri.Foreground := clPurple;
AddAttribute(fNumberAttri);
fRegisterAttri := TSynHighLighterAttributes.Create(SYNS_AttrRegister);
fRegisterAttri.Foreground := $00C05000;
AddAttribute(fRegisterAttri);
fSpaceAttri := TSynHighLighterAttributes.Create(SYNS_AttrWhitespace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighLighterAttributes.Create(SYNS_AttrString);
fStringAttri.Foreground := clMaroon;
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighLighterAttributes.Create(SYNS_AttrSymbol);
fSymbolAttri.Foreground := clNavy;
AddAttribute(fSymbolAttri);
MakeMethodTables;
//Keywords list //Kan
EnumerateKeywords(Ord(tkKey), OpCodes, IdentChars, {$IFDEF FPC}@{$ENDIF}DoAddKeyword);
EnumerateKeywords(Ord(tkRegister), RegCodes, IdentChars, {$IFDEF FPC}@{$ENDIF}DoAddKeyword);
EnumerateKeywords(Ord(tkDirective), DirectCodes, IdentChars, {$IFDEF FPC}@{$ENDIF}DoAddKeyword);
SetAttributesOnChange({$IFDEF FPC}@{$ENDIF}DefHighlightChange);
fDefaultFilter:= SYNS_FilterX86Asm;
end;
destructor TSyn8051Syn.Destroy;
begin
fKeywords.Free;
inherited Destroy;
end;
procedure TSyn8051Syn.SetLine(const NewValue :String; LineNumber :Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSyn8051Syn.CommentProc;
begin
fTokenID := tkComment;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
procedure TSyn8051Syn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then Inc(Run);
end;
procedure TSyn8051Syn.GreaterProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] = '=' then Inc(Run);
end;
procedure TSyn8051Syn.IdentProc;
begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
while Identifiers[fLine[Run]] do inc(Run);
end;
procedure TSyn8051Syn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSyn8051Syn.LowerProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] in ['=', '>'] then Inc(Run);
end;
procedure TSyn8051Syn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSyn8051Syn.NumberProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in ['0'..'9', '.', 'a'..'f', 'h', 'A'..'F', 'H'] do
Inc(Run);
end;
procedure TSyn8051Syn.SlashProc;
begin
Inc(Run);
if fLine[Run] = '/' then begin
fTokenID := tkComment;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end else
fTokenID := tkSymbol;
end;
procedure TSyn8051Syn.SpaceProc;
begin
fTokenID := tkSpace;
repeat
Inc(Run);
until (fLine[Run] > #32) or (fLine[Run] in [#0, #10, #13]);
end;
procedure TSyn8051Syn.StringProc;
begin
fTokenID := tkString;
if (FLine[Run + 1] = #34) and (FLine[Run + 2] = #34) then
inc(Run, 2);
repeat
case FLine[Run] of
#0, #10, #13: break;
end;
inc(Run);
until FLine[Run] = #34;
if FLine[Run] <> #0 then inc(Run);
end;
procedure TSyn8051Syn.SingleQuoteStringProc;
begin
fTokenID := tkString;
if (FLine[Run + 1] = #39) and (FLine[Run + 2] = #39) then
inc(Run, 2);
repeat
case FLine[Run] of
#0, #10, #13: break;
end;
inc(Run);
until FLine[Run] = #39;
if FLine[Run] <> #0 then inc(Run);
end;
procedure TSyn8051Syn.SymbolProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSyn8051Syn.UnknownProc;
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then
Inc(Run,2)
else
{$ENDIF}
Inc(Run);
fTokenID := tkIdentifier;
end;
procedure TSyn8051Syn.Next;
begin
fTokenPos := Run;
fProcTable[fLine[Run]];
end;
class function TSyn8051Syn.GetLanguageName :string;
begin
Result := SYNS_Lang8051;
end;
function TSyn8051Syn.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_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSyn8051Syn.GetEol: Boolean;
begin
Result := fTokenId = tkNull;
end;
function TSyn8051Syn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
{$IFDEF SYN_LAZARUS}
procedure TSyn8051Syn.GetTokenEx(out TokenStart :PChar; out TokenLength :integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
function TSyn8051Syn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case fTokenID of
tkComment: Result := fCommentAttri;
tkDirective: Result := fDirectiveAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkRegister: Result := fRegisterAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fIdentifierAttri;
else Result := nil;
end;
end;
function TSyn8051Syn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSyn8051Syn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSyn8051Syn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSyn8051Syn.GetIdentChars: TSynIdentChars;
begin
Result := TSynValidStringChars;
end;
function TSyn8051Syn.IsFilterStored :boolean;
begin
Result := (fDefaultFilter <> SYNS_FilterX86Asm);
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSyn8051Syn);
{$ENDIF}
end.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,56 @@
(******************************************************************************)
(* SynEdit Include File. This file was adapted from Brad Stowers' DFS.INC *)
(* file and used with permission. This will help reduce headaches when new *)
(* versions of Delphi and C++Builder are released, among other things. *)
(******************************************************************************)
(* Brad Stowers: bstowers@pobox.com *)
(* Delphi Free Stuff: http://delphifreestuff.com/ *)
(* February 24, 1999 *)
(******************************************************************************)
(* *)
(* Complete Boolean Evaluation compiler directive is turned off by including *)
(* this file. *)
(* *)
(* Here is a brief explanation of what each of the defines mean: *)
(* SYN_WIN32 : Compilation target is 32-bit Windows *)
(******************************************************************************)
{$IFDEF FPC}
{$MODE OBJFPC}
{$DEFINE SYN_LAZARUS}
{$ENDIF}
{$DEFINE SYNEDIT_INCLUDE}
{$IFdef MSWindows}
{$DEFINE SYN_WIN32}
{$ENDIF}
{------------------------------------------------------------------------------}
{ Common compiler defines }
{------------------------------------------------------------------------------}
// defaults are short evaluation of boolean values and long strings
// lazarus change no $B-
{$H+}
{------------------------------------------------------------------------------}
{ Please change this to suit your needs }
{------------------------------------------------------------------------------}
// support for multibyte character sets
{.$DEFINE SYN_MBCSSUPPORT}
// additional tests for debugging
{.$DEFINE SYN_DEVELOPMENT_CHECKS}
{$IFDEF SYN_DEVELOPMENT_CHECKS}
{$R+,Q+,S+,T+}
{$ENDIF}
// $Id: synedit.inc 42184 2013-07-23 18:44:37Z martin $

View File

@ -0,0 +1,317 @@
unit SynEditStrConstExtra;
Interface
uses SynEditStrConst;
ResourceString
SYNS_AttrSingleString = 'Single Quoted String';
SYNS_AttrURI = 'URI';
SYNS_AttrVisitedURI = 'Visited URI';
SYNS_AttrVrmlAppearance = 'Vrml_Appearance';
SYNS_AttrVrmlAttribute = 'Vrml_Attribute';
SYNS_AttrVrmlDefinition = 'Vrml_Definition';
SYNS_AttrVrmlEvent = 'Vrml_Event';
SYNS_AttrVrmlGrouping = 'Vrml_Grouping';
SYNS_AttrVrmlInterpolator = 'Vrml_Interpolator';
SYNS_AttrVrmlLight = 'Vrml_Light';
SYNS_AttrVrmlNode = 'Vrml_Node';
SYNS_AttrVrmlParameter = 'Vrml_Parameter';
SYNS_AttrVrmlProto = 'Vrml_Proto';
SYNS_AttrVrmlSensor = 'Vrml_Sensor';
SYNS_AttrVrmlShape = 'Vrml_Shape';
SYNS_AttrVrmlShape_Hint = 'Vrml_Shape_Hint';
SYNS_AttrVrmlTime_dependent = 'Vrml_Time_dependent';
SYNS_AttrVrmlViewpoint = 'Vrml_Viewpoint';
SYNS_AttrVrmlWorldInfo = 'Vrml_WorldInfo';
SYNS_AttrX3DDocType = 'X3DDocType';
SYNS_AttrX3DHeader = 'X3DHeader';
SYNS_AttrAttribute = 'Attribute';
SYNS_AttrArrowHead = 'Arrow Head';
SYNS_AttrDirections = 'Direction';
SYNS_AttrShape = 'Shape';
// names for highlighter attributes
SYNS_AttrAreaAIdentifier = 'Area A Identifier';
SYNS_AttrAsm = 'Asm';
SYNS_AttrAsmComment = 'Asm Comment';
SYNS_AttrAsmKey = 'Asm Key';
SYNS_AttrBasicTypes = 'Basic Types';
SYNS_AttrBoolean = 'Boolean value';
SYNS_AttrColor = 'Color Value';
SYNS_AttrDebugLines = 'Debugging Lines';
SYNS_AttrFirstTri = 'FirstTri';
SYNS_AttrFourthTri = 'FourthTri';
SYNS_AttrIndicator = 'Indicator Area';
SYNS_AttrLace = 'Lace';
SYNS_AttrLine = 'Line';
SYNS_AttrOperatorAndSymbols = 'Operator And Symbols';
SYNS_AttrOpLine = 'OpLine';
SYNS_AttrPredefined = 'Predefined';
SYNS_AttrQuad = 'Quad';
SYNS_AttrResultValue = 'Result Value';
SYNS_AttrSecondTri = 'SecondTri';
SYNS_AttrSequence = 'Sequence Number Area';
SYNS_AttrTagArea = 'Tag Area';
SYNS_AttrThirdTri = 'ThirdTri';
SYNS_AttrTriangle = 'Triangle';
//SYNS_AttrAssembler = 'Assembler';
//SYNS_AttrBlock = 'Block';
//SYNS_AttrBrackets = 'Brackets';
//SYNS_AttrCDATASection = 'CDATA Section';
//SYNS_AttrCharacter = 'Character';
//SYNS_AttrClass = 'Class';
//SYNS_AttrComment = 'Comment';
//SYNS_AttrCondition = 'Condition';
//SYNS_AttrConditionalComment = 'Conditional Comment';
//SYNS_AttrDataType = 'Data Type';
//SYNS_AttrDefaultPackage = 'Default Packages';
//SYNS_AttrDelimitedIdentifier = 'Delimited Identifier';
//SYNS_AttrDir = 'Direction';
//SYNS_AttrDirections = 'Directions';
//SYNS_AttrDirective = 'Directive';
//SYNS_AttrDOCTYPESection = 'DOCTYPE Section';
//SYNS_AttrDocumentation = 'Documentation';
//SYNS_AttrElementName = 'Element Name';
//SYNS_AttrEmbedSQL = 'Embedded SQL';
//SYNS_AttrEmbedText = 'Embedded Text';
//SYNS_AttrEntityReference = 'Entity Reference';
//SYNS_AttrEscapeAmpersand = 'Escape Ampersand';
//SYNS_AttrEvent = 'Event';
//SYNS_AttrException = 'Exception';
//SYNS_AttrFloat = 'Float';
//SYNS_AttrForm = 'Form';
//SYNS_AttrFunction = 'Function';
//SYNS_AttrHexadecimal = 'Hexadecimal';
//SYNS_AttrIcon = 'Icon Reference';
//SYNS_AttrIdentifier = 'Identifier';
//SYNS_AttrIllegalChar = 'Illegal Char';
//SYNS_AttrInclude = 'Include';
//SYNS_AttrIndirect = 'Indirect';
//SYNS_AttrInvalidSymbol = 'Invalid Symbol';
//SYNS_AttrInternalFunction = 'Internal Function';
//SYNS_AttrKey = 'Key';
//SYNS_AttrLabel = 'Label';
//SYNS_AttrMacro = 'Macro';
//SYNS_AttrMarker = 'Marker';
//SYNS_AttrMathMode = 'Math Mode';
//SYNS_AttrMessage = 'Message';
//SYNS_AttrMiscellaneous = 'Miscellaneous';
//SYNS_AttrNamespaceAttrName = 'Namespace Attribute Name';
//SYNS_AttrNamespaceAttrValue = 'Namespace Attribute Value';
//SYNS_AttrNonReservedKeyword = 'Non-reserved Keyword';
//SYNS_AttrNull = 'Null';
//SYNS_AttrNumber = 'Number';
//SYNS_AttrOctal = 'Octal';
//SYNS_AttrOperator = 'Operator';
//SYNS_AttrPLSQL = 'PL/SQL Reserved Word';
//SYNS_AttrPragma = 'Pragma';
//SYNS_AttrPreprocessor = 'Preprocessor';
//SYNS_AttrProcessingInstr = 'Processing Instruction';
//SYNS_AttrQualifier = 'Qualifier';
//SYNS_AttrRegister = 'Register';
//SYNS_AttrReservedWord = 'Reserved Word';
//SYNS_AttrRoundBracket = 'Round Bracket';
//SYNS_AttrRpl = 'Rpl';
//SYNS_AttrRplKey = 'Rpl Key';
//SYNS_AttrRplComment = 'Rpl Comment';
//SYNS_AttrSASM = 'SASM';
//SYNS_AttrSASMComment = 'SASM Comment';
//SYNS_AttrSASMKey = 'SASM Key';
//SYNS_AttrSecondReservedWord = 'Second Reserved Word';
//SYNS_AttrSection = 'Section';
//SYNS_AttrShape = 'Shape';
//SYNS_AttrSingleString = 'Single Quoted String';
//SYNS_AttrSpace = 'Space';
//SYNS_AttrSpecialVariable = 'Special Variable';
//SYNS_AttrSQLKey = 'SQL Keyword';
//SYNS_AttrSQLPlus = 'SQL*Plus Command';
//SYNS_AttrSquareBracket = 'Square Bracket';
//SYNS_AttrString = 'String';
//SYNS_AttrSymbol = 'Symbol';
//SYNS_AttrSyntaxError = 'Syntax Error';
//SYNS_AttrSystem = 'System Functions and Variables';
//SYNS_AttrSystemValue = 'System Value';
//SYNS_AttrTableName = 'Table Name';
//SYNS_AttrTerminator = 'Terminator';
//SYNS_AttrTeXCommand = 'TeX Command';
//SYNS_AttrText = 'Text';
//SYNS_AttrTextMathMode = 'Text in Math Mode';
//SYNS_AttrUnknownWord = 'Unknown Word';
//SYNS_AttrURI = 'URI';
//SYNS_AttrUser = 'User Functions and Variables';
//SYNS_AttrUserFunction = 'User Functions';
//SYNS_AttrValue = 'Value';
//SYNS_AttrVariable = 'Variable';
//SYNS_AttrVisitedURI = 'Visited URI';
//SYNS_AttrVrmlAppearance = 'Vrml_Appearance';
//SYNS_AttrVrmlAttribute = 'Vrml_Attribute';
//SYNS_AttrVrmlDefinition = 'Vrml_Definition';
//SYNS_AttrVrmlEvent = 'Vrml_Event';
//SYNS_AttrVrmlGrouping = 'Vrml_Grouping';
//SYNS_AttrVrmlInterpolator = 'Vrml_Interpolator';
//SYNS_AttrVrmlLight = 'Vrml_Light';
//SYNS_AttrVrmlNode = 'Vrml_Node';
//SYNS_AttrVrmlParameter = 'Vrml_Parameter';
//SYNS_AttrVrmlProto = 'Vrml_Proto';
//SYNS_AttrVrmlSensor = 'Vrml_Sensor';
//SYNS_AttrVrmlShape = 'Vrml_Shape';
//SYNS_AttrVrmlShape_Hint = 'Vrml_Shape_Hint';
//SYNS_AttrVrmlTime_dependent = 'Vrml_Time_dependent';
//SYNS_AttrVrmlViewpoint = 'Vrml_Viewpoint';
//SYNS_AttrVrmlWorldInfo = 'Vrml_WorldInfo';
//SYNS_AttrWhitespace = 'Whitespace';
//SYNS_AttrX3DDocType = 'X3DDocType';
//SYNS_AttrX3DHeader = 'X3DHeader';
//// names of exporter output formats
//SYNS_ExporterFormatHTML = 'HTML';
//SYNS_ExporterFormatRTF = 'RTF';
//SYNS_ExporterFormatTeX = 'TeX';
//// TCustomSynEdit scroll hint window caption
//SYNS_ScrollInfoFmt = '%d - %d';
//SYNS_ScrollInfoFmtTop = 'Top Line: %d';
//// TSynEditPrintPreview page number
//SYNS_PreviewScrollInfoFmt = 'Page: %d';
//// strings for property editors etc
//SYNS_EDuplicateShortcut = 'Shortcut already exists';
//SYNS_ShortcutNone = '<none>';
//SYNS_DuplicateShortcutMsg = 'The keystroke "%s" is already assigned ' +
//'to another editor command. (%s)';
//SYNS_DuplicateShortcutMsg2 = 'The keystroke "%s" is already assigned ' +
//'to another editor command.'#13#10'The ' +
//'shortcut for this item has not been changed.';
//// Filters used for open/save dialog
SYNS_FilterHP = 'HP48 Files (*.s,*.sou,*.a,*.hp)|*.S;*.SOU;*.A;*.HP';
SYNS_FilterRuby = 'Ruby Files (*.rb;*.rbw)|*.rb;*.rbw';
SYNS_FilterRC = 'Resource Files (*.rc)|*.rc';
SYNS_FilterST = 'Structured Text Files (*.st)|*.st';
SYNS_FilterURI = 'All Files (*.*)|*.*';
SYNS_FilterVrml97 = 'Vrml97/X3D World (*.wrl;*.wrml;*.vrl;*.vrml;*.x3d)|*.wrl;*.wrml;*.vrl;*.vrml;*.x3d';
SYNS_FilterCS = 'C# Files (*.cs)|*.cs';
SYNS_FilterInno = 'Inno Setup Scripts (*.iss)|*.iss';
SYNS_FilterCOBOL = 'COBOL Files (*.cbl;*.cob)|*.cbl;*.cob';
SYNS_FilterHaskell = 'Haskell Files (*.hs;*.lhs)|*.hs;*.lhs';
SYNS_FilterDOT = 'DOT Graph Drawing Description (*.dot)|*.dot';
SYNS_FilterEiffel = 'Eiffel (*.e;*.ace)|*.e;*.ace';
SYNS_FilterLDraw = 'LEGO LDraw Files (*.ldr)|*.ldr';
SYNS_FilterLua = 'Lua Script File (*.Lua)|*.Lua';
SYNS_FilterProlog = 'Prolog Files (*.pl;*.pro;*.prl)|*.pl;*.pro;*.prl';
//SYNS_FilterX86Assembly = 'x86 Assembly Files (*.asm)|*.asm';
//SYNS_FilterPascal = 'Pascal Files (*.pas;*.pp;*.dpr;*.dpk;*.inc)|*.pas;*.pp;*.dpr;*.dpk;*.inc';
//SYNS_FilterHP48 = 'HP48 Files (*.s;*.sou;*.a;*.hp)|*.s;*.sou;*.a;*.hp';
//SYNS_FilterCAClipper = 'CA-Clipper Files (*.prg;*.ch;*.inc)|*.prg;*.ch;*.inc';
//SYNS_FilterCORBAIDL = 'CORBA IDL Files (*.idl)|*.idl';
//SYNS_FilterCPM = 'CPM Reports (*.rdf;*.rif;*.rmf;*.rxf)|*.rdf;*.rif;*.rmf;*.rxf';
//SYNS_FilterCPP = 'C/C++ Files (*.c;*.cpp;*.h;*.hpp)|*.c;*.cpp;*.h;*.hpp';
//SYNS_FilterCS = 'C# Files (*.cs)|*.cs';
//SYNS_FilterJava = 'Java Files (*.java)|*.java';
//SYNS_FilterPerl = 'Perl Files (*.pl;*.pm;*.cgi)|*.pl;*.pm;*.cgi';
//SYNS_FilterAWK = 'AWK Scripts (*.awk)|*.awk';
//SYNS_FilterHTML = 'HTML Documents (*.htm;*.html)|*.htm;*.html';
//SYNS_FilterVBScript = 'VBScript Files (*.vbs)|*.vbs';
//SYNS_FilterGalaxy = 'Galaxy Files (*.gtv;*.galrep;*.txt)|*.gtv;*.galrep;*.txt';
//SYNS_FilterPython = 'Python Files (*.py)|*.py';
//SYNS_FilterSQL = 'SQL Files (*.sql)|*.sql';
//SYNS_FilterTclTk = 'Tcl/Tk Files (*.tcl)|*.tcl';
//SYNS_FilterRTF = 'Rich Text Format Documents (*.rtf)|*.rtf';
//SYNS_FilterBatch = 'MS-DOS Batch Files (*.bat;*.cmd)|*.bat;*.cmd';
//SYNS_FilterDFM = 'Borland Form Files (*.dfm;*.xfm)|*.dfm;*.xfm';
//SYNS_FilterX86Assembly = 'x86 Assembly Files (*.asm)|*.asm';
//SYNS_FilterGembase = 'GEMBASE Files (*.dml;*.gem)|*.dml;*.gem';
//SYNS_FilterINI = 'INI Files (*.ini)|*.ini';
//SYNS_FilterSML = 'Standard ML Files (*.sml)|*.sml';
//SYNS_FilterVisualBASIC = 'Visual Basic Files (*.bas)|*.bas';
//SYNS_FilterADSP21xx = 'DSP Files (*.dsp;*.inc)|*.dsp;*.inc';
//SYNS_FilterPHP = 'PHP Files (*.php;*.php3;*.phtml;*.inc)|*.php;*.php3;*.phtml;*.inc';
//SYNS_FilterCache = 'Cache Files (*.mac;*.inc;*.int)|*.mac;*.inc;*.int';
//SYNS_FilterCSS = 'Cascading Stylesheets (*.css)|*.css';
//SYNS_FilterJScript = 'Javascript Files (*.js)|*.js';
//SYNS_FilterKIX = 'KiXtart Scripts (*.kix)|*.kix';
//SYNS_FilterBaan = 'Baan 4GL Files (*.cln)|*.cln';
//SYNS_FilterFoxpro = 'Foxpro Files (*.prg)|*.prg';
//SYNS_FilterFortran = 'Fortran Files (*.for)|*.for';
//SYNS_FilterAsm68HC11 = '68HC11 Assembler Files (*.hc11;*.asm;*.asc)|*.hc11;*.asm;*.asc';
//SYNS_FilterProgress = 'Progress Files (*.w;*.p;*.i)|*.w;*.p;*.i';
//SYNS_FilterModelica = 'Modelica Files (*.mo)|*.mo';
//SYNS_FilterModula3 = 'Modula-3 Files (*.m3)|*.m3';
//SYNS_FilterSDD = 'Semanta DD Files (*.sdd)|*.sdd';
//SYNS_FilterXML = 'XML Files (*.xml;*.xsd;*.xsl;*.xslt;*.dtd)|*.xml;*.xsd;*.xsl;*.xslt;*.dtd';
//SYNS_FilterGWS = 'GW-TEL Scripts (*.gws)|*.gws';
//SYNS_FilterSynGenMsgfiles = 'Msg Files (*.msg)|*.msg';
//SYNS_FilterST = 'Structured Text Files (*.st)|*.st';
//SYNS_FilterTeX = 'TeX Files (*.tex)|*.tex';
//SYNS_FilterRC = 'Resource Files (*.rc)|*.rc';
//SYNS_FilterRuby = 'Ruby Files (*.rb;*.rbw)|*.rb;*.rbw';
//SYNS_FilterUNIXShellScript = 'UNIX Shell Scripts (*.sh)|*.sh';
//SYNS_FilterURI = 'All Files (*.*)|*.*';
//SYNS_FilterVrml97 = 'Vrml97/X3D World (*.wrl;*.wrml;*.vrl;*.vrml;*.x3d)|*.wrl;*.wrml;*.vrl;*.vrml;*.x3d';
//// Language names. Maybe somebody wants them translated / more detailed...
SYNS_LangCS = 'CSharp';
SYNS_LangInno = 'Inno Setup Script';
SYNS_LangST = 'Structured Text';
SYNS_LangCOBOL = 'COBOL';
SYNS_LangRC = 'Resource';
SYNS_LangRuby = 'Ruby';
SYNS_LangHaskell = 'Haskell';
SYNS_LangDOT = 'DOT Graph Drawing Description language';
SYNS_LangEiffel = 'Eiffel';
SYNS_LangLDraw = 'LEGO LDraw';
SYNS_LangURI = 'URI';
SYNS_LangVrml97 = 'Vrml97';
SYNS_LangLua = 'Lua Script';
SYNS_Lang8051 = '8051 Assembler';
SYNS_LangProlog = 'Prolog';
//SYNS_LangHP48 = 'HP48';
//SYNS_LangCAClipper = 'CA-Clipper';
//SYNS_LangCPM = 'COAS Product Manager Report';
//SYNS_LangCPP = 'C/C++';
//SYNS_LangCS = 'C#';
//SYNS_LangJava = 'Java';
//SYNS_LangPerl = 'Perl';
//SYNS_LangBatch = 'MS-DOS Batch';
//SYNS_LangDfm = 'Borland Forms';
//SYNS_LangAWK = 'AWK';
//SYNS_LangCORBAIDL = 'CORBA IDL';
//SYNS_LangHTML = 'HTML';
//SYNS_LangVBSScript = 'MS VBScript';
//SYNS_LangGalaxy = 'Galaxy';
//SYNS_LangGeneral = 'General';
//SYNS_LangPascal = 'Object Pascal';
//SYNS_LangX86Asm = 'x86 Assembly';
//SYNS_LangPython = 'Python';
//SYNS_LangTclTk = 'Tcl/Tk';
//SYNS_LangSQL = 'SQL';
//SYNS_LangGembase = 'Gembase';
//SYNS_LangINI = 'INI';
//SYNS_LangSML = 'Standard ML';
//SYNS_LangVisualBASIC = 'Visual Basic';
//SYNS_LangADSP21xx = 'ADSP21xx';
//SYNS_LangPHP = 'PHP';
//SYNS_LangSybaseSQL = 'Sybase SQL';
//SYNS_LangGeneralMulti = 'General Multi-Highlighter';
//SYNS_LangCache = 'Cache Object Script';
//SYNS_LangCSS = 'Cascading Style Sheet';
//SYNS_LangJScript = 'JavaScript';
//SYNS_LangKIX = 'KiXtart';
//SYNS_LangBaan = 'Baan 4GL';
//SYNS_LangFoxpro = 'Foxpro';
//SYNS_LangFortran = 'Fortran';
//SYNS_Lang68HC11 = '68HC11 Assembler';
//SYNS_LangProgress = 'Progress';
//SYNS_LangModelica = 'Modelica';
//SYNS_LangModula3 = 'Modula 3';
//SYNS_LangSDD = 'Semanta Data Dictionary';
//SYNS_LangXML = 'XML';
//SYNS_LangGWS = 'GW-TEL';
//SYNS_LangSynGenMsgfiles = 'SynGen Msg';
//SYNS_LangUnreal = 'Unreal';
//SYNS_LangTeX = 'TeX';
//SYNS_LangNameUNIXShellScript = 'UNIX Shell Script';
implementation
end.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,565 @@
{-------------------------------------------------------------------------------
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: SynHighlighterASM.pas, released 2000-04-18.
The Original Code is based on the nhAsmSyn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Nick Hoddinott.
All Rights Reserved.
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: SynHighlighterAsm.pas,v 1.15 2005/01/28 16:53:20 maelh 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 a x86 Assembler highlighter for SynEdit)
@author(Nick Hoddinott <nickh@conceptdelta.com>, converted to SynEdit by David Muir <david@loanhead45.freeserve.co.uk>)
@created(7 November 1999, converted to SynEdit April 18, 2000)
@lastmod(April 18, 2000)
The SynHighlighterASM unit provides SynEdit with a x86 Assembler (.asm) highlighter.
The highlighter supports all x86 op codes, Intel MMX and AMD 3D NOW! op codes.
Thanks to Martin Waldenburg, Hideo Koiso.
}
unit SynHighlighterAsm;
{$I synedit.inc}
interface
uses
Graphics,
SynEditTypes,
SynEditHighlighter,
SynHighlighterHashEntries,
Classes;
type
TtkTokenKind = (tkComment, tkIdentifier, tkKey, tkNull, tkNumber, tkSpace,
tkString, tkSymbol, tkUnknown);
TProcTableProc = procedure of object;
type
TSynAsmSyn = class(TSynCustomHighlighter)
private
fLine: PChar;
fLineNumber: Integer;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fStringLen: Integer;
fToIdent: PChar;
fTokenPos: Integer;
fTokenID: TtkTokenKind;
fCommentAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
fKeywords: TSynHashEntryList;
function KeyHash(ToHash: PChar): Integer;
function KeyComp(const aKey: String): Boolean;
procedure CommentProc;
procedure CRProc;
procedure GreaterProc;
procedure IdentProc;
procedure LFProc;
procedure LowerProc;
procedure NullProc;
procedure NumberProc;
procedure SlashProc;
procedure SpaceProc;
procedure StringProc;
procedure SingleQuoteStringProc;
procedure SymbolProc;
procedure UnknownProc;
procedure DoAddKeyword(AKeyword: string; AKind: integer);
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
protected
function GetIdentChars: TSynIdentChars; override;
function GetSampleSource: string; override;
function IsFilterStored: Boolean; 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 GetTokenID: TtkTokenKind;
procedure SetLine(const NewValue: String; LineNumber:Integer); override;
function GetToken: String; override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
published
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
write fIdentifierAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
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;
end;
implementation
uses
SynEditStrConst, SynEditStrConstExtra;
var
Identifiers: array[#0..#255] of ByteBool;
mHashTable: array[#0..#255] of Integer;
const
OpCodes: string = 'aaa,aad,aam,adc,add,and,arpl,bound,bsf,bsr,bswap,bt,btc,' +
'btr,bts,call,cbw,cdq,clc,cld,cli,clts,cmc,cmp,cmps,cmpsb,cmpsd,cmpsw,' +
'cmpxchg,cwd,cwde,daa,das,dec,div,emms,enter,f2xm1,fabs,fadd,faddp,fbld,' +
'fbstp,fchs,fclex,fcmovb,fcmovbe,fcmove,fcmovnb,fcmovnbe,fcmovne,fcmovnu,' +
'fcmovu,fcom,fcomi,fcomip,fcomp,fcompp,fcos,fdecstp,fdiv,fdivp,fdivr,' +
'fdivrp,femms,ffree,fiadd,ficom,ficomp,fidiv,fidivr,fild,fimul,fincstp,' +
'finit,fist,fistp,fisub,fisubr,fld,fld1,fldcw,fldenv,fldl2e,fldl2t,fldlg2,' +
'fldln2,fldpi,fldz,fmul,fmulp,fnclex,fninit,fnop,fnsave,fnstcw,fnstenv,' +
'fnstsw,fpatan,fprem1,fptan,frndint,frstor,fsave,fscale,fsin,fsincos,' +
'fsqrt,fst,fstcw,fstenv,fstp,fstsw,fsub,fsubp,fsubr,fsubrp,ftst,' +
'fucom,fucomi,fucomip,fucomp,fucompp,fwait,fxch,fxtract,fyl2xp1,hlt,idiv,' +
'imul,in,inc,ins,insb,insd,insw,int,into,invd,invlpg,iret,iretd,iretw,' +
'ja,jae,jb,jbe,jc,jcxz,je,jecxz,jg,jge,jl,jle,jmp,jna,jnae,jnb,jnbe,jnc,' +
'jne,jng,jnge,jnl,jnle,jno,jnp,jns,jnz,jo,jp,jpe,jpo,js,jz,lahf,lar,lds,' +
'lea,leave,les,lfs,lgdt,lgs,lidt,lldt,lmsw,lock,lods,lodsb,lodsd,lodsw,' +
'loop,loope,loopne,loopnz,loopz,lsl,lss,ltr,mov,movd,movq, movs,movsb,' +
'movsd,movsw,movsx,movzx,mul,neg,nop,not,or,out,outs,outsb,outsd,outsw,' +
'packssdw,packsswb,packuswb,paddb,paddd,paddsb,paddsw,paddusb,paddusw,' +
'paddw,pand,pandn,pavgusb,pcmpeqb,pcmpeqd,pcmpeqw,pcmpgtb,pcmpgtd,pcmpgtw,' +
'pf2id,pfacc,pfadd,pfcmpeq,pfcmpge,pfcmpgt,pfmax,pfmin,pfmul,pfrcp,' +
'pfrcpit1,pfrcpit2,pfrsqit1,pfrsqrt,pfsub,pfsubr,pi2fd,pmaddwd,pmulhrw,' +
'pmulhw,pmullw,pop,popa,popad,popaw,popf,popfd,popfw,por,prefetch,prefetchw,' +
'pslld,psllq,psllw,psrad,psraw,psrld,psrlq,psrlw,psubb,psubd,psubsb,' +
'psubsw,psubusb,psubusw,psubw,punpckhbw,punpckhdq,punpckhwd,punpcklbw,' +
'punpckldq,punpcklwd,push,pusha,pushad,pushaw,pushf,pushfd,pushfw,pxor,' +
'rcl,rcr,rep,repe,repne,repnz,repz,ret,rol,ror,sahf,sal,sar,sbb,scas,' +
'scasb,scasd,scasw,seta,setae,setb,setbe,setc,sete,setg,setge,setl,setle,' +
'setna,setnae,setnb,setnbe,setnc,setne,setng,setnge,setnl,setnle,setno,' +
'setnp,setns,setnz,seto,setp,setpo,sets,setz,sgdt,shl,shld,shr,shrd,sidt,' +
'sldt,smsw,stc,std,sti,stos,stosb,stosd,stosw,str,sub,test,verr,verw,' +
'wait,wbinvd,xadd,xchg,xlat,xlatb,xor';
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);
for c := 'a' to 'z' do
mHashTable[c] := 1 + Ord(c) - Ord('a');
for c := 'A' to 'Z' do
mHashTable[c] := 1 + Ord(c) - Ord('A');
for c := '0' to '9' do
mHashTable[c] := 27 + Ord(c) - Ord('0');
end;
function TSynAsmSyn.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 $3FF;
fStringLen := ToHash - fToIdent;
end;
function TSynAsmSyn.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;
procedure TSynAsmSyn.DoAddKeyword(AKeyword: string; AKind: integer);
var
HashValue: integer;
begin
HashValue := KeyHash(PChar(AKeyword));
fKeywords[HashValue] := TSynHashEntry.Create(AKeyword, AKind);
end;
function TSynAsmSyn.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 TSynAsmSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
#0 : fProcTable[I] := @NullProc;
#10 : fProcTable[I] := @LFProc;
#13 : fProcTable[I] := @CRProc;
#34 : fProcTable[I] := @StringProc;
#39 : fProcTable[I] := @SingleQuoteStringProc;
'>' : fProcTable[I] := @GreaterProc;
'<' : fProcTable[I] := @LowerProc;
'/' : fProcTable[I] := @SlashProc;
'A'..'Z', 'a'..'z', '_':
fProcTable[I] := @IdentProc;
'0'..'9':
fProcTable[I] := @NumberProc;
#1..#9, #11, #12, #14..#32:
fProcTable[I] := @SpaceProc;
'#', ';':
fProcTable[I] := @CommentProc;
'.', ':', '&', '{', '}', '=', '^', '-', '+', '(', ')', '*':
fProcTable[I] := @SymbolProc;
else
fProcTable[I] := @UnknownProc;
end;
end;
constructor TSynAsmSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fKeywords := TSynHashEntryList.Create;
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style := [fsItalic];
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
MakeMethodTables;
EnumerateKeywords(Ord(tkKey), OpCodes, IdentChars, @DoAddKeyword);
SetAttributesOnChange(@DefHighlightChange);
fDefaultFilter := SYNS_FilterX86Asm;
end;
destructor TSynAsmSyn.Destroy;
begin
fKeywords.Free;
inherited Destroy;
end;
procedure TSynAsmSyn.SetLine(const NewValue: String; LineNumber:Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynAsmSyn.CommentProc;
begin
fTokenID := tkComment;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
procedure TSynAsmSyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then Inc(Run);
end;
procedure TSynAsmSyn.GreaterProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] = '=' then Inc(Run);
end;
procedure TSynAsmSyn.IdentProc;
begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
while Identifiers[fLine[Run]] do inc(Run);
end;
procedure TSynAsmSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynAsmSyn.LowerProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] in ['=', '>'] then Inc(Run);
end;
procedure TSynAsmSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynAsmSyn.NumberProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in ['0'..'9', '.', 'a'..'f', 'h', 'A'..'F', 'H'] do
Inc(Run);
end;
procedure TSynAsmSyn.SlashProc;
begin
Inc(Run);
if fLine[Run] = '/' then begin
fTokenID := tkComment;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end else
fTokenID := tkSymbol;
end;
procedure TSynAsmSyn.SpaceProc;
begin
fTokenID := tkSpace;
repeat
Inc(Run);
until (fLine[Run] > #32) or (fLine[Run] in [#0, #10, #13]);
end;
procedure TSynAsmSyn.StringProc;
begin
fTokenID := tkString;
if (FLine[Run + 1] = #34) and (FLine[Run + 2] = #34) then
inc(Run, 2);
repeat
case FLine[Run] of
#0, #10, #13: break;
end;
inc(Run);
until FLine[Run] = #34;
if FLine[Run] <> #0 then inc(Run);
end;
procedure TSynAsmSyn.SingleQuoteStringProc;
begin
fTokenID := tkString;
if (FLine[Run + 1] = #39) and (FLine[Run + 2] = #39) then
inc(Run, 2);
repeat
case FLine[Run] of
#0, #10, #13: break;
end;
inc(Run);
until FLine[Run] = #39;
if FLine[Run] <> #0 then inc(Run);
end;
procedure TSynAsmSyn.SymbolProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynAsmSyn.UnknownProc;
begin
inc(Run);
fTokenID := tkIdentifier;
end;
procedure TSynAsmSyn.Next;
begin
fTokenPos := Run;
fProcTable[fLine[Run]];
end;
function TSynAsmSyn.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_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynAsmSyn.GetEol: Boolean;
begin
Result := fTokenId = tkNull;
end;
function TSynAsmSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
{$IFDEF SYN_LAZARUS}
procedure TSynAsmSyn.GetTokenEx(out TokenStart :PChar; out TokenLength :integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
function TSynAsmSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case fTokenID of
tkComment: Result := fCommentAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fIdentifierAttri;
else Result := nil;
end;
end;
function TSynAsmSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynAsmSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynAsmSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSynAsmSyn.GetIdentChars: TSynIdentChars;
begin
Result := TSynValidStringChars;
end;
class function TSynAsmSyn.GetLanguageName: string;
begin
Result := SYNS_LangX86Asm;
end;
function TSynAsmSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterX86Asm;
end;
function TSynAsmSyn.GetSampleSource: string;
begin
Result := '; x86 assembly sample source'#13#10 +
' CODE SEGMENT BYTE PUBLIC'#13#10 +
' ASSUME CS:CODE'#13#10 +
#13#10 +
' PUSH SS'#13#10 +
' POP DS'#13#10 +
' MOV AX, AABBh'#13#10 +
' MOV BYTE PTR ES:[DI], 255'#13#10 +
' JMP SHORT AsmEnd'#13#10 +
#13#10 +
' welcomeMsg DB ''Hello World'', 0'#13#10 +
#13#10 +
' AsmEnd:'#13#10 +
' MOV AX, 0'#13#10 +
#13#10 +
' CODE ENDS'#13#10 +
'END';
end;
initialization
MakeIdentTable;
RegisterPlaceableHighlighter(TSynAsmSyn);
end.

View File

@ -0,0 +1,620 @@
{-------------------------------------------------------------------------------
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: SynHighlighterAWK.pas, released 2000-06-18.
The Original Code is based on the hkAWKSyn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Hideo Koiso.
All Rights Reserved.
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: SynHighlighterAWK.pas,v 1.10 2004/07/13 00:00:29 markonjezic 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 a AWK Script highlighter for SynEdit)
@author(Hideo Koiso <sprhythm@fureai.or.jp>, converted to SynEdit by David Muir <dhm@dmsoftware.co.uk>)
@created(7 November 1999, converted to SynEdit April 18, 2000)
@lastmod(June 19, 2000)
The SynHighlighterAWK unit provides SynEdit with a AWK Script (.awk) highlighter.
}
unit SynHighlighterAWK;
interface
{$I synedit.inc}
uses
Graphics,
SynEditTypes,
SynEditHighlighter,
SysUtils,
Classes;
type
TtkTokenKind = (tkComment, tkIdentifier, tkInterFunc, tkKey, tkNull,
tkNumber, tkSpace, tkString, tkSymbol, tkSysVar, tkUnknown);
TProcTableProc = procedure of object;
{ TSynAWKSyn }
TSynAWKSyn = class(TSynCustomHighLighter)
private
AWKSyntaxList: TStringList;
fLine: PChar;
fProcTable: array[#0..#255] of TProcTableProc;
Run: Longint;
fTokenPos: Integer;
FTokenID: TtkTokenKind;
fCommentAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fInterFuncAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
fSysVarAttri: TSynHighlighterAttributes;
fLineNumber: Integer;
procedure AndProc;
procedure CommentProc;
procedure CRProc;
procedure ExclamProc;
procedure FieldRefProc;
procedure IdentProc;
procedure LFProc;
procedure MakeMethodTables;
procedure MakeSyntaxList;
procedure MinusProc;
procedure NullProc;
procedure OpInputProc;
procedure OrProc;
procedure PlusProc;
procedure QuestionProc;
procedure SpaceProc;
procedure StringProc;
procedure SymbolProc;
procedure NumberProc;
procedure BraceProc;
protected
function GetIdentChars: TSynIdentChars; override;
function GetSampleSource: String; override;
function IsFilterStored: Boolean; 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 GetTokenID: TtkTokenKind;
function GetToken: string; override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart :PChar; out TokenLength :integer); override;
{$ENDIF}
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
procedure SetLine(const NewValue: string; LineNumber: Integer); override;
published
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
write fIdentifierAttri;
property InterFuncAttri: TSynHighlighterAttributes read fInterFuncAttri
write fInterFuncAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property NumberAttri: TSynHighlighterAttributes read fNumberAttri
write fNumberAttri;
property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
write fSpaceAttri;
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
write fSymbolAttri;
property SysVarAttri: TSynHighlighterAttributes read fSysVarAttri
write fSysVarAttri;
property StringAttri: TSynHighlighterAttributes read fStringAttri
write fStringAttri;
end;
implementation
uses
SynEditStrConst;
procedure TSynAWKSyn.MakeSyntaxList;
begin
with AWKSyntaxList do begin
Sorted := True;
{ *** Preferably sort and put previously. *** }
AddObject('ARGC', TObject(tkSysVar));
AddObject('ARGIND', TObject(tkSysVar)); { GNU Extention }
AddObject('ARGV', TObject(tkSysVar));
AddObject('atan2', TObject(tkInterFunc));
AddObject('BEGIN', TObject(tkKey));
AddObject('break', TObject(tkKey));
AddObject('close', TObject(tkInterFunc));
AddObject('continue', TObject(tkKey));
AddObject('CONVFMT', TObject(tkSysVar)); { POSIX Extention }
AddObject('cos', TObject(tkInterFunc));
AddObject('delete', TObject(tkInterFunc));
AddObject('do', TObject(tkKey));
AddObject('else', TObject(tkKey));
AddObject('END', TObject(tkKey));
AddObject('ENVIRON', TObject(tkSysVar));
AddObject('ERRNO', TObject(tkSysVar)); { GNU Extention }
AddObject('exit', TObject(tkKey));
AddObject('exp', TObject(tkInterFunc));
AddObject('FIELDWIDTH', TObject(tkSysVar)); { GNU Extention }
AddObject('FILENAME', TObject(tkSysVar));
AddObject('FNR', TObject(tkSysVar));
AddObject('for', TObject(tkKey));
AddObject('FS', TObject(tkSysVar));
AddObject('function', TObject(tkKey));
AddObject('getline', TObject(tkKey));
AddObject('gsub', TObject(tkInterFunc));
AddObject('if', TObject(tkKey));
AddObject('IGNORECASE', TObject(tkSysVar));
AddObject('index', TObject(tkInterFunc));
AddObject('int', TObject(tkInterFunc));
AddObject('jindex', TObject(tkInterFunc)); { jgawk }
AddObject('jlength', TObject(tkInterFunc)); { jgawk }
AddObject('jsubstr', TObject(tkInterFunc)); { jgawk }
AddObject('length', TObject(tkInterFunc));
AddObject('log', TObject(tkInterFunc));
AddObject('match', TObject(tkInterFunc));
AddObject('next', TObject(tkUnknown)); { & next file (GNU Extention) }
AddObject('NF', TObject(tkSysVar));
AddObject('NR', TObject(tkSysVar));
AddObject('OFMT', TObject(tkSysVar));
AddObject('OFS', TObject(tkSysVar));
AddObject('ORS', TObject(tkSysVar));
AddObject('print', TObject(tkKey));
AddObject('printf', TObject(tkInterFunc));
AddObject('rand', TObject(tkInterFunc));
AddObject('return', TObject(tkKey));
AddObject('RLENGTH', TObject(tkSysVar));
AddObject('RS', TObject(tkSysVar));
AddObject('RSTART', TObject(tkSysVar));
AddObject('sin', TObject(tkInterFunc));
AddObject('split', TObject(tkInterFunc));
AddObject('sprintf', TObject(tkInterFunc));
AddObject('sqrt', TObject(tkInterFunc));
AddObject('srand', TObject(tkInterFunc));
AddObject('strftime', TObject(tkInterFunc)); { GNU Extention }
AddObject('sub', TObject(tkInterFunc));
AddObject('SUBSEP', TObject(tkSysVar));
AddObject('substr', TObject(tkInterFunc));
AddObject('system', TObject(tkInterFunc));
AddObject('systime', TObject(tkInterFunc)); { GNU Extention }
AddObject('tolower', TObject(tkInterFunc));
AddObject('toupper', TObject(tkInterFunc));
AddObject('while', TObject(tkKey));
end;
end;
procedure TSynAWKSyn.MakeMethodTables;
var
i: Char;
begin
for i := #0 to #255 do begin
case i of
#0:
fProcTable[i] := @NullProc;
#10:
fProcTable[i] := @LFProc;
#13:
fProcTable[i] := @CRProc;
#1..#9, #11, #12, #14..#32:
fProcTable[i] := @SpaceProc;
'"', #$27:
fProcTable[i] := @StringProc; { "..." }
'(', ')', '[', ']':
fProcTable[i] := @BraceProc; { (, ), [ and ] }
'#':
fProcTable[i] := @CommentProc; { # ... }
'$':
fProcTable[i] := @FieldRefProc; { $0 .. $9 }
'+':
fProcTable[i] := @PlusProc; { +, ++ and += }
'-':
fProcTable[i] := @MinusProc; { -, -- and -= }
'!':
fProcTable[i] := @ExclamProc; { ! and !~ }
'?':
fProcTable[i] := @QuestionProc; { ?: }
'|':
fProcTable[i] := @OrProc; { || }
'&':
fProcTable[i] := @AndProc; { && }
'*', '/', '%', '^', '<', '=', '>':
fProcTable[i] := @OpInputProc; { *=, /=, %= ... etc. }
'a'..'z', 'A'..'Z':
fProcTable[i] := @IdentProc;
'0'..'9':
fProcTable[i] := @NumberProc;
else
fProcTable[i] := @SymbolProc;
end;
end;
end;
procedure TSynAWKSyn.BraceProc;
begin
fTokenID := tkIdentifier;
Inc(Run);
end;
procedure TSynAWKSyn.NumberProc;
begin
fTokenID := tkNumber;
Inc(Run);
while (fLine[Run] in ['0'..'9']) do begin
Inc(Run);
end;
end;
procedure TSynAWKSyn.IdentProc;
var
i: Integer;
idx: Integer;
s: string;
begin
i := Run;
while (fLine[i] in ['a'..'z', 'A'..'Z']) do begin
Inc(i);
end;
SetLength(s, (i - Run));
StrLCopy(PChar(s), (fLine + Run), (i - Run));
Run := i;
if AWKSyntaxList.Find(s, idx) and (AWKSyntaxList.Strings[idx] = s) then begin
fTokenID := TtkTokenKind(AWKSyntaxList.Objects[idx]);
if (fTokenID = tkUnKnown) then begin
fTokenID := tkKey;
if (fLine[i] = ' ') then begin
while (fLine[i] = ' ') do begin
Inc(i);
end;
if (fLine[i + 0] = 'f') and
(fLine[i + 1] = 'i') and
(fLine[i + 2] = 'l') and
(fLine[i + 3] = 'e') and
(fLine[i + 4] in [#0..#32, ';']) then begin
Run := (i + 4);
end;
end;
end;
end
else begin
fTokenID := tkIdentifier;
end;
end;
procedure TSynAWKSyn.Next;
begin
fTokenPos := Run;
fProcTable[fLine[Run]];
end;
procedure TSynAWKSyn.StringProc;
begin
repeat
Inc(Run);
if (fLine[Run] = '"') and (fLine[Run - 1] <> '\') then begin
fTokenID := tkString;
Inc(Run);
Exit;
end;
until (fLine[Run] in [#0..#31]);
fTokenID := tkIdentifier;
end;
procedure TSynAWKSyn.CommentProc;
begin
fTokenID := tkComment;
while not (fLine[Run] in [#0, #10, #13]) do begin
Inc(Run);
end;
end;
procedure TSynAWKSyn.FieldRefProc;
begin
Inc(Run);
if (fLine[Run] in ['0'..'9']) and
not (fLine[Run + 1] in ['0'..'9', 'a'..'z', 'A'..'Z']) then begin
fTokenID := tkSymbol;
Inc(Run);
end
else begin
fTokenID := tkIdentifier;
end;
end;
procedure TSynAWKSyn.SymbolProc;
begin
fTokenID := tkSymbol;
Inc(Run);
end;
procedure TSynAWKSyn.PlusProc;
begin
fTokenID := tkSymbol;
Inc(Run);
if (fLine[Run] in ['+', '=']) then begin
Inc(Run);
end;
end;
procedure TSynAWKSyn.MinusProc;
begin
fTokenID := tkSymbol;
Inc(Run);
if (fLine[Run] in ['-', '=']) then begin
Inc(Run);
end;
end;
procedure TSynAWKSyn.OpInputProc;
begin
fTokenID := tkSymbol;
Inc(Run);
if (fLine[Run] = '=') then begin
Inc(Run);
end;
end;
procedure TSynAWKSyn.ExclamProc;
begin
fTokenID := tkSymbol;
Inc(Run);
if (fLine[Run] in ['=', '~']) then begin
Inc(Run);
end;
end;
procedure TSynAWKSyn.QuestionProc;
begin
Inc(Run);
if (fLine[Run] = ':') then begin
fTokenID := tkSymbol;
Inc(Run);
end
else begin
fTokenID := tkIdentifier;
end;
end;
procedure TSynAWKSyn.OrProc;
begin
Inc(Run);
if (fLine[Run] = '|') then begin
fTokenID := tkSymbol;
Inc(Run);
end
else begin
fTokenID := tkIdentifier;
end;
end;
procedure TSynAWKSyn.AndProc;
begin
Inc(Run);
if (fLine[Run] = '&') then begin
fTokenID := tkSymbol;
Inc(Run);
end
else begin
fTokenID := tkIdentifier;
end;
end;
constructor TSynAWKSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Foreground := clBlue;
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fInterFuncAttri := TSynHighlighterAttributes.Create(SYNS_AttrInternalFunction);
fInterFuncAttri.Foreground := $00408080;
fInterFuncAttri.Style := [fsBold];
AddAttribute(fInterFuncAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Foreground := $00FF0080;
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
fStringAttri.Foreground := clTeal;
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
fSymbolAttri.Style := [fsBold];
AddAttribute(fSymbolAttri);
fSysVarAttri := TSynHighlighterAttributes.Create(SYNS_AttrSystemValue);
fSysVarAttri.Foreground := $000080FF;
fSysVarAttri.Style := [fsBold];
AddAttribute(fSysVarAttri);
SetAttributesOnChange(@DefHighlightChange);
AWKSyntaxList := TStringList.Create;
MakeSyntaxList;
MakeMethodTables;
fDefaultFilter := SYNS_FilterAWK;
end;
destructor TSynAWKSyn.Destroy;
begin
AWKSyntaxList.Free;
inherited Destroy;
end;
procedure TSynAWKSyn.SetLine(const NewValue: string; LineNumber: Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynAWKSyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then Inc(Run);
end;
procedure TSynAWKSyn.LFProc;
begin
fTokenID := tkSpace;
Inc(Run);
end;
procedure TSynAWKSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynAWKSyn.SpaceProc;
begin
Inc(Run);
fTokenID := tkSpace;
while (fLine[Run] in [#1..#9, #11, #12, #14..#32]) do begin
Inc(Run);
end;
end;
function TSynAWKSyn.GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
begin
case Index of
SYN_ATTR_COMMENT: Result := fCommentAttri;
SYN_ATTR_KEYWORD: Result := fKeyAttri;
SYN_ATTR_WHITESPACE: Result := fSpaceAttri;
SYN_ATTR_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynAWKSyn.GetEol: Boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynAWKSyn.GetToken: string;
var
len: Longint;
begin
len := (Run - fTokenPos);
SetString(Result, (fLine + fTokenPos), len);
end;
{$IFDEF SYN_LAZARUS}
procedure TSynAWKSyn.GetTokenEx(out TokenStart :PChar; out TokenLength :integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
function TSynAWKSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynAWKSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case fTokenID of
tkComment: Result := fCommentAttri;
tkIdentifier: Result := fIdentifierAttri;
tkInterFunc: Result := fInterFuncAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkSysVar: Result := fSysVarAttri;
else
Result := nil;
end;
end;
function TSynAWKSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynAWKSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSynAWKSyn.GetIdentChars: TSynIdentChars;
begin
Result := ['0'..'9', 'a'..'z', 'A'..'Z'] + TSynSpecialChars;
end;
function TSynAWKSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterAWK;
end;
class function TSynAWKSyn.GetLanguageName: string;
begin
Result := SYNS_LangAWK;
end;
function TSynAWKSyn.GetSampleSource :string;
begin
Result :=
'BEGIN { FS='':''; print "This is the first line\n" }' + LineEnding +
'{ print "LINE",NR,$1 }' + LineEnding +
'END { print "This is the last line\n" }';
end;
initialization
RegisterPlaceableHighlighter(TSynAWKSyn);
end.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,979 @@
{-------------------------------------------------------------------------------
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: SynHighlighterFortran.pas, released 2000-04-21.
The Original Code is based on the mwFortranSyn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is "riceball".
All Rights Reserved.
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: SynHighlighterFortran.pas,v 1.16 2005/01/28 16:53:22 maelh 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 a Fortran syntax highlighter for SynEdit)
@author(riceball <teditor@mailroom.com>, converted to SynEdit by Bruno Mikkelsen <btm@scientist.com>)
@created(2000, converted to SynEdit 2000-04-21)
@lastmod(2000-06-23)
The SynHighlighterFortran unit provides SynEdit with a Fortran syntax highlighter.
Thanks to Martin Waldenburg.
}
unit SynHighlighterFortran;
{$I synedit.inc}
interface
uses
Graphics,
SynEditTypes,
SynEditHighlighter,
Classes;
type
TtkTokenKind = (tkComment, tkIdentifier, tkKey, tkNull, tkNumber, tkSpace,
tkString, tkSymbol, tkUnknown);
TProcTableProc = procedure of object;
PIdentFuncTableFunc = ^TIdentFuncTableFunc;
TIdentFuncTableFunc = function: TtkTokenKind of object;
type
TSynFortranSyn = class(TSynCustomHighlighter)
private
fLine: PChar;
fLineNumber: Integer;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fStringLen: Integer;
fToIdent: PChar;
fTokenPos: Integer;
FTokenID: TtkTokenKind;
fIdentFuncTable: array[0..145] of TIdentFuncTableFunc;
fCommentAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
function KeyHash(ToHash: PChar): Integer;
function KeyComp(const aKey: String): Boolean;
function Func15: TtkTokenKind;
function Func19: TtkTokenKind;
function Func23: TtkTokenKind;
function Func26: TtkTokenKind;
function Func28: TtkTokenKind;
function Func30: TtkTokenKind;
function Func36: TtkTokenKind;
function Func38: TtkTokenKind;
function Func41: TtkTokenKind;
function Func42: TtkTokenKind;
function Func47: TtkTokenKind;
function Func48: TtkTokenKind;
function Func50: TtkTokenKind;
function Func56: TtkTokenKind;
function Func57: TtkTokenKind;
function Func58: TtkTokenKind;
function Func59: TtkTokenKind;
function Func61: TtkTokenKind;
function Func63: TtkTokenKind;
function Func64: TtkTokenKind;
function Func66: TtkTokenKind;
function Func68: TtkTokenKind;
function Func69: TtkTokenKind;
function Func70: TtkTokenKind;
function Func73: TtkTokenKind;
function Func75: TtkTokenKind;
function Func77: TtkTokenKind;
function Func78: TtkTokenKind;
function Func81: TtkTokenKind;
function Func82: TtkTokenKind;
function Func84: TtkTokenKind;
function Func88: TtkTokenKind;
function Func96: TtkTokenKind;
function Func97: TtkTokenKind;
function Func99: TtkTokenKind;
function Func101: TtkTokenKind;
function Func102: TtkTokenKind;
function Func114: TtkTokenKind;
function Func127: TtkTokenKind;
function Func144: TtkTokenKind;
function Func145: TtkTokenKind;
procedure AsciiCharProc;
procedure CRProc;
procedure CommaProc;
procedure EqualProc;
procedure ExclamationProc;
procedure GreaterProc;
procedure IdentProc;
procedure LFProc;
procedure LowerProc;
procedure MinusProc;
procedure ModSymbolProc;
procedure NullProc;
procedure NumberProc;
procedure PlusProc;
procedure PointProc;
procedure RoundCloseProc;
procedure RoundOpenProc;
procedure SemiColonProc;
procedure SlashProc;
procedure SpaceProc;
procedure StarProc;
procedure StringProc;
procedure UnknownProc;
function AltFunc: TtkTokenKind;
procedure InitIdent;
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
procedure CommentProc;
protected
function GetIdentChars: TSynIdentChars; override;
function IsFilterStored: Boolean; override;
public
class function GetLanguageName: string; override;
public
constructor Create(AOwner: TComponent); override;
function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
override;
function GetEol: Boolean; override;
function GetTokenID: TtkTokenKind;
procedure SetLine(const NewValue: String; LineNumber: Integer); override;
function GetToken: String; override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
published
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
write fIdentifierAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
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;
end;
implementation
uses
SynEditStrConst;
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;
procedure TSynFortranSyn.InitIdent;
var
I: Integer;
pF: PIdentFuncTableFunc;
begin
pF := PIdentFuncTableFunc(@fIdentFuncTable);
for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do begin
pF^ := @AltFunc;
Inc(pF);
end;
fIdentFuncTable[15] := @Func15;
fIdentFuncTable[19] := @Func19;
fIdentFuncTable[23] := @Func23;
fIdentFuncTable[26] := @Func26;
fIdentFuncTable[28] := @Func28;
fIdentFuncTable[30] := @Func30;
fIdentFuncTable[36] := @Func36;
fIdentFuncTable[38] := @Func38;
fIdentFuncTable[41] := @Func41;
fIdentFuncTable[42] := @Func42;
fIdentFuncTable[47] := @Func47;
fIdentFuncTable[48] := @Func48;
fIdentFuncTable[50] := @Func50;
fIdentFuncTable[56] := @Func56;
fIdentFuncTable[57] := @Func57;
fIdentFuncTable[58] := @Func58;
fIdentFuncTable[59] := @Func59;
fIdentFuncTable[61] := @Func61;
fIdentFuncTable[63] := @Func63;
fIdentFuncTable[64] := @Func64;
fIdentFuncTable[66] := @Func66;
fIdentFuncTable[68] := @Func68;
fIdentFuncTable[69] := @Func69;
fIdentFuncTable[70] := @Func70;
fIdentFuncTable[73] := @Func73;
fIdentFuncTable[75] := @Func75;
fIdentFuncTable[77] := @Func77;
fIdentFuncTable[78] := @Func78;
fIdentFuncTable[81] := @Func81;
fIdentFuncTable[82] := @Func82;
fIdentFuncTable[84] := @Func84;
fIdentFuncTable[88] := @Func88;
fIdentFuncTable[96] := @Func96;
fIdentFuncTable[97] := @Func97;
fIdentFuncTable[99] := @Func99;
fIdentFuncTable[101] := @Func101;
fIdentFuncTable[102] := @Func102;
fIdentFuncTable[114] := @Func114;
fIdentFuncTable[127] := @Func127;
fIdentFuncTable[144] := @Func144;
fIdentFuncTable[145] := @Func145;
end;
function TSynFortranSyn.KeyHash(ToHash: PChar): Integer;
begin
Result := 0;
while ToHash^ in ['_', '0'..'9', 'a'..'z', 'A'..'Z'] do
begin
inc(Result, mHashTable[ToHash^]);
inc(ToHash);
end;
fStringLen := ToHash - fToIdent;
end;
function TSynFortranSyn.KeyComp(const aKey: String): Boolean;
var
I: Integer;
Temp: PChar;
begin
Temp := fToIdent;
if Length(aKey) = fStringLen then
begin
Result := True;
for i := 1 to fStringLen do
begin
if mHashTable[Temp^] <> mHashTable[aKey[i]] then
begin
Result := False;
break;
end;
inc(Temp);
end;
end else Result := False;
end;
function TSynFortranSyn.Func15: TtkTokenKind;
begin
if KeyComp('if') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func19: TtkTokenKind;
begin
if KeyComp('do') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func23: TtkTokenKind;
begin
if KeyComp('end') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func26: TtkTokenKind;
begin
if KeyComp('data') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func28: TtkTokenKind;
begin
if KeyComp('call') then Result := tkKey else
if KeyComp('case') then Result := tkKey else
if KeyComp('read') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func30: TtkTokenKind;
begin
if KeyComp('map') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func36: TtkTokenKind;
begin
if KeyComp('real') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func38: TtkTokenKind;
begin
if KeyComp('endif') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func41: TtkTokenKind;
begin
if KeyComp('else') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func42: TtkTokenKind;
begin
if KeyComp('enddo') then Result := tkKey else
if KeyComp('enddo') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func47: TtkTokenKind;
begin
if KeyComp('then') then Result := tkKey else
if KeyComp('save') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func48: TtkTokenKind;
begin
if KeyComp('cycle') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func50: TtkTokenKind;
begin
if KeyComp('open') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func56: TtkTokenKind;
begin
if KeyComp('elseif') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func57: TtkTokenKind;
begin
if KeyComp('while') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func58: TtkTokenKind;
begin
if KeyComp('exit') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func59: TtkTokenKind;
begin
if KeyComp('logical') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func61: TtkTokenKind;
begin
if KeyComp('value') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func63: TtkTokenKind;
begin
if KeyComp('record') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func64: TtkTokenKind;
begin
if KeyComp('select') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func66: TtkTokenKind;
begin
if KeyComp('type') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func68: TtkTokenKind;
begin
if KeyComp('include') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func69: TtkTokenKind;
begin
if KeyComp('allocate') then Result := tkKey else
if KeyComp('default') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func70: TtkTokenKind;
begin
if KeyComp('stop') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func73: TtkTokenKind;
begin
if KeyComp('union') then Result := tkKey else
if KeyComp('common') then Result := tkKey else
if KeyComp('format') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func75: TtkTokenKind;
begin
if KeyComp('write') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func77: TtkTokenKind;
begin
if KeyComp('character') then Result := tkKey else
if KeyComp('print') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func78: TtkTokenKind;
begin
if KeyComp('integer') then Result := tkKey else
if KeyComp('deallocate') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func81: TtkTokenKind;
begin
if KeyComp('interface') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func82: TtkTokenKind;
begin
if KeyComp('entry') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func84: TtkTokenKind;
begin
if KeyComp('allocatable') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func88: TtkTokenKind;
begin
if KeyComp('program') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func96: TtkTokenKind;
begin
if KeyComp('return') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func97: TtkTokenKind;
begin
if KeyComp('parameter') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func99: TtkTokenKind;
begin
if KeyComp('external') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func101: TtkTokenKind;
begin
if KeyComp('continue') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func102: TtkTokenKind;
begin
if KeyComp('function') then Result := tkKey else
if KeyComp('dimension') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func114: TtkTokenKind;
begin
if KeyComp('equivalence') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func127: TtkTokenKind;
begin
if KeyComp('stucture') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func144: TtkTokenKind;
begin
if KeyComp('subroutine') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.Func145: TtkTokenKind;
begin
if KeyComp('structure') then Result := tkKey else Result := tkIdentifier;
end;
function TSynFortranSyn.AltFunc: TtkTokenKind;
begin
Result := tkIdentifier;
end;
function TSynFortranSyn.IdentKind(MayBe: PChar): TtkTokenKind;
var
HashKey: Integer;
begin
fToIdent := MayBe;
HashKey := KeyHash(MayBe);
if HashKey < 146 then Result := fIdentFuncTable[HashKey]() else Result := tkIdentifier;
end;
procedure TSynFortranSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
#39: fProcTable[I] := @AsciiCharProc;
#13: fProcTable[I] := @CRProc;
',': fProcTable[I] := @CommaProc;
'=': fProcTable[I] := @EqualProc;
'!': fProcTable[I] := @ExclamationProc;
'>': fProcTable[I] := @GreaterProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := @IdentProc;
#10: fProcTable[I] := @LFProc;
'<': fProcTable[I] := @LowerProc;
'-': fProcTable[I] := @MinusProc;
'%': fProcTable[I] := @ModSymbolProc;
#0: fProcTable[I] := @NullProc;
'0'..'9': fProcTable[I] := @NumberProc;
'+': fProcTable[I] := @PlusProc;
'.': fProcTable[I] := @PointProc;
')': fProcTable[I] := @RoundCloseProc;
'(': fProcTable[I] := @RoundOpenProc;
';': fProcTable[I] := @SemiColonProc;
'/': fProcTable[I] := @SlashProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := @SpaceProc;
'*': fProcTable[I] := @StarProc;
#34: fProcTable[I] := @StringProc;
else
fProcTable[I] := @UnknownProc;
end;
end;
constructor TSynFortranSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style := [fsItalic];
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
SetAttributesOnChange(@DefHighlightChange);
InitIdent;
MakeMethodTables;
fDefaultFilter := SYNS_FilterFortran;
end;
procedure TSynFortranSyn.SetLine(const NewValue: String; LineNumber: Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynFortranSyn.AsciiCharProc;
begin
fTokenID := tkString;
repeat
case FLine[Run] of
#0, #10, #13: break;
end;
inc(Run);
until FLine[Run] = #39;
if FLine[Run] <> #0 then inc(Run);
end;
procedure TSynFortranSyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then Inc(Run);
end;
procedure TSynFortranSyn.CommaProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynFortranSyn.EqualProc;
begin
case FLine[Run + 1] of
'=': {logical equal}
begin
inc(Run, 2);
fTokenID := tkSymbol;
end;
else {assign}
begin
inc(Run);
fTokenID := tkSymbol;
end;
end;
end;
procedure TSynFortranSyn.ExclamationProc;
begin
inc(Run, 1); {Fortran Comments}
fTokenID := tkComment;
while FLine[Run] <> #0 do
begin
case FLine[Run] of
#10, #13: break;
end;
inc(Run);
end;
end;
procedure TSynFortranSyn.GreaterProc;
begin
Case FLine[Run + 1] of
'=': {greater than or equal to}
begin
inc(Run, 2);
fTokenID := tkSymbol;
end;
'>':
begin
if FLine[Run + 2] = '=' then {shift right assign}
inc(Run, 3)
else {shift right}
inc(Run, 2);
fTokenID := tkSymbol;
end;
else {greater than}
begin
inc(Run);
fTokenID := tkSymbol;
end;
end;
end;
procedure TSynFortranSyn.IdentProc;
begin
if (FLine[Run] in ['C', 'c']) and (Run = 0) then
begin //Fortran comments
inc(Run, 1);
CommentProc;
end
else begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
while Identifiers[fLine[Run]] do inc(Run);
end;
end;
procedure TSynFortranSyn.LFProc;
begin
inc(Run);
fTokenID := tkSpace;
end;
procedure TSynFortranSyn.LowerProc;
begin
case FLine[Run + 1] of
'=': {less than or equal to}
begin
inc(Run, 2);
fTokenID := tkSymbol;
end;
'<':
begin
if FLine[Run + 2] = '=' then {shift left assign}
inc(Run, 3)
else {shift left}
inc(Run, 2);
fTokenID := tkSymbol;
end;
else {less than}
begin
inc(Run);
fTokenID := tkSymbol;
end;
end;
end;
procedure TSynFortranSyn.MinusProc;
begin
{subtract}
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynFortranSyn.ModSymbolProc;
begin
{mod}
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynFortranSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynFortranSyn.NumberProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in
['0'..'9', '.', 'x', 'X', 'e', 'E', 'f', 'F'] do
begin
case FLine[Run] of
'.':
if FLine[Run + 1] = '.' then break;
end;
inc(Run);
end;
end;
procedure TSynFortranSyn.PlusProc;
begin
{subtract}
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynFortranSyn.PointProc;
begin
if (((UpCase(FLine[Run + 1]) = 'G') and (UpCase(FLine[Run + 2]) in ['E','T'])) {.ge. .gt.}
or ((UpCase(FLine[Run + 1]) = 'L') and (UpCase(FLine[Run + 2]) in ['E','T'])) {.le. .lt.}
or ((UpCase(FLine[Run + 1]) = 'N') and (UpCase(FLine[Run + 2]) = 'E')) {.ne.}
or ((UpCase(FLine[Run + 1]) = 'E') and (UpCase(FLine[Run + 2]) = 'Q')) {.eq.}
or ((UpCase(FLine[Run + 1]) = 'O') and (UpCase(FLine[Run + 2]) = 'R'))){.or.}
and (FLine[Run + 3] = '.') then
begin
inc(Run, 4);
fTokenID := tkSymbol;
end
else if (((UpCase(FLine[Run + 1]) = 'A')
and (UpCase(FLine[Run + 2]) = 'N')
and (UpCase(FLine[Run + 3]) = 'D')) {.and.}
or ((UpCase(FLine[Run + 1]) = 'N')
and (UpCase(FLine[Run + 2]) = 'O')
and (UpCase(FLine[Run + 3]) = 'T'))) {.not.}
and (FLine[Run + 4] = '.') then
begin
inc(Run, 5);
fTokenID := tkSymbol;
end
else if (UpCase(FLine[Run + 1]) = 'T')
and (UpCase(FLine[Run + 2]) = 'R')
and (UpCase(FLine[Run + 3]) = 'U')
and (UpCase(FLine[Run + 4]) = 'E')
and (FLine[Run + 5] = '.') then {.true.}
begin
inc(Run, 6);
fTokenID := tkSymbol;
end
else if (UpCase(FLine[Run + 1]) = 'F')
and (UpCase(FLine[Run + 2]) = 'A')
and (UpCase(FLine[Run + 3]) = 'L')
and (UpCase(FLine[Run + 4]) = 'S')
and (UpCase(FLine[Run + 5]) = 'E')
and (FLine[Run + 6] = '.') then {.false.}
begin
inc(Run, 7);
fTokenID := tkSymbol;
end
else {point}
begin
inc(Run);
fTokenID := tkSymbol;
end;
end;
procedure TSynFortranSyn.RoundCloseProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynFortranSyn.RoundOpenProc;
begin
inc(Run);
FTokenID := tkSymbol;
end;
procedure TSynFortranSyn.SemiColonProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynFortranSyn.SlashProc;
begin
{division}
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynFortranSyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
end;
procedure TSynFortranSyn.StarProc;
begin
if (Run = 0) then begin //Fortran comments
inc(Run);
CommentProc;
end
else begin
{star}
inc(Run);
fTokenID := tkSymbol;
end;
end;
procedure TSynFortranSyn.CommentProc;
begin
fTokenID := tkComment;
while FLine[Run] <> #0 do
begin
case FLine[Run] of
#10, #13: break;
end; //case
inc(Run);
end; //while
end;
procedure TSynFortranSyn.StringProc;
begin
fTokenID := tkString;
if (FLine[Run + 1] = #34) and (FLine[Run + 2] = #34) then inc(Run, 2);
repeat
case FLine[Run] of
#0, #10, #13: break;
#92:
if FLine[Run + 1] = #10 then inc(Run);
end;
inc(Run);
until FLine[Run] = #34;
if FLine[Run] <> #0 then inc(Run);
end;
procedure TSynFortranSyn.UnknownProc;
begin
inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynFortranSyn.Next;
begin
fTokenPos := Run;
fProcTable[fLine[Run]];
end;
function TSynFortranSyn.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_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynFortranSyn.GetEol: Boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynFortranSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
{$IFDEF SYN_LAZARUS}
procedure TSynFortranSyn.GetTokenEx(out TokenStart :PChar; out TokenLength :integer);
begin
TokenLength:=Run-fTokenPos;
TokenStart:=FLine + fTokenPos;
end;
{$ENDIF}
function TSynFortranSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynFortranSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case GetTokenID of
tkComment: Result := fCommentAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fIdentifierAttri;
else Result := nil;
end;
end;
function TSynFortranSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynFortranSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSynFortranSyn.GetIdentChars: TSynIdentChars;
begin
Result := TSynValidStringChars;
end;
function TSynFortranSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterFortran;
end;
class function TSynFortranSyn.GetLanguageName: string;
begin
Result := SYNS_LangFortran;
end;
initialization
MakeIdentTable;
RegisterPlaceableHighlighter(TSynFortranSyn);
end.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,451 @@
{-------------------------------------------------------------------------------
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: SynHighlighterGalaxy.pas, released 2000-04-07.
The Original Code is based on the mkGalaxySyn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Martijn van der Kooij.
All Rights Reserved.
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: SynHighlighterGalaxy.pas,v 1.13 2005/01/28 16:53:22 maelh 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 a Galaxy highlighter for SynEdit)
@author(Martijn van der Kooij, converted to SynEdit by David Muir <dhm@dmsoftware.co.uk>)
@created(May 1999, converted to SynEdit June 19, 2000)
@lastmod(2000-06-23)
The SynHighlighterGalaxy unit provides SynEdit with a Galaxy highlighter.
Galaxy is a PBEM game for 10 to 500+ players, to see it wokring goto: http://members.tripod.com/~erisande/kooij.html .
The keywords in the string list KeyWords have to be in UPPERCASE and sorted.
}
unit SynHighlighterGalaxy;
{$I synedit.inc}
interface
uses
Graphics,
SynEditHighlighter,
SysUtils, Classes;
type
TtkTokenKind = (tkComment, tkIdentifier, tkKey, tkNull, tkSpace, tkMessage,
tkUnknown);
TRangeState = (rsUnKnown, rsMessageStyle);
TProcTableProc = procedure of object;
type
TSynGalaxySyn = class(TSynCustomHighlighter)
private
fRange: TRangeState;
fLine: PChar;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fTokenPos: Integer;
FTokenID: TtkTokenKind;
fLineNumber : Integer;
fMessageAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fCommentAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fKeyWords: TStrings;
procedure PointCommaProc;
procedure CRProc;
procedure IdentProc;
procedure LFProc;
procedure NullProc;
procedure SpaceProc;
procedure StringProc;
procedure UnknownProc;
procedure MakeMethodTables;
procedure MessageStyleProc;
procedure SetKeyWords(const Value: TStrings);
protected
function IsFilterStored: Boolean; 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;
function GetToken: String; override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
function IsKeyword(const AKeyword: string): boolean; 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 KeyWords: TStrings read fKeyWords write SetKeyWords;
property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
write fSpaceAttri;
property MessageAttri: TSynHighlighterAttributes read fMessageAttri
write fMessageAttri;
end;
implementation
uses
SynEditStrConst;
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 := UpperCase(I)[1];
Case I in ['_', 'a'..'z', 'A'..'Z'] of
True: mHashTable[I] := Ord(J) - 64
else mHashTable[I] := 0;
end;
end;
end;
function TSynGalaxySyn.IsKeyword(const AKeyword: string): boolean;
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 }
procedure TSynGalaxySyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
';': fProcTable[I] := @PointCommaProc;
#13: fProcTable[I] := @CRProc;
'#','A'..'Z', 'a'..'z', '_': fProcTable[I] := @IdentProc;
#10: fProcTable[I] := @LFProc;
#0: fProcTable[I] := @NullProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := @SpaceProc;
'@': fProcTable[I] := @StringProc;
else
fProcTable[I] := @UnknownProc;
end;
end;
constructor TSynGalaxySyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fKeyWords := TStringList.Create;
TStringList(fKeyWords).Sorted := True;
TStringList(fKeyWords).Duplicates := dupIgnore;
TStringList(fKeyWords).CommaText :=
'#END,#GALAXY,A,ANONYMOUS,AUTOUNLOAD,B,BATTLEPROTOCOL,C,CAP,CARGO,COL,' +
'COMPRESS,D,DRIVE,E,EMP,F,FLEET,FLEETTABLES,G,GALAXYTV,GPLUS,GROUPFORECAST,' +
'H,I,J,L,M,MACHINEREPORT,MAT,N,NAMECASE,NO,O,OPTIONS,P,PLANETFORECAST,' +
'PRODTABLE,PRODUCE,Q,R,ROUTESFORECAST,S,SEND,SHIELDS,SHIPTYPEFORECAST,' +
'SORTGROUPS,T,TWOCOL,U,UNDERSCORES,V,W,WAR,WEAPONS,X,Y,Z';
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style := [fsItalic];
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fMessageAttri := TSynHighlighterAttributes.Create(SYNS_AttrMessage);
AddAttribute(fMessageAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
SetAttributesOnChange(@DefHighlightChange);
MakeMethodTables;
fRange := rsUnknown;
fDefaultFilter := SYNS_FilterGalaxy;
end; { Create }
destructor TSynGalaxySyn.Destroy;
begin
fKeyWords.Free;
inherited Destroy;
end; { Destroy }
procedure TSynGalaxySyn.SetLine(const NewValue: String; LineNumber:Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end; { SetLine }
procedure TSynGalaxySyn.MessageStyleProc;
begin
fTokenID := tkMessage;
case FLine[Run] of
#0:
begin
NullProc;
exit;
end;
#10:
begin
LFProc;
exit;
end;
#13:
begin
CRProc;
exit;
end;
end;
if (Run = 0) and (FLine[Run] = '@') then begin
fRange := rsUnKnown;
inc(Run);
end else
while FLine[Run] <> #0 do
inc(Run);
end;
procedure TSynGalaxySyn.PointCommaProc;
begin
fTokenID := tkComment;
fRange := rsUnknown;
repeat
inc(Run);
until fLine[Run] = #0;
end;
procedure TSynGalaxySyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then
Inc(Run);
end;
procedure TSynGalaxySyn.IdentProc;
begin
while Identifiers[fLine[Run]] do
Inc(Run);
if IsKeyWord(GetToken) then
fTokenId := tkKey
else
fTokenId := tkIdentifier;
end;
procedure TSynGalaxySyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynGalaxySyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynGalaxySyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
end;
procedure TSynGalaxySyn.StringProc;
begin
if (Run = 0) and (fTokenID <> tkMessage) then
begin
fTokenID := tkMessage;
fRange := rsMessageStyle;
end;
inc(Run);
end;
procedure TSynGalaxySyn.UnknownProc;
begin
inc(Run);
fTokenID := tkUnKnown;
end;
procedure TSynGalaxySyn.Next;
begin
fTokenPos := Run;
if fRange = rsMessageStyle then
MessageStyleProc
else
fProcTable[fLine[Run]];
end;
function TSynGalaxySyn.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_WHITESPACE: Result := fSpaceAttri;
SYN_ATTR_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynGalaxySyn.GetEol: Boolean;
begin
Result := fTokenId = tkNull;
end;
function TSynGalaxySyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
function TSynGalaxySyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
{$IFDEF SYN_LAZARUS}
procedure TSynGalaxySyn.GetTokenEx(out TokenStart :PChar; out TokenLength :integer);
begin
TokenLength:=Run-fTokenPos;
TokenStart:=FLine + fTokenPos;
end;
{$ENDIF}
function TSynGalaxySyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynGalaxySyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case fTokenID of
tkComment: Result := fCommentAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkMessage: Result := fMessageAttri;
tkSpace: Result := fSpaceAttri;
tkUnknown: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynGalaxySyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynGalaxySyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
procedure TSynGalaxySyn.ResetRange;
begin
fRange := rsUnknown;
end;
procedure TSynGalaxySyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
procedure TSynGalaxySyn.SetKeyWords(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;
fKeyWords.Assign(Value);
DefHighLightChange(nil);
end;
function TSynGalaxySyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterGalaxy;
end;
class function TSynGalaxySyn.GetLanguageName: string;
begin
Result := SYNS_LangGalaxy;
end;
initialization
MakeIdentTable;
RegisterPlaceableHighlighter(TSynGalaxySyn);
end.

View File

@ -0,0 +1,806 @@
{-------------------------------------------------------------------------------
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: SynHighlighterGeneral.pas, released 2000-04-07.
The Original Code is based on the mwGeneralSyn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Martin Waldenburg.
Portions written by Martin Waldenburg are copyright 1999 Martin Waldenburg.
All Rights Reserved.
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: SynHighlighterGeneral.pas,v 1.16 2005/01/28 16:53:22 maelh 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 a customizable highlighter for SynEdit)
@author(Martin Waldenburg, converted to SynEdit by Michael Hieke)
@created(1999)
@lastmod(2000-06-23)
The SynHighlighterGeneral unit provides a customizable highlighter for SynEdit.
}
{$IFNDEF QSYNHIGHLIGHTERGENERAL}
unit SynHighlighterGeneral;
{$ENDIF}
{$I synedit.inc}
interface
uses
Graphics,
SynEditTypes,
SynEditHighlighter,
SysUtils,
Classes;
type
TtkTokenKind = (tkComment, tkIdentifier, tkKey, tkNull, tkNumber,
tkPreprocessor, tkSpace, tkString, tkSymbol, tkUnknown);
TCommentStyle = (csAnsiStyle, csPasStyle, csCStyle, csAsmStyle, csBasStyle,
csCPPStyle);
TCommentStyles = set of TCommentStyle;
TRangeState = (rsANil, rsAnsi, rsPasStyle, rsCStyle, rsUnKnown);
TStringDelim = (sdSingleQuote, sdDoubleQuote);
TProcTableProc = procedure of object;
type
TSynGeneralSyn = class(TSynCustomHighlighter)
private
fRange: TRangeState;
fLine: PChar;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fTokenPos: Integer;
fTokenID: TtkTokenKind;
fLineNumber : Integer;
fCommentAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fPreprocessorAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
fKeyWords: TStrings;
fComments: TCommentStyles;
fStringDelimCh: char;
fIdentChars: TSynIdentChars;
fDetectPreprocessor: boolean;
procedure AsciiCharProc;
procedure BraceOpenProc;
procedure PointCommaProc;
procedure CRProc;
procedure IdentProc;
procedure IntegerProc;
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 SetKeyWords(const Value: TStrings);
procedure SetComments(Value: TCommentStyles);
function GetStringDelim: TStringDelim;
procedure SetStringDelim(const Value: TStringDelim);
function GetIdentifierChars: string;
procedure SetIdentifierChars(const Value: string);
procedure SetDetectPreprocessor(Value: boolean);
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;
function GetToken: String; override;
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
function IsKeyword(const AKeyword: string): boolean; override;
procedure Next; override;
procedure ResetRange; override;
procedure SetRange(Value: Pointer); override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
// procedure SetLine(NewValue: String; LineNumber: Integer); override;
procedure SetLine(const NewValue: String; LineNumber: Integer); override;
{$IFNDEF SYN_LAZARUS}
function SaveToRegistry(RootKey: HKEY; Key: string): boolean; override;
function LoadFromRegistry(RootKey: HKEY; Key: string): boolean; override;
{$ENDIF}
published
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
property Comments: TCommentStyles read fComments write SetComments;
property DetectPreprocessor: boolean read fDetectPreprocessor
write SetDetectPreprocessor;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
write fIdentifierAttri;
property IdentifierChars: string read GetIdentifierChars
write SetIdentifierChars;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property KeyWords: TStrings read fKeyWords write SetKeyWords;
property NumberAttri: TSynHighlighterAttributes read fNumberAttri
write fNumberAttri;
property PreprocessorAttri: TSynHighlighterAttributes
read fPreprocessorAttri write fPreprocessorAttri;
property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
write fSpaceAttri;
property StringAttri: TSynHighlighterAttributes read fStringAttri
write fStringAttri;
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
write fSymbolAttri;
property StringDelim: TStringDelim read GetStringDelim write SetStringDelim
default sdSingleQuote;
end;
implementation
uses
{$IFDEF SYN_CLX}
QSynEditStrConst;
{$ELSE}
SynEditStrConst;
{$ENDIF}
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 TSynGeneralSyn.IsKeyword(const AKeyword: string): boolean;
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 := AnsiCompareText(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 }
procedure TSynGeneralSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
'#': fProcTable[I] := {$ifdef FPC} @ {$endif}AsciiCharProc;
'{': fProcTable[I] := {$ifdef FPC} @ {$endif}BraceOpenProc;
';': fProcTable[I] := {$ifdef FPC} @ {$endif}PointCommaProc;
#13: fProcTable[I] := {$ifdef FPC} @ {$endif}CRProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := {$ifdef FPC} @ {$endif}IdentProc;
'$': fProcTable[I] := {$ifdef FPC} @ {$endif}IntegerProc;
#10: fProcTable[I] := {$ifdef FPC} @ {$endif}LFProc;
#0: fProcTable[I] := {$ifdef FPC} @ {$endif}NullProc;
'0'..'9': fProcTable[I] := {$ifdef FPC} @ {$endif}NumberProc;
'(': fProcTable[I] := {$ifdef FPC} @ {$endif}RoundOpenProc;
'/': fProcTable[I] := {$ifdef FPC} @ {$endif}SlashProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := {$ifdef FPC} @ {$endif}SpaceProc;
else fProcTable[I] := {$ifdef FPC} @ {$endif}UnknownProc;
end;
fProcTable[fStringDelimCh] := {$ifdef FPC} @ {$endif}StringProc;
end;
constructor TSynGeneralSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fKeyWords := TStringList.Create;
TStringList(fKeyWords).Sorted := True;
TStringList(fKeyWords).Duplicates := dupIgnore;
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style := [fsItalic];
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
fPreprocessorAttri := TSynHighlighterAttributes.Create(SYNS_AttrPreprocessor);
AddAttribute(fPreprocessorAttri);
SetAttributesOnChange({$ifdef FPC} @ {$endif}DefHighlightChange);
fStringDelimCh := '''';
fIdentChars := inherited GetIdentChars;
MakeMethodTables;
fRange := rsUnknown;
end; { Create }
destructor TSynGeneralSyn.Destroy;
begin
fKeyWords.Free;
inherited Destroy;
end; { Destroy }
{$IFDEF SYN_LAZARUS}
procedure TSynGeneralSyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
procedure TSynGeneralSyn.SetLine(const NewValue: String; LineNumber:Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end; { SetLine }
procedure TSynGeneralSyn.AnsiProc;
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 TSynGeneralSyn.PasStyleProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
fTokenID := tkComment;
repeat
if fLine[Run] = '}' then begin
fRange := rsUnKnown;
Inc(Run);
break;
end;
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
end;
procedure TSynGeneralSyn.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 TSynGeneralSyn.AsciiCharProc;
begin
if fDetectPreprocessor then begin
fTokenID := tkPreprocessor;
repeat
inc(Run);
until fLine[Run] in [#0, #10, #13];
end else begin
fTokenID := tkString;
repeat
inc(Run);
until not (fLine[Run] in ['0'..'9']);
end;
end;
procedure TSynGeneralSyn.BraceOpenProc;
begin
if csPasStyle in fComments then
begin
fTokenID := tkComment;
fRange := rsPasStyle;
inc(Run);
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 else
begin
inc(Run);
fTokenID := tkSymbol;
end;
end;
procedure TSynGeneralSyn.PointCommaProc;
begin
if (csASmStyle in fComments) or (csBasStyle in fComments) then
begin
fTokenID := tkComment;
fRange := rsUnknown;
inc(Run);
while FLine[Run] <> #0 do
begin
fTokenID := tkComment;
inc(Run);
end;
end else
begin
inc(Run);
fTokenID := tkSymbol;
end;
end;
procedure TSynGeneralSyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then Inc(Run);
end;
procedure TSynGeneralSyn.IdentProc;
begin
while Identifiers[fLine[Run]] do inc(Run);
if IsKeyWord(GetToken) then fTokenId := tkKey else fTokenId := tkIdentifier;
end;
procedure TSynGeneralSyn.IntegerProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in ['0'..'9', 'A'..'F', 'a'..'f'] do inc(Run);
end;
procedure TSynGeneralSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynGeneralSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynGeneralSyn.NumberProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in ['0'..'9', '.', 'e', 'E', 'x'] do
begin
case FLine[Run] of
'x': begin // handle C style hex numbers
IntegerProc;
break;
end;
'.':
if FLine[Run + 1] = '.' then break;
end;
inc(Run);
end;
end;
procedure TSynGeneralSyn.RoundOpenProc;
begin
inc(Run);
if csAnsiStyle in fComments then
begin
case fLine[Run] of
'*':
begin
fTokenID := tkComment;
fRange := rsAnsi;
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;
'.':
begin
inc(Run);
fTokenID := tkSymbol;
end;
else
begin
FTokenID := tkSymbol;
end;
end;
end else fTokenId := tkSymbol;
end;
procedure TSynGeneralSyn.SlashProc;
begin
Inc(Run);
case FLine[Run] of
'/':
begin
if csCPPStyle in fComments then
begin
fTokenID := tkComment;
Inc(Run);
while FLine[Run] <> #0 do
begin
case FLine[Run] of
#10, #13: break;
end;
inc(Run);
end;
end
else
fTokenId := tkSymbol;
end;
'*':
begin
if csCStyle in fComments then
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, #13:
break;
else
Inc(Run);
end;
end
else
fTokenId := tkSymbol;
end;
else
fTokenID := tkSymbol;
end;
end;
procedure TSynGeneralSyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
end;
procedure TSynGeneralSyn.StringProc;
begin
fTokenID := tkString;
if (fLine[Run + 1] = fStringDelimCh) and (fLine[Run + 2] = fStringDelimCh) then
Inc(Run, 2);
repeat
case FLine[Run] of
#0, #10, #13: break;
end;
inc(Run);
until FLine[Run] = fStringDelimCh;
if FLine[Run] <> #0 then inc(Run);
end;
procedure TSynGeneralSyn.UnknownProc;
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then
Inc(Run, 2)
else
{$ENDIF}
inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynGeneralSyn.Next;
begin
fTokenPos := Run;
case fRange of
rsAnsi: AnsiProc;
rsPasStyle: PasStyleProc;
rsCStyle: CStyleProc;
else
fProcTable[fLine[Run]];
end;
end;
function TSynGeneralSyn.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_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynGeneralSyn.GetEol: Boolean;
begin
Result := fTokenId = tkNull;
end;
function TSynGeneralSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
function TSynGeneralSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
function TSynGeneralSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynGeneralSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case fTokenID of
tkComment: Result := fCommentAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkPreprocessor: Result := fPreprocessorAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynGeneralSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynGeneralSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
procedure TSynGeneralSyn.ResetRange;
begin
fRange := rsUnknown;
end;
procedure TSynGeneralSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
procedure TSynGeneralSyn.SetKeyWords(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;
fKeyWords.Assign(Value);
DefHighLightChange(nil);
end;
procedure TSynGeneralSyn.SetComments(Value: TCommentStyles);
begin
if fComments <> Value then
begin
fComments := Value;
DefHighLightChange(Self);
end;
end;
class function TSynGeneralSyn.GetLanguageName: string;
begin
Result := SYNS_LangGeneral;
end;
{$IFNDEF SYN_LAZARUS}
function TSynGeneralSyn.LoadFromRegistry(RootKey: HKEY; Key: string): boolean;
var
r: TBetterRegistry;
begin
r:= TBetterRegistry.Create;
try
r.RootKey := RootKey;
if r.OpenKeyReadOnly(Key) then begin
if r.ValueExists('KeyWords') then KeyWords.Text:= r.ReadString('KeyWords');
Result := inherited LoadFromRegistry(RootKey, Key);
end
else Result := false;
finally r.Free; end;
end;
function TSynGeneralSyn.SaveToRegistry(RootKey: HKEY; Key: string): boolean;
var
r: TBetterRegistry;
begin
r:= TBetterRegistry.Create;
try
r.RootKey := RootKey;
if r.OpenKey(Key,true) then begin
Result := true;
r.WriteString('KeyWords', KeyWords.Text);
Result := inherited SaveToRegistry(RootKey, Key);
end
else Result := false;
finally r.Free; end;
end;
{$ENDIF}
function TSynGeneralSyn.GetStringDelim: TStringDelim;
begin
if fStringDelimCh = '''' then
Result := sdSingleQuote
else
Result := sdDoubleQuote;
end;
procedure TSynGeneralSyn.SetStringDelim(const Value: TStringDelim);
var
newCh: char;
begin
case Value of
sdSingleQuote: newCh := '''';
else newCh := '"';
end; //case
if newCh <> fStringDelimCh then begin
fStringDelimCh := newCh;
MakeMethodTables;
end;
end;
function TSynGeneralSyn.GetIdentifierChars: string;
var
ch: char;
s: shortstring;
begin
s := '';
for ch := #0 to #255 do
if ch in fIdentChars then s := s + ch;
Result := s;
end;
procedure TSynGeneralSyn.SetIdentifierChars(const Value: string);
var
i: integer;
begin
fIdentChars := [];
for i := 1 to Length(Value) do begin
fIdentChars := fIdentChars + [Value[i]];
end; //for
WordBreakChars := WordBreakChars - fIdentChars;
end;
function TSynGeneralSyn.GetIdentChars: TSynIdentChars;
begin
Result := fIdentChars;
end;
procedure TSynGeneralSyn.SetDetectPreprocessor(Value: boolean);
begin
if Value <> fDetectPreprocessor then begin
fDetectPreprocessor := Value;
DefHighlightChange(Self);
end;
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSynGeneralSyn);
{$ENDIF}
end.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,975 @@
{-------------------------------------------------------------------------------
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: SynHighlighterHP48.pas, released 2000-06-23.
The Original Code is based on the cbHPSyn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Cyrille de Brebisson.
All Rights Reserved.
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: SynHighlighterHP48.pas,v 1.11 2005/12/31 07:34:36 skyweb Exp $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
Known Issues:
- small memory leak in TSpeedStringList has to be fixed
-------------------------------------------------------------------------------}
{
@abstract(Provides SynEdit with a HP48 assembler syntax highlighter.)
@author(Cyrille de Brebisson <cyrille_de-brebisson@aus.hp.com>, converted to SynEdit by David Muir <dhm@dmsoftware.co.uk>)
@created(1998-12, converted to SynEdit 2000-06-23)
@lastmod(2000-06-23)
The unit SynHighlighterHP48 provides SynEdit with a HP48 assembler highlighter.
}
unit SynHighlighterHP48;
{$I synedit.inc}
interface
uses
SynEditHighlighter,
SysUtils,
Classes;
const
NbSubList = 128;
type
TSpeedStringList = class;
TSpeedListObject = class
protected
FName: string;
FSpeedList: TSpeedStringList;
fobject: tobject;
procedure SetName(const Value: string); virtual;
public
property Name: string read FName write SetName;
constructor Create(Aname: string);
destructor Destroy; override;
property SpeedList: TSpeedStringList read FSpeedList write FSpeedList;
property pointer: tobject read fobject write fobject;
end;
PSpeedListObjects = ^TSpeedListObjects;
TSpeedListObjects = array[0..0] of TSpeedListObject;
TSpeedStringList = class
private
function GetText: string;
procedure SetText(const Value: string);
function GetInObject(Index: Integer): TObject;
procedure SetInObject(Index: Integer; const Value: TObject);
protected
FOnChange: TNotifyEvent;
SumOfUsed: array[0..NbSubList - 1] of integer;
datasUsed: array[0..NbSubList - 1] of integer;
datas: array[0..NbSubList - 1] of PSpeedListObjects;
lengthDatas: array[0..NbSubList - 1] of integer;
procedure Changed; virtual;
function Get(Index: Integer): string; virtual;
function GetObject(Index: Integer): TSpeedListObject;
function GetCount: integer;
function GetStringList: TStrings;
procedure SetStringList(const value: TStrings);
public
procedure NameChange(const obj: TSpeedListObject; const NewName: string);
procedure ObjectDeleted(const obj: TSpeedListObject);
destructor Destroy; override;
constructor create;
function AddObj(const Value: TSpeedListObject): Integer;
function Add(const Value: string): TSpeedListObject;
procedure Clear;
function Find(const name: string): TSpeedListObject;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property Objects[Index: Integer]: TSpeedListObject read GetObject;
property inobject[Index: Integer]: TObject read GetInObject write SetInObject;
property Strings[Index: Integer]: string read Get; default;
property count: integer read GetCount;
property StringList: TStrings read GetStringList write SetStringList;
property text: string read GetText write SetText;
end;
TtkTokenKind = (tkNull, tkAsmKey, tkAsm, tkAsmComment, tksAsmKey, tksAsm,
tksAsmComment, tkRplKey, tkRpl, tkRplComment);
TRangeState = (rsRpl, rsComRpl, rssasm1, rssasm2, rssasm3, rsAsm, rsComAsm2,
rsComAsm1);
TSynHP48Syn = class(TSynCustomHighLighter)
private
fTockenKind: TtkTokenKind;
fRange: TRangeState;
fLine: string;
Run: LongInt;
fTokenPos: Integer;
fEol: Boolean;
Attribs: array[TtkTokenKind] of TSynHighlighterAttributes;
FRplKeyWords: TSpeedStringList;
FAsmKeyWords: TSpeedStringList;
FSAsmNoField: TSpeedStringList;
FBaseRange: TRangeState;
function GetAttrib(Index: integer): TSynHighlighterAttributes;
procedure SetAttrib(Index: integer; Value: TSynHighlighterAttributes);
function NullProc: TtkTokenKind;
function SpaceProc: TtkTokenKind;
function ParOpenProc: TtkTokenKind;
function RplComProc: TtkTokenKind;
function AsmComProc(c: char): TtkTokenKind;
function PersentProc: TtkTokenKind;
function IdentProc: TtkTokenKind;
function SlashProc: TtkTokenKind;
function SasmProc1: TtkTokenKind;
function SasmProc2: TtkTokenKind;
function SasmProc3: TtkTokenKind;
procedure EndOfToken;
procedure SetHighLightChange;
function Next1: TtkTokenKind;
procedure Next2(tkk: TtkTokenKind);
function GetTokenFromRange: TtkTokenKind;
function StarProc: TtkTokenKind;
protected
function GetAttribCount: integer; override;
function GetAttribute(idx: integer): TSynHighlighterAttributes; override;
function IsFilterStored: Boolean; 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;
procedure SetLine(const NewValue: string; LineNumber: Integer); override;
function GetToken: string; override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
function GetTokenPos: Integer; override;
procedure Next; override;
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetRange: Pointer; override;
procedure SetRange(Value: Pointer); override;
procedure ResetRange; override;
procedure Assign(Source: TPersistent); override;
property AsmKeyWords: TSpeedStringList read FAsmKeyWords;
property SAsmFoField: TSpeedStringList read FSAsmNoField;
property RplKeyWords: TSpeedStringList read FRplKeyWords;
published
property AsmKey: TSynHighlighterAttributes index Ord(tkAsmKey)
read GetAttrib write SetAttrib;
property AsmTxt: TSynHighlighterAttributes index Ord(tkAsm)
read GetAttrib write SetAttrib;
property AsmComment: TSynHighlighterAttributes index Ord(tkAsmComment)
read GetAttrib write SetAttrib;
property sAsmKey: TSynHighlighterAttributes index Ord(tksAsmKey)
read GetAttrib write SetAttrib;
property sAsmTxt: TSynHighlighterAttributes index Ord(tksAsm)
read GetAttrib write SetAttrib;
property sAsmComment: TSynHighlighterAttributes index Ord(tksAsmComment)
read GetAttrib write SetAttrib;
property RplKey: TSynHighlighterAttributes index Ord(tkRplKey)
read GetAttrib write SetAttrib;
property RplTxt: TSynHighlighterAttributes index Ord(tkRpl)
read GetAttrib write SetAttrib;
property RplComment: TSynHighlighterAttributes index Ord(tkRplComment)
read GetAttrib write SetAttrib;
property BaseRange: TRangeState read FBaseRange write FBaseRange;
end;
implementation
uses
SynEditStrConst, SynEditStrConstExtra;
const
tkTokenName: array[TtkTokenKind] of string = (SYNS_AttrNull,
SYNS_AttrAsmKey, SYNS_AttrAsm, SYNS_AttrAsmComment,
SYNS_AttrSASMKey, SYNS_AttrSASM, SYNS_AttrSASMComment,
SYNS_AttrRplKey, SYNS_AttrRpl, SYNS_AttrRplComment);
DefaultAsmKeyWords: string = '!RPL'#13#10'ENDCODE'#13#10'{'#13#10'}'#13#10 +
'GOTO'#13#10'GOSUB'#13#10'GOSBVL'#13#10'GOVLNG'#13#10'GOLONG'#13#10'SKIP' +
#13#10'SKIPYES' + #13#10'->'#13#10'SKUB'#13#10'SKUBL'#13#10'SKC'#13#10'SKNC'#13#10'SKELSE' +
#13#10'SKEC'#13#10'SKENC'#13#10'SKLSE'#13#10 + 'GOTOL'#13#10'GOSUBL'#13#10 +
'RTN'#13#10'RTNC'#13#10'RTNNC'#13#10'RTNSC'#13#10'RTNCC'#13#10'RTNSXM'#13#10'RTI';
OtherAsmKeyWords: array[0..5] of string = ('UP', 'EXIT', 'UPC', 'EXITC', 'UPNC', 'EXITNC');
DefaultRplKeyWords: string =
'CODEM'#13#10'ASSEMBLEM'#13#10'CODE'#13#10'ASSEMBLE'#13#10'IT'#13#10'ITE'#13#10'case'#13#10'::'#13#10';'#13#10'?SEMI'#13#10''''#13#10'#=case'#13#10'{'#13#10'}'#13#10'NAMELESS'#13#10'LOCAL'#13#10'LOCALNAME'#13#10'LABEL'#13#10 +
'LOCALLABEL'#13#10'xNAME'#13#10'tNAME' + 'COLA'#13#10'NULLNAME'#13#10'xROMID'#13#10'#0=ITE'#13#10'#<ITE'#13#10'#=ITE'#13#10'#>ITE'#13#10'2''RCOLARPITE'#13#10'ANDITE'#13#10'COLAITE'#13#10'COLARPITE'#13#10'DUP#0=ITE'#13#10 +
'EQITE'#13#10'ITE'#13#10'RPITE'#13#10'SysITE'#13#10'UNxSYMRPITE'#13#10'UserITE'#13#10'snnSYMRPITE'#13#10'snsSYMRPITE'#13#10'ssnSYMRPITE'#13#10'sssSYMRPITE'#13#10'$_EXIT'#13#10'DA1OK?NOTIT'#13#10'DA2aOK?NOTIT'#13#10 +
'DA2bOK?NOTIT'#13#10'DA3OK?NOTIT'#13#10'DO#EXIT'#13#10'DO$EXIT'#13#10'DO%EXIT'#13#10'DOHXSEXIT'#13#10'DUP#0=IT'#13#10'EQIT'#13#10'GCDHEULPEXIT'#13#10'GSPLIT'#13#10'NOT_IT'#13#10'POINTEXIT'#13#10'POLYARIT'#13#10'RPIT'#13#10 +
'parleftIT'#13#10'parrightIT'#13#10''''#13#10'IT'#13#10'ITE'#13#10'SEMI'#13#10'UNTIL'#13#10'LOOP'#13#10'?SEMI'#13#10'NOT?SEMI'#13#10'#0=case'#13#10'#1=case'#13#10'#<>case'#13#10'#<case'#13#10'#=case'#13#10'#=casedrop'#13#10 +
'#=casedrpfls'#13#10'#>2case'#13#10'#>33case'#13#10'#>case'#13#10'%-1=case'#13#10'%0=case'#13#10'%1=case'#13#10'%2=case'#13#10'AEQ1stcase'#13#10'AEQopscase'#13#10'ANDNOTcase'#13#10'ANDcase'#13#10'C%-1=case'#13#10 +
'C%0=case'#13#10'C%1=case'#13#10'C%2=case'#13#10'COLANOTcase'#13#10'COLAcase'#13#10'DUP#0=case'#13#10'EQUALNOTcase'#13#10'EQUALcase'#13#10'EQUALcasedrop'#13#10'EQUALcasedrp'#13#10'EQcase'#13#10'EQcaseDROP'#13#10 +
'EQcasedrop'#13#10'EnvNGcase'#13#10'M-1stcasechs'#13#10'MEQ*case'#13#10'MEQ+case'#13#10'MEQ-case'#13#10'MEQ/case'#13#10'MEQ1stcase'#13#10'MEQCHScase'#13#10'MEQFCNcase'#13#10'MEQINVcase'#13#10'MEQSQcase'#13#10'MEQ^case'#13#10 +
'MEQopscase'#13#10'Mid1stcase'#13#10'NOTBAKcase'#13#10'NOTLIBcase'#13#10'NOTLISTcase'#13#10'NOTMATRIXcase'#13#10'NOTROMPcase'#13#10'NOTSECOcase'#13#10'NOTTYPEcase'#13#10'NOTcase'#13#10'NOTcase2DROP'#13#10'NOTcase2drop'#13#10 +
'NOTcaseDROP'#13#10'NOTcaseFALSE'#13#10'NOTcaseTRUE'#13#10'NOTcasedrop'#13#10'NULLargcase'#13#10'NcaseSIZEERR'#13#10'NcaseTYPEERR'#13#10'NoEdit?case'#13#10'ORcase'#13#10'OVER#=case'#13#10'REALcase'#13#10'REQcase'#13#10 +
'REQcasedrop'#13#10'Z-1=case'#13#10'Z0=case'#13#10'Z1=case'#13#10'accNBAKcase'#13#10'accNLIBcase'#13#10'case'#13#10'case2DROP'#13#10'case2drop'#13#10'case2drpfls'#13#10'caseDEADKEY'#13#10'caseDROP'#13#10'caseDoBadKey'#13#10 +
'caseDrpBadKy'#13#10'caseERRJMP'#13#10'caseFALSE'#13#10'caseSIZEERR'#13#10'caseTRUE'#13#10'casedrop'#13#10'casedrpfls'#13#10'casedrptru'#13#10'caseout'#13#10'cxcasecheck'#13#10'dARRYcase'#13#10'dIDNTNcase'#13#10'dLISTcase'#13#10 +
'dMATRIXcase'#13#10'dREALNcase'#13#10'dREALcase'#13#10'dZINTNcase'#13#10'delimcase'#13#10'estcase'#13#10'idntcase'#13#10'idntlamcase'#13#10'j#-1=case'#13#10'j#0=case'#13#10'j#1=case'#13#10'j%-1=case'#13#10'j%0=case'#13#10 +
'j%1=case'#13#10'jEQcase'#13#10'jZ-1=case'#13#10'jZ0=case'#13#10'jZ1=case'#13#10'namelscase'#13#10'need''case'#13#10'negrealcase'#13#10'ngsizecase'#13#10'nonopcase'#13#10'nonrmcase'#13#10'num#-1=case'#13#10'num#0=case'#13#10 +
'num#1=case'#13#10'num-1=case'#13#10'num0=case'#13#10'num0case'#13#10'num1=case'#13#10'num2=case'#13#10'numb1stcase'#13#10'rebuildcase'#13#10'tok=casedrop'#13#10'wildcase'#13#10'zerdercase'#13#10;
SasmNoField: string = 'LOOP'#13#10'RTNSXM'#13#10'RTN'#13#10'RTNSC'#13#10'RTNCC'#13#10'SETDEC'#13#10'SETHEX'#13#10'RSTK=C'#13#10'C=RSTK'#13#10'CLRST'#13#10'C=ST'#13#10'ST=C'#13#10'CSTEX'#13#10 +
'RTI'#13#10'R0=A'#13#10'R1=A'#13#10'R2=A'#13#10'R3=A'#13#10'R4=A'#13#10'R0=C'#13#10'R1=C'#13#10'R2=C'#13#10'R3=C'#13#10'R4=C'#13#10'A=R0'#13#10'A=R1'#13#10'A=R2'#13#10'A=R3'#13#10'A=R4'#13#10 +
'C=R0'#13#10'C=R1'#13#10'C=R2'#13#10'C=R3'#13#10'C=R4'#13#10'AR0EX'#13#10'AR1EX'#13#10'AR2EX'#13#10'AR3EX'#13#10'AR4EX'#13#10'CR0EX'#13#10'CR1EX'#13#10'CR2EX'#13#10'CR3EX'#13#10'CR4EX'#13#10 +
'D0=A'#13#10'D0=C'#13#10'D1=A'#13#10'D1=C'#13#10'AD0EX'#13#10'AD1EX'#13#10'CD0EX'#13#10'CD1EX'#13#10'D0=AS'#13#10'D1=AS'#13#10'D0=CS'#13#10'D1=CD'#13#10'CD1XS'#13#10'CD0XS'#13#10'AD1XS'#13#10'AD0XS'#13#10 +
'RTNC'#13#10'RTNNC'#13#10'OUT=CS'#13#10'OUT=C'#13#10'A=IN'#13#10'C=IN'#13#10'SHUTDN'#13#10'INTON'#13#10'C=ID'#13#10'CONFIG'#13#10'UNCNFG'#13#10'RSI'#13#10'PC=(A)'#13#10'PC=(C)'#13#10'INTOFF'#13#10 +
'C+P+1'#13#10'RESET'#13#10'SREQ?'#13#10'ASLC'#13#10'BSLC'#13#10'CSLC'#13#10'DSLC'#13#10'ASRC'#13#10'BSRC'#13#10'CSRC'#13#10'DSRC'#13#10'ASRB'#13#10'BSRB'#13#10'CSRB'#13#10'DSRB'#13#10'PC=A'#13#10'PC=C'#13#10 +
'A=PC'#13#10'C=PC'#13#10'APCEX'#13#10'CPCEX'#13#10'XM=0'#13#10'SB=0'#13#10'SR=0'#13#10'MP=0'#13#10'CLRHST'#13#10'?XM=0'#13#10'?SR=0'#13#10'?MP=0'#13#10'?SB=0'#13#10'RTNYES'#13#10'SKIPYES{'#13#10'{'#13#10'}'#13#10'UP'#13#10'EXIT'#13#10'EXITNC'#13#10'EXITC'#13#10'UPC'#13#10'UPNC' +
'}SKELSE{'#13#10'SKC{'#13#10'SKNC{'#13#10'SKUB{'#13#10'SKUBL{'#13#10'SKIPC{'#13#10'SKIPNC{'#13#10'EXIT2'#13#10'EXIT3'#13#10'UP2'#13#10'UP3'#13#10'}SKLSE{'#13#10'}SKEC{'#13#10'}SKENC{'#13#10;
function StringCrc(S: string): integer;
var
i: integer;
begin
result := 0;
for i := 1 to length(s) do begin
result := (result shr 4) xor (((result xor ord(s[i])) and $F) * $1081);
result := (result shr 4) xor (((result xor (ord(s[i]) shr 4)) and $F) * $1081);
end;
end;
{ TSpeedListObject }
constructor TSpeedListObject.create(Aname: string);
begin
inherited create;
FName := Aname;
end;
destructor TSpeedListObject.destroy;
begin
if FSpeedList <> nil then
FSpeedList.ObjectDeleted(Self);
inherited destroy;
end;
procedure TSpeedListObject.SetName(const Value: string);
begin
FName := Value;
if FSpeedList <> nil then
FSpeedList.NameChange(Self, Value);
end;
{ TSpeedStringList }
function TSpeedStringList.AddObj(const Value: TSpeedListObject): Integer;
var
crc: integer;
i: integer;
begin
crc := StringCrc(Value.Name) mod High(Datas) + 1;
if DatasUsed[crc] = lengthDatas[crc] then begin
ReallocMem(datas[crc], (lengthDatas[crc] * 2 + 1) * SizeOf(datas[1][0]));
lengthDatas[crc] := lengthDatas[crc] * 2 + 1;
end;
Datas[crc]^[DatasUsed[crc]] := Value;
result := SumOfUsed[crc] + DatasUsed[crc];
inc(DatasUsed[crc]);
for i := crc + 1 to High(SumOfUsed) do
inc(SumOfUsed[i]);
Value.SpeedList := Self;
end;
function TSpeedStringList.Add(const Value: string): TSpeedListObject;
begin
result := TSpeedListObject.Create(value);
AddObj(Result);
end;
procedure TSpeedStringList.Changed;
begin
if Assigned(FOnChange) then
FOnChange(Self);
end;
procedure TSpeedStringList.Clear;
var
i, j: integer;
begin
for i := low(datas) to high(datas) do begin
for j := 0 to DatasUsed[i] - 1 do
datas[i]^[j].free;
datasUsed[i] := 0;
ReallocMem(datas[i], 0);
lengthDatas[i] := 0;
SumOfUsed[i] := 0;
end;
Changed;
end;
constructor TSpeedStringList.create;
var
i: integer;
begin
inherited Create;
for i := Low(Datas) to high(datas) do begin
SumOfUsed[i] := 0;
DatasUsed[i] := 0;
lengthDatas[i] := 0;
datas[i] := nil;
end;
end;
destructor TSpeedStringList.Destroy;
begin
Clear;
inherited destroy;
end;
function TSpeedStringList.Find(const name: string): TSpeedListObject;
var
crc: integer;
i: integer;
begin
crc := StringCrc(name) mod High(Datas) + 1;
for i := 0 to DatasUsed[crc] - 1 do
if Datas[crc]^[i].name = name then begin
result := Datas[crc]^[i];
exit;
end;
result := nil;
end;
function TSpeedStringList.Get(Index: Integer): string;
var
i: integer;
begin
for i := low(SumOfUsed) + 1 to High(SumOfUsed) do
if Index > SumOfUsed[i] then begin
result := Datas[i - 1]^[Index - SumOfUsed[i - 1]].name;
exit;
end;
result := '';
end;
function TSpeedStringList.GetCount: integer;
begin
result := SumOfUsed[High(datas)] + DatasUsed[High(Datas)];
end;
function TSpeedStringList.GetInObject(Index: Integer): TObject;
var
i: integer;
begin
for i := low(SumOfUsed) + 1 to High(SumOfUsed) do
if Index > SumOfUSed[i] then begin
result := Datas[i - 1]^[Index - SumOfUsed[i - 1]].pointer;
exit;
end;
result := nil;
end;
function TSpeedStringList.GetObject(Index: Integer): TSpeedListObject;
var
i: integer;
begin
for i := low(SumOfUsed) + 1 to High(SumOfUsed) do
if Index > SumOfUSed[i] then begin
result := Datas[i - 1]^[Index - SumOfUsed[i - 1]];
exit;
end;
result := nil;
end;
function TSpeedStringList.GetStringList: TStrings;
var
i, j: integer;
begin
result := TStringList.Create;
for i := Low(Datas) to High(Datas) do
for j := 0 to DatasUsed[i] - 1 do
result.add(datas[i]^[j].name);
end;
function TSpeedStringList.GetText: string;
begin
with StringList do begin
result := Text;
free;
end;
end;
procedure TSpeedStringList.NameChange(const Obj: TSpeedListObject; const NewName: string);
var
crc: integer;
i: integer;
j: integer;
begin
crc := StringCrc(obj.Name) mod High(Datas) + 1;
for i := 0 to DatasUsed[crc] - 1 do
if Datas[crc]^[i] = Obj then begin
for j := i + 1 to DatasUsed[crc] - 1 do
Datas[i - 1] := Datas[i];
for j := crc + 1 to High(Datas) do
dec(SumOfUsed[j]);
if DatasUsed[crc] < lengthDatas[crc] div 2 then begin
ReallocMem(Datas[crc], DatasUsed[crc] * SizeOf(Datas[crc][0]));
lengthDatas[crc] := DatasUsed[crc];
end;
AddObj(Obj);
exit;
end;
end;
procedure TSpeedStringList.ObjectDeleted(const obj: TSpeedListObject);
var
crc: integer;
i: integer;
j: integer;
begin
crc := StringCrc(obj.Name) mod High(Datas) + 1;
for i := 0 to DatasUsed[crc] - 1 do
if Datas[crc]^[i] = Obj then begin
for j := i + 1 to DatasUsed[crc] - 1 do
Datas[i - 1] := Datas[i];
for j := crc + 1 to High(Datas) do
dec(SumOfUsed[j]);
Obj.FSpeedList := nil;
exit;
end;
end;
procedure TSpeedStringList.SetInObject(Index: Integer;
const Value: TObject);
var
i: integer;
begin
for i := low(SumOfUsed) + 1 to High(SumOfUsed) do
if Index > SumOfUSed[i] then begin
Datas[i - 1]^[Index - SumOfUsed[i - 1]].pointer := value;
exit;
end;
end;
procedure TSpeedStringList.SetStringList(const value: TStrings);
var
i: integer;
begin
clear;
for i := 0 to Value.Count - 1 do
AddObj(TSpeedListObject.Create(value[i]));
end;
procedure TSpeedStringList.SetText(const Value: string);
var
s: TStrings;
begin
s := TStringList.Create;
try
s.Text := Value;
StringList := s;
finally
s.Free;
end;
end;
{ TSynHP48Syn }
constructor TSynHP48Syn.Create(AOwner: TComponent);
var
i: TtkTokenKind;
j, k: integer;
begin
for i := low(TtkTokenKind) to High(TtkTokenKind) do
Attribs[i] := TSynHighlighterAttributes.Create(tkTokenName[i]);
inherited Create(AOwner);
SetHighlightChange;
FAsmKeyWords := TSpeedStringList.Create;
FAsmKeyWords.Text := DefaultAsmKeyWords;
for j := low(OtherAsmKeyWords) to High(OtherAsmKeyWords) do begin
FAsmKeyWords.AddObj(TSpeedListObject.Create(OtherAsmKeyWords[j]));
for k := 1 to 8 do
FAsmKeyWords.AddObj(TSpeedListObject.Create(OtherAsmKeyWords[j] + IntToStr(k)));
end;
FRplKeyWords := TSpeedStringList.Create;
FRplKeyWords.Text := DefaultRplKeyWords;
FSAsmNoField := TSpeedStringList.Create;
FSAsmNoField.Text := SAsmNoField;
BaseRange := rsRpl;
fRange := rsRpl;
fDefaultFilter := SYNS_FilterHP48;
end; { Create }
destructor TSynHP48Syn.Destroy;
var
i: TtkTokenKind;
begin
for i := low(TtkTokenKind) to High(TtkTokenKind) do
Attribs[i].Free;
FAsmKeyWords.Free;
FRplKeyWords.Free;
FSAsmNoField.free;
inherited Destroy;
end; { Destroy }
procedure TSynHP48Syn.SetLine(const NewValue: string; LineNumber: Integer);
begin
fLine := PChar(NewValue);
Run := 1;
fEol := False;
Next;
end; { SetLine }
function TSynHP48Syn.AsmComProc(c: char): TtkTokenKind;
begin
Result := tkAsmComment;
if (Run > Length(fLine)) then
Result := NullProc
else
while Run <= Length(FLine) do
if ((run = 1) or (fLine[run - 1] <= ' ')) and
(fLine[Run] = '*') and
((run < Length(fLine)) and (fLine[run + 1] = c)) and
((run + 1 = Length(fLine)) or (fLine[run + 2] <= ' ')) then begin
inc(run, 2);
fRange := rsAsm;
break;
end
else
inc(Run);
end;
function TSynHP48Syn.RplComProc: TtkTokenKind;
begin
Result := tkRplComment;
if (Run > Length(fLine)) then
Result := NullProc
else
while Run <= Length(FLine) do
if fLine[Run] = ')' then begin
inc(run);
fRange := rsRpl;
break;
end
else
inc(Run);
end;
function TSynHP48Syn.SlashProc: TtkTokenKind;
begin
if fRange = rsRpl then
Result := IdentProc
else if ((Run = 1) or (fLine[Run - 1] <= ' ')) and
(fLine[Run] = '/') and
(run < Length(fLine)) and
(fLine[run + 1] = '*') and
((run + 1 = Length(fLine)) or (fLine[Run + 2] <= ' ')) then begin
inc(Run, 2);
Result := tkAsmComment;
fRange := rsComAsm2;
end
else if (run < Length(fLine)) and (fLine[Run + 1] = '/') then begin
inc(Run, 2);
Result := tkAsmComment;
while (run <= Length(fLine)) do
if FLine[Run] in [#10, #13] then begin
inc(Run);
break;
end
else
inc(Run);
end
else
Result := IdentProc
end;
function TSynHP48Syn.ParOpenProc: TtkTokenKind;
begin
if fRange = rsRpl then
if ((Run = 1) and ((Length(fLine) = 1) or (fLine[Run + 1] <= ' '))) or
((fLine[Run - 1] <= ' ') and ((Length(fLine) = Run) or (fLine[Run + 1] <= ' '))) then begin
inc(Run);
Result := tkRplComment;
fRange := rsComRpl;
end
else
Result := IdentProc
else if ((run = 1) or (fLine[run - 1] <= ' ')) and
(fline[Run] = '(') and
(run < Length(fLine)) and
(fLine[run + 1] = '*') and
((run + 2 > Length(fLine)) or (fLine[run + 2] <= ' ')) then begin
inc(Run, 2);
Result := tkAsmComment;
fRange := rsComAsm1;
end
else
Result := IdentProc
end;
function TSynHP48Syn.PersentProc: TtkTokenKind;
begin
if fRange = rsAsm then begin
inc(Run);
Result := tkAsmComment;
while (run <= Length(fLine)) do
case FLine[Run] of
#10, #13: begin
inc(Run);
break;
end;
else
inc(Run);
end;
end
else
Result := IdentProc;
end;
function TSynHP48Syn.StarProc: TtkTokenKind;
begin
if fRange = rsRpl then begin
inc(Run);
Result := tkRplComment;
while (run <= Length(fLine)) do
case FLine[Run] of
#10, #13: begin
inc(Run);
break;
end;
else
inc(Run);
end;
end
else
Result := IdentProc;
end;
function TSynHP48Syn.IdentProc: TtkTokenKind;
var
i: integer;
s: string;
begin
i := Run;
EndOfToken;
s := Copy(fLine, i, run - i);
if fRange = rsAsm then
if FAsmKeyWords.Find(s) <> nil then
if (s = '!RPL') or (s = 'ENDCODE') then begin
fRange := rsRpl;
result := tkAsmKey;
end
else
result := tkAsmKey
else if fLine[i] <> '*' then
result := tkAsm
else
result := tkAsmKey
else if FRplKeyWords.Find(s) <> nil then
if (s = 'CODEM') or (s = 'ASSEMBLEM') then begin
fRange := rsAsm;
result := tkAsmKey;
end
else if (s = 'CODE') or (s = 'ASSEMBLE') then begin
fRange := rssAsm1;
result := tksAsmKey;
end
else
result := tkRplKey
else
result := tkRpl;
end;
function TSynHP48Syn.GetTokenFromRange: TtkTokenKind;
begin
case frange of
rsAsm: result := tkAsm;
rssAsm1: result := tksAsmKey;
rssAsm2: result := tksAsm;
rssAsm3: result := tksAsmComment;
rsRpl: result := tkRpl;
rsComRpl: result := tkRplComment;
rsComAsm1, rsComAsm2: result := tkAsmComment;
else
result := tkNull;
end;
end;
function TSynHP48Syn.NullProc: TtkTokenKind;
begin
Result := tkNull;
fEol := True;
end;
function TSynHP48Syn.SpaceProc: TtkTokenKind;
begin
inc(Run);
while (Run <= Length(FLine)) and (FLine[Run] in [#1..#32]) do
inc(Run);
result := GetTokenFromRange;
end;
function TSynHP48Syn.Next1: TtkTokenKind;
begin
fTokenPos := Run;
if Run > Length(fLine) then
result := NullProc
else if fRange = rsComRpl then
result := RplComProc
else if fRange = rsComAsm1 then
result := AsmComProc(')')
else if fRange = rsComAsm2 then
result := AsmComProc('/')
else if frange = rssasm1 then
result := SasmProc1
else if frange = rssasm2 then
result := sasmproc2
else if frange = rssasm3 then
result := sasmproc3
else if fLine[Run] in [#1..#32] then
result := SpaceProc
else if fLine[Run] = '(' then
result := ParOpenProc
else if fLine[Run] = '%' then
result := PersentProc
else if fLine[Run] = '/' then
result := SlashProc
else if (run = 1) and (fRange = rsRpl) and (fLine[1] = '*') then
result := StarProc
else
result := IdentProc;
end;
procedure TSynHP48Syn.Next2(tkk: TtkTokenKind);
begin
fTockenKind := tkk;
end;
procedure TSynHP48Syn.Next;
begin
Next2(Next1);
end;
function TSynHP48Syn.GetEol: Boolean;
begin
Result := fEol;
end;
function TSynHP48Syn.GetToken: string;
var
Len: LongInt;
a: PChar;
begin
a := @(fLine[fTokenPos]);
Len := Run - fTokenPos;
SetString(Result, a, Len);
end;
{$IFDEF SYN_LAZARUS}
procedure TSynHP48Syn.GetTokenEx(out TokenStart :PChar; out TokenLength :integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := @FLine[fTokenPos];
end;
{$ENDIF}
function TSynHP48Syn.GetTokenPos: Integer;
begin
Result := fTokenPos - 1;
end;
function TSynHP48Syn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
procedure TSynHP48Syn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
procedure TSynHP48Syn.ResetRange;
begin
fRange := BaseRange;
end;
function TSynHP48Syn.GetAttrib(Index: integer): TSynHighlighterAttributes;
begin
Result := Attribs[TtkTokenKind(Index)];
end;
procedure TSynHP48Syn.SetAttrib(Index: integer; Value: TSynHighlighterAttributes);
begin
Attribs[TtkTokenKind(Index)].Assign(Value);
end;
procedure TSynHP48Syn.EndOfToken;
begin
while (Run <= Length(fLine)) and (FLine[Run] > ' ') do
Inc(Run);
end;
procedure TSynHP48Syn.Assign(Source: TPersistent);
var
i: TtkTokenKind;
begin
if Source is TSynHP48Syn then begin
for i := Low(Attribs) to High(Attribs) do begin
Attribs[i].Background := TSynHP48Syn(source).Attribs[i].Background;
Attribs[i].Foreground := TSynHP48Syn(source).Attribs[i].Foreground;
Attribs[i].Style := TSynHP48Syn(source).Attribs[i].Style;
end;
AsmKeyWords.Text := TSynHP48Syn(source).AsmKeyWords.Text;
RplKeyWords.Text := TSynHP48Syn(source).RplKeyWords.Text;
end
else
inherited Assign(Source);
end;
function TSynHP48Syn.GetAttribCount: integer;
begin
Result := Ord(High(Attribs)) - Ord(Low(Attribs)) + 1;
end;
function TSynHP48Syn.GetAttribute(idx: integer): TSynHighlighterAttributes;
begin // sorted by name
if (idx <= Ord(High(TtkTokenKind))) then
Result := Attribs[TtkTokenKind(idx)]
else
Result := nil;
end;
function TSynHP48Syn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterHP48;
end;
class function TSynHP48Syn.GetLanguageName: string;
begin
Result := SYNS_LangHP48;
end;
procedure TSynHP48Syn.SetHighLightChange;
var
i: TtkTokenKind;
begin
for i := Low(Attribs) to High(Attribs) do begin
Attribs[i].OnChange := @DefHighLightChange;
Attribs[i].InternalSaveDefaultValues;
end;
end;
function TSynHP48Syn.SasmProc1: TtkTokenKind;
var
i: integer;
s: string;
begin
Result := tksAsmKey;
if run > Length(fLine) then
exit;
if FLine[Run] = '*' then begin
frange := rssasm3;
result := tksAsmComment;
exit;
end;
if FLine[Run] >= ' ' then begin
i := run;
while (run <= Length(fLine)) and (FLine[run] > ' ') do
inc(run);
s := Copy(fLine, i, run - i);
if (s = 'RPL') or (s = 'ENDCODE') then begin
frange := rsRpl;
exit;
end;
end;
while (run <= Length(fLine)) and (FLine[run] <= ' ') and (FLine[run] <> #10) do
inc(run);
if run <= Length(fLine) then
frange := rssasm2
else
frange := rssasm1;
end;
function TSynHP48Syn.SasmProc2: TtkTokenKind;
var
i: integer;
s: string;
begin
Result := tksAsm;
while (run <= Length(fLine)) and (FLine[run] <= ' ') and (fline[run] <> #10) do
inc(run);
if run > 30 then begin
frange := rssasm3;
exit;
end;
i := run;
while (run <= Length(fLine)) and (FLine[run] > ' ') do
inc(run);
s := Copy(fLine, i, run - i);
if (s = 'ENDCODE') or (s = 'RPL') then begin
frange := rsRpl;
result := tksAsmKey;
end
else begin
if FSAsmNoField.Find(s) = nil then begin
while (run <= Length(fLine)) and (FLine[run] <= ' ') and (FLine[run] <> #10) do
inc(run);
while (run <= Length(fLine)) and (FLine[run] > ' ') do
inc(run);
while (run <= Length(fLine)) and (FLine[run] <= ' ') and (FLine[run] <> #10) do
inc(run);
end;
if run <= Length(fLine) then
frange := rssasm3
else
frange := rssasm1;
end;
end;
function TSynHP48Syn.SasmProc3: TtkTokenKind;
begin
Result := tksAsmComment;
while (run <= Length(fLine)) and (FLine[run] <> #10) do
inc(run);
if run <= Length(fLine) then inc(run);
frange := rssasm1;
end;
function TSynHP48Syn.GetTokenAttribute: TSynHighlighterAttributes;
begin
Result := GetAttrib(Ord(fTockenKind));
end;
function TSynHP48Syn.GetTokenKind: integer;
begin
Result := Ord(fTockenKind);
end;
function TSynHP48Syn.GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
begin
Result := nil;
end;
initialization
RegisterPlaceableHighlighter(TSynHP48Syn);
end.

View File

@ -0,0 +1,924 @@
{-------------------------------------------------------------------------------
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.
Code template generated with SynGen.
The original code is: SynHighlighterIDL.pas, released 2001-10-15.
Description: CORBA IDL Parser/Highlighter
The initial author of this file is P.L. Polak.
Copyright (c) 2001, all rights reserved.
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: SynHighlighterIDL.pas,v 1.9 2005/01/28 16:53:23 maelh Exp $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
-------------------------------------------------------------------------------}
unit SynHighlighterIDL;
{$I synedit.inc}
interface
uses
Graphics,
SynEditTypes,
SynEditHighlighter,
SysUtils,
Classes;
Type
TtkTokenKind = (
tkComment,
tkDatatype,
tkIdentifier,
tkKey,
tkNull,
tkNumber,
tkPreprocessor,
tkSpace,
tkString,
tkSymbol,
tkUnknown);
TRangeState = (rsUnKnown, rsComment, rsString, rsChar);
TProcTableProc = procedure of object;
PIdentFuncTableFunc = ^TIdentFuncTableFunc;
TIdentFuncTableFunc = function: TtkTokenKind of object;
const
MaxKey = 152;
type
TSynIdlSyn = class(TSynCustomHighlighter)
private
fLine: PChar;
fLineNumber: Integer;
fProcTable: array[#0..#255] of TProcTableProc;
fRange: TRangeState;
Run: LongInt;
fStringLen: Integer;
fToIdent: PChar;
fTokenPos: Integer;
fTokenID: TtkTokenKind;
fIdentFuncTable: array[0 .. MaxKey] of TIdentFuncTableFunc;
fCommentAttri: TSynHighlighterAttributes;
fDatatypeAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fPreprocessorAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
function KeyHash(ToHash: PChar): Integer;
function KeyComp(const aKey: string): Boolean;
function Func25: TtkTokenKind;
function Func32: TtkTokenKind;
function Func34: TtkTokenKind;
function Func43: TtkTokenKind;
function Func48: TtkTokenKind;
function Func52: TtkTokenKind;
function Func53: TtkTokenKind;
function Func54: TtkTokenKind;
function Func57: TtkTokenKind;
function Func58: TtkTokenKind;
function Func59: TtkTokenKind;
function Func60: TtkTokenKind;
function Func64: TtkTokenKind;
function Func65: TtkTokenKind;
function Func68: TtkTokenKind;
function Func69: TtkTokenKind;
function Func71: TtkTokenKind;
function Func76: TtkTokenKind;
function Func77: TtkTokenKind;
function Func78: TtkTokenKind;
function Func84: TtkTokenKind;
function Func85: TtkTokenKind;
function Func88: TtkTokenKind;
function Func89: TtkTokenKind;
function Func90: TtkTokenKind;
function Func92: TtkTokenKind;
function Func93: TtkTokenKind;
function Func95: TtkTokenKind;
function Func97: TtkTokenKind;
function Func98: TtkTokenKind;
function Func101: TtkTokenKind;
function Func102: TtkTokenKind;
function Func107: TtkTokenKind;
function Func108: TtkTokenKind;
function Func117: TtkTokenKind;
function Func120: TtkTokenKind;
function Func125: TtkTokenKind;
function Func128: TtkTokenKind;
function Func136: TtkTokenKind;
function Func152: TtkTokenKind;
procedure IdentProc;
procedure SymbolProc;
procedure UnknownProc;
function AltFunc: TtkTokenKind;
procedure InitIdent;
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
procedure NullProc;
procedure NumberProc;
procedure SpaceProc;
procedure CRProc;
procedure LFProc;
procedure CommentOpenProc;
procedure CommentProc;
procedure StringOpenProc;
procedure StringProc;
procedure CharOpenProc;
procedure CharProc;
procedure PreProcessorProc;
protected
function GetIdentChars: TSynIdentChars; override;
function GetSampleSource: string; override;
function IsFilterStored: Boolean; override;
public
constructor Create(AOwner: TComponent); override;
class function GetLanguageName: string; override;
function GetRange: Pointer; override;
procedure ResetRange; override;
procedure SetRange(Value: Pointer); override;
function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes; override;
function GetEol: Boolean; override;
function GetTokenID: TtkTokenKind;
procedure SetLine(const NewValue: String; LineNumber: Integer); override;
function GetToken: String; override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
published
property CommentAttri: TSynHighlighterAttributes read fCommentAttri write fCommentAttri;
property DatatypeAttri: TSynHighlighterAttributes read fDatatypeAttri write fDatatypeAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri write fIdentifierAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property NumberAttri: TSynHighlighterAttributes read fNumberAttri write fNumberAttri;
property PreprocessorAttri: TSynHighlighterAttributes read fPreprocessorAttri write fPreprocessorAttri;
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;
procedure MakeIdentTable;
var
I: Char;
begin
for I := #0 to #255 do
begin
case I of
'_', 'a'..'z', 'A'..'Z': Identifiers[I] := True;
else
Identifiers[I] := False;
end;
case I in ['_', 'A'..'Z', 'a'..'z'] of
True:
begin
if (I > #64) and (I < #91) then
mHashTable[I] := Ord(I) - 64
else if (I > #96) then
mHashTable[I] := Ord(I) - 95;
end;
else
mHashTable[I] := 0;
end;
end;
end;
procedure TSynIdlSyn.InitIdent;
var
I: Integer;
pF: PIdentFuncTableFunc;
begin
pF := PIdentFuncTableFunc(@fIdentFuncTable);
for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do
begin
pF^ := @AltFunc;
Inc(pF);
end;
fIdentFuncTable[25] := @Func25;
fIdentFuncTable[32] := @Func32;
fIdentFuncTable[34] := @Func34;
fIdentFuncTable[43] := @Func43;
fIdentFuncTable[48] := @Func48;
fIdentFuncTable[52] := @Func52;
fIdentFuncTable[53] := @Func53;
fIdentFuncTable[54] := @Func54;
fIdentFuncTable[57] := @Func57;
fIdentFuncTable[58] := @Func58;
fIdentFuncTable[59] := @Func59;
fIdentFuncTable[60] := @Func60;
fIdentFuncTable[64] := @Func64;
fIdentFuncTable[65] := @Func65;
fIdentFuncTable[68] := @Func68;
fIdentFuncTable[69] := @Func69;
fIdentFuncTable[71] := @Func71;
fIdentFuncTable[76] := @Func76;
fIdentFuncTable[77] := @Func77;
fIdentFuncTable[78] := @Func78;
fIdentFuncTable[84] := @Func84;
fIdentFuncTable[85] := @Func85;
fIdentFuncTable[88] := @Func88;
fIdentFuncTable[89] := @Func89;
fIdentFuncTable[90] := @Func90;
fIdentFuncTable[92] := @Func92;
fIdentFuncTable[93] := @Func93;
fIdentFuncTable[95] := @Func95;
fIdentFuncTable[97] := @Func97;
fIdentFuncTable[98] := @Func98;
fIdentFuncTable[101] := @Func101;
fIdentFuncTable[102] := @Func102;
fIdentFuncTable[107] := @Func107;
fIdentFuncTable[108] := @Func108;
fIdentFuncTable[117] := @Func117;
fIdentFuncTable[120] := @Func120;
fIdentFuncTable[125] := @Func125;
fIdentFuncTable[128] := @Func128;
fIdentFuncTable[136] := @Func136;
fIdentFuncTable[152] := @Func152;
end;
function TSynIdlSyn.KeyHash(ToHash: PChar): Integer;
begin
Result := 0;
while ToHash^ in ['_', 'a'..'z', 'A'..'Z'] do
begin
inc(Result, mHashTable[ToHash^]);
inc(ToHash);
end;
fStringLen := ToHash - fToIdent;
end;
function TSynIdlSyn.KeyComp(const aKey :string) :Boolean;
var
I: Integer;
Temp: PChar;
begin
Temp := fToIdent;
if Length(aKey) = fStringLen then
begin
Result := True;
for i := 1 to fStringLen do
begin
if Temp^ <> aKey[i] then
begin
Result := False;
break;
end;
inc(Temp);
end;
end else Result := False;
end;
function TSynIdlSyn.Func25: TtkTokenKind;
begin
if KeyComp('in') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func32: TtkTokenKind;
begin
if KeyComp('case') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func34: TtkTokenKind;
begin
if KeyComp('char') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func43: TtkTokenKind;
begin
if KeyComp('FALSE') then Result := tkKey else
if KeyComp('any') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func48: TtkTokenKind;
begin
if KeyComp('local') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func52: TtkTokenKind;
begin
if KeyComp('long') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func53: TtkTokenKind;
begin
if KeyComp('fixed') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func54: TtkTokenKind;
begin
if KeyComp('void') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func57: TtkTokenKind;
begin
if KeyComp('enum') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func58: TtkTokenKind;
begin
if KeyComp('wchar') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func59: TtkTokenKind;
begin
if KeyComp('out') then Result := tkKey else
if KeyComp('float') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func60: TtkTokenKind;
begin
if KeyComp('Object') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func64: TtkTokenKind;
begin
if KeyComp('TRUE') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func65: TtkTokenKind;
begin
if KeyComp('double') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func68: TtkTokenKind;
begin
if KeyComp('octet') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func69: TtkTokenKind;
begin
if KeyComp('public') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func71: TtkTokenKind;
begin
if KeyComp('boolean') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func76: TtkTokenKind;
begin
if KeyComp('default') then Result := tkKey else
if KeyComp('const') then Result := tkKey else
if KeyComp('module') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func77: TtkTokenKind;
begin
if KeyComp('raises') then Result := tkKey else
if KeyComp('native') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func78: TtkTokenKind;
begin
if KeyComp('union') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func84: TtkTokenKind;
begin
if KeyComp('inout') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func85: TtkTokenKind;
begin
if KeyComp('short') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func88: TtkTokenKind;
begin
if KeyComp('switch') then Result := tkKey else
if KeyComp('typedef') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func89: TtkTokenKind;
begin
if KeyComp('oneway') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func90: TtkTokenKind;
begin
if KeyComp('interface') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func92: TtkTokenKind;
begin
if KeyComp('abstract') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func93: TtkTokenKind;
begin
if KeyComp('string') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func95: TtkTokenKind;
begin
if KeyComp('factory') then Result := tkKey else
if KeyComp('ValueBase') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func97: TtkTokenKind;
begin
if KeyComp('custom') then Result := tkKey else
if KeyComp('sequence') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func98: TtkTokenKind;
begin
if KeyComp('private') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func101: TtkTokenKind;
begin
if KeyComp('unsigned') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func102: TtkTokenKind;
begin
if KeyComp('readonly') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func107: TtkTokenKind;
begin
if KeyComp('struct') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func108: TtkTokenKind;
begin
if KeyComp('context') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func117: TtkTokenKind;
begin
if KeyComp('wstring') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynIdlSyn.Func120: TtkTokenKind;
begin
if KeyComp('exception') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func125: TtkTokenKind;
begin
if KeyComp('attribute') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func128: TtkTokenKind;
begin
if KeyComp('truncatable') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func136: TtkTokenKind;
begin
if KeyComp('valuetype') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.Func152: TtkTokenKind;
begin
if KeyComp('supports') then Result := tkKey else Result := tkIdentifier;
end;
function TSynIdlSyn.AltFunc: TtkTokenKind;
begin
Result := tkIdentifier;
end;
function TSynIdlSyn.IdentKind(MayBe: PChar): TtkTokenKind;
var
HashKey: Integer;
begin
fToIdent := MayBe;
HashKey := KeyHash(MayBe);
if HashKey <= MaxKey then
Result := fIdentFuncTable[HashKey]()
else
Result := tkIdentifier;
end;
procedure TSynIdlSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
#0 : fProcTable[I] := @NullProc;
#10 : fProcTable[I] := @LFProc;
#13 : fProcTable[I] := @CRProc;
'/' : fProcTable[I] := @CommentOpenProc;
'"' : fProcTable[I] := @StringOpenProc;
'''' : fProcTable[I] := @CharOpenProc;
'#' : fProcTable[I] := @PreProcessorProc;
#1..#9,
#11,
#12,
#14..#32 : fProcTable[I] := @SpaceProc;
'A'..'Z',
'a'..'z',
'_' : fProcTable[I] := @IdentProc;
'0'..'9' : fProcTable[I] := @NumberProc;
'-', '+',
'*', '\',
',', '.',
'[', ']',
'{', '}',
'<', '>',
'(', ')',
'=', '?',
':', ';' : fProcTable[I] := @SymbolProc;
else
fProcTable[I] := @UnknownProc;
end;
end;
procedure TSynIdlSyn.SpaceProc;
begin
fTokenID := tkSpace;
repeat
inc(Run);
until not (fLine[Run] in [#1..#32]);
end;
procedure TSynIdlSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynIdlSyn.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; { NumberProc }
procedure TSynIdlSyn.CRProc;
begin
fTokenID := tkSpace;
inc(Run);
if fLine[Run] = #10 then
inc(Run);
end;
procedure TSynIdlSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynIdlSyn.CommentOpenProc;
begin
Inc(Run);
if (fLine[Run] = '*') then
begin
fRange := rsComment;
CommentProc;
fTokenID := tkComment;
end
else if (fLine[Run] = '/') then
begin
while not (fLine[Run] in [#0, #10, #13]) do
Inc(Run);
fTokenID := tkComment;
end
else
fTokenID := tkSymbol;
end;
procedure TSynIdlSyn.CommentProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
begin
fTokenID := tkComment;
repeat
if (fLine[Run] = '*') and
(fLine[Run + 1] = '/') then
begin
Inc(Run, 2);
fRange := rsUnKnown;
Break;
end;
if not (fLine[Run] in [#0, #10, #13]) then
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
end;
end;
procedure TSynIdlSyn.StringOpenProc;
begin
Inc(Run);
fRange := rsString;
StringProc;
fTokenID := tkString;
end;
procedure TSynIdlSyn.StringProc;
begin
fTokenID := tkString;
repeat
if (fLine[Run] = '"') then
begin
Inc(Run);
fRange := rsUnKnown;
Break;
end
else if (fLine[Run] = '\') then
Inc(Run);
if not (fLine[Run] in [#0, #10, #13]) then
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
procedure TSynIdlSyn.CharOpenProc;
begin
Inc(Run);
fRange := rsChar;
CharProc;
fTokenID := tkString;
end;
procedure TSynIdlSyn.CharProc;
begin
fTokenID := tkString;
repeat
if (fLine[Run] = '''') then
begin
Inc(Run);
fRange := rsUnKnown;
Break;
end;
if not (fLine[Run] in [#0, #10, #13]) then
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
procedure TSynIdlSyn.PreProcessorProc;
var
Directive: String;
begin
Directive := '';
while not (fLine[Run] in [#0, #9, #10, #13, #32]) do
begin
Directive := Directive + fLine[Run];
Inc(Run);
end;
if (AnsiCompareStr(Directive, '#include') = 0) then
fTokenID := tkPreprocessor
else if (AnsiCompareStr(Directive, '#pragma') = 0) then
fTokenID := tkPreprocessor
else
fTokenID := tkIdentifier;
end; { PreProcessorProc }
constructor TSynIdlSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCommentAttri := TSynHighLighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style := [fsItalic];
fCommentAttri.Foreground := clNavy;
AddAttribute(fCommentAttri);
fDatatypeAttri := TSynHighLighterAttributes.Create(SYNS_AttrDatatype);
fDatatypeAttri.Style := [fsBold];
fDatatypeAttri.Foreground := clTeal;
AddAttribute(fDatatypeAttri);
fIdentifierAttri := TSynHighLighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighLighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighLighterAttributes.Create(SYNS_AttrNumber);
fNumberAttri.Foreground := clBlue;
AddAttribute(fNumberAttri);
fPreprocessorAttri := TSynHighLighterAttributes.Create(SYNS_AttrPreprocessor);
fPreprocessorAttri.Foreground := clRed;
AddAttribute(fPreprocessorAttri);
fSpaceAttri := TSynHighLighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighLighterAttributes.Create(SYNS_AttrString);
fStringAttri.Foreground := clBlue;
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighLighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
SetAttributesOnChange(@DefHighlightChange);
InitIdent;
MakeMethodTables;
fDefaultFilter := SYNS_FilterCORBAIDL;
fRange := rsUnknown;
end;
procedure TSynIdlSyn.SetLine(const NewValue: String; LineNumber: Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynIdlSyn.IdentProc;
begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
while Identifiers[fLine[Run]] do
Inc(Run);
end;
procedure TSynIdlSyn.SymbolProc;
begin
Inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynIdlSyn.UnknownProc;
begin
inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynIdlSyn.Next;
begin
fTokenPos := Run;
case fRange of
rsComment: CommentProc;
else
begin
fRange := rsUnknown;
fProcTable[fLine[Run]];
end;
end;
end;
function TSynIdlSyn.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_SYMBOL : Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynIdlSyn.GetEol: Boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynIdlSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
{$IFDEF SYN_LAZARUS}
procedure TSynIdlSyn.GetTokenEx(out TokenStart :PChar; out TokenLength :integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
function TSynIdlSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynIdlSyn.GetTokenAttribute :TSynHighlighterAttributes;
begin
case GetTokenID of
tkComment: Result := fCommentAttri;
tkDatatype: Result := fDatatypeAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkPreprocessor: Result := fPreprocessorAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fIdentifierAttri;
else
Result := nil;
end;
end;
function TSynIdlSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynIdlSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSynIdlSyn.GetIdentChars: TSynIdentChars;
begin
Result := ['_', 'a'..'z', 'A'..'Z'] + TSynSpecialChars;
end;
function TSynIdlSyn.GetSampleSource: string;
begin
Result := '/* CORBA IDL sample source */'#13#10 +
'#include <sample.idl>'#13#10 +
#13#10 +
'const string TestString = "Hello World";'#13#10 +
'const long TestLong = 10;'#13#10 +
#13#10 +
'module TestModule {'#13#10 +
' interface DemoInterface {'#13#10 +
' boolean HelloWorld(in string Message);'#13#10 +
' }'#13#10 +
'}';
end;
function TSynIdlSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterCORBAIDL;
end;
class function TSynIdlSyn.GetLanguageName: string;
begin
Result := SYNS_LangCORBAIDL;
end;
procedure TSynIdlSyn.ResetRange;
begin
fRange := rsUnknown;
end;
procedure TSynIdlSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
function TSynIdlSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
initialization
MakeIdentTable;
RegisterPlaceableHighlighter(TSynIdlSyn);
end.

View File

@ -0,0 +1,967 @@
{-------------------------------------------------------------------------------
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.
$Id: SynHighlighterInno.pas,v 1.23 2005/01/28 16:53:23 maelh 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://www.wintax.nl/isx/ for My Inno Setup Extensions.
}
unit SynHighlighterInno;
{$I synedit.inc}
interface
uses
Graphics,
SynEditTypes,
SynEditHighlighter,
SynHighlighterHashEntries,
Classes;
type
TtkTokenKind = (tkComment, tkConstant, tkIdentifier, tkKey, tkKeyOrParameter,
tkNull, tkNumber, tkParameter, tkSection, tkSpace, tkString, tkSymbol,
tkUnknown);
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;
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;
function IsFilterStored: Boolean; 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 GetToken: string; override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenID: TtkTokenKind;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
procedure SetLine(const NewValue: string; LineNumber:Integer); override;
function GetSampleSource :string; override;
published
property ConstantAttri: TSynHighlighterAttributes read fConstantAttri
write fConstantAttri;
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
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,SynEditStrConstExtra;
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}
Keywords: string =
'AdminPrivilegesRequired,AllowNoIcons,AllowRootDirectory,AllowUNCPath,' +
'AlwaysCreateUninstallIcon,AlwaysRestart,AlwaysShowComponentsList,' +
'AlwaysShowDirOnReadyPage,AlwaysShowGroupOnReadyPage,' +
'AlwaysUsePersonalGroup,AppCopyright,AppId,AppMutex,AppName,AppPublisher,' +
'AppPublisherURL,AppSupportURL,AppUpdatesURL,AppVerName,AppVersion,' +
'Attribs,BackColor,BackColor2,BackColorDirection,BackSolid,Bits,' +
'ChangesAssociations,Check,CodeFile,Comment,Components,Compression,CompressLevel,CopyMode,'+
'CreateAppDir,CreateUninstallRegKey,DefaultDirName,DefaultGroupName,' +
'Description,DestDir,DestName,DirExistsWarning,DisableAppendDir,' +
'DisableDirExistsWarning,DisableDirPage,DisableFinishedPage,' +
'DisableProgramGroupPage,DisableReadyMemo,DisableReadyPage,' +
'DisableStartupPrompt,DiskClusterSize,DiskSize,DiskSpaceMBLabel,' +
'DiskSpanning,DontMergeDuplicateFiles,EnableDirDoesntExistWarning,' +
'ExtraDiskSpaceRequired,Filename,Flags,FlatComponentsList,FontInstall,' +
'GroupDescription,HotKey,IconFilename,IconIndex,InfoAfterFile,InfoBeforeFile,' +
'InstallMode,InternalCompressLevel,Key,LicenseFile,MessagesFile,MinVersion,Name,' +
'OnlyBelowVersion,OutputBaseFilename,OutputDir,OverwriteUninstRegEntries,' +
'Parameters,Password,ReserveBytes,Root,RunOnceId,Section,' +
'ShowComponentSizes,Source,SourceDir,StatusMsg,Subkey,Tasks,Type,Types,' +
'UninstallDisplayIcon,UninstallDisplayName,UninstallFilesDir,' +
'UninstallIconName,UninstallLogMode,UninstallStyle,Uninstallable,' +
'UpdateUninstallLogAppName,UsePreviousAppDir,UsePreviousGroup,' +
'UsePreviousTasks,UsePreviousSetupType,UseSetupLdr,ValueData,ValueName,' +
'ValueType,WindowResizable,WindowShowCaption,WindowStartMaximized,' +
'WindowVisible,WizardImageBackColor,WizardImageFile,WizardSmallImageFile,' +
'WizardStyle,WorkingDir';
Parameters: string =
'HKCC,HKCR,HKCU,HKLM,HKU,alwaysoverwrite,alwaysskipifsameorolder,append,' +
'binary,classic,closeonexit,comparetimestampalso,confirmoverwrite,' +
'createkeyifdoesntexist,createonlyiffileexists,createvalueifdoesntexist,' +
'deleteafterinstall,deletekey,deletevalue,dirifempty,dontcloseonexit,' +
'dontcreatekey,disablenouninstallwarning,dword,exclusive,expandsz,' +
'external,files,filesandordirs,fixed,fontisnttruetype,iscustom,isreadme,' +
'modern,multisz,new,noerror,none,normal,nowait,onlyifdestfileexists,' +
'onlyifdoesntexist,overwrite,overwritereadonly,postinstall,' +
'preservestringtype,regserver,regtypelib,restart,restartreplace,' +
'runmaximized,runminimized,sharedfile,shellexec,showcheckbox,' +
'skipifnotsilent,skipifsilent,silent,skipifdoesntexist,' +
'skipifsourcedoesntexist,unchecked,uninsalwaysuninstall,' +
'uninsclearvalue,uninsdeleteentry,uninsdeletekey,uninsdeletekeyifempty,' +
'uninsdeletesection,uninsdeletesectionifempty,uninsdeletevalue,' +
'uninsneveruninstall,useapppaths,verysilent,waituntilidle';
KeyOrParameter: string = 'string';
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);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
fStringAttri.Foreground := clBlue;
AddAttribute(fStringAttri);
fConstantAttri := TSynHighlighterAttributes.Create(SYNS_AttrDirective);
fConstantAttri.Style := [fsBold, fsItalic];
fConstantAttri.Foreground := clTeal;
AddAttribute(fConstantAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
//Parameters
fParamAttri := TSynHighlighterAttributes.Create(SYNS_AttrPreprocessor);
fParamAttri.Style := [fsBold];
fParamAttri.Foreground := clOlive;
AddAttribute(fParamAttri);
fSectionAttri := TSynHighlighterAttributes.Create(SYNS_AttrSection);
fSectionAttri.Style := [fsBold];
fSectionAttri.Foreground := clRed;
AddAttribute(fSectionAttri);
SetAttributesOnChange(@DefHighlightChange);
EnumerateKeywords(Ord(tkKey), Keywords, IdentChars, @DoAddKeyword);
EnumerateKeywords(Ord(tkParameter), Parameters, IdentChars, @DoAddKeyword);
EnumerateKeywords(Ord(tkKeyOrParameter), KeyOrParameter, IdentChars,
@DoAddKeyword);
MakeMethodTables;
fDefaultFilter := SYNS_FilterInno;
end;
destructor TSynInnoSyn.Destroy;
begin
fKeywords.Free;
inherited Destroy;
end;
procedure TSynInnoSyn.SetLine(const NewValue: string; LineNumber: Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
function TSynInnoSyn.GetSampleSource :string;
begin
Result:='; Inno Setup '+LineEnding+
'; Copyright (C) 1997-2012 Jordan Russell. All rights reserved.'+LineEnding+
'; Portions by Martijn Laan'+LineEnding+
'; For conditions of distribution and use, see LICENSE.TXT.'+LineEnding+
';'+LineEnding+
'; Setup script'+LineEnding+LineEnding+
'[Setup]'+LineEnding+
'AppName=Inno Setup'+LineEnding+
'AppId=Inno Setup 5'+LineEnding+
'AppVersion=5.5.5'+LineEnding+
'AppPublisher=jrsoftware.org'+LineEnding+
'AppPublisherURL=http://www.innosetup.com/'+LineEnding+
'AppSupportURL=http://www.innosetup.com/'+LineEnding+
'AppUpdatesURL=http://www.innosetup.com/'+LineEnding+
'VersionInfoCopyright=Copyright (C) 1997-2012 Jordan Russell. Portions Copyright (C) 2000-2012 Martijn Laan.'+LineEnding+
'AppMutex=InnoSetupCompilerAppMutex,Global\InnoSetupCompilerAppMutex'+LineEnding+
'MinVersion=0,5.0'+LineEnding+
'DefaultDirName={pf}\Inno Setup 5'+LineEnding+
'DefaultGroupName=Inno Setup 5'+LineEnding+
'AllowNoIcons=yes'+LineEnding+
'Compression=lzma2/max'+LineEnding+
'SolidCompression=yes'+LineEnding+
'Uninstallable=not PortableCheck'+LineEnding+
'UninstallDisplayIcon={app}\Compil32.exe'+LineEnding+
'LicenseFile=license.txt'+LineEnding+
'TimeStampsInUTC=yes'+LineEnding+
'TouchDate=none'+LineEnding+
'TouchTime=00:00'+LineEnding+
'WizardImageFile=compiler:WizModernImage-IS.bmp'+LineEnding+
'WizardSmallImageFile=compiler:WizModernSmallImage-IS.bmp'+LineEnding+
'#ifndef NOSIGNTOOL'+LineEnding+
'SignTool=issigntool'+LineEnding+
'SignedUninstaller=yes'+LineEnding+
'#endif'+LineEnding+LineEnding+
'[Languages]'+LineEnding+
'Name: en; MessagesFile: "files\Default.isl"'+LineEnding+
'Name: br; MessagesFile: "files\Languages\BrazilianPortuguese.isl"'+LineEnding+
'Name: ca; MessagesFile: "files\Languages\Catalan.isl"'+LineEnding+
'Name: co; MessagesFile: "files\Languages\Corsican.isl"'+LineEnding+
'Name: cz; MessagesFile: "files\Languages\Czech.isl"'+LineEnding+
'Name: da; MessagesFile: "files\Languages\Danish.isl"'+LineEnding+
'Name: nl; MessagesFile: "files\Languages\Dutch.isl"'+LineEnding+
'Name: fi; MessagesFile: "files\Languages\Finnish.isl"'+LineEnding+
'Name: fr; MessagesFile: "files\Languages\French.isl"'+LineEnding+
'Name: de; MessagesFile: "files\Languages\German.isl"'+LineEnding+
'Name: gr; MessagesFile: "files\Languages\Greek.isl"'+LineEnding+
'Name: he; MessagesFile: "files\Languages\Hebrew.isl"'+LineEnding+
'Name: hu; MessagesFile: "files\Languages\Hungarian.isl"'+LineEnding+
'Name: it; MessagesFile: "files\Languages\Italian.isl"'+LineEnding+
'Name: ja; MessagesFile: "files\Languages\Japanese.isl"'+LineEnding+
'#ifdef UNICODE'+LineEnding+
'Name: nep; MessagesFile: "files\Languages\Nepali.islu"'+LineEnding+
'#endif'+LineEnding+
'Name: no; MessagesFile: "files\Languages\Norwegian.isl"'+LineEnding+
'Name: pl; MessagesFile: "files\Languages\Polish.isl"'+LineEnding+
'Name: pt; MessagesFile: "files\Languages\Portuguese.isl"'+LineEnding+
'Name: ru; MessagesFile: "files\Languages\Russian.isl"'+LineEnding+
'Name: sg; MessagesFile: "files\Languages\ScottishGaelic.isl"'+LineEnding+
'Name: se; MessagesFile: "files\Languages\SerbianLatin.isl"'+LineEnding+
'Name: se2; MessagesFile: "files\Languages\SerbianCyrillic.isl"'+LineEnding+
'Name: sl2; MessagesFile: "files\Languages\Slovenian.isl"'+LineEnding+
'Name: sp; MessagesFile: "files\Languages\Spanish.isl"'+LineEnding+
'Name: tu; MessagesFile: "files\Languages\Turkish.isl"'+LineEnding+
'Name: uk; MessagesFile: "files\Languages\Ukrainian.isl"'+LineEnding+LineEnding+
'[Messages]'+LineEnding+
'; two "Setup" on the same line looks weird, so put a line break in between'+LineEnding+
'en.WelcomeLabel1=Welcome to the Inno Setup%nSetup Wizard'+LineEnding+LineEnding+
'[Tasks]'+LineEnding+
'Name: desktopicon; Description: "{cm:CreateDesktopIcon}"; Flags: unchecked'+LineEnding+
'Name: fileassoc; Description: "{cm:AssocFileExtension,Inno Setup,.iss}"'+LineEnding+LineEnding+
'[InstallDelete]'+LineEnding+
'; Remove Unicode-only files if needed'+LineEnding+
'#ifndef UNICODE'+LineEnding+
'Type: files; Name: "{app}\Languages\Nepali.islu"'+LineEnding+
'#endif'+LineEnding+
'; Remove ISPP files if needed'+LineEnding+
'Type: files; Name: "{app}\ISPP.dll"; Check: not ISPPCheck'+LineEnding+
'Type: files; Name: "{app}\ISPPBuiltins.iss"; Check: not ISPPCheck'+LineEnding+
'; Remove old ISPP files'+LineEnding+
'Type: files; Name: "{app}\ISCmplr.dls"'+LineEnding+
'Type: files; Name: "{app}\Builtins.iss"'+LineEnding+
'; Older versions created the desktop icon under {userdesktop}'+LineEnding+
'Type: files; Name: "{userdesktop}\Inno Setup Compiler.lnk"'+LineEnding+LineEnding+
'[Files]'+LineEnding+
'; Files used by [Code] first so these can be quickly decompressed despite solid compression'+LineEnding+
'Source: "files\ISPP.ico"; Flags: dontcopy'+LineEnding+
'; Other files'+LineEnding+
'Source: "license.txt"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "ishelp\Staging\ISetup.chm"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Compil32.exe"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\isscint.dll"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\ISCC.exe"; DestDir: "{app}"; Flags: ignoreversion touch; Check: not ISPPCheck'+LineEnding+
'Source: "files\ISCmplr.dll"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Setup.e32"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\SetupLdr.e32"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Default.isl"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\BrazilianPortuguese.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Catalan.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Corsican.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Czech.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Danish.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Dutch.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\French.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Finnish.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\German.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Greek.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Hebrew.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Hungarian.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Italian.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Japanese.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'#ifdef UNICODE'+LineEnding+
'Source: "files\Languages\Nepali.islu"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'#endif'+LineEnding+
'Source: "files\Languages\Norwegian.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Polish.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Portuguese.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Russian.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\ScottishGaelic.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\SerbianCyrillic.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\SerbianLatin.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Slovenian.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Spanish.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Turkish.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\Languages\Ukrainian.isl"; DestDir: "{app}\Languages"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\WizModernImage.bmp"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\WizModernImage-IS.bmp"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\WizModernSmallImage.bmp"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\WizModernSmallImage-IS.bmp"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\iszlib.dll"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\isunzlib.dll"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\isbzip.dll"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\isbunzip.dll"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\islzma.dll"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\islzma32.exe"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\islzma64.exe"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "whatsnew.htm"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "ishelp\isfaq.htm"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\Example1.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\Example2.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\Example3.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\64Bit.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\64BitThreeArch.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\64BitTwoArch.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\Components.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\Languages.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\MyProg.exe"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\MyProg-x64.exe"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\MyProg-IA64.exe"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\MyProg.chm"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\Readme.txt"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\Readme-Dutch.txt"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\Readme-German.txt"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\CodeExample1.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\CodeDlg.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\CodeClasses.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\CodeDll.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\CodeAutomation.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\CodeAutomation2.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\CodePrepareToInstall.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\UninstallCodeExample1.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\MyDll.dll"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\MyDll\C\MyDll.c"; DestDir: "{app}\Examples\MyDll\C"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\MyDll\C\MyDll.def"; DestDir: "{app}\Examples\MyDll\C"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\MyDll\C\MyDll.dsp"; DestDir: "{app}\Examples\MyDll\C"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\MyDll\Delphi\MyDll.dpr"; DestDir: "{app}\Examples\MyDll\Delphi"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\ISPPExample1.iss"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'Source: "Examples\ISPPExample1License.txt"; DestDir: "{app}\Examples"; Flags: ignoreversion touch'+LineEnding+
'; ISPP files'+LineEnding+
'Source: "Projects\ISPP\Help\Staging\ISPP.chm"; DestDir: "{app}"; Flags: ignoreversion touch'+LineEnding+
'Source: "files\ISPPCC.exe"; DestDir: "{app}"; DestName: "ISCC.exe"; Flags: ignoreversion touch; Check: ISPPCheck'+LineEnding+
'Source: "files\ISPP.dll"; DestDir: "{app}"; Flags: ignoreversion touch; Check: ISPPCheck'+LineEnding+
'Source: "files\ISPPBuiltins.iss"; DestDir: "{app}"; Flags: ignoreversion touch; Check: ISPPCheck'+LineEnding+LineEnding+
'[Icons]'+LineEnding+
'Name: "{group}\Inno Setup Compiler"; Filename: "{app}\Compil32.exe"; WorkingDir: "{app}"; AppUserModelID: "JR'+
'.InnoSetup.IDE.5"'+LineEnding+
'Name: "{group}\Inno Setup Documentation"; Filename: "{app}\ISetup.chm"'+LineEnding+
'Name: "{group}\Inno Setup Example Scripts"; Filename: "{app}\Examples\"'+LineEnding+
'Name: "{group}\Inno Setup FAQ"; Filename: "{app}\isfaq.htm"'+LineEnding+
'Name: "{group}\Inno Setup Revision History"; Filename: "{app}\whatsnew.htm"'+LineEnding+
'Name: "{commondesktop}\Inno Setup Compiler"; Filename: "{app}\Compil32.exe"; WorkingDir: "{app}"; AppUserMode'+
'lID: "JR.InnoSetup.IDE.5"; Tasks: desktopicon'+LineEnding+LineEnding+
'[Run]'+LineEnding+
'Filename: "{app}\Compil32.exe"; Parameters: "/ASSOC"; StatusMsg: "{cm:AssocingFileExtension,Inno Setup,.iss}"'+
'; Tasks: fileassoc'+LineEnding+
'Filename: "{app}\Compil32.exe"; WorkingDir: "{app}"; Description: "{cm:LaunchProgram,Inno Setup}"; Flags: now'+
'ait postinstall skipifsilent'+LineEnding+LineEnding+
'[UninstallRun]'+LineEnding+
'Filename: "{app}\Compil32.exe"; Parameters: "/UNASSOC"; RunOnceId: "RemoveISSAssoc"'+LineEnding+LineEnding+
'[CustomMessages]'+LineEnding+
'ISPPTitle=Inno Setup Preprocessor'+LineEnding+
'ISPPSubtitle=Would you like to install Inno Setup Preprocessor?'+LineEnding+
'ISPPText=Inno Setup Preprocessor (ISPP) is an official add-on for Inno Setup. ISPP allows you to conditionall'+
'y compile parts of scripts, to use compile time variables in your scripts and to use built-in functions which'+
'for example can read from the registry or INI files at compile time.%n%nISPP also contains a special version '+
'of the ISCC command line compiler which can take variable definitions as command line parameters and use them'+
'during compilation.'+LineEnding+
'ISPPText2=Select whether you would like to install ISPP, then click Next.'+LineEnding+
'ISPPCheck=&Install Inno Setup Preprocessor'+LineEnding+LineEnding+
'[Code]'+LineEnding+
'var'+LineEnding+
' ISPPPage: TWizardPage;'+LineEnding+
' ISPPCheckBox: TCheckBox;'+LineEnding+LineEnding+
'function GetModuleHandle(lpModuleName: LongInt): LongInt;'+LineEnding+
'external ''GetModuleHandleA@kernel32.dll stdcall'';'+LineEnding+
'function ExtractIcon(hInst: LongInt; lpszExeFileName: AnsiString; nIconIndex: LongInt): LongInt;'+LineEnding+
'external ''ExtractIconA@shell32.dll stdcall'';'+LineEnding+
'function DrawIconEx(hdc: LongInt; xLeft, yTop: Integer; hIcon: LongInt; cxWidth, cyWidth: Integer; istepIfAni'+
'Cur: LongInt; hbrFlickerFreeDraw, diFlags: LongInt): LongInt;'+LineEnding+
'external ''DrawIconEx@user32.dll stdcall'';'+LineEnding+
'function DestroyIcon(hIcon: LongInt): LongInt;'+LineEnding+
'external ''DestroyIcon@user32.dll stdcall'';'+LineEnding+LineEnding+
'const'+LineEnding+
' DI_NORMAL = 3;'+LineEnding+LineEnding+
'function CreateCustomOptionPage(AAfterId: Integer; ACaption, ASubCaption, AIconFileName, ALabel1Caption, ALab'+
'el2Caption,'+LineEnding+
' ACheckCaption: String; var CheckBox: TCheckBox): TWizardPage;'+LineEnding+
'var'+LineEnding+
' Page: TWizardPage;'+LineEnding+
' Rect: TRect;'+LineEnding+
' hIcon: LongInt;'+LineEnding+
' Label1, Label2: TNewStaticText;'+LineEnding+
'begin'+LineEnding+
' Page := CreateCustomPage(AAfterID, ACaption, ASubCaption);'+LineEnding+LineEnding+
' try'+LineEnding+
' AIconFileName := ExpandConstant(''{tmp}\'' + AIconFileName);'+LineEnding+
' if not FileExists(AIconFileName) then'+LineEnding+
' ExtractTemporaryFile(ExtractFileName(AIconFileName));'+LineEnding+LineEnding+
' Rect.Left := 0;'+LineEnding+
' Rect.Top := 0;'+LineEnding+
' Rect.Right := 32;'+LineEnding+
' Rect.Bottom := 32;'+LineEnding+LineEnding+
' hIcon := ExtractIcon(GetModuleHandle(0), AIconFileName, 0);'+LineEnding+
' try'+LineEnding+
' with TBitmapImage.Create(Page) do begin'+LineEnding+
' with Bitmap do begin'+LineEnding+
' Width := 32;'+LineEnding+
' Height := 32;'+LineEnding+
' Canvas.Brush.Color := WizardForm.Color;'+LineEnding+
' Canvas.FillRect(Rect);'+LineEnding+
' DrawIconEx(Canvas.Handle, 0, 0, hIcon, 32, 32, 0, 0, DI_NORMAL);'+LineEnding+
' end;'+LineEnding+
' Parent := Page.Surface;'+LineEnding+
' end;'+LineEnding+
' finally'+LineEnding+
' DestroyIcon(hIcon);'+LineEnding+
' end;'+LineEnding+
' except'+LineEnding+
' end;'+LineEnding+LineEnding+
' Label1 := TNewStaticText.Create(Page);'+LineEnding+
' with Label1 do begin'+LineEnding+
' AutoSize := False;'+LineEnding+
' Left := WizardForm.SelectDirLabel.Left;'+LineEnding+
' Width := Page.SurfaceWidth - Left;'+LineEnding+
' WordWrap := True;'+LineEnding+
' Caption := ALabel1Caption;'+LineEnding+
' Parent := Page.Surface;'+LineEnding+
' end;'+LineEnding+
' WizardForm.AdjustLabelHeight(Label1);'+LineEnding+LineEnding+
' Label2 := TNewStaticText.Create(Page);'+LineEnding+
' with Label2 do begin'+LineEnding+
' Top := Label1.Top + Label1.Height + ScaleY(12);'+LineEnding+
' Caption := ALabel2Caption;'+LineEnding+
' Parent := Page.Surface;'+LineEnding+
' end;'+LineEnding+
' WizardForm.AdjustLabelHeight(Label2);'+LineEnding+LineEnding+
' CheckBox := TCheckBox.Create(Page);'+LineEnding+
' with CheckBox do begin'+LineEnding+
' Top := Label2.Top + Label2.Height + ScaleY(12);'+LineEnding+
' Width := Page.SurfaceWidth;'+LineEnding+
' Caption := ACheckCaption;'+LineEnding+
' Parent := Page.Surface;'+LineEnding+
' end;'+LineEnding+LineEnding+
' Result := Page;'+LineEnding+
'end;'+LineEnding+LineEnding+
'procedure CreateCustomPages;'+LineEnding+
'var'+LineEnding+
' Caption, SubCaption1, IconFileName, Label1Caption, Label2Caption, CheckCaption: String;'+LineEnding+
'begin'+LineEnding+
' Caption := CustomMessage(''ISPPTitle'');'+LineEnding+
' SubCaption1 := CustomMessage(''ISPPSubtitle'');'+LineEnding+
' IconFileName := ''ISPP.ico'';'+LineEnding+
' Label1Caption := CustomMessage(''ISPPText'');'+LineEnding+
' Label2Caption := CustomMessage(''ISPPText2'');'+LineEnding+
' CheckCaption := CustomMessage(''ISPPCheck'');'+LineEnding+LineEnding+
' ISPPPage := CreateCustomOptionPage(wpSelectProgramGroup, Caption, SubCaption1, IconFileName, Label1Caption,'+
' Label2Caption, CheckCaption, ISPPCheckBox);'+LineEnding+
'end;'+LineEnding+LineEnding+
'procedure InitializeWizard;'+LineEnding+
'begin'+LineEnding+
' CreateCustomPages;'+LineEnding+LineEnding+
' ISPPCheckBox.Checked := (GetPreviousData(''ISPP'', ''1'') = ''1'') or (ExpandConstant(''{param:ispp|0}'') ='+
' ''1'');'+LineEnding+
'end;'+LineEnding+LineEnding+
'procedure RegisterPreviousData(PreviousDataKey: Integer);'+LineEnding+
'begin'+LineEnding+
' SetPreviousData(PreviousDataKey, ''ISPP'', IntToStr(Ord(ISPPCheckBox.Checked)));'+LineEnding+
'end;'+LineEnding+LineEnding+
'function ISPPCheck: Boolean;'+LineEnding+
'begin'+LineEnding+
' Result := ISPPCheckBox.Checked;'+LineEnding+
'end;'+LineEnding+LineEnding+
'function PortableCheck: Boolean;'+LineEnding+
'begin'+LineEnding+
' Result := ExpandConstant(''{param:portable|0}'') = ''1'';'+LineEnding+
'end;'+LineEnding+LineEnding
;
end;
procedure TSynInnoSyn.SymbolProc;
begin
fTokenID := tkSymbol;
inc(Run);
end;
procedure TSynInnoSyn.CRProc;
begin
fTokenID := tkSpace;
inc(Run);
if fLine[Run] = #10 then inc(Run);
end;
procedure TSynInnoSyn.EqualProc;
begin
// If any word has equal (=) symbol,
// then the immediately followed text is treated as string
// (though it does not have quotes)
fTokenID := tkString;
repeat
Inc(Run);
if fLine[Run] = ';' then begin
Inc(Run);
break;
end;
until fLine[Run] in [#0, #10, #13];
end;
procedure TSynInnoSyn.IdentProc;
var
LookAhead: integer;
begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
if fTokenID = tkKeyOrParameter then begin
LookAhead := Run;
while fLine[LookAhead] in [#9, ' '] do
Inc(LookAhead);
if fLine[LookAhead] = ':' then
fTokenID := tkKey
else
fTokenID := tkParameter;
end;
end;
procedure TSynInnoSyn.SectionProc;
begin
// if it is not column 0 mark as tkParameter and get out of here
if Run > 0 then
begin
fTokenID := tkUnknown;
inc(Run);
Exit;
end;
// this is column 0 ok it is a Section
fTokenID := tkSection;
repeat
Inc(Run);
if fLine[Run] = ']' then
begin
Inc(Run);
break;
end;
until fLine[Run] in [#0, #10, #13];
end;
procedure TSynInnoSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynInnoSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynInnoSyn.NumberProc;
begin
fTokenID := tkNumber;
repeat
Inc(Run);
until not (fLine[Run] in ['0'..'9']);
end;
procedure TSynInnoSyn.ConstantProc;
var
BraceLevel, LastOpenBrace: Integer;
begin
{ Much of this is based on code from the SkipPastConst function in IS's
CmnFunc2 unit. [jr] }
if fLine[Run + 1] = '{' then begin
fTokenID := tkUnknown;
Inc(Run, 2);
Exit;
end;
fTokenID := tkConstant;
BraceLevel := 1;
LastOpenBrace := Low(Integer);
repeat
Inc(Run);
case fLine[Run] of
'{': begin
if LastOpenBrace <> Run-1 then begin
Inc(BraceLevel);
LastOpenBrace := Run;
end
else
Dec(BraceLevel);
end;
'}': begin
Dec (BraceLevel);
if BraceLevel = 0 then begin
Inc(Run);
Break;
end;
end;
end;
until fLine[Run] in [#0, #10, #13];
end;
procedure TSynInnoSyn.SpaceProc;
begin
fTokenID := tkSpace;
repeat
Inc(Run);
until (fLine[Run] > #32) or (fLine[Run] in [#0, #10, #13]);
end;
procedure TSynInnoSyn.SemiColonProc;
var
I: Integer;
begin
for I := Run-1 downto 0 do
if fLine[I] > ' ' then begin
// If the semicolon is not the first non-whitespace character on the
// line, then it isn't the start of a comment.
fTokenID := tkUnknown;
inc(Run);
Exit;
end;
fTokenID := tkComment;
repeat
Inc(Run);
until (fLine[Run] in [#0, #10, #13]);
end;
procedure TSynInnoSyn.StringProc;
begin
fTokenID := tkString;
repeat
Inc(Run);
if fLine[Run] = '"' then begin
Inc(Run);
if fLine[Run] <> '"' then // embedded "" does not end the string
break;
end;
until fLine[Run] in [#0, #10, #13];
end;
procedure TSynInnoSyn.UnknownProc;
begin
inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynInnoSyn.Next;
begin
fTokenPos := Run;
fProcTable[fLine[Run]];
end;
function TSynInnoSyn.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_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynInnoSyn.GetEol: Boolean;
begin
Result := (fTokenId = tkNull);
end;
function TSynInnoSyn.GetToken :string;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
{$IFDEF SYN_LAZARUS}
procedure TSynInnoSyn.GetTokenEx(out TokenStart :PChar; out TokenLength :integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
function TSynInnoSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case fTokenID of
tkComment: Result := fCommentAttri;
tkParameter: Result := fParamAttri;
tkSection: Result := fSectionAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkConstant: Result := fConstantAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fIdentifierAttri;
else
Result := nil;
end;
end;
function TSynInnoSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynInnoSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynInnoSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSynInnoSyn.GetIdentChars: TSynIdentChars;
begin
Result := TSynValidStringChars;
end;
function TSynInnoSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterInno;
end;
class function TSynInnoSyn.GetLanguageName: string;
begin
Result := SYNS_LangInno;
end;
procedure TSynInnoSyn.DoAddKeyword(AKeyword: string; AKind: integer);
var
HashValue: integer;
begin
HashValue := KeyHash(PChar(AKeyword));
fKeywords[HashValue] := TSynHashEntry.Create(AKeyword, AKind);
end;
initialization
MakeIdentTable;
RegisterPlaceableHighlighter(TSynInnoSyn);
end.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,579 @@
{-------------------------------------------------------------------------------
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.
Code template generated with SynGen.
The original code is: SynHighlighterLDraw.pas, released 2003-04-12.
Description: LDraw Parser/Highlighter
The initial author of this file is Orion Pobursky.
Copyright (c) 2003, all rights reserved.
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: SynHighlighterLDraw.pas,v 1.8 2005/01/28 16:53:24 maelh Exp $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
-------------------------------------------------------------------------------}
{
@abstract(Provides an LDraw syntax highlighter for SynEdit)
@author(Orion Pobursky)
@created(03/01/2003)
@lastmod(07/05/2003)
The SynHighlighterLDraw unit provides SynEdit with a LEGO LDraw (.ldr / .dat) highlighter.
}
unit SynHighlighterLDraw;
{$I synedit.inc}
interface
uses
Graphics,
SynEditHighlighter, SynEditTypes,
Classes;
type
TtkTokenKind = (
tkColor,
tkComment,
tkFirstTri,
tkFourthTri,
tkIdentifier,
tkKey,
tkLine,
tkNull,
tkOpLine,
tkQuad,
tkSecondTri,
tkThirdTri,
tkTriangle,
tkUnknown);
TRangeState = (rsUnKnown);
TProcTableProc = procedure of object;
PIdentFuncTableFunc = ^TIdentFuncTableFunc;
TIdentFuncTableFunc = function: TtkTokenKind of object;
const
MaxKey = 83;
type
TSynLDRSyn = class(TSynCustomHighlighter)
private
fLine: PChar;
fLineNumber: Integer;
fProcTable: array[#0..#255] of TProcTableProc;
fRange: TRangeState;
Run: LongInt;
fStringLen: Integer;
fToIdent: PChar;
fTokenPos: Integer;
fTokenID: TtkTokenKind;
fIdentFuncTable: array[0 .. MaxKey] of TIdentFuncTableFunc;
fColorAttri: TSynHighlighterAttributes;
fCommentAttri: TSynHighlighterAttributes;
fFirstTriAttri: TSynHighlighterAttributes;
fFourthTriAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fLineAttri: TSynHighlighterAttributes;
fOpLineAttri: TSynHighlighterAttributes;
fQuadAttri: TSynHighlighterAttributes;
fSecondTriAttri: TSynHighlighterAttributes;
fThirdTriAttri: TSynHighlighterAttributes;
fTriangleAttri: TSynHighlighterAttributes;
function KeyHash(ToHash: PChar): Integer;
function KeyComp(const aKey: string): Boolean;
function Func83: TtkTokenKind;
procedure IdentProc;
procedure Number1Proc;
procedure UnknownProc;
function AltFunc: TtkTokenKind;
procedure InitIdent;
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
procedure NullProc;
procedure CRProc;
procedure LFProc;
function FirstChar(DatLine: PChar): Char;
protected
function GetIdentChars: TSynIdentChars; override;
function GetSampleSource: string; override;
function IsFilterStored: Boolean; override;
public
constructor Create(AOwner: TComponent); override;
class function GetLanguageName: string; override;
function GetRange: Pointer; override;
procedure ResetRange; override;
procedure SetRange(Value: Pointer); override;
function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes; override;
function GetEol: Boolean; override;
function GetKeyWords: string;
function GetTokenID: TtkTokenKind;
procedure SetLine(const NewValue: String; LineNumber: Integer); override;
function GetToken: String; override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
published
property ColorAttri: TSynHighlighterAttributes read fColorAttri write fColorAttri;
property CommentAttri: TSynHighlighterAttributes read fCommentAttri write fCommentAttri;
property FirstTriAttri: TSynHighlighterAttributes read fFirstTriAttri write fFirstTriAttri;
property FourthTriAttri: TSynHighlighterAttributes read fFourthTriAttri write fFourthTriAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri write fIdentifierAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property LineAttri: TSynHighlighterAttributes read fLineAttri write fLineAttri;
property OpLineAttri: TSynHighlighterAttributes read fOpLineAttri write fOpLineAttri;
property QuadAttri: TSynHighlighterAttributes read fQuadAttri write fQuadAttri;
property SecondTriAttri: TSynHighlighterAttributes read fSecondTriAttri write fSecondTriAttri;
property ThirdTriAttri: TSynHighlighterAttributes read fThirdTriAttri write fThirdTriAttri;
property TriangleAttri: TSynHighlighterAttributes read fTriangleAttri write fTriangleAttri;
end;
implementation
uses
SynEditStrConst, SynEditStrConstExtra;
var
Identifiers: array[#0..#255] of ByteBool;
mHashTable : array[#0..#255] of Integer;
function RGB(CONST r, g, b: BYTE): TColor;
begin
RESULT := (r OR (g SHL 8) OR (b SHL 16))
end;
procedure MakeIdentTable;
var
I, J: Char;
begin
for I := #0 to #255 do
begin
case I of
'_', '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;
procedure TSynLDRSyn.InitIdent;
var
I: Integer;
pF: PIdentFuncTableFunc;
begin
pF := PIdentFuncTableFunc(@fIdentFuncTable);
for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do
begin
pF^ := @AltFunc;
Inc(pF);
end;
fIdentFuncTable[83] := @Func83;
end;
function TSynLDRSyn.KeyHash(ToHash: PChar): Integer;
begin
Result := 0;
while ToHash^ in ['_', 'a'..'z', 'A'..'Z'] do
begin
inc(Result, mHashTable[ToHash^]);
inc(ToHash);
end;
fStringLen := ToHash - fToIdent;
end;
function TSynLDRSyn.KeyComp(const aKey :string) :Boolean;
var
I: Integer;
Temp: PChar;
begin
Temp := fToIdent;
if Length(aKey) = fStringLen then
begin
Result := True;
for i := 1 to fStringLen do
begin
if mHashTable[Temp^] <> mHashTable[aKey[i]] then
begin
Result := False;
break;
end;
inc(Temp);
end;
end
else
Result := False;
end;
function TSynLDRSyn.Func83: TtkTokenKind;
begin
if KeyComp('Author') then Result := tkKey else Result := tkIdentifier;
end;
function TSynLDRSyn.AltFunc: TtkTokenKind;
begin
Result := tkIdentifier;
end;
function TSynLDRSyn.IdentKind(MayBe: PChar): TtkTokenKind;
var
HashKey: Integer;
begin
fToIdent := MayBe;
HashKey := KeyHash(MayBe);
if HashKey <= MaxKey then
Result := fIdentFuncTable[HashKey]()
else
Result := tkIdentifier;
end;
procedure TSynLDRSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
#0: fProcTable[I] := @NullProc;
#10: fProcTable[I] := @LFProc;
#13: fProcTable[I] := @CRProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := @IdentProc;
'0'..'9': fProcTable[I] := @Number1Proc;
else
fProcTable[I] := @UnknownProc;
end;
end;
procedure TSynLDRSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynLDRSyn.CRProc;
begin
fTokenID := tkUnknown;
inc(Run);
if fLine[Run] = #10 then
inc(Run);
end;
procedure TSynLDRSyn.LFProc;
begin
fTokenID := tkUnknown;
inc(Run);
end;
constructor TSynLDRSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fColorAttri := TSynHighLighterAttributes.Create(SYNS_AttrColor);
fColorAttri.Foreground := clNavy;
AddAttribute(fColorAttri);
fCommentAttri := TSynHighLighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Foreground := clBlue;
AddAttribute(fCommentAttri);
fFirstTriAttri := TSynHighLighterAttributes.Create(SYNS_AttrFirstTri);
fFirstTriAttri.Foreground := RGB(206,111,73);
AddAttribute(fFirstTriAttri);
fFourthTriAttri := TSynHighLighterAttributes.Create(SYNS_AttrFourthTri);
fFourthTriAttri.Foreground := RGB(54,99,12);
AddAttribute(fFourthTriAttri);
fIdentifierAttri := TSynHighLighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighLighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fLineAttri := TSynHighLighterAttributes.Create(SYNS_AttrLine);
fLineAttri.Foreground := clBlack;
AddAttribute(fLineAttri);
fOpLineAttri := TSynHighLighterAttributes.Create(SYNS_AttrOpLine);
fOpLineAttri.Foreground := clBlack;
AddAttribute(fOpLineAttri);
fQuadAttri := TSynHighLighterAttributes.Create(SYNS_AttrQuad);
fQuadAttri.Foreground := clRed;
AddAttribute(fQuadAttri);
fSecondTriAttri := TSynHighLighterAttributes.Create(SYNS_AttrSecondTri);
fSecondTriAttri.Foreground := RGB(54,99,12);
AddAttribute(fSecondTriAttri);
fThirdTriAttri := TSynHighLighterAttributes.Create(SYNS_AttrThirdTri);
fThirdTriAttri.Foreground := RGB(206,111,73);
AddAttribute(fThirdTriAttri);
fTriangleAttri := TSynHighLighterAttributes.Create(SYNS_AttrTriangle);
fTriangleAttri.Foreground := clBlack;
AddAttribute(fTriangleAttri);
SetAttributesOnChange(@DefHighlightChange);
InitIdent;
MakeMethodTables;
fDefaultFilter := SYNS_FilterLDraw;
fRange := rsUnknown;
end;
procedure TSynLDRSyn.SetLine(const NewValue: String; LineNumber: Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
function TSynLDRSyn.FirstChar(DatLine: PChar): Char;
var
index: Integer;
begin
index := 0;
while DATLine[index] = ' ' do inc(index);
Result := DATLine[index];
end;
procedure TSynLDRSyn.IdentProc;
begin
if FirstChar(fLine) = '0' then
begin
fTokenID := tkComment;
while (fLine[Run] <> #10) and (fLine[Run] <> #13)
and (fLine[Run] <> #0) do inc(Run);
end
else
begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
while Identifiers[fLine[Run]] do
Inc(Run);
end;
end;
procedure TSynLDRSyn.Number1Proc;
function ArgNumber(DatLine: PChar): Byte;
var
index: Integer;
flag: Boolean;
begin
index := 0;
Result := 0;
flag := false;
while index <= Run do
begin
if DatLine[index] = ' ' then
begin
inc(index);
flag := false;
end
else
begin
if flag = false then inc(Result);
flag := true;
inc(index)
end;
end;
end;
begin
case ArgNumber(fLine) of
1: begin
case fLine[Run] of
'0': fTokenID := tkComment;
'1': fTokenID := tkIdentifier;
'2': fTokenID := tkLine;
'3': fTokenID := tkTriangle;
'4': fTokenID := tkQuad;
'5': fTokenID := tkOpLine;
end;
end;
2: if FirstChar(fLine) <> '0' then fTokenID := tkColor
else fTokenID := tkComment;
3..5: if FirstChar(fLine) <> '0' then fTokenID := tkFirstTri
else fTokenID := tkComment;
6..8: if FirstChar(fLine) <> '0' then fTokenID := tkSecondTri
else fTokenID := tkComment;
9..11: if FirstChar(fLine) <> '0' then fTokenID := tkThirdTri
else fTokenID := tkComment;
12..14: if FirstChar(fLine) <> '0' then fTokenID := tkFourthTri
else fTokenID := tkComment;
else
fTokenID := tkIdentifier;
end;
while FLine[Run] in ['0'..'9', '.'] do inc(Run);
end;
procedure TSynLDRSyn.UnknownProc;
begin
inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynLDRSyn.Next;
begin
fTokenPos := Run;
fProcTable[fLine[Run]];
end;
function TSynLDRSyn.GetDefaultAttribute(Index :integer) :TSynHighlighterAttributes;
begin
case Index of
SYN_ATTR_COMMENT : Result := fCommentAttri;
SYN_ATTR_IDENTIFIER : Result := fIdentifierAttri;
SYN_ATTR_KEYWORD : Result := fKeyAttri;
else
Result := nil;
end;
end;
function TSynLDRSyn.GetEol: Boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynLDRSyn.GetKeyWords: string;
begin
Result :=
'Author';
end;
function TSynLDRSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
{$IFDEF SYN_LAZARUS}
procedure TSynLDRSyn.GetTokenEx(out TokenStart :PChar; out TokenLength :integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
function TSynLDRSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynLDRSyn.GetTokenAttribute :TSynHighlighterAttributes;
begin
case GetTokenID of
tkColor: Result := fColorAttri;
tkComment: Result := fCommentAttri;
tkFirstTri: Result := fFirstTriAttri;
tkFourthTri: Result := fFourthTriAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkLine: Result := fLineAttri;
tkOpLine: Result := fOpLineAttri;
tkQuad: Result := fQuadAttri;
tkSecondTri: Result := fSecondTriAttri;
tkThirdTri: Result := fThirdTriAttri;
tkTriangle: Result := fTriangleAttri;
tkUnknown: Result := fIdentifierAttri;
else
Result := nil;
end;
end;
function TSynLDRSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynLDRSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSynLDRSyn.GetIdentChars: TSynIdentChars;
begin
Result := ['_', 'a'..'z', 'A'..'Z', '0'..'9'];
end;
function TSynLDRSyn.GetSampleSource: string;
begin
Result := #13#10 +
'Sample source for: '#13#10 +
'Ldraw Parser/Highlighter'#13#10 +
'0 Comment'#13#10 +
'1 16 0 0 0 1 0 0 0 1 0 0 0 1 stud.dat'#13#10 +
'2 16 0 0 0 1 1 1'#13#10 +
'3 16 0 0 0 1 1 1 2 2 2'#13#10 +
'4 16 0 0 0 1 1 1 2 2 2 3 3 3'#13#10 +
'5 16 0 0 0 1 1 1 2 2 2 3 3 3';
end;
function TSynLDRSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterLDraw;
end;
class function TSynLDRSyn.GetLanguageName: string;
begin
Result := SYNS_LangLDraw;
end;
procedure TSynLDRSyn.ResetRange;
begin
fRange := rsUnknown;
end;
procedure TSynLDRSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
function TSynLDRSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
initialization
MakeIdentTable;
RegisterPlaceableHighlighter(TSynLDRSyn);
end.

View File

@ -0,0 +1,758 @@
{-------------------------------------------------------------------------------
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: SynHighlighterM3.pas, released 2000-11-23.
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: SynHighlighterM3.pas,v 1.12 2005/01/28 16:53:24 maelh 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 a Modula-3 syntax highlighter for SynEdit)
@author(Martin Pley <synedit@pley.de>)
@created(January 2000, converted to SynEdit November 23, 2000)
@lastmod(2000-11-23)
The SynHighlighterM3 unit provides SynEdit with a Modula-3 (.m3) highlighter.
}
unit SynHighlighterM3;
{$I synedit.inc}
interface
uses
Graphics,
SynEditTypes,
SynEditHighlighter,
SynHighlighterHashEntries,
Classes;
type
TtkTokenKind = (tkComment, tkIdentifier, tkKey, tkNull, tkNumber, tkPragma,
tkReserved, tkSpace, tkString, tkSymbol, tkUnknown, tkSyntaxError);
TTokenRange = (trNone, trComment, trPragma);
TRangeState = packed record
case boolean of
FALSE: (p: pointer);
TRUE: (TokenRange: word; Level: word);
end;
TProcTableProc = procedure of object;
TSynM3Syn = class(TSynCustomHighLighter)
private
fLine: PChar;
fLineNumber: integer;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fRange: TRangeState;
fStringLen: integer;
fToIdent: PChar;
fTokenPos: integer;
FTokenID: TtkTokenKind;
fCommentAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fPragmaAttri: TSynHighlighterAttributes;
fReservedAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
fSyntaxErrorAttri: TSynHighlighterAttributes;
fKeywords: TSynHashEntryList;
procedure DoAddKeyword(AKeyword: string; AKind: integer);
function IdentKind(MayBe: PChar): TtkTokenKind;
function KeyComp(AKey: string): boolean;
function KeyHash(ToHash: PChar): integer;
procedure MakeMethodTables;
procedure SymAsciiCharProc;
procedure SymCommentHelpProc;
procedure SymCRProc;
procedure SymIdentProc;
procedure SymLFProc;
procedure SymNestedHelperProc(AOpenChar, ACloseChar: char);
procedure SymNullProc;
procedure SymNumberProc;
procedure SymPragmaProc;
procedure SymPragmaHelpProc;
procedure SymRoundOpenProc;
procedure SymSpaceProc;
procedure SymStringProc;
procedure SymSymbolProc;
procedure SymUnknownProc;
protected
function GetIdentChars: TSynIdentChars; override;
function IsFilterStored: Boolean; 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;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
function GetToken: String; override;
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
procedure ResetRange; override;
procedure SetLine(const NewValue: String; LineNumber:Integer); override;
procedure SetRange(Value: Pointer); override;
function GetSampleSource :string; override;
published
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
write fIdentifierAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property NumberAttri: TSynHighlighterAttributes read fNumberAttri
write fNumberAttri;
property PragmaAttri: TSynHighlighterAttributes read fPragmaAttri
write fPragmaAttri;
property ReservedAttri: TSynHighlighterAttributes read fReservedAttri
write fReservedAttri;
property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
write fSpaceAttri;
property StringAttri: TSynHighlighterAttributes read fStringAttri
write fStringAttri;
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
write fSymbolAttri;
property SyntaxErrorAttri: TSynHighlighterAttributes read fSyntaxErrorAttri
write fSyntaxErrorAttri;
end;
implementation
uses
SynEditStrConst;
var
Identifiers: array[#0..#255] of ByteBool;
mHashTable: array[#0..#255] of integer;
const
Keywords: string =
'AS,AND,ANY,ARRAY,BEGIN,BITS,BRANDED,BY,CASE,CONST,DIV,DO,ELSE,ELSIF,END,' +
'EVAL,EXCEPT,EXCEPTION,EXIT,EXPORTS,FINALLY,FOR,FROM,GENERIC,IF,IMPORT,' +
'IN,INTERFACE,LOCK,LOOP,METHODS,MOD,MODULE,NOT,OBJECT,OF,OR,OVERRIDES,' +
'PROCEDURE,RAISE,RAISES,READONLY,RECORD,REF,REPEAT,RETURN,REVEAL,ROOT,' +
'SET,THEN,TO,TRY,TYPE,TYPECASE,UNSAFE,UNTIL,UNTRACED,VALUE,VAR,WHILE,WITH';
ReservedWords: string =
'ABS,ADDRESS,ADR,ADRSIZE,BITSIZE,BOOLEAN,BYTESIZE,CARDINAL,CEILING,CHAR,' +
'DEC,DISPOSE,FALSE,FIRST,FLOAT,FLOOR,INC,INTEGER,ISTYPE,LAST,LONGFLOAT,' +
'LONGREAL,LOOPHOLE,MAX,MIN,MUTEX,NARROW,NEW,NIL,NULL,NUMBER,ORD,REAL,' +
'REFANY,ROUND,SUBARRAY,TEXT,TRUE,TRUNC,TYPECODE,VAL';
procedure MakeIdentTable;
var
I: Char;
begin
FillChar(Identifiers, SizeOf(Identifiers), 0);
for I := 'a' to 'z' do
Identifiers[i] := TRUE;
for I := 'A' to 'Z' do
Identifiers[i] := TRUE;
for I := '0' to '9' do
Identifiers[i] := TRUE;
Identifiers['_'] := TRUE;
FillChar(mHashTable, SizeOf(mHashTable), 0);
for I := 'a' to 'z' do
mHashTable[I] := 1 + Ord(I) - Ord('a');
for I := 'A' to 'Z' do
mHashTable[I] := 1 + Ord(I) - Ord('A');
mHashTable['_'] := 27;
for I := '0' to '9' do
mHashTable[I] := 28 + Ord(I) - Ord('0');
end;
procedure TSynM3Syn.DoAddKeyword(AKeyword: string; AKind: integer);
var
HashValue: integer;
begin
HashValue := KeyHash(PChar(AKeyword));
fKeywords[HashValue] := TSynHashEntry.Create(AKeyword, AKind);
end;
function TSynM3Syn.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;
function TSynM3Syn.KeyComp(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 pKey1^ <> pKey2^ then begin
Result := FALSE;
exit;
end;
Inc(pKey1);
Inc(pKey2);
end;
Result := TRUE;
end;
function TSynM3Syn.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 $FF; // 255
fStringLen := ToHash - fToIdent;
end;
procedure TSynM3Syn.MakeMethodTables;
var
I: char;
begin
for I := #0 to #255 do
case I of
#39: fProcTable[I] := @SymAsciiCharProc;
#13: fProcTable[I] := @SymCRProc;
'A'..'Z', 'a'..'z', '_':
fProcTable[I] := @SymIdentProc;
#10: fProcTable[I] := @SymLFProc;
#0: fProcTable[I] := @SymNullProc;
'0'..'9':
fProcTable[I] := @SymNumberProc;
'(': fProcTable[I] := @SymRoundOpenProc;
#1..#9, #11, #12, #14..#32:
fProcTable[I] := @SymSpaceProc;
'{','}','|','!', #35..#38, #42..#47, #58, #59, #61..#64, #91..#94, ')':
fProcTable[I] := @SymSymbolProc;
'<' : fProcTable[I]:= @SymPragmaProc;
#34: fProcTable[I] := @SymStringProc;
else
fProcTable[I] := @SymUnknownProc;
end;
end;
constructor TSynM3Syn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fKeywords := TSynHashEntryList.Create;
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style:= [fsItalic];
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrKey);
fKeyAttri.Style:= [fsBold];
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
AddAttribute(fNumberAttri);
fPragmaAttri := TSynHighlighterAttributes.Create(SYNS_AttrPreprocessor);
fPragmaAttri.Style:= [fsBold];
AddAttribute(fPragmaAttri);
fReservedAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
AddAttribute(fReservedAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
fSyntaxErrorAttri := TSynHighlighterAttributes.Create(SYNS_AttrSyntaxError);
fSyntaxErrorAttri.Foreground := clRed;
AddAttribute(fSyntaxErrorAttri);
SetAttributesOnChange(@DefHighlightChange);
MakeMethodTables;
EnumerateKeywords(Ord(tkKey), Keywords, IdentChars, @DoAddKeyword);
EnumerateKeywords(Ord(tkReserved), ReservedWords, IdentChars, @DoAddKeyword);
fDefaultFilter := SYNS_FilterModula3;
end;
destructor TSynM3Syn.Destroy;
begin
fKeywords.Free;
inherited Destroy;
end;
procedure TSynM3Syn.SymAsciiCharProc;
begin
fTokenID := tkString;
Inc(Run);
while not (fLine[Run] in [#0, #10, #13]) do begin
case fLine[Run] of
'\': if fLine[Run + 1] = #39 then
Inc(Run);
#39: begin
Inc(Run);
if fLine[Run] <> #39 then
break;
end;
end;
Inc(Run);
end;
end;
procedure TSynM3Syn.SymCommentHelpProc;
begin
fTokenID := tkComment;
SymNestedHelperProc('(', ')');
end;
procedure TSynM3Syn.SymCRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then
Inc(Run);
end;
procedure TSynM3Syn.SymIdentProc;
begin
fTokenID := IdentKind(fLine + Run);
Inc(Run, fStringLen);
while Identifiers[fLine[Run]] do
Inc(Run);
end;
procedure TSynM3Syn.SymLFProc;
begin
fTokenID := tkSpace;
Inc(Run);
end;
procedure TSynM3Syn.SymNestedHelperProc(AOpenChar, ACloseChar: char);
begin
case fLine[Run] of
#0: SymNullProc;
#10: SymLFProc;
#13: SymCRProc;
else
repeat
if fLine[Run]= AOpenChar then begin
Inc(Run);
if fLine[Run] = '*' then begin
Inc(Run);
Inc(fRange.Level);
end;
end else if fLine[Run] = '*' then begin
Inc(Run);
if fLine[Run] = ACloseChar then begin
Inc(Run);
if fRange.Level > 0 then
Dec(fRange.Level);
if fRange.Level = 0 then begin
fRange.TokenRange := Ord(trNone);
break
end;
end;
end else
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
end;
procedure TSynM3Syn.SymNullProc;
begin
fTokenID := tkNull;
end;
procedure TSynM3Syn.SymNumberProc;
const
Digits: array[0..15] of char = '0123456789abcdef';
var
BasedNumber: boolean;
i, MaxDigit: integer;
ValidDigits: TSynIdentChars;
begin
fTokenID := tkNumber;
BasedNumber := FALSE;
MaxDigit := 9;
// skip leading zeros, but they can be numbers too
while fLine[Run] = '0' do
Inc(Run);
if not Identifiers[fLine[Run]] then
exit;
// check for numbers with a base prefix
if (fLine[Run] in ['2'..'9']) and (fLine[Run + 1] = '_') then begin
BasedNumber := TRUE;
MaxDigit := Ord(fLine[Run]) - Ord('0') - 1;
Inc(Run, 2);
end else if (fLine[Run] ='1') and (fLine[Run + 1] in ['0'..'6'])
and (fLine[Run + 2] = '_')
then begin
BasedNumber := TRUE;
MaxDigit := 10 + Ord(fLine[Run + 1]) - Ord('0') - 1;
Inc(Run, 3);
end;
if BasedNumber then begin
ValidDigits := [];
i := MaxDigit;
while i >= 10 do begin
Include(ValidDigits, Digits[i]);
Include(ValidDigits, UpCase(Digits[i]));
Dec(i);
end;
while i >= 0 do begin
Include(ValidDigits, Digits[i]);
Dec(i);
end;
// advance over all valid digits, but at least one has to be there
if fLine[Run] in ValidDigits then begin
repeat
Inc(Run);
until not (fLine[Run] in ValidDigits);
end else
fTokenID := tkSyntaxError;
end else begin
// "normal" numbers
repeat
Inc(Run);
until not (fLine[Run] in ['0'..'9']);
// can include a decimal point and an exponent
if fLine[Run] = '.' then begin
Inc(Run);
if fLine[Run] in ['0'..'9'] then begin
repeat
Inc(Run);
until not (fLine[Run] in ['0'..'9']);
end else
fTokenID := tkSyntaxError; // must be a number after the '.'
end;
// can include an exponent
if fLine[Run] in ['d', 'D', 'e', 'E', 'x', 'X'] then begin
Inc(Run);
if fLine[Run] in ['+', '-'] then
Inc(Run);
if fLine[Run] in ['0'..'9'] then begin
repeat
Inc(Run);
until not (fLine[Run] in ['0'..'9']);
end else // exponent must include a number
fTokenID := tkSyntaxError;
end;
end;
// it's a syntax error if there are any Identifier chars left
if Identifiers[fLine[Run]] then begin
fTokenID := tkSyntaxError;
repeat
Inc(Run);
until not Identifiers[fLine[Run]];
end;
end;
procedure TSynM3Syn.SymPragmaProc;
begin
Inc(Run);
if fLine[Run] = '*' then begin
Inc(Run);
fRange.TokenRange := Ord(trPragma);
Inc(fRange.Level);
if fLine[Run] in [#0, #10, #13] then
fTokenID := tkPragma
else
SymPragmaHelpProc;
end else
fTokenID := tkSymbol;
end;
procedure TSynM3Syn.SymPragmaHelpProc;
begin
fTokenID := tkPragma;
SymNestedHelperProc('<', '>');
end;
procedure TSynM3Syn.SymRoundOpenProc;
begin
Inc(Run);
if fLine[Run] = '*' then begin
Inc(Run);
fRange.TokenRange := Ord(trComment);
Inc(fRange.Level);
if fLine[Run] in [#0, #10, #13] then
fTokenID := tkComment
else
SymCommentHelpProc;
end else begin
fTokenID := tkSymbol;
if fLine[Run] = '.' then
Inc(Run);
end;
end;
procedure TSynM3Syn.SymSpaceProc;
begin
fTokenID := tkSpace;
repeat
Inc(Run);
until (fLine[Run] > #32) or (fLine[Run] in [#0, #10, #13]);
end;
procedure TSynM3Syn.SymStringProc;
begin
fTokenID := tkString;
Inc(Run);
while not (fLine[Run] in [#0, #10, #13]) do begin
case fLine[Run] of
#34: begin
Inc(Run);
break;
end;
'\': if fLine[Run + 1] in [#34, '\'] then
Inc(Run);
end;
Inc(Run);
end;
end;
procedure TSynM3Syn.SymSymbolProc;
begin
Inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynM3Syn.SymUnknownProc;
begin
inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynM3Syn.Next;
begin
fTokenPos := Run;
case TTokenRange(fRange.TokenRange) of
trComment: SymCommentHelpProc;
trPragma: SymPragmaHelpProc;
else
fProcTable[fLine[Run]];
end;
end;
function TSynM3Syn.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_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynM3Syn.GetEol: Boolean;
begin
Result := fTokenId = tkNull;
end;
function TSynM3Syn.GetIdentChars: TSynIdentChars;
begin
Result := TSynValidStringChars;
end;
function TSynM3Syn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterModula3;
end;
class function TSynM3Syn.GetLanguageName: string;
begin
Result := SYNS_LangModula3;
end;
function TSynM3Syn.GetRange :Pointer;
begin
result := fRange.p;
end;
function TSynM3Syn.GetToken :String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, fLine + fTokenPos, Len);
end;
function TSynM3Syn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case fTokenID of
tkComment: Result := fCommentAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkPragma: Result:= fPragmaAttri;
tkReserved: Result := fReservedAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkSyntaxError: Result := fSyntaxErrorAttri;
tkUnknown: Result := fIdentifierAttri;
else
Result := nil;
end;
end;
function TSynM3Syn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
procedure TSynM3Syn.GetTokenEx(out TokenStart :PChar; out TokenLength :integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
function TSynM3Syn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynM3Syn.GetTokenPos :Integer;
begin
Result := fTokenPos;
end;
procedure TSynM3Syn.ResetRange;
begin
fRange.p := nil;
end;
procedure TSynM3Syn.SetLine(const NewValue :String; LineNumber :Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynM3Syn.SetRange(Value :Pointer);
begin
fRange.p := Value;
end;
function TSynM3Syn.GetSampleSource :string;
begin
Result:='INTERFACE Shape;'+LineEnding+
' TYPE'+LineEnding+
' T <: Public;'+LineEnding+
' Public = ROOT OBJECT'+LineEnding+
' METHODS'+LineEnding+
' draw();'+LineEnding+
' moveTo(newx: INTEGER; newy: INTEGER);'+LineEnding+
' rMoveTo(deltax: INTEGER; deltay: INTEGER);'+LineEnding+
' getX(): INTEGER;'+LineEnding+
' getY(): INTEGER;'+LineEnding+
' END;'+LineEnding+
'END Shape.'+LineEnding+LineEnding+
'-------------------------------------------------------------------------------------------------------------'+LineEnding+
'-------------------------------------------------------------------------------------------------------------'+LineEnding+
'-------------------------------------------------------------------------------------------------------------'+LineEnding+LineEnding+
'MODULE Shape;'+LineEnding+LineEnding+
' REVEAL'+LineEnding+
' T = Public BRANDED OBJECT'+LineEnding+
' x: INTEGER;'+LineEnding+
' y: INTEGER;'+LineEnding+
' METHODS'+LineEnding+
' setX(newx: INTEGER) := SetX;'+LineEnding+
' setY(newy: INTEGER) := SetY;'+LineEnding+
' OVERRIDES'+LineEnding+
' moveTo := MoveTo;'+LineEnding+
' rMoveTo := RMoveTo;'+LineEnding+
' getX := GetX;'+LineEnding+
' getY := GetY;'+LineEnding+
' END;'+LineEnding+LineEnding+
' (* accessors for x & y *)'+LineEnding+
' PROCEDURE GetX(self: T): INTEGER ='+LineEnding+
' BEGIN'+LineEnding+
' RETURN self.x;'+LineEnding+
' END GetX;'+LineEnding+LineEnding+
' PROCEDURE GetY(self: T): INTEGER ='+LineEnding+
' BEGIN'+LineEnding+
' RETURN self.y;'+LineEnding+
' END GetY;'+LineEnding+LineEnding+
' PROCEDURE SetX(self: T; newx: INTEGER) ='+LineEnding+
' BEGIN'+LineEnding+
' self.x := newx;'+LineEnding+
' END SetX;'+LineEnding+LineEnding+
' PROCEDURE SetY(self: T; newy: INTEGER) ='+LineEnding+
' BEGIN'+LineEnding+
' self.y := newy;'+LineEnding+
' END SetY;'+LineEnding+LineEnding+
' (* move the shape position *)'+LineEnding+
' PROCEDURE MoveTo(self: T; newx: INTEGER; newy: INTEGER) ='+LineEnding+
' BEGIN'+LineEnding+
' self.setX(newx);'+LineEnding+
' self.setY(newy);'+LineEnding+
' END MoveTo;'+LineEnding+LineEnding+
' PROCEDURE RMoveTo(self: T; deltax: INTEGER; deltay: INTEGER) ='+LineEnding+
' BEGIN'+LineEnding+
' self.moveTo(self.getX() + deltax, self.getY() + deltay);'+LineEnding+
' END RMoveTo;'+LineEnding+LineEnding+
'BEGIN'+LineEnding+
'END Shape.'+LineEnding;
end;
initialization
MakeIdentTable;
RegisterPlaceableHighlighter(TSynM3Syn);
end.

View File

@ -0,0 +1,968 @@
{-------------------------------------------------------------------------------
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: SynHighlighterModelica.pas, released 2000-11-09.
The Initial Author of this file is Falko Jens Wagner.
Portions created by Falko Jens Wagner are Copyright 2000 Falko Jens Wagner.
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.
$Id: SynHighlighterModelica.pas,v 1.13 2005/01/28 16:53:24 maelh Exp $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
Known Issues:
-------------------------------------------------------------------------------}
unit SynHighlighterModelica;
{$I synedit.inc}
interface
uses
Graphics,
SynEditTypes,
SynEditHighlighter,
Classes;
type
TtkTokenKind = (tkComment, tkDirective, tkIdentifier, tkKey, tkNull, tkNumber,
tkSpace, tkString, tkSymbol, tkUnknown);
TRangeState = (rsUnknown, rsString39, rsString34, rsComment);
TProcTableProc = procedure of object;
PIdentFuncTableFunc = ^TIdentFuncTableFunc;
TIdentFuncTableFunc = function: TtkTokenKind of object;
type
TSynModelicaSyn = class(TSynCustomHighlighter)
private
fRange: TRangeState;
fLine: PChar;
fLineNumber: integer;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fStringLen: integer;
fToIdent: PChar;
fTokenID: TtkTokenKind;
fTokenPos: integer;
fIdentFuncTable: array[0..137] of TIdentFuncTableFunc;
fCommentAttri: TSynHighlighterAttributes;
fDirectiveAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
function KeyHash(ToHash: PChar): integer;
function KeyComp(const aKey: string): boolean;
function Func17: TtkTokenKind;
function Func22: TtkTokenKind;
function Func25: TtkTokenKind;
function Func26: TtkTokenKind;
function Func30: TtkTokenKind;
function Func35: TtkTokenKind;
function Func39: TtkTokenKind;
function Func42: TtkTokenKind;
function Func45: TtkTokenKind;
function Func47: TtkTokenKind;
function Func48: TtkTokenKind;
function Func51: TtkTokenKind;
function Func52: TtkTokenKind;
function Func54: TtkTokenKind;
function Func59: TtkTokenKind;
function Func60: TtkTokenKind;
function Func62: TtkTokenKind;
function Func68: TtkTokenKind;
function Func69: TtkTokenKind;
function Func70: TtkTokenKind;
function Func80: TtkTokenKind;
function Func81: TtkTokenKind;
function Func84: TtkTokenKind;
function Func85: TtkTokenKind;
function Func88: TtkTokenKind;
function Func91: TtkTokenKind;
function Func98: TtkTokenKind;
function Func106: TtkTokenKind;
function Func107: TtkTokenKind;
function Func110: TtkTokenKind;
function Func112: TtkTokenKind;
function Func114: TtkTokenKind;
function Func115: TtkTokenKind;
function Func116: TtkTokenKind;
function Func119: TtkTokenKind;
function Func133: TtkTokenKind;
function Func137: TtkTokenKind;
procedure AndSymbolProc;
procedure AsciiCharProc;
procedure CRProc;
procedure ColonProc;
procedure DirectiveProc;
procedure GreaterProc;
procedure IdentProc;
procedure LFProc;
procedure LowerProc;
procedure MinusProc;
procedure NullProc;
procedure NumberProc;
procedure OrSymbolProc;
procedure PlusProc;
procedure PointProc;
procedure SlashProc;
procedure SpaceProc;
procedure StringProc;
procedure SymbolProc;
procedure SymbolProcWithEqual;
procedure UnknownProc;
function AltFunc: TtkTokenKind;
procedure InitIdent;
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
procedure AnsiCProc;
procedure String34Proc;
procedure String39Proc;
protected
function GetIdentChars: TSynIdentChars; override;
function IsFilterStored: Boolean; override;
public
class function GetLanguageName: string; override;
public
constructor Create(AOwner: TComponent); 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;
function GetToken: string; override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$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 DirectiveAttri: TSynHighlighterAttributes read fDirectiveAttri
write fDirectiveAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
write fIdentifierAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
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;
end;
implementation
uses
SynEditStrConst;
var
Identifiers: array[#0..#255] of ByteBool;
mHashTable: array[#0..#255] of integer;
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;
case I in ['_', 'A'..'Z', 'a'..'z'] of
True:
begin
if (I > #64) and (I < #91) then mHashTable[I] := Ord(I) - 64 else
if (I > #96) then mHashTable[I] := Ord(I) - 95;
end;
else mHashTable[I] := 0;
end;
end;
end;
procedure TSynModelicaSyn.InitIdent;
var
I: integer;
pF: PIdentFuncTableFunc;
begin
pF := PIdentFuncTableFunc(@fIdentFuncTable);
for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do begin
pF^ := @AltFunc;
Inc(pF);
end;
fIdentFuncTable[17] := @Func17;
fIdentFuncTable[22] := @Func22;
fIdentFuncTable[25] := @Func25;
fIdentFuncTable[26] := @Func26;
fIdentFuncTable[30] := @Func30;
fIdentFuncTable[35] := @Func35;
fIdentFuncTable[39] := @Func39;
fIdentFuncTable[42] := @Func42;
fIdentFuncTable[45] := @Func45;
fIdentFuncTable[47] := @Func47;
fIdentFuncTable[48] := @Func48;
fIdentFuncTable[51] := @Func51;
fIdentFuncTable[52] := @Func52;
fIdentFuncTable[54] := @Func54;
fIdentFuncTable[59] := @Func59;
fIdentFuncTable[60] := @Func60;
fIdentFuncTable[62] := @Func62;
fIdentFuncTable[68] := @Func68;
fIdentFuncTable[69] := @Func69;
fIdentFuncTable[70] := @Func70;
fIdentFuncTable[80] := @Func80;
fIdentFuncTable[81] := @Func81;
fIdentFuncTable[84] := @Func84;
fIdentFuncTable[85] := @Func85;
fIdentFuncTable[88] := @Func88;
fIdentFuncTable[91] := @Func91;
fIdentFuncTable[98] := @Func98;
fIdentFuncTable[106] := @Func106;
fIdentFuncTable[107] := @Func107;
fIdentFuncTable[110] := @Func110;
fIdentFuncTable[112] := @Func112;
fIdentFuncTable[114] := @Func114;
fIdentFuncTable[115] := @Func115;
fIdentFuncTable[116] := @Func116;
fIdentFuncTable[119] := @Func119;
fIdentFuncTable[133] := @Func133;
fIdentFuncTable[137] := @Func137;
end;
function TSynModelicaSyn.KeyHash(ToHash: PChar): integer;
begin
Result := 0;
while Identifiers[ToHash^] do begin
inc(Result, mHashTable[ToHash^]);
inc(ToHash);
end;
fStringLen := ToHash - fToIdent;
end;
function TSynModelicaSyn.KeyComp(const aKey: string): boolean;
var
I: integer;
Temp: PChar;
begin
Temp := fToIdent;
if Length(aKey) = fStringLen then
begin
Result := True;
for i := 1 to fStringLen do
begin
if Temp^ <> aKey[i] then
begin
Result := False;
break;
end;
inc(Temp);
end;
end else Result := False;
end;
function TSynModelicaSyn.Func17: TtkTokenKind;
begin
if KeyComp('if') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func22: TtkTokenKind;
begin
if KeyComp('and') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func25: TtkTokenKind;
begin
if KeyComp('in') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func26: TtkTokenKind;
begin
if KeyComp('end') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func30: TtkTokenKind;
begin
if KeyComp('der') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func35: TtkTokenKind;
begin
if KeyComp('or') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func39: TtkTokenKind;
begin
if KeyComp('Real') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func42: TtkTokenKind;
begin
if KeyComp('for') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func45: TtkTokenKind;
begin
if KeyComp('else') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func47: TtkTokenKind;
begin
if KeyComp('final') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func48: TtkTokenKind;
begin
if KeyComp('block') then Result := tkKey else
if KeyComp('false') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func51: TtkTokenKind;
begin
if KeyComp('package') then Result := tkKey else
if KeyComp('then') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func52: TtkTokenKind;
begin
if KeyComp('not') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func54: TtkTokenKind;
begin
if KeyComp('when') then Result := tkKey else
if KeyComp('model') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func59: TtkTokenKind;
begin
if KeyComp('class') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func60: TtkTokenKind;
begin
if KeyComp('flow') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func62: TtkTokenKind;
begin
if KeyComp('elseif') then Result := tkKey else
if KeyComp('while') then Result := tkKey else
if KeyComp('loop') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func68: TtkTokenKind;
begin
if KeyComp('true') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func69: TtkTokenKind;
begin
if KeyComp('public') then Result := tkKey else
if KeyComp('record') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func70: TtkTokenKind;
begin
if KeyComp('Boolean') then Result := tkKey else
if KeyComp('type') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func80: TtkTokenKind;
begin
if KeyComp('redeclare') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func81: TtkTokenKind;
begin
if KeyComp('connect') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func84: TtkTokenKind;
begin
if KeyComp('partial') then Result := tkKey else
if KeyComp('Integer') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func85: TtkTokenKind;
begin
if KeyComp('input') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func88: TtkTokenKind;
begin
if KeyComp('assert') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func91: TtkTokenKind;
begin
if KeyComp('replaceable') then Result := tkKey else
if KeyComp('discrete') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func98: TtkTokenKind;
begin
if KeyComp('extends') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func106: TtkTokenKind;
begin
if KeyComp('parameter') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func107: TtkTokenKind;
begin
if KeyComp('external') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func110: TtkTokenKind;
begin
if KeyComp('function') then Result := tkKey else
if KeyComp('equation') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func112: TtkTokenKind;
begin
if KeyComp('algorithm') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func114: TtkTokenKind;
begin
if KeyComp('constant') then Result := tkKey else
if KeyComp('terminate') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func115: TtkTokenKind;
begin
if KeyComp('protected') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func116: TtkTokenKind;
begin
if KeyComp('connector') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func119: TtkTokenKind;
begin
if KeyComp('output') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func133: TtkTokenKind;
begin
if KeyComp('annotation') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.Func137: TtkTokenKind;
begin
if KeyComp('nondiscrete') then Result := tkKey else Result := tkIdentifier;
end;
function TSynModelicaSyn.AltFunc: TtkTokenKind;
begin
Result := tkIdentifier;
end;
function TSynModelicaSyn.IdentKind(MayBe: PChar): TtkTokenKind;
var
HashKey: integer;
begin
fToIdent := MayBe;
HashKey := KeyHash(MayBe);
if HashKey < 138 then
Result := fIdentFuncTable[HashKey]()
else
Result := tkIdentifier;
end;
procedure TSynModelicaSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
'&': fProcTable[I] := @AndSymbolProc;
#39: fProcTable[I] := @AsciiCharProc;
#13: fProcTable[I] := @CRProc;
':': fProcTable[I] := @ColonProc;
'#': fProcTable[I] := @DirectiveProc;
'>': fProcTable[I] := @GreaterProc;
'A'..'Z', 'a'..'z', '_':
fProcTable[I] := @IdentProc;
#10: fProcTable[I] := @LFProc;
'<': fProcTable[I] := @LowerProc;
'-': fProcTable[I] := @MinusProc;
#0: fProcTable[I] := @NullProc;
'0'..'9':
fProcTable[I] := @NumberProc;
'|': fProcTable[I] := @OrSymbolProc;
'+': fProcTable[I] := @PlusProc;
'.': fProcTable[I] := @PointProc;
'/': fProcTable[I] := @SlashProc;
#1..#9, #11, #12, #14..#32:
fProcTable[I] := @SpaceProc;
#34: fProcTable[I] := @StringProc;
'~', '[', ']', '@', '{', '}', '(', ')', ';', ',':
fProcTable[I] := @SymbolProc;
'*', '^', '=', '%', '!':
fProcTable[I] := @SymbolProcWithEqual;
else
fProcTable[I] := @UnknownProc;
end;
end;
constructor TSynModelicaSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style := [fsItalic];
AddAttribute(fCommentAttri);
fDirectiveAttri := TSynHighlighterAttributes.Create(SYNS_AttrDirective);
AddAttribute(fDirectiveAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
SetAttributesOnChange(@DefHighlightChange);
InitIdent;
MakeMethodTables;
fDefaultFilter := SYNS_FilterModelica;
fRange := rsUnknown;
end;
procedure TSynModelicaSyn.SetLine(const NewValue: string; LineNumber: integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynModelicaSyn.AndSymbolProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] in ['=', '&'] then
Inc(Run);
end;
procedure TSynModelicaSyn.AsciiCharProc;
begin
fRange := rsString39;
fTokenID := tkString;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13, #39];
if fLine[Run] = #39 then begin
fRange := rsUnknown;
Inc(Run);
end;
end;
procedure TSynModelicaSyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then
Inc(Run);
end;
procedure TSynModelicaSyn.ColonProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] = ':' then
Inc(Run);
end;
procedure TSynModelicaSyn.DirectiveProc;
begin
fTokenID := tkDirective;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
procedure TSynModelicaSyn.GreaterProc;
begin
Inc(Run);
fTokenID := tkSymbol;
case fLine[Run] of
'=': Inc(Run);
'>': begin
Inc(Run);
if fLine[Run] = '=' then
Inc(Run);
end;
end;
end;
procedure TSynModelicaSyn.IdentProc;
begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
while Identifiers[fLine[Run]] do inc(Run);
end;
procedure TSynModelicaSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynModelicaSyn.LowerProc;
begin
Inc(Run);
fTokenID := tkSymbol;
case fLine[Run] of
'=': Inc(Run);
'<': begin
Inc(Run);
if fLine[Run] = '=' then
Inc(Run);
end;
end;
end;
procedure TSynModelicaSyn.MinusProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] in ['=', '-', '>'] then
Inc(Run);
end;
procedure TSynModelicaSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynModelicaSyn.NumberProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in
['0'..'9', '.', 'u', 'U', 'l', 'L', 'x', 'X', 'e', 'E', 'f', 'F'] do
begin
case FLine[Run] of
'.':
if FLine[Run + 1] = '.' then break;
end;
inc(Run);
end;
end;
procedure TSynModelicaSyn.OrSymbolProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] in ['=', '|'] then
Inc(Run);
end;
procedure TSynModelicaSyn.PlusProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] in ['=', '+'] then
Inc(Run);
end;
procedure TSynModelicaSyn.PointProc;
begin
Inc(Run);
fTokenID := tkSymbol;
if (fLine[Run] = '.') and (fLine[Run + 1] = '.') then
Inc(Run, 2);
end;
procedure TSynModelicaSyn.SlashProc;
begin
Inc(Run);
case fLine[Run] of
'/':
begin
fTokenID := tkComment;
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
'*':
begin
fRange := rsComment;
inc(Run);
if fLine[Run] in [#0, #10, #13] then
fTokenID := tkComment
else
AnsiCProc;
end;
else
fTokenID := tkSymbol;
if fLine[Run] = '=' then
Inc(Run);
end;
end;
procedure TSynModelicaSyn.SpaceProc;
begin
fTokenID := tkSpace;
repeat
Inc(Run);
until (fLine[Run] > #32) or (fLine[Run] in [#0, #10, #13]);
end;
procedure TSynModelicaSyn.StringProc;
begin
fRange := rsString34;
Inc(Run);
if fLine[Run] in [#0, #10, #13] then
fTokenID := tkString
else
String34Proc;
end;
procedure TSynModelicaSyn.SymbolProc;
begin
Inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynModelicaSyn.SymbolProcWithEqual;
begin
Inc(Run);
fTokenID := tkSymbol;
if fLine[Run] = '=' then
Inc(Run);
end;
procedure TSynModelicaSyn.UnknownProc;
begin
inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynModelicaSyn.AnsiCProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
fTokenID := tkComment;
repeat
if (fLine[Run] = '*') and (fLine[Run + 1] = '/') then begin
inc(Run, 2);
fRange := rsUnknown;
break;
end;
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
end;
procedure TSynModelicaSyn.String39Proc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
fTokenID := tkString;
repeat
if fLine[Run] = #39 then begin
inc(Run);
fRange := rsUnknown;
break;
end;
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
end;
procedure TSynModelicaSyn.String34Proc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
fTokenID := tkString;
repeat
case fLine[Run] of
#34:
begin
Inc(Run);
fRange := rsUnknown;
break;
end;
#92:
begin
Inc(Run);
if fLine[Run] = #34 then
Inc(Run);
end;
else
Inc(Run);
end;
until fLine[Run] in [#0, #10, #13];
end;
end;
procedure TSynModelicaSyn.Next;
begin
fTokenPos := Run;
case fRange of
rsComment: AnsiCProc;
rsString39: String39Proc;
rsString34: String34Proc;
else
fRange := rsUnknown;
fProcTable[fLine[Run]];
end;
end;
function TSynModelicaSyn.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_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynModelicaSyn.GetEol: boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynModelicaSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
function TSynModelicaSyn.GetToken: string;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
{$IFDEF SYN_LAZARUS}
procedure TSynModelicaSyn.GetTokenEx(out TokenStart :PChar; out TokenLength :integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
function TSynModelicaSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynModelicaSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case GetTokenID of
tkComment: Result := fCommentAttri;
tkDirective: Result := fDirectiveAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fIdentifierAttri;
else
Result := nil;
end;
end;
function TSynModelicaSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynModelicaSyn.GetTokenPos: integer;
begin
Result := fTokenPos;
end;
procedure TSynModelicaSyn.ResetRange;
begin
fRange := rsUnknown;
end;
procedure TSynModelicaSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
function TSynModelicaSyn.GetIdentChars: TSynIdentChars;
begin
Result := TSynValidStringChars;
end;
function TSynModelicaSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterModelica;
end;
class function TSynModelicaSyn.GetLanguageName: string;
begin
Result := SYNS_LangModelica;
end;
initialization
MakeIdentTable;
RegisterPlaceableHighlighter(TSynModelicaSyn);
end.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,794 @@
{-------------------------------------------------------------------------------
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: SynHighlighterRuby.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)
"Heredoc" syntax highlighting implementation by Marko Njezic.
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 cas, 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: SynHighlighterRuby.pas,v 1.11 2005/01/28 16:53:25 maelh 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 a Ruby highlighter for SynEdit)
@author(Stefan Ascher <stievie2002@yahoo.com>)
@created(21 May 2001)
@lastmod(2001-11-13)
The SynHighlighterVisualLisp unit provides SynEdit with a Ruby highlighter.
}
{$IFNDEF QSYNHIGHLIGHTERRUBY}
unit SynHighlighterRuby;
{$ENDIF}
//SynEdit.inc is the synedit.inc from laz 1.2.0 synedit package source if it has changed
//in newer version you might need to copy it again. REmeber to redclare the syn_lazarus define.
{$I synedit.inc}
interface
uses
{$IFDEF SYN_CLX}
QGraphics,
QSynEditTypes,
QSynEditHighlighter,
{$ELSE}
Graphics,
SynEditTypes,
SynEditHighlighter,
{$ENDIF}
SysUtils,
Classes;
type
TtkTokenKind = (tkComment, tkIdentifier, tkKey, tkNull, tkNumber, tkSecondKey,
tkSpace, tkString, tkSymbol, tkUnknown);
{$IFDEF SYN_HEREDOC}
TRangeState = (rsUnknown, rsHeredoc, rsIndentedHeredoc);
TRangePointer = packed record
case Boolean of
True : (Ptr: Pointer);
False : (Range: Byte; Length: Byte; Checksum: Word);
end;
{$ELSE}
TRangeState = (rsUnknown);
{$ENDIF}
TProcTableProc = procedure of object;
type
TSynRubySyn = class(TSynCustomHighlighter)
private
fRange: TRangeState;
{$IFDEF SYN_HEREDOC}
fHeredocLength : Byte;
fHeredocChecksum : Word;
{$ENDIF}
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;
fKeyWords: TStrings;
fSecondKeys: TStrings;
procedure BraceOpenProc;
procedure PointCommaProc;
procedure CRProc;
procedure IdentProc;
procedure LFProc;
procedure LowerProc;
procedure NullProc;
procedure NumberProc;
procedure RoundOpenProc;
procedure SlashProc;
procedure SpaceProc;
procedure StringProc;
procedure UnknownProc;
procedure MakeMethodTables;
{$IFDEF SYN_HEREDOC}
procedure HeredocProc;
{$ENDIF}
procedure SetSecondKeys(const Value: TStrings);
protected
function GetSampleSource: string; override;
function IsFilterStored: Boolean; 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;
function IsKeyword(const AKeyword: string): boolean; override;
function IsSecondKeyWord(aToken: string): Boolean;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
// procedure SetLine(NewValue: string; LineNumber:Integer); override;
procedure SetLine(const NewValue: String; LineNumber: Integer); override;
function GetToken: string; override;
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;
end;
implementation
uses
{$IFDEF SYN_CLX}
QSynEditMiscProcs,
QSynEditStrConst;
{$ELSE}
SynEditMiscProcs,
SynEditStrConst, SynEditStrConstExtra;
{$ENDIF}
const
RubyKeysCount = 43;
RubyKeys: array[1..RubyKeysCount] of string = (
'ALIAS', 'ATTR', 'BEGIN', 'BREAK', 'CASE', 'CLASS', 'DEF', 'DO', 'ELSE',
'ELSIF', 'END', 'ENSURE', 'EXIT', 'EXTEND', 'FALSE', 'FOR', 'GETS', 'IF',
'IN', 'INCLUDE', 'LOAD', 'LOOP', 'MODULE', 'NEXT', 'NIL', 'NOT', 'PRINT',
'PRIVATE', 'PUBLIC', 'PUTS', 'RAISE', 'REDO', 'REQUIRE', 'RESCUE', 'RETRY',
'RETURN', 'SELF', 'THEN', 'TRUE', 'UNLESS', 'WHEN', 'WHILE', 'YIELD');
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 TSynRubySyn.IsKeyword(const AKeyword: string): boolean;
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 TSynRubySyn.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 TSynRubySyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
'<': fProcTable[I] := {$ifdef FPC} @ {$endif} LowerProc;
'#': fProcTable[I] := {$ifdef FPC} @ {$endif}SlashProc;
'{': fProcTable[I] := {$ifdef FPC} @ {$endif}BraceOpenProc;
';': fProcTable[I] := {$ifdef FPC} @ {$endif}PointCommaProc;
#13: fProcTable[I] := {$ifdef FPC} @ {$endif}CRProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := {$ifdef FPC} @ {$endif}IdentProc;
#10: fProcTable[I] := {$ifdef FPC} @ {$endif}LFProc;
#0: fProcTable[I] := {$ifdef FPC} @ {$endif}NullProc;
'0'..'9': fProcTable[I] := {$ifdef FPC} @ {$endif}NumberProc;
'(': fProcTable[I] := {$ifdef FPC} @ {$endif}RoundOpenProc;
'/': fProcTable[I] := {$ifdef FPC} @ {$endif}SlashProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := {$ifdef FPC} @ {$endif}SpaceProc;
#34, #39: fProcTable[I] := {$ifdef FPC} @ {$endif}StringProc;
else fProcTable[I] := {$ifdef FPC} @ {$endif}UnknownProc;
end;
end;
constructor TSynRubySyn.Create(AOwner: TComponent);
var
i: integer;
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
for i := 1 to RubyKeysCount do
fKeyWords.Add(RubyKeys[i]);
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Foreground := clMaroon;
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Foreground := clBlue;
AddAttribute(fKeyAttri);
fSecondKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrSecondReservedWord);
AddAttribute(fSecondKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
fNumberAttri.Foreground := clGreen;
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
fStringAttri.Foreground := clPurple;
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
fSymbolAttri.Foreground := clBlue;
AddAttribute(fSymbolAttri);
SetAttributesOnChange({$ifdef FPC} @ {$endif}DefHighlightChange);
MakeMethodTables;
fRange := rsUnknown;
fDefaultFilter := SYNS_FilterRuby;
end; { Create }
destructor TSynRubySyn.Destroy;
begin
fKeyWords.Free;
fSecondKeys.Free;
inherited Destroy;
end; { Destroy }
{$IFDEF SYN_LAZARUS}
procedure TSynRubySyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
procedure TSynRubySyn.SetLine(const NewValue: String; LineNumber:Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end; { SetLine }
procedure TSynRubySyn.BraceOpenProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynRubySyn.PointCommaProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynRubySyn.CRProc;
begin
fTokenID := tkSpace;
case FLine[Run + 1] of
#10: inc(Run, 2);
else inc(Run);
end;
end;
procedure TSynRubySyn.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 TSynRubySyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynRubySyn.LowerProc;
{$IFDEF SYN_HEREDOC}
const
AlphaNumericChars = ['A'..'Z', 'a'..'z', '0'..'9', '_'];
var
i, Len, SkipRun : Integer;
IndentedHeredoc : Boolean;
QuoteChar : Char;
{$ENDIF}
begin
{$IFDEF SYN_HEREDOC}
if FLine[Run + 1] = '<' then
begin
fTokenID := tkSymbol;
SkipRun := 0;
QuoteChar := #0;
if (FLine[Run + 2] = '-') and (FLine[Run + 3] in ['"', '''', '`']) then
begin
SkipRun := 2;
QuoteChar := FLine[Run + 3];
end
else
if (FLine[Run + 2] in ['-', '"', '''', '`']) then
begin
SkipRun := 1;
if FLine[Run + 2] <> '-' then
QuoteChar := FLine[Run + 2];
end;
IndentedHeredoc := (SkipRun > 0) and (FLine[Run + 2] = '-');
if (FLine[Run + SkipRun + 2] in AlphaNumericChars) then
begin
inc(Run, 2);
i := Run;
while FLine[SkipRun + i] in AlphaNumericChars do Inc(i);
Len := i - Run;
if Len > 255 then
begin
fTokenID := tkUnknown;
Exit;
end;
if (QuoteChar <> #0) and (FLine[Run + SkipRun + Len] <> QuoteChar) then
begin
fTokenID := tkUnknown;
Exit;
end;
if IndentedHeredoc then
fRange := rsIndentedHeredoc
else
fRange := rsHeredoc;
fHeredocLength := Len;
fHeredocChecksum := CalcFCS(FLine[Run + SkipRun], Len);
Inc(Run, SkipRun + Len);
fTokenID := tkString;
end
else
inc(Run, 2);
end
else
{$ENDIF}
begin
inc(Run);
fTokenID := tkSymbol;
end;
end;
procedure TSynRubySyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynRubySyn.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 TSynRubySyn.RoundOpenProc;
begin
inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynRubySyn.SlashProc;
begin
case FLine[Run] of
'/':
begin
inc(Run);
fTokenId := tkSymbol;
end;
'*':
begin
inc(Run);
fTokenId := tkSymbol;
end;
else
begin
fTokenID := tkComment;
while FLine[Run] <> #0 do
begin
case FLine[Run] of
#10, #13: break;
end;
inc(Run);
end;
end;
end;
end;
procedure TSynRubySyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
end;
procedure TSynRubySyn.StringProc;
var
QuoteChar: Char;
begin
// Ha, ha, Strings in Ruby (could be anything)!!!!
//There are three more ways to construct string literals: %q, %Q, and ``here
//documents.''
//
//%q and %Q start delimited single- and double-quoted strings.
//
//%q/general single-quoted string/ � general single-quoted string
//%Q!general double-quoted string! � general double-quoted string
//%Q{Seconds/day: #{24*60*60}} � Seconds/day: 86400
//
//The character following the ``q'' or ``Q'' is the delimiter. If it is an
//opening bracket, brace, parenthesis, or less-than sign, the string is read
//until the matching close symbol is found. Otherwise the string is read until
//the next occurrence of the same delimiter.
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 TSynRubySyn.UnknownProc;
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then
Inc(Run, 2)
else
{$ENDIF}
inc(Run);
fTokenID := tkUnknown;
end;
{$IFDEF SYN_HEREDOC}
procedure TSynRubySyn.HeredocProc;
procedure SkipToEOL;
begin
case FLine[Run] of
#0 : NullProc;
#10 : LFProc;
#13 : CRProc;
else
repeat
inc(Run);
until FLine[Run] in [#0, #10, #13];
end;
end;
var
i : Integer;
begin
if (FLine[Run] in [#0, #10, #13]) and (fTokenPos = Run) then
begin
fProcTable[ FLine[Run] ];
Exit;
end;
fTokenID := tkString;
if fRange = rsIndentedHeredoc then
while FLine[Run] in [#9, #32] do Inc(Run);
if ((Run = 0) and (fRange = rsHeredoc)) or (fRange = rsIndentedHeredoc) then
begin
i := 0;
while not (FLine[Run + i] in [#0, #10, #13]) do
begin
if i > fHeredocLength then
begin
SkipToEOL;
Exit;
end;
Inc(i);
end;
if i <> fHeredocLength then
begin
SkipToEOL;
Exit;
end;
if (CalcFCS(FLine[Run], i) = fHeredocChecksum) then
begin
fRange := rsUnknown;
Run := Run + i;
Exit;
end;
end;
SkipToEOL;
end;
{$ENDIF}
procedure TSynRubySyn.Next;
begin
fTokenPos := Run;
{$IFDEF SYN_HEREDOC}
if fRange in [rsHeredoc, rsIndentedHeredoc] then
HeredocProc
else
{$ENDIF}
fProcTable[fLine[Run]];
end;
function TSynRubySyn.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 TSynRubySyn.GetEol: Boolean;
begin
Result := False;
if fTokenId = tkNull then Result := True;
end;
function TSynRubySyn.GetRange: Pointer;
{$IFDEF SYN_HEREDOC}
var
RangePointer : TRangePointer;
{$ENDIF}
begin
{$IFDEF SYN_HEREDOC}
RangePointer.Range := Ord(fRange);
RangePointer.Length := 0;
RangePointer.Checksum := 0;
if fRange in [rsHeredoc, rsIndentedHeredoc] then
begin
RangePointer.Length := fHeredocLength;
RangePointer.Checksum := fHeredocChecksum;
end;
Result := RangePointer.Ptr;
{$ELSE}
Result := Pointer(fRange);
{$ENDIF}
end;
function TSynRubySyn.GetToken: string;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
function TSynRubySyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynRubySyn.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;
tkUnknown: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynRubySyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynRubySyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
procedure TSynRubySyn.ResetRange;
begin
fRange := rsUnknown;
{$IFDEF SYN_HEREDOC}
fHeredocLength := 0;
fHeredocChecksum := 0;
{$ENDIF}
end;
procedure TSynRubySyn.SetRange(Value: Pointer);
{$IFDEF SYN_HEREDOC}
var
RangePointer : TRangePointer;
{$ENDIF}
begin
{$IFDEF SYN_HEREDOC}
RangePointer := TRangePointer(Value);
fRange := TRangeState(RangePointer.Range);
fHeredocLength := 0;
fHeredocChecksum := 0;
if fRange in [rsHeredoc, rsIndentedHeredoc] then
begin
fHeredocLength := RangePointer.Length;
fHeredocChecksum := RangePointer.Checksum;
end;
{$ELSE}
fRange := TRangeState(Value);
{$ENDIF}
end;
procedure TSynRubySyn.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 TSynRubySyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterRuby;
end;
class function TSynRubySyn.GetLanguageName: string;
begin
Result := SYNS_LangRuby;
end;
function TSynRubySyn.GetSampleSource: string;
begin
Result :=
'# Factorial'+#13#10+
'def fact(n)'+#13#10+
' if n == 0'+#13#10+
' 1'+#13#10+
' else'+#13#10+
' n * fact(n-1)'+#13#10+
' end'+#13#10+
'end'+#13#10+
'print fact(ARGV[0].to_i), "\n"';
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSynRubySyn);
{$ENDIF}
end.

View File

@ -0,0 +1,726 @@
{-------------------------------------------------------------------------------
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: SynHighlighterSDD.pas, released 2001-08-20.
The Initial Author of this file is Pieter Polak.
All Rights Reserved.
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: SynHighlighterSDD.pas,v 1.14 2005/01/28 16:53:25 maelh Exp $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
-------------------------------------------------------------------------------}
{$IFNDEF QSYNHIGHLIGHTERSDD}
unit SynHighlighterSDD;
{$ENDIF}
{$I synedit.inc}
interface
uses
{$IFDEF SYN_CLX}
QGraphics,
QSynEditTypes,
QSynEditHighlighter,
{$ELSE}
Graphics,
SynEditTypes,
SynEditHighlighter,
{$ENDIF}
SysUtils,
Classes;
type
TtkTokenKind = (
tkComment,
tkIdentifier,
tkKey,
tkDatatype,
tkNumber,
tkNull,
tkSpace,
tkSymbol,
tkUnknown);
TProcTableProc = procedure of object;
PIdentFuncTableFunc = ^TIdentFuncTableFunc;
TIdentFuncTableFunc = function: TtkTokenKind of object;
TRangeState = (rsComment, rsUnKnown);
type
TSynSDDSyn = class(TSynCustomHighlighter)
private
fLine: PChar;
fLineNumber: Integer;
fProcTable: array[#0..#255] of TProcTableProc;
fRange: TRangeState;
Run: LongInt;
fStringLen: Integer;
fToIdent: PChar;
fTokenPos: Integer;
fTokenID: TtkTokenKind;
fIdentFuncTable: array[0..141] of TIdentFuncTableFunc;
fCommentAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fDatatypeAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
function KeyHash(ToHash: PChar): Integer;
function KeyComp(const aKey: string): Boolean;
function Func21: TtkTokenKind;
function Func23: TtkTokenKind;
function Func30: TtkTokenKind;
function Func36: TtkTokenKind;
function Func41: TtkTokenKind;
function Func43: TtkTokenKind;
function Func47: TtkTokenKind;
function Func52: TtkTokenKind;
function Func53: TtkTokenKind;
function Func55: TtkTokenKind;
function Func60: TtkTokenKind;
function Func63: TtkTokenKind;
function Func66: TtkTokenKind;
function Func74: TtkTokenKind;
function Func75: TtkTokenKind;
function Func78: TtkTokenKind;
function Func87: TtkTokenKind;
function Func91: TtkTokenKind;
function Func95: TtkTokenKind;
function Func100: TtkTokenKind;
function Func104: TtkTokenKind;
function Func115: TtkTokenKind;
function Func122: TtkTokenKind;
function Func141: TtkTokenKind;
procedure BraceOpenProc;
procedure BraceCommentProc;
procedure NumberProc;
procedure CRProc;
procedure LFProc;
procedure IdentProc;
procedure NullProc;
procedure SpaceProc;
procedure UnknownProc;
procedure SymbolProc;
function AltFunc: TtkTokenKind;
procedure InitIdent;
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
protected
function GetIdentChars: TSynIdentChars; override;
function GetSampleSource: string; override;
function IsFilterStored: Boolean; override;
public
class function GetLanguageName: string; override;
function GetRange: Pointer; override;
procedure ResetRange; override;
procedure SetRange(Value: Pointer); override;
public
constructor Create(AOwner: TComponent); override;
function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
override;
function GetEol: Boolean; override;
function GetTokenID: TtkTokenKind;
procedure SetLine(const NewValue: String; LineNumber: Integer); override;
function GetToken: String; override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
published
property CommentAttri: TSynHighlighterAttributes read fCommentAttri write fCommentAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri write fIdentifierAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property DatatypeAttri: TSynHighlighterAttributes read fDatatypeAttri write fDatatypeAttri;
property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri write fSpaceAttri;
property NumberAttri: TSynHighlighterAttributes read fNumberAttri write fNumberAttri;
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri write fSymbolAttri;
end;
implementation
uses
{$IFDEF SYN_CLX}
QSynEditStrConst;
{$ELSE}
SynEditStrConst;
{$ENDIF}
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;
procedure TSynSDDSyn.InitIdent;
var
I: Integer;
pF: PIdentFuncTableFunc;
begin
pF := PIdentFuncTableFunc(@fIdentFuncTable);
for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do begin
pF^ := {$ifdef FPC} @ {$endif} AltFunc;
Inc(pF);
end;
fIdentFuncTable[21] := {$IFDEF FPC}@{$ENDIF} Func21;
fIdentFuncTable[23] := {$IFDEF FPC}@{$ENDIF} Func23;
fIdentFuncTable[30] := {$IFDEF FPC}@{$ENDIF} Func30;
fIdentFuncTable[36] := {$IFDEF FPC}@{$ENDIF} Func36;
fIdentFuncTable[41] := {$IFDEF FPC}@{$ENDIF} Func41;
fIdentFuncTable[43] := {$IFDEF FPC}@{$ENDIF} Func43;
fIdentFuncTable[47] := {$IFDEF FPC}@{$ENDIF} Func47;
fIdentFuncTable[52] := {$IFDEF FPC}@{$ENDIF} Func52;
fIdentFuncTable[53] := {$IFDEF FPC}@{$ENDIF} Func53;
fIdentFuncTable[55] := {$IFDEF FPC}@{$ENDIF} Func55;
fIdentFuncTable[60] := {$IFDEF FPC}@{$ENDIF} Func60;
fIdentFuncTable[63] := {$IFDEF FPC}@{$ENDIF} Func63;
fIdentFuncTable[66] := {$IFDEF FPC}@{$ENDIF} Func66;
fIdentFuncTable[74] := {$IFDEF FPC}@{$ENDIF} Func74;
fIdentFuncTable[75] := {$IFDEF FPC}@{$ENDIF} Func75;
fIdentFuncTable[78] := {$IFDEF FPC}@{$ENDIF} Func78;
fIdentFuncTable[87] := {$IFDEF FPC}@{$ENDIF} Func87;
fIdentFuncTable[91] := {$IFDEF FPC}@{$ENDIF} Func91;
fIdentFuncTable[95] := {$IFDEF FPC}@{$ENDIF} Func95;
fIdentFuncTable[100] := {$IFDEF FPC}@{$ENDIF} Func100;
fIdentFuncTable[104] := {$IFDEF FPC}@{$ENDIF} Func104;
fIdentFuncTable[115] := {$IFDEF FPC}@{$ENDIF} Func115;
fIdentFuncTable[122] := {$IFDEF FPC}@{$ENDIF} Func122;
fIdentFuncTable[141] := {$IFDEF FPC}@{$ENDIF} Func141;
end;
function TSynSDDSyn.KeyHash(ToHash: PChar): Integer;
begin
Result := 0;
while ToHash^ in ['_', '0'..'9', 'a'..'z', 'A'..'Z'] do
begin
inc(Result, mHashTable[ToHash^]);
inc(ToHash);
end;
fStringLen := ToHash - fToIdent;
end;
function TSynSDDSyn.KeyComp(const aKey: String): Boolean;
var
I: Integer;
Temp: PChar;
begin
Temp := fToIdent;
if Length(aKey) = fStringLen then
begin
Result := True;
for i := 1 to fStringLen do
begin
if mHashTable[Temp^] <> mHashTable[aKey[i]] then
begin
Result := False;
break;
end;
inc(Temp);
end;
end else Result := False;
end;
function TSynSDDSyn.Func21: TtkTokenKind;
begin
if KeyComp('of') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func23: TtkTokenKind;
begin
if KeyComp('end') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func30: TtkTokenKind;
begin
if KeyComp('date') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynSDDSyn.Func36: TtkTokenKind;
begin
if KeyComp('real') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynSDDSyn.Func41: TtkTokenKind;
begin
if KeyComp('var') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func43: TtkTokenKind;
begin
if KeyComp('spec') then Result := tkKey else
if KeyComp('block') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func47: TtkTokenKind;
begin
if KeyComp('time') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynSDDSyn.Func52: TtkTokenKind;
begin
if KeyComp('byte') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynSDDSyn.Func53: TtkTokenKind;
begin
if KeyComp('database') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func55: TtkTokenKind;
begin
if KeyComp('object') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func60: TtkTokenKind;
begin
if KeyComp('keys') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func63: TtkTokenKind;
begin
if KeyComp('array') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynSDDSyn.Func66: TtkTokenKind;
begin
if KeyComp('endblock') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func74: TtkTokenKind;
begin
if KeyComp('objects') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func75: TtkTokenKind;
begin
if KeyComp('owner') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func78: TtkTokenKind;
begin
if KeyComp('integer') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynSDDSyn.Func87: TtkTokenKind;
begin
if KeyComp('string') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynSDDSyn.Func91: TtkTokenKind;
begin
if KeyComp('longint') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynSDDSyn.Func95: TtkTokenKind;
begin
if KeyComp('binarydata') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynSDDSyn.Func100: TtkTokenKind;
begin
if KeyComp('primary') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func104: TtkTokenKind;
begin
if KeyComp('secondary') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func115: TtkTokenKind;
begin
if KeyComp('memotext') then Result := tkDatatype else Result := tkIdentifier;
end;
function TSynSDDSyn.Func122: TtkTokenKind;
begin
if KeyComp('partition') then Result := tkKey else
if KeyComp('superspec') then Result := tkKey else
if KeyComp('superblock') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.Func141: TtkTokenKind;
begin
if KeyComp('partitions') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSDDSyn.AltFunc: TtkTokenKind;
begin
Result := tkIdentifier;
end;
function TSynSDDSyn.IdentKind(MayBe: PChar): TtkTokenKind;
var
HashKey: Integer;
begin
fToIdent := MayBe;
HashKey := KeyHash(MayBe);
if HashKey < 142 then Result := fIdentFuncTable[HashKey]{$ifdef FPC} () {$endif} else Result := tkIdentifier;
end;
procedure TSynSDDSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
'{' : fProcTable[I] := {$ifdef FPC} @ {$endif}BraceOpenProc;
'}',
'!',
'%',
'&',
'('..'/',
':'..'@',
'['..'^',
'`', '~' : fProcTable[I] := {$ifdef FPC} @ {$endif}SymbolProc;
'A'..'Z',
'a'..'z',
'_' : fProcTable[I] := {$ifdef FPC} @ {$endif}IdentProc;
'0'..'9' : fProcTable[I] := {$ifdef FPC} @ {$endif}NumberProc;
#0 : fProcTable[I] := {$ifdef FPC} @ {$endif}NullProc;
#1..#32 : fProcTable[I] := {$ifdef FPC} @ {$endif}SpaceProc;
else
fProcTable[I] := {$ifdef FPC} @ {$endif}UnknownProc;
end;
end; { MakeMethodTables }
constructor TSynSDDSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCommentAttri := TSynHighLighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Foreground := clNavy;
fCommentAttri.Style := [fsItalic];
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighLighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighLighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
fKeyAttri.Foreground := clGreen;
AddAttribute(fKeyAttri);
fDatatypeAttri := TSynHighlighterAttributes.Create(SYNS_AttrDataType);
fDatatypeAttri.Style := [fsBold];
fDatatypeAttri.Foreground := clTeal;
AddAttribute(fDatatypeAttri);
fSpaceAttri := TSynHighLighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fNumberAttri := TSynHighLighterAttributes.Create(SYNS_AttrNumber);
fNumberAttri.Foreground := clBlue;
AddAttribute(fNumberAttri);
fSymbolAttri := TSynHighLighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
SetAttributesOnChange({$ifdef FPC} @ {$endif}DefHighlightChange);
InitIdent;
MakeMethodTables;
fDefaultFilter := SYNS_FilterSDD;
fRange := rsUnknown;
end; { Create }
{$IFDEF SYN_LAZARUS}
procedure TSynSDDSyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
procedure TSynSDDSyn.SetLine(const NewValue: String; LineNumber: Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end; { SetLine }
procedure TSynSDDSyn.BraceOpenProc;
begin
fRange := rsComment;
BraceCommentProc;
fTokenID := tkComment;
end; { BraceOpenProc }
procedure TSynSDDSyn.IdentProc;
begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
while Identifiers[fLine[Run]] do
Inc(Run);
end; { IdentProc }
procedure TSynSDDSyn.NullProc;
begin
fTokenID := tkNull;
end; { NullProc }
procedure TSynSDDSyn.SpaceProc;
begin
fTokenID := tkSpace;
repeat
inc(Run);
until not (fLine[Run] in [#1..#32]);
end; { SpaceProc }
procedure TSynSDDSyn.BraceCommentProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
begin
fTokenID := tkComment;
repeat
if fLine[Run] = '}' then
begin
Inc(Run);
fRange := rsUnKnown;
Break;
end;
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
end;
end; { BraceCommentProc }
procedure TSynSDDSyn.UnknownProc;
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then
Inc(Run, 2)
else
{$ENDIF}
inc(Run);
fTokenID := tkUnknown;
end; { UnknownProc }
procedure TSynSDDSyn.Next;
begin
fTokenPos := Run;
case fRange of
rsComment: BraceCommentProc;
else
fProcTable[fLine[Run]];
end;
end; { Next }
procedure TSynSDDSyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run] = #10 then
inc(Run);
end; { CRProc }
procedure TSynSDDSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end; { LFProc }
function TSynSDDSyn.GetSampleSource: string;
begin
Result := '{ Semanta data dictionary }'#13#10 +
'database Sample.001;'#13#10 +
'owner = COAS;'#13#10 +
#13#10 +
'objects'#13#10 +
' Test = object'#13#10 +
' Code : string[4];'#13#10 +
' Name : string[80];'#13#10 +
' end;'#13#10 +
'keys'#13#10 +
' primary Test.Index = [Code];'#13#10 +
'end.';
end; { GetSampleSource }
function TSynSDDSyn.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_WHITESPACE: Result := fSpaceAttri;
SYN_ATTR_SYMBOL : Result := fSymbolAttri;
else
Result := nil;
end;
end; { GetDefaultAttribute }
function TSynSDDSyn.GetEol: Boolean;
begin
Result := fTokenID = tkNull;
end; { GetEol }
function TSynSDDSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end; { GetToken }
function TSynSDDSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end; { GetTokenId }
function TSynSDDSyn.GetTokenAttribute: TSynHighLighterAttributes;
begin
case GetTokenID of
tkComment: Result := fCommentAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkDatatype: Result := fDatatypeAttri;
tkSpace: Result := fSpaceAttri;
tkNumber: Result := fNumberAttri;
tkUnknown: Result := fIdentifierAttri;
tkSymbol: Result := fSymbolAttri;
else
Result := nil;
end;
end; { GetTokenAttribute }
function TSynSDDSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end; { GetTokenKind }
function TSynSDDSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end; { GetTokenPos }
procedure TSynSDDSyn.ResetRange;
begin
inherited;
fRange := rsUnknown;
end; { ResetRange }
procedure TSynSDDSyn.SetRange(Value: Pointer);
begin
inherited;
fRange := TRangeState(Value);
end; { SetRange }
function TSynSDDSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end; { GetRange }
function TSynSDDSyn.GetIdentChars: TSynIdentChars;
begin
Result := TSynValidStringChars;
end; { GetIdentChars }
class function TSynSDDSyn.GetLanguageName: string;
begin
Result := SYNS_LangSDD;
end; { GetLanguageName }
procedure TSynSDDSyn.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; { NumberProc }
function TSynSDDSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterSDD;
end; { IsFilterStored }
procedure TSynSDDSyn.SymbolProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSynSDDSyn);
{$ENDIF}
end.

View File

@ -0,0 +1,955 @@
{-------------------------------------------------------------------------------
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: SynHighlighterSML.pas, released 2000-04-17.
The Original Code is based on the dmMLSyn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is David H. Muir.
All Rights Reserved.
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: SynHighlighterSml.pas,v 1.15 2005/01/28 16:53:25 maelh 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 SynEdit with a Standard ML syntax highlighter, with extra options for the standard Basis library.)
@author(David H Muir <dhm@dmsoftware.co.uk>)
@created(1999)
@lastmod(2000-06-23)
The SynHighlighterSML.pas unit provides SynEdit text control with a Standard ML highlighter. Many formatting attributes can
be specified, and there is an option to include extra keywords and operators only found in the Basis library, this option can
be disabled for backwards compatibility with older ML compilers that do not have support for the Basis Library.
}
unit SynHighlighterSml;
{$I synedit.inc}
interface
uses
{$IFDEF SYN_CLX}
QGraphics,
QSynEditTypes,
QSynEditHighlighter,
{$ELSE}
Graphics,
SynEditTypes,
SynEditHighlighter,
{$ENDIF}
SysUtils,
Classes;
Type
TtkTokenKind = (tkCharacter, tkComment, tkIdentifier, tkKey, tkNull, tkNumber,
tkOperator, tkSpace, tkString, tkSymbol, tkSyntaxError, tkUnknown);
TProcTableProc = procedure of object;
TRangeState = (rsUnknown, rsComment, rsMultilineString);
PIdentFuncTableFunc = ^TIdentFuncTableFunc;
TIdentFuncTableFunc = function: TtkTokenKind of object;
type
TSynSMLSyn = class(TSynCustomHighlighter)
private
fBasis: Boolean;
fLine: PChar;
fLineNumber: Integer;
fProcTable: array[#0..#255] of TProcTableProc;
fRange: TRangeState;
Run: LongInt;
fStringLen: Integer;
fToIdent: PChar;
fTokenPos: Integer;
FTokenID: TtkTokenKind;
fIdentFuncTable: array[0..145] of TIdentFuncTableFunc;
fCharacterAttri: TSynHighlighterAttributes;
fCommentAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fNumberAttri: TSynHighlighterAttributes;
fOperatorAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
fSyntaxErrorAttri: TSynHighlighterAttributes;
function IsValidMLCharacter: Boolean;
function KeyHash(ToHash: PChar): Integer;
function KeyComp(const aKey: String): Boolean;
function Func15: TtkTokenKind;
function Func19: TtkTokenKind;
function Func20: TtkTokenKind;
function Func21: TtkTokenKind;
function Func23: TtkTokenKind;
function Func26: TtkTokenKind;
function Func28: TtkTokenKind;
function Func31: TtkTokenKind;
function Func35: TtkTokenKind;
function Func37: TtkTokenKind;
function Func41: TtkTokenKind;
function Func43: TtkTokenKind;
function Func44: TtkTokenKind;
function Func47: TtkTokenKind;
function Func50: TtkTokenKind;
function Func52: TtkTokenKind;
function Func57: TtkTokenKind;
function Func59: TtkTokenKind;
function Func60: TtkTokenKind;
function Func62: TtkTokenKind;
function Func66: TtkTokenKind;
function Func68: TtkTokenKind;
function Func74: TtkTokenKind;
function Func76: TtkTokenKind;
function Func80: TtkTokenKind;
function Func82: TtkTokenKind;
function Func88: TtkTokenKind;
function Func92: TtkTokenKind;
function Func97: TtkTokenKind;
function Func101: TtkTokenKind;
function Func111: TtkTokenKind;
function Func114: TtkTokenKind;
function Func126: TtkTokenKind;
function Func145: TtkTokenKind;
procedure CRProc;
procedure CharacterProc;
procedure ColonProc;
procedure CommentProc;
procedure IdentProc;
procedure LFProc;
procedure NullProc;
procedure NumberProc;
procedure OperatorProc;
procedure RoundBracketOpenProc;
procedure SpaceProc;
procedure StringProc;
procedure SymbolProc;
procedure UnknownProc;
procedure BasisOpProc;
function AltFunc: TtkTokenKind;
procedure InitIdent;
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
procedure StringEndProc;
procedure PoundProc;
protected
function GetIdentChars: TSynIdentChars; override;
function GetSampleSource: string; override;
function IsFilterStored: Boolean; override;
public
class function GetLanguageName: string; override;
function GetRange: Pointer; override;
procedure ResetRange; override;
procedure SetRange(Value: Pointer); override;
public
constructor Create(AOwner: TComponent); override;
function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
override;
function GetEol: Boolean; override;
function GetTokenID: TtkTokenKind;
procedure SetLine(const NewValue: String; LineNumber: Integer); override;
function GetToken: String; override;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
published
property CharacterAttri: TSynHighlighterAttributes read fCharacterAttri
write fCharacterAttri;
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
write fIdentifierAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property NumberAttri: TSynHighlighterAttributes read fNumberAttri
write fNumberAttri;
property OperatorAttri: TSynHighlighterAttributes read fOperatorAttri
write fOperatorAttri;
property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri
write fSpaceAttri;
property StringAttri: TSynHighlighterAttributes read fStringAttri
write fStringAttri;
property SymbolAttri: TSynHighlighterAttributes read fSymbolAttri
write fSymbolAttri;
property SyntaxErrorAttri: TSynHighlighterAttributes read fSyntaxErrorAttri
write fSyntaxErrorAttri;
property Basis: Boolean read FBasis write FBasis default True;
end;
implementation
uses
{$IFDEF SYN_CLX}
QSynEditStrConst;
{$ELSE}
SynEditStrConst;
{$ENDIF}
const
Identifiers = [#39, '_', '0'..'9', 'a'..'z', 'A'..'Z'];
var
mHashTable: array[#0..#255] of Integer;
procedure MakeIdentTable;
var
I: Char;
begin
for I := #0 to #255 do
begin
if I in ['_', 'A'..'Z', 'a'..'z'] then
mHashTable[I] := Ord(UpCase(I)) - 64
else
mHashTable[I] := 0;
end;
end;
function TSynSMLSyn.IsValidMLCharacter: Boolean;
var
ASCIIStr: string;
ASCIICode, Error: Integer;
begin
Result := False;
if (fLine[Run] = '"') then
if (Run > 2) and (fLine[Run - 1] <> '\') and (fLine[Run - 2] = '"') then
Result := True
else if (Run > 3) and (fLine[Run - 1] = '\') and (fLine[Run - 2] = '\')
and (fLine[Run - 3] = '"') then
Result := True
else if (Run > 3) and (fLine[Run - 1] in ['a', 'b', 'n', 'r', 't']) and
(fLine[Run - 2] = '\') and (fLine[Run - 3] = '"') then
Result := True
else if (Run > 5) and (fLine[Run - 4] = '\') and (fLine[Run - 5] = '"') then
begin
ASCIIStr := copy(fLine, Run - 2, 3);
Val(ASCIIStr, ASCIICode, Error);
if (Error = 0) and (ASCIICode >= 0) and (ASCIICode <= 255) then
Result := True
end
end;
procedure TSynSMLSyn.InitIdent;
var
I: Integer;
pF: PIdentFuncTableFunc;
begin
pF := PIdentFuncTableFunc(@fIdentFuncTable);
for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do begin
pF^ := {$ifdef FPC} @ {$endif}AltFunc;
Inc(pF);
end;
fIdentFuncTable[15] := {$IFDEF FPC}@{$ENDIF} Func15;
fIdentFuncTable[19] := {$IFDEF FPC}@{$ENDIF} Func19;
fIdentFuncTable[20] := {$IFDEF FPC}@{$ENDIF} Func20;
fIdentFuncTable[21] := {$IFDEF FPC}@{$ENDIF} Func21;
fIdentFuncTable[23] := {$IFDEF FPC}@{$ENDIF} Func23;
fIdentFuncTable[26] := {$IFDEF FPC}@{$ENDIF} Func26;
fIdentFuncTable[28] := {$IFDEF FPC}@{$ENDIF} Func28;
fIdentFuncTable[31] := {$IFDEF FPC}@{$ENDIF} Func31;
fIdentFuncTable[35] := {$IFDEF FPC}@{$ENDIF} Func35;
fIdentFuncTable[37] := {$IFDEF FPC}@{$ENDIF} Func37;
fIdentFuncTable[41] := {$IFDEF FPC}@{$ENDIF} Func41;
fIdentFuncTable[43] := {$IFDEF FPC}@{$ENDIF} Func43;
fIdentFuncTable[44] := {$IFDEF FPC}@{$ENDIF} Func44;
fIdentFuncTable[47] := {$IFDEF FPC}@{$ENDIF} Func47;
fIdentFuncTable[50] := {$IFDEF FPC}@{$ENDIF} Func50;
fIdentFuncTable[52] := {$IFDEF FPC}@{$ENDIF} Func52;
fIdentFuncTable[57] := {$IFDEF FPC}@{$ENDIF} Func57;
fIdentFuncTable[59] := {$IFDEF FPC}@{$ENDIF} Func59;
fIdentFuncTable[60] := {$IFDEF FPC}@{$ENDIF} Func60;
fIdentFuncTable[62] := {$IFDEF FPC}@{$ENDIF} Func62;
fIdentFuncTable[66] := {$IFDEF FPC}@{$ENDIF} Func66;
fIdentFuncTable[68] := {$IFDEF FPC}@{$ENDIF} Func68;
fIdentFuncTable[74] := {$IFDEF FPC}@{$ENDIF} Func74;
fIdentFuncTable[76] := {$IFDEF FPC}@{$ENDIF} Func76;
fIdentFuncTable[80] := {$IFDEF FPC}@{$ENDIF} Func80;
fIdentFuncTable[82] := {$IFDEF FPC}@{$ENDIF} Func82;
fIdentFuncTable[88] := {$IFDEF FPC}@{$ENDIF} Func88;
fIdentFuncTable[92] := {$IFDEF FPC}@{$ENDIF} Func92;
fIdentFuncTable[97] := {$IFDEF FPC}@{$ENDIF} Func97;
fIdentFuncTable[101] := {$IFDEF FPC}@{$ENDIF} Func101;
fIdentFuncTable[111] := {$IFDEF FPC}@{$ENDIF} Func111;
fIdentFuncTable[114] := {$IFDEF FPC}@{$ENDIF} Func114;
fIdentFuncTable[126] := {$IFDEF FPC}@{$ENDIF} Func126;
fIdentFuncTable[145] := {$IFDEF FPC}@{$ENDIF} Func145;
end;
function TSynSMLSyn.KeyHash(ToHash: PChar): Integer;
begin
Result := 0;
while ToHash^ in Identifiers do
begin
inc(Result, mHashTable[ToHash^]);
inc(ToHash);
end;
fStringLen := ToHash - fToIdent;
end;
function TSynSMLSyn.KeyComp(const aKey: String): Boolean;
var
I: Integer;
Temp: PChar;
begin
Temp := fToIdent;
if Length(aKey) = fStringLen then
begin
Result := True;
for i := 1 to fStringLen do
begin
if Temp^ <> aKey[i] then
begin
Result := False;
break;
end;
inc(Temp);
end;
end else Result := False;
end;
function TSynSMLSyn.Func15: TtkTokenKind;
begin
if KeyComp('if') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func19: TtkTokenKind;
begin
if KeyComp('do') then Result := tkKey else
if KeyComp('and') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func20: TtkTokenKind;
begin
if KeyComp('as') then Result := tkKey else
if KeyComp('fn') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func21: TtkTokenKind;
begin
if KeyComp('of') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func23: TtkTokenKind;
begin
if KeyComp('in') then Result := tkKey else
if KeyComp('end') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func26: TtkTokenKind;
begin
if KeyComp('rec') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func28: TtkTokenKind;
begin
if KeyComp('case') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func31: TtkTokenKind;
begin
if KeyComp('op') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func35: TtkTokenKind;
begin
if KeyComp('val') then Result := tkKey else
if KeyComp('sig') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func37: TtkTokenKind;
begin
if KeyComp('let') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func41: TtkTokenKind;
begin
if KeyComp('fun') then Result := tkKey else
if KeyComp('else') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func43: TtkTokenKind;
begin
if KeyComp('local') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func44: TtkTokenKind;
begin
if KeyComp('handle') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func47: TtkTokenKind;
begin
if KeyComp('then') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func50: TtkTokenKind;
begin
if KeyComp('open') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func52: TtkTokenKind;
begin
if KeyComp('raise') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func57: TtkTokenKind;
begin
if KeyComp('while') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func59: TtkTokenKind;
begin
if KeyComp('where') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func60: TtkTokenKind;
begin
if KeyComp('with') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func62: TtkTokenKind;
begin
if KeyComp('infix') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func66: TtkTokenKind;
begin
if KeyComp('andalso') then Result := tkKey else
if KeyComp('type') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func68: TtkTokenKind;
begin
if KeyComp('include') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func74: TtkTokenKind;
begin
if KeyComp('orelse') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func76: TtkTokenKind;
begin
if KeyComp('sharing') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func80: TtkTokenKind;
begin
if KeyComp('infixr') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func82: TtkTokenKind;
begin
if KeyComp('nonfix') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func88: TtkTokenKind;
begin
if KeyComp('abstype') then Result := tkKey else
if KeyComp('eqtype') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func92: TtkTokenKind;
begin
if KeyComp('datatype') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func97: TtkTokenKind;
begin
if KeyComp('functor') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func101: TtkTokenKind;
begin
if KeyComp('struct') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func111: TtkTokenKind;
begin
if KeyComp('exception') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func114: TtkTokenKind;
begin
if KeyComp('signature') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func126: TtkTokenKind;
begin
if KeyComp('withtype') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.Func145: TtkTokenKind;
begin
if KeyComp('structure') then Result := tkKey else Result := tkIdentifier;
end;
function TSynSMLSyn.AltFunc: TtkTokenKind;
begin
Result := tkIdentifier;
end;
function TSynSMLSyn.IdentKind(MayBe: PChar): TtkTokenKind;
var
HashKey: Integer;
begin
fToIdent := MayBe;
HashKey := KeyHash(MayBe);
if HashKey < 146 then Result := fIdentFuncTable[HashKey]{$ifdef FPC} () {$endif} else Result := tkIdentifier;
end;
procedure TSynSMLSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
#13: fProcTable[I] := {$ifdef FPC} @ {$endif}CRProc;
'#': fProcTable[I] := {$ifdef FPC} @ {$endif}PoundProc;
':': fProcTable[I] := {$ifdef FPC} @ {$endif}ColonProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := {$ifdef FPC} @ {$endif}IdentProc;
#10: fProcTable[I] := {$ifdef FPC} @ {$endif}LFProc;
#0: fProcTable[I] := {$ifdef FPC} @ {$endif}NullProc;
'0'..'9': fProcTable[I] := {$ifdef FPC} @ {$endif}NumberProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := {$ifdef FPC} @ {$endif}SpaceProc;
'"': fProcTable[I] := {$ifdef FPC} @ {$endif}StringProc;
'@', '^': fProcTable[I] := {$ifdef FPC} @ {$endif}BasisOpProc;
'(': fProcTable[I] := {$ifdef FPC} @ {$endif}RoundBracketOpenProc;
'+', '-', '~', '*', '/', '=', '<', '>': fProcTable[i] := {$ifdef FPC} @ {$endif}OperatorProc;
',', '.', ';': fProcTable[I] := {$ifdef FPC} @ {$endif}SymbolProc;
else
fProcTable[I] := {$ifdef FPC} @ {$endif}UnknownProc;
end;
end;
constructor TSynSMLSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCharacterAttri := TSynHighlighterAttributes.Create(SYNS_AttrCharacter);
fCharacterAttri.Foreground := clBlue;
AddAttribute(fCharacterAttri);
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style := [fsItalic];
fCommentAttri.Foreground := clNavy;
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
fKeyAttri.Foreground := clGreen;
AddAttribute(fKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
fNumberAttri.Foreground := clRed;
AddAttribute(fNumberAttri);
fOperatorAttri := TSynHighlighterAttributes.Create(SYNS_AttrOperator);
fOperatorAttri.Foreground := clMaroon;
AddAttribute(fOperatorAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
fStringAttri.Foreground := clBlue;
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
fSyntaxErrorAttri := TSynHighlighterAttributes.Create(SYNS_AttrSyntaxError);
fSyntaxErrorAttri.Foreground := clRed;
fSyntaxErrorAttri.Style := [fsBold];
AddAttribute(fSyntaxErrorAttri);
SetAttributesOnChange({$ifdef FPC} @ {$endif}DefHighlightChange);
InitIdent;
MakeMethodTables;
fDefaultFilter := SYNS_FilterSML;
Basis := True;
end;
{$IFDEF SYN_LAZARUS}
procedure TSynSMLSyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
procedure TSynSMLSyn.SetLine(const NewValue: String; LineNumber: Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynSMLSyn.CRProc;
begin
fTokenID := tkSpace;
Case FLine[Run + 1] of
#10: inc(Run, 2);
else inc(Run);
end;
end;
procedure TSynSMLSyn.ColonProc;
begin
inc(Run);
if Basis and (fLine[Run] = ':') then begin
fTokenID := tkOperator;
inc(Run);
end
else fTokenID := tkSymbol;
end;
procedure TSynSMLSyn.IdentProc;
begin
fTokenID := IdentKind((fLine + Run));
inc(Run, fStringLen);
while fLine[Run] in Identifiers do inc(Run);
end;
procedure TSynSMLSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynSMLSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynSMLSyn.NumberProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in
['0'..'9', '.', 'u', 'U', 'l', 'L', 'x', 'X', 'e', 'E', 'f', 'F'] do
begin
case FLine[Run] of
'.': if FLine[Run + 1] = '.' then break;
end;
inc(Run);
end;
end;
procedure TSynSMLSyn.OperatorProc;
begin
inc(Run);
fTokenID := tkOperator;
end;
procedure TSynSMLSyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
end;
procedure TSynSMLSyn.StringProc;
begin
fTokenID := tkString;
repeat
if fLine[Run] = '\' then begin
case fLine[Run + 1] of
'"', '\':
Inc(Run);
#00:
begin
Inc(Run);
fRange := rsMultilineString;
Exit;
end;
end;
end;
inc(Run);
until fLine[Run] in [#0, #10, #13, '"'];
if FLine[Run] = '"' then
inc(Run);
end;
procedure TSynSMLSyn.StringEndProc;
begin
fTokenID := tkString;
case FLine[Run] of
#0:
begin
NullProc;
Exit;
end;
#10:
begin
LFProc;
Exit;
end;
#13:
begin
CRProc;
Exit;
end;
end;
fRange := rsUnknown;
repeat
case FLine[Run] of
#0, #10, #13: Break;
'\':
begin
case fLine[Run + 1] of
'"', '\':
Inc(Run);
#00:
begin
Inc(Run);
fRange := rsMultilineString;
Exit;
end;
end;
end;
'"': Break;
end;
inc(Run);
until fLine[Run] in [#0, #10, #13, '"'];
if FLine[Run] = '"' then
inc(Run);
end;
procedure TSynSMLSyn.SymbolProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynSMLSyn.UnknownProc;
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then
Inc(Run, 2)
else
{$ENDIF}
inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynSMLSyn.BasisOpProc;
begin
inc(Run);
if Basis then fTokenID := tkOperator else fTokenID := tkIdentifier;
end;
procedure TSynSMLSyn.PoundProc;
begin
Inc(Run);
if (fLine[Run] = '"') then
CharacterProc
else
fTokenID := tkIdentifier;
end;
procedure TSynSMLSyn.CharacterProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
begin
repeat
Inc(Run);
until fLine[Run] in [#0, #10, #13, '"'];
if IsValidMLCharacter then
fTokenID := tkCharacter
else
begin
if fLine[Run] = '"' then Inc(Run);
fTokenID := tkSyntaxError;
end;
end
end
end;
procedure TSynSMLSyn.RoundBracketOpenProc;
begin
Inc(Run);
if (fLine[Run] = '*') then
begin
fRange := rsComment;
CommentProc;
fTokenID := tkComment;
end
else
fTokenID := tkIdentifier;
end;
procedure TSynSMLSyn.CommentProc;
begin
case fLine[Run] of
#0: NullProc;
#10: LFProc;
#13: CRProc;
else
begin
fTokenID := tkComment;
repeat
if (fLine[Run] = '*') and
(fLine[Run + 1] = ')') then
begin
Inc(Run, 2);
fRange := rsUnknown;
Break;
end;
if not (fLine[Run] in [#0, #10, #13]) then
Inc(Run);
until fLine[Run] in [#0, #10, #13];
end;
end;
end;
procedure TSynSMLSyn.Next;
begin
fTokenPos := Run;
case fRange of
rsComment: CommentProc;
rsMultilineString: StringEndProc;
else
begin
fRange := rsUnknown;
fProcTable[fLine[Run]];
end;
end;
end;
function TSynSMLSyn.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_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynSMLSyn.GetEol: Boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynSMLSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
function TSynSMLSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynSMLSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case GetTokenID of
tkCharacter: Result := fCharacterAttri;
tkComment: Result := fCommentAttri;
tkIdentifier: Result := fIdentifierAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkOperator: Result := fOperatorAttri;
tkSpace: Result := fSpaceAttri;
tkString: Result := fStringAttri;
tkSymbol: Result := fSymbolAttri;
tkSyntaxError: Result := fSyntaxErrorAttri;
tkUnknown: Result := fIdentifierAttri;
else Result := nil;
end;
end;
function TSynSMLSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynSMLSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSynSMLSyn.GetIdentChars: TSynIdentChars;
begin
Result := TSynValidStringChars;
end;
function TSynSMLSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterSML;
end;
class function TSynSMLSyn.GetLanguageName: string;
begin
Result := SYNS_LangSML;
end;
function TSynSMLSyn.GetSampleSource: string;
begin
Result := '(* Syntax highlighting *)'#13#10 +
'load "Real";'#13#10 +
'fun PrintNumber(x: int) ='#13#10 +
' let'#13#10 +
' val Number = real(x) / 10.0;'#13#10 +
' val Text = "The Number is " ^ Real.toString(~Number) ^ "\n";'#13#10 +
' in'#13#10 +
' print Text;'#13#10 +
' if x = 0 then () else PrintNumber(x-1)'#13#10+
' end;'
end;
procedure TSynSMLSyn.ResetRange;
begin
fRange := rsUnknown;
end;
procedure TSynSMLSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
function TSynSMLSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSynSMLSyn);
{$ENDIF}
end.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,800 @@
{-------------------------------------------------------------------------------
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: SynHighlighterTclTk.pas, released 2000-05-05.
The Original Code is based on the siTclTkSyn.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Igor Shitikov.
All Rights Reserved.
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: SynHighlighterTclTk.pas,v 1.19 2005/01/28 16:53:25 maelh 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 a TCL/Tk highlighter for SynEdit)
@author(Igor Shitikov, converted to SynEdit by David Muir <dhm@dmsoftware.co.uk>)
@created(5 December 1999, converted to SynEdit April 18, 2000)
@lastmod(2000-06-23)
The SynHighlighterTclTk unit provides SynEdit with a TCL/Tk highlighter.
}
{$IFNDEF QSYNHIGHLIGHTERTCLTK}
unit SynHighlighterTclTk;
{$ENDIF}
{$I synedit.inc}
interface
uses
{$IFDEF SYN_CLX}
QGraphics,
QSynEditTypes,
QSynEditHighlighter,
{$ELSE}
Windows,
Graphics,
SynEditTypes,
SynEditHighlighter,
{$ENDIF}
SysUtils,
Classes;
type
TtkTokenKind = (tkComment, tkIdentifier, tkKey, tkNull, tkNumber, tkSecondKey,
tkSpace, tkString, tkSymbol, tkUnknown);
TRangeState = (rsUnknown, rsAnsi, rsPasStyle, rsCStyle);
TProcTableProc = procedure of object;
type
TSynTclTkSyn = 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;
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 SetKeyWords(const Value: TStrings);
procedure SetSecondKeys(const Value: TStrings);
function IsKeywordListStored: boolean;
protected
function GetSampleSource: string; override;
function IsFilterStored: Boolean; 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;
function IsKeyword(const AKeyword: string): boolean; override;
function IsSecondKeyWord(aToken: string): Boolean;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
procedure SetLine(const NewValue: string; LineNumber:Integer); override;
function GetToken: string; override;
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
procedure SetRange(Value: Pointer); override;
procedure ResetRange; override;
{$IFNDEF SYN_LAZARUS} {$IFNDEF SYN_CLX}
function SaveToRegistry(RootKey: HKEY; Key: string): boolean; override;
function LoadFromRegistry(RootKey: HKEY; Key: string): boolean; override;
{$ENDIF} {$ENDIF}
published
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
property IdentifierAttri: TSynHighlighterAttributes read fIdentifierAttri
write fIdentifierAttri;
property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri;
property KeyWords: TStrings read fKeyWords write SetKeyWords
stored IsKeywordListStored;
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;
end;
implementation
uses
{$IFDEF SYN_CLX}
QSynEditStrConst;
{$ELSE}
SynEditStrConst, SynEditStrConstExtra;
{$ENDIF}
const
TclTkKeys: array[0..146] of string = (
'AFTER', 'APPEND', 'ARRAY', 'BELL', 'BGERROR', 'BINARY', 'BIND',
'BINDIDPROC', 'BINDPROC', 'BINDTAGS', 'BITMAP', 'BREAK', 'BUTTON',
'CANVAS', 'CATCH', 'CD', 'CHECKBUTTON', 'CLIPBOARD', 'CLOCK',
'CLOSE', 'CONCAT', 'CONTINUE', 'DESTROY', 'ELSE', 'ENTRY', 'EOF',
'ERROR', 'EVAL', 'EVENT', 'EXEC', 'EXIT', 'EXPR', 'FBLOCKED',
'FCONFIGURE', 'FCOPY', 'FILE', 'FILEEVENT', 'FILENAME', 'FLUSH',
'FOCUS', 'FONT', 'FOR', 'FOREACH', 'FORMAT', 'FRAME', 'GETS', 'GLOB',
'GLOBAL', 'GRAB', 'GRID', 'HISTORY', 'HTTP', 'IF', 'IMAGE', 'INCR',
'INFO', 'INTERP', 'JOIN', 'LABEL', 'LAPPEND', 'LIBRARY', 'LINDEX',
'LINSERT', 'LIST', 'LISTBOX', 'LLENGTH', 'LOAD', 'LOADTK', 'LOWER',
'LRANGE', 'LREPLACE', 'LSEARCH', 'LSORT', 'MENU', 'MESSAGE', 'NAMESPACE',
'NAMESPUPD', 'OPEN', 'OPTION', 'OPTIONS', 'PACK', 'PACKAGE', 'PHOTO',
'PID', 'PKG_MKINDEX', 'PLACE', 'PROC', 'PUTS', 'PWD', 'RADIOBUTTON',
'RAISE', 'READ', 'REGEXP', 'REGISTRY', 'REGSUB', 'RENAME', 'RESOURCE',
'RETURN', 'RGB', 'SAFEBASE', 'SCALE', 'SCAN', 'SEEK', 'SELECTION',
'SEND', 'SENDOUT', 'SET', 'SOCKET', 'SOURCE', 'SPLIT', 'STRING', 'SUBST',
'SWITCH', 'TCL', 'TCLVARS', 'TELL', 'TEXT', 'THEN', 'TIME', 'TK',
'TK_BISQUE', 'TK_CHOOSECOLOR', 'TK_DIALOG', 'TK_FOCUSFOLLOWSMOUSE',
'TK_FOCUSNEXT', 'TK_FOCUSPREV', 'TK_GETOPENFILE', 'TK_GETSAVEFILE',
'TK_MESSAGEBOX', 'TK_OPTIONMENU', 'TK_POPUP', 'TK_SETPALETTE', 'TKERROR',
'TKVARS', 'TKWAIT', 'TOPLEVEL', 'TRACE', 'UNKNOWN', 'UNSET', 'UPDATE',
'UPLEVEL', 'UPVAR', 'VARIABLE', 'VWAIT', 'WHILE', 'WINFO', 'WM');
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 TSynTclTkSyn.IsKeyword(const AKeyword: string): boolean;
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 TSynTclTkSyn.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 TSynTclTkSyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
'#': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} SlashProc;
'{': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} BraceOpenProc;
';': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} PointCommaProc;
#13: fProcTable[I] := {$IFDEF FPC}@{$ENDIF} CRProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} IdentProc;
#10: fProcTable[I] := {$IFDEF FPC}@{$ENDIF} LFProc;
#0: fProcTable[I] := {$IFDEF FPC}@{$ENDIF} NullProc;
'0'..'9': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} NumberProc;
'(': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} RoundOpenProc;
'/': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} SlashProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := {$IFDEF FPC}@{$ENDIF} SpaceProc;
#34: fProcTable[I] := {$IFDEF FPC}@{$ENDIF} StringProc;
else
fProcTable[I] := {$IFDEF FPC}@{$ENDIF} UnknownProc;
end;
end;
constructor TSynTclTkSyn.Create(AOwner: TComponent);
var
i: integer;
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;
for i := Low(TclTkKeys) to High(TclTkKeys) do
FKeyWords.Add(TclTkKeys[i]);
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style := [fsItalic];
AddAttribute(fCommentAttri);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
AddAttribute(fIdentifierAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord);
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fSecondKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrSecondReservedWord);
fSecondKeyAttri.Style := [fsBold];
AddAttribute(fSecondKeyAttri);
fNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber);
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString);
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol);
AddAttribute(fSymbolAttri);
SetAttributesOnChange({$IFDEF FPC}@{$ENDIF}DefHighlightChange);
MakeMethodTables;
fRange := rsUnknown;
fDefaultFilter := SYNS_FilterTclTk;
end; { Create }
destructor TSynTclTkSyn.Destroy;
begin
fKeyWords.Free;
fSecondKeys.Free;
inherited Destroy;
end; { Destroy }
{$IFDEF SYN_LAZARUS}
procedure TSynTclTkSyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
procedure TSynTclTkSyn.SetLine(const NewValue: String; LineNumber:Integer);
begin
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end; { SetLine }
procedure TSynTclTkSyn.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 TSynTclTkSyn.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 TSynTclTkSyn.CStyleProc;
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 TSynTclTkSyn.BraceOpenProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynTclTkSyn.PointCommaProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynTclTkSyn.CRProc;
begin
fTokenID := tkSpace;
Case FLine[Run + 1] of
#10: inc(Run, 2);
else inc(Run);
end;
end;
procedure TSynTclTkSyn.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 TSynTclTkSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynTclTkSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynTclTkSyn.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 TSynTclTkSyn.RoundOpenProc;
begin
inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynTclTkSyn.SlashProc;
begin
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
inc(Run);
fTokenId := tkSymbol;
end;
else
begin
fTokenID := tkComment;
while FLine[Run] <> #0 do
begin
case FLine[Run] of
#10, #13: break;
end;
inc(Run);
end;
end;
end;
end;
procedure TSynTclTkSyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
end;
procedure TSynTclTkSyn.StringProc;
begin
fTokenID := tkString;
if (FLine[Run + 1] = #34) and (FLine[Run + 2] = #34)
then inc(Run, 2);
repeat
case FLine[Run] of
#0, #10, #13: break;
end;
inc(Run);
until (FLine[Run] = #34) and (FLine[Pred(Run)] <> '\');
if FLine[Run] <> #0 then inc(Run);
end;
procedure TSynTclTkSyn.UnknownProc;
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then
Inc(Run, 2)
else
{$ENDIF}
inc(Run);
fTokenID := tkUnKnown;
end;
procedure TSynTclTkSyn.Next;
begin
fTokenPos := Run;
case fRange of
rsAnsi: AnsiProc;
rsPasStyle: PasStyleProc;
rsCStyle: CStyleProc;
else
fProcTable[fLine[Run]];
end;
end;
function TSynTclTkSyn.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_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynTclTkSyn.GetEol: Boolean;
begin
Result := False;
if fTokenId = tkNull then Result := True;
end;
function TSynTclTkSyn.GetRange: Pointer;
begin
Result := Pointer(fRange);
end;
function TSynTclTkSyn.GetToken: string;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
function TSynTclTkSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynTclTkSyn.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;
tkUnknown: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynTclTkSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynTclTkSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
procedure TSynTclTkSyn.ResetRange;
begin
fRange := rsUnknown;
end;
procedure TSynTclTkSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(Value);
end;
procedure TSynTclTkSyn.SetKeyWords(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;
fKeyWords.Assign(Value);
DefHighLightChange(nil);
end;
procedure TSynTclTkSyn.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 TSynTclTkSyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterTclTk;
end;
class function TSynTclTkSyn.GetLanguageName: string;
begin
Result := SYNS_LangTclTk;
end;
{$IFNDEF SYN_LAZARUS} {$IFNDEF SYN_CLX}
function TSynTclTkSyn.LoadFromRegistry(RootKey: HKEY; Key: string): boolean;
var
r: TBetterRegistry;
begin
r:= TBetterRegistry.Create;
try
r.RootKey := RootKey;
if r.OpenKeyReadOnly(Key) then begin
if r.ValueExists('KeyWords') then KeyWords.Text:= r.ReadString('KeyWords');
Result := inherited LoadFromRegistry(RootKey, Key);
end
else Result := false;
finally r.Free; end;
end;
function TSynTclTkSyn.SaveToRegistry(RootKey: HKEY; Key: string): boolean;
var
r: TBetterRegistry;
begin
r:= TBetterRegistry.Create;
try
r.RootKey := RootKey;
if r.OpenKey(Key,true) then begin
Result := true;
r.WriteString('KeyWords', KeyWords.Text);
Result := inherited SaveToRegistry(RootKey, Key);
end
else Result := false;
finally r.Free; end;
end;
{$ENDIF} {$ENDIF}
function TSynTclTkSyn.IsKeywordListStored: boolean;
var
iKeys: TStringList;
cDefKey: integer;
iIndex: integer;
begin
iKeys := TStringList.Create;
try
iKeys.Assign( KeyWords );
iIndex := 0;
for cDefKey := Low(TclTkKeys) to High(TclTkKeys) do
begin
if not iKeys.Find( TclTkKeys[cDefKey], iIndex ) then
begin
Result := True;
Exit;
end;
iKeys.Delete( iIndex );
end;
Result := iKeys.Count <> 0;
finally
iKeys.Free;
end;
end;
function TSynTclTkSyn.GetSampleSource: string;
begin
Result :=
'#!/usr/local/tclsh8.0'#13#10 +
'if {$argc < 2} {'#13#10 +
' puts stderr "Usage: $argv0 parameter"'#13#10 +
' exit 1'#13#10 +
'}';
end;
initialization
MakeIdentTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSynTclTkSyn);
{$ENDIF}
end.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,736 @@
{-------------------------------------------------------------------------------
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: SynHighlighterURI.pas, released 2003-04-10.
The initial author of this file is Ma�l H�rz.
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.
$Id: SynHighlighterURI.pas,v 1.17 2004/09/03 10:52:41 maelh Exp $
You may retrieve the latest version of SynEdit from the SynEdit home page,
located at http://SynEdit.SourceForge.net
-------------------------------------------------------------------------------}
{
@abstract(Provides an URI syntax highlighter for SynEdit)
@author(Ma�l H�rz)
@created(2003)
@lastmod(2003-10-21)
http://www.mh-nexus.de
The SynHighlighterURI unit implements an URI syntax highlighter for SynEdit.
Recognition of URIs is based on the information provided in the document
"Uniform Resource Identifiers (URI): Generic Syntax" of "The Internet Society",
that can be found at http://www.ietf.org/rfc/rfc2396.txt.
Also interesting is http://www.freesoft.org/CIE/RFC/1738/33.htm which describes
general URL syntax and major protocols.
these protocols are recognized:
-------------------------------
http://
https://
ftp://
mailto:
news: or news://
nntp://
telnet://
gopher://
prospero://
wais://
as well as commonly used shorthands:
------------------------------------
someone@somewhere.org
www.host.org
}
{$IFNDEF QSYNHIGHLIGHTERURI}
unit SynHighlighterURI;
{$ENDIF}
{$I synedit.inc}
interface
uses
{$IFDEF SYN_CLX}
QGraphics,
QSynEditTypes,
QSynEditHighlighter,
{$ELSE}
Graphics,
SynEditTypes,
SynEditHighlighter,
{$ENDIF}
SysUtils,
Classes;
type
TtkTokenKind = (tkNull, tkSpace, tkFtpLink, tkGopherLink,
tkHttpLink, tkHttpsLink, tkMailtoLink, tkNewsLink, tkNntpLink,
tkProsperoLink, tkTelnetLink, tkWaisLink, tkWebLink, tkUnknown, tkNullChar);
TProcTableProc = procedure of object;
PIdentFuncTableFunc = ^TIdentFuncTableFunc;
TIdentFuncTableFunc = function: TtkTokenKind of object;
TAlreadyVisitedURIFunc = function (URI: string): Boolean of object;
TSynURISyn = class(TSynCustomHighlighter)
private
fLine: PChar;
fLineNumber: Integer;
fLineStr: string;
fMayBeProtocol: PChar;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fStringLen: Integer;
FTokenID: TtkTokenKind;
fTokenPos: Integer;
fIdentFuncTable: array[0..97] of TIdentFuncTableFunc;
fIdentifierAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fURIAttri: TSynHighlighterAttributes;
fVisitedURIAttri: TSynHighlighterAttributes;
FAlreadyVisitedURI: TAlreadyVisitedURIFunc;
function KeyComp(const Key: string): Boolean;
function KeyHash(ToHash: PChar): Integer;
procedure InitIdent;
procedure MakeMethodTables;
procedure CRProc;
procedure LFProc;
procedure NullProc;
procedure ProtocolProc;
procedure SpaceProc;
procedure UnknownProc;
function AltFunc: TtkTokenKind;
function FtpFunc: TtkTokenKind;
function GopherFunc: TtkTokenKind;
function HttpFunc: TtkTokenKind;
function HttpsFunc: TtkTokenKind;
function MailtoFunc: TtkTokenKind;
function NewsFunc: TtkTokenKind;
function NntpFunc: TtkTokenKind;
function ProsperoFunc: TtkTokenKind;
function TelnetFunc: TtkTokenKind;
function WaisFunc: TtkTokenKind;
function WebFunc: TtkTokenKind;
function IsValidEmailAddress: Boolean;
function IsValidURI: Boolean;
function IsValidWebLink: Boolean;
procedure SetURIAttri(const Value: TSynHighlighterAttributes);
procedure SetVisitedURIAttri(const Value: TSynHighlighterAttributes);
protected
function GetIdentChars: TSynIdentChars; override;
function GetSampleSource: string; override;
function IsFilterStored: Boolean; override;
procedure SetAlreadyVisitedURIFunc(Value: TAlreadyVisitedURIFunc);
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 GetTokenID: TtkTokenKind;
{$IFDEF SYN_LAZARUS}
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
{$ENDIF}
procedure SetLine(const NewValue: string; LineNumber: Integer); override;
function GetToken: string; override;
function GetTokenAttribute: TSynHighlighterAttributes; override;
function GetTokenKind: Integer; override;
function GetTokenPos: Integer; override;
procedure Next; override;
published
property URIAttri: TSynHighlighterAttributes read fURIAttri write SetURIAttri;
property VisitedURIAttri: TSynHighlighterAttributes read fVisitedURIAttri
write SetVisitedURIAttri;
end;
const
SYN_ATTR_URI = 6;
SYN_ATTR_VISITEDURI = 7;
implementation
uses
{$IFDEF SYN_CLX}
QSynEditStrConst,
{$ELSE}
SynEditStrConst,
{$ENDIF}
SynEditStrConstExtra;
const
AlphaNum = ['0'..'9', 'A'..'Z', 'a'..'z'];
Mark = ['-', '_', '.', '!', '~', '*', '''', '(' , ')'];
Unreserved = Mark + AlphaNum;
Reserved = [';', '/', '?', ':', '@', '&', '=', '+', '$', ',', '%', '#'];
URIChars = Reserved + Unreserved;
NeverAtEnd = Mark - [''''] + Reserved - ['/', '$'];
URIBreakChars = [#0..#255] - URIChars - [#0..#32];
EMailAddressChars = ['.', '_', '-', '@'] + AlphaNum;
NeverAtEMailAddressEnd = ['.', '@'];
var
HashTable: array[#0..#255] of Integer;
procedure MakeHashTable;
var
c: Char;
u: Byte;
begin
FillChar(HashTable, sizeof(HashTable), 0);
for c := 'A' to 'Z' do
begin
u := Ord(UpCase(c));
HashTable[c] := (u * u - 64) div 771;
end;
for c := 'a' to 'z' do
begin
u := Ord(UpCase(c));
HashTable[c] := (u * u - 64) div 771;
end;
HashTable[':'] := HashTable['Z'] + 1;
HashTable['/'] := HashTable['Z'] + 2;
end;
procedure TSynURISyn.InitIdent;
var
I: Integer;
pF: PIdentFuncTableFunc;
begin
pF := PIdentFuncTableFunc(@fIdentFuncTable);
for I := Low(fIdentFuncTable) to High(fIdentFuncTable) do begin
pF^ := {$IFDEF FPC}@{$ENDIF}AltFunc;
Inc(pF);
end;
fIdentFuncTable[27] := {$IFDEF FPC}@{$ENDIF}WebFunc;
fIdentFuncTable[41] := {$IFDEF FPC}@{$ENDIF}NewsFunc;
fIdentFuncTable[53] := {$IFDEF FPC}@{$ENDIF}MailtoFunc;
fIdentFuncTable[58] := {$IFDEF FPC}@{$ENDIF}FtpFunc;
fIdentFuncTable[63] := {$IFDEF FPC}@{$ENDIF}WaisFunc;
fIdentFuncTable[65] := {$IFDEF FPC}@{$ENDIF}NewsFunc;
fIdentFuncTable[66] := {$IFDEF FPC}@{$ENDIF}NntpFunc;
fIdentFuncTable[67] := {$IFDEF FPC}@{$ENDIF}HttpFunc;
fIdentFuncTable[77] := {$IFDEF FPC}@{$ENDIF}GopherFunc;
fIdentFuncTable[79] := {$IFDEF FPC}@{$ENDIF}TelnetFunc;
fIdentFuncTable[75] := {$IFDEF FPC}@{$ENDIF}HttpsFunc;
fIdentFuncTable[97] := {$IFDEF FPC}@{$ENDIF}ProsperoFunc;
end;
function TSynURISyn.KeyComp(const Key: string): Boolean;
var
I: Integer;
begin
Result := True;
for I := 1 to fStringLen do
if HashTable[fMayBeProtocol[I - 1]] <> HashTable[Key[I]] then
begin
Result := False;
break;
end;
end;
function TSynURISyn.KeyHash(ToHash: PChar): Integer;
begin
Result := 0;
while ToHash^ in ['A'..'Z', 'a'..'z'] do
begin
inc(Result, HashTable[ToHash^]);
inc(ToHash);
end;
if ToHash^ = ':' then
begin
inc(Result, HashTable[ToHash^]);
inc(ToHash);
if ToHash^ = '/' then
begin
inc(Result, HashTable[ToHash^]);
inc(ToHash);
if ToHash^ = '/' then
begin
inc(Result, HashTable[ToHash^]);
inc(ToHash);
end;
end;
end;
fStringLen := ToHash - fMayBeProtocol;
end;
function TSynURISyn.AltFunc: TtkTokenKind;
begin
Result := tkUnknown;
end;
procedure TSynURISyn.MakeMethodTables;
var
I: Char;
begin
for I := #0 to #255 do
case I of
#13: fProcTable[I] := {$IFDEF FPC}@{$ENDIF}CRProc;
#10: fProcTable[I] := {$IFDEF FPC}@{$ENDIF}LFProc;
#0: fProcTable[I] := {$IFDEF FPC}@{$ENDIF}NullProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := {$IFDEF FPC}@{$ENDIF}SpaceProc;
'A'..'Z', 'a'..'z': fProcTable[I] := {$IFDEF FPC}@{$ENDIF}ProtocolProc;
else
fProcTable[I] := {$IFDEF FPC}@{$ENDIF}UnknownProc;
end;
end;
constructor TSynURISyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace);
fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier);
fURIAttri := TSynHighlighterAttributes.Create(SYNS_AttrURI);
fURIAttri.Foreground := clBlue;
fURIAttri.Style := [fsUnderline];
AddAttribute(fURIAttri);
fVisitedURIAttri := TSynHighlighterAttributes.Create(SYNS_AttrVisitedURI);
fVisitedURIAttri.Foreground := clPurple;
fVisitedURIAttri.Style := [fsUnderline];
AddAttribute(fVisitedURIAttri);
SetAttributesOnChange({$IFDEF FPC}@{$ENDIF}DefHighlightChange);
InitIdent;
MakeMethodTables;
fDefaultFilter := SYNS_FilterURI;
end;
destructor TSynURISyn.Destroy;
begin
inherited;
// the other attributes are automatically freed because of AddAttribute()
fSpaceAttri.Free;
fIdentifierAttri.Free;
end;
{$IFDEF SYN_LAZARUS}
procedure TSynURISyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
{$ENDIF}
procedure TSynURISyn.SetLine(const NewValue: string; LineNumber: Integer);
begin
fLineStr := NewValue;
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynURISyn.CRProc;
begin
fTokenID := tkSpace;
inc(Run);
if fLine[Run] = #10 then
Inc(Run);
end;
procedure TSynURISyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynURISyn.NullProc;
begin
if Run < Length(fLineStr) then
begin
inc(Run);
fTokenID := tkNullChar;
end
else
fTokenID := tkNull
end;
procedure TSynURISyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
end;
procedure TSynURISyn.UnknownProc;
begin
if IsValidEmailAddress then
fTokenID := tkMailtoLink
else
begin
{$IFDEF SYN_MBCSSUPPORT}
if FLine[Run] in LeadBytes then
Inc(Run, 2)
else
{$ENDIF}
inc(Run);
fTokenID := tkUnknown;
end;
end;
procedure TSynURISyn.Next;
begin
fTokenPos := Run;
fProcTable[fLine[Run]];
end;
function TSynURISyn.GetDefaultAttribute(Index: Integer): TSynHighlighterAttributes;
begin
case Index of
SYN_ATTR_IDENTIFIER: Result := fIdentifierAttri;
SYN_ATTR_WHITESPACE: Result := fSpaceAttri;
SYN_ATTR_URI: Result := fURIAttri;
SYN_ATTR_VISITEDURI: Result := fVisitedURIAttri;
else
Result := nil;
end;
end;
function TSynURISyn.GetEol: Boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynURISyn.GetToken: string;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
function TSynURISyn.GetTokenAttribute: TSynHighlighterAttributes;
var
Visited: Boolean;
begin
case GetTokenID of
tkSpace: Result := fSpaceAttri;
tkFtpLink, tkGopherLink, tkHttpLink, tkHttpsLink, tkMailtoLink, tkNewsLink,
tkNntpLink, tkProsperoLink, tkTelnetLink, tkWaisLink, tkWebLink:
begin
Visited := False;
if Assigned(FAlreadyVisitedURI) then
Visited := FAlreadyVisitedURI(GetToken);
if Visited then
Result := fVisitedURIAttri
else
Result := fURIAttri;
end;
tkUnknown: Result := fIdentifierAttri;
else Result := nil;
end;
end;
function TSynURISyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynURISyn.GetTokenKind: Integer;
begin
Result := Ord(fTokenId);
end;
function TSynURISyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSynURISyn.GetIdentChars: TSynIdentChars;
begin
Result := TSynValidStringChars + [#0];
end;
class function TSynURISyn.GetLanguageName: string;
begin
Result := SYNS_LangURI;
end;
function TSynURISyn.GetSampleSource: string;
begin
Result := 'Universal Resource Identifier highlighting'#13#10#13#10 +
'http://www.somewhere.org'#13#10 +
'ftp://superhost.org/downloads/gems.zip'#13#10 +
'www.w3c.org'#13#10 +
'mailto:big@lebowski.edu'#13#10 +
'douglas@adams.lod'#13#10 +
'news:comp.lang.pascal.borland';
end;
function TSynURISyn.IsFilterStored: Boolean;
begin
Result := fDefaultFilter <> SYNS_FilterURI;
end;
procedure TSynURISyn.SetAlreadyVisitedURIFunc(Value: TAlreadyVisitedURIFunc);
begin
FAlreadyVisitedURI := Value;
end;
procedure TSynURISyn.SetURIAttri(const Value: TSynHighlighterAttributes);
begin
fURIAttri.Assign(Value);
end;
procedure TSynURISyn.SetVisitedURIAttri(const Value: TSynHighlighterAttributes);
begin
fVisitedURIAttri.Assign(Value);
end;
function TSynURISyn.IsValidEmailAddress: Boolean;
var
StartPos, AtPos, DotPos: Integer;
begin
StartPos := Run;
AtPos := -1;
DotPos := -1;
while fLine[Run] in EMailAddressChars do
begin
if fLine[Run] = '@' then
AtPos := Run
else if fLine[Run] = '.' then
// reject array of dots: "neighbour" dots are not allowed
if (Run = StartPos) or (DotPos >= 0) and (DotPos = Run - 1) then
break
else
DotPos := Run;
Inc(Run);
end;
while (Run > StartPos) and (fLine[Run - 1] in NeverAtEMailAddressEnd) do
dec(Run);
while (DotPos >= Run) or (DotPos > -1) and (fLine[DotPos] <> '.') do
Dec(DotPos);
Result := (StartPos < AtPos) and (AtPos < Run - 1) and (DotPos > AtPos + 1);
if not Result then Run := StartPos;
end;
function TSynURISyn.IsValidURI: Boolean;
var
ProtocolEndPos, DotPos: Integer;
function IsRelativePath: Boolean;
begin
Result := (DotPos - 1 >= 0) and
((fLine[DotPos - 1] = '/') and (fLine[DotPos + 2] = '/')) or
((fLine[DotPos - 1] = '\') and (fLine[DotPos + 2] = '\'));
end;
begin
ProtocolEndPos := Run;
DotPos := -1;
while fLine[Run] in URIChars do
begin
if fLine[Run] = '.' then
// reject array of dots: "neighbour" dots are not allowed
if (DotPos >= 0) and (DotPos = Run - 1) and not IsRelativePath then
break
else
DotPos := Run;
inc(Run);
end;
while (Run > ProtocolEndPos) and (fLine[Run - 1] in NeverAtEnd) do
dec(Run);
Result := Run > ProtocolEndPos;
end;
function TSynURISyn.IsValidWebLink: Boolean;
var
WWWEndPos, DotPos, SecondDotPos: Integer;
function IsRelativePath: Boolean;
begin
Result := (DotPos - 1 >= 0) and
((fLine[DotPos - 1] = '/') and (fLine[DotPos + 2] = '/')) or
((fLine[DotPos - 1] = '\') and (fLine[DotPos + 2] = '\'));
end;
begin
WWWEndPos := Run;
DotPos := -1;
SecondDotPos := -1;
while fLine[Run] in URIChars do
begin
if fLine[Run] = '.' then
// reject array of dots: "neighbour" dots are not allowed
if (DotPos >= 0) and (DotPos = Run - 1) and not IsRelativePath then
break
else
begin
DotPos := Run;
if SecondDotPos = -2 then SecondDotPos := DotPos;
if SecondDotPos = -1 then SecondDotPos := -2;
end;
inc(Run);
end;
while (Run > WWWEndPos) and (fLine[Run - 1] in NeverAtEnd) do
dec(Run);
Result := (Run > WWWEndPos) and (fLine[WWWEndPos] = '.') and
(SecondDotPos > WWWEndPos + 1) and (SecondDotPos < Run);
end;
procedure TSynURISyn.ProtocolProc;
var
HashKey: Integer;
begin
if IsValidEmailAddress then
fTokenID := tkMailtoLink
else
begin
fMayBeProtocol := fLine + Run;
HashKey := KeyHash(fMayBeProtocol);
inc(Run, fStringLen);
if HashKey <= 97 then
fTokenID := fIdentFuncTable[HashKey] {$IFDEF FPC}(){$ENDIF}
else
fTokenID := tkUnknown;
end;
end;
function TSynURISyn.FtpFunc: TtkTokenKind;
begin
if KeyComp('ftp://') and IsValidURI then
Result := tkFtpLink
else
Result := tkUnknown;
end;
function TSynURISyn.GopherFunc: TtkTokenKind;
begin
if KeyComp('gopher://') and IsValidURI then
Result := tkGopherLink
else
Result := tkUnknown;
end;
function TSynURISyn.HttpFunc: TtkTokenKind;
begin
if KeyComp('http://') and IsValidURI then
Result := tkHttpLink
else
Result := tkUnknown;
end;
function TSynURISyn.HttpsFunc: TtkTokenKind;
begin
if KeyComp('https://') and IsValidURI then
Result := tkHttpsLink
else
Result := tkUnknown;
end;
function TSynURISyn.MailtoFunc: TtkTokenKind;
begin
if KeyComp('mailto:') and IsValidURI then
Result := tkMailtoLink
else
Result := tkUnknown;
end;
function TSynURISyn.NewsFunc: TtkTokenKind;
begin
if KeyComp('news:') and IsValidURI then
Result := tkNewsLink
else
Result := tkUnknown;
end;
function TSynURISyn.NntpFunc: TtkTokenKind;
begin
if KeyComp('nntp://') and IsValidURI then
Result := tkNntpLink
else
Result := tkUnknown;
end;
function TSynURISyn.ProsperoFunc: TtkTokenKind;
begin
if KeyComp('prospero://') and IsValidURI then
Result := tkProsperoLink
else
Result := tkUnknown;
end;
function TSynURISyn.TelnetFunc: TtkTokenKind;
begin
if KeyComp('telnet://') and IsValidURI then
Result := tkTelnetLink
else
Result := tkUnknown;
end;
function TSynURISyn.WaisFunc: TtkTokenKind;
begin
if KeyComp('wais://') and IsValidURI then
Result := tkWaisLink
else
Result := tkUnknown;
end;
function TSynURISyn.WebFunc: TtkTokenKind;
begin
if KeyComp('www') and IsValidWebLink then
Result := tkWebLink
else
Result := tkUnknown;
end;
initialization
MakeHashTable;
{$IFNDEF SYN_CPPB_1}
RegisterPlaceableHighlighter(TSynURISyn);
{$ENDIF}
end.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff