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

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 219 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 219 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 219 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

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.

Some files were not shown because too many files have changed in this diff Show More