extrasyn: Add highlighters for JSON, Verilog, VHDL. Kindly provided by MRisco, issue #18248. Shorten menu in demo program.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8075 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2021-08-18 21:27:43 +00:00
parent 89d246386d
commit f0bada71d3
23 changed files with 3215 additions and 462 deletions

View File

@ -198,6 +198,10 @@ ResourceString
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_FilterVHDL = 'VHDL Files (*.vhd;*.vhdl)|*.vhd;*.vhdl';
SYNS_FilterVerilog = 'Verilog Files (*.v;*.vl;*.ver)|*.v;*.vl;*.ver';
SYNS_FilterJSON = 'JSON Files (*.json)|*.json';
//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';
@ -265,6 +269,9 @@ ResourceString
SYNS_LangLua = 'Lua Script';
SYNS_Lang8051 = '8051 Assembler';
SYNS_LangProlog = 'Prolog';
SYNS_LangVHDL = 'VHDL';
SYNS_LangVerilog = 'Verilog';
SYNS_LangJSON = 'JSON';
//SYNS_LangHP48 = 'HP48';
//SYNS_LangCAClipper = 'CA-Clipper';
//SYNS_LangCPM = 'COAS Product Manager Report';

View File

@ -0,0 +1,694 @@
{-------------------------------------------------------------------------------
SynHighlighterJSON v1.1
This unit provides a SBA JSON highlighter for SynEdit.
(c) Miguel A. Risco-Castillo
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.
Some concepts in this unit are based in the Original Code of Zhou Kan and
"La Biblia del SynEdit" of Tito Hinostroza.
All Rights Reserved.
v1.1 2019/12/21
Adapted to extrasyn package
v1.0 2016
Initial
-------------------------------------------------------------------------------}
unit SynHighlighterJSON;
// extrasyn.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 extrasyn.inc}
{$H+}
interface
uses
SysUtils, Classes, Graphics, SynEditStrConstExtra, SynEditHighlighterFoldBase, SynEditHighlighter, SynEditTypes, SynEditStrConst;
type
// TtkTokenKind = (tkComment, tkIdentifier, tkKey, tkNull,
// tkNumber, tkSpace, tkString, tkSymbol, tkAttribute, tkUnknown);
// TRangeState = (rsUnknown, rsComment);
TtkTokenKind = (tkKey, tkString, tkReserved, tkNull, tkNumber, tkSpace,
tkSymbol, tkUnknown);
TRangeState = (rsUnknown, rsAttribute, rsObjectValue, rsArrayValue);
TProcTableProc = procedure of object;
type
{ TSynJSONSyn }
TSynJSONSyn = class(TSynCustomFoldHighlighter)
private
FHLWordsList: TStringList;
fRange: TRangeState;
fLine: PChar;
fLineNumber: integer;
fProcTable: array[#0..#255] of TProcTableProc;
Run: longint;
fStringLen: integer;
fToIdent: PChar;
fTokenPos: integer;
FTokenID: TtkTokenKind;
FValueAttri: TSynHighlighterAttributes;
fIdentifierAttri: TSynHighLighterAttributes;
fKeyAttri: TSynHighLighterAttributes;
fNumberAttri: TSynHighLighterAttributes;
fSpaceAttri: TSynHighLighterAttributes;
fSymbolAttri: TSynHighLighterAttributes;
fAttribAttri: TSynHighLighterAttributes;
fDivider:TSynDividerDrawConfigSetting;
procedure CloseArrayProc;
procedure CloseObjectProc;
procedure CommaProc;
function KeyComp(const aKey: string): boolean;
procedure OpenArrayProc;
procedure OpenObjectProc;
procedure SetHLWordsList(AValue: TStringList);
procedure SymbolsProc;
procedure CRProc;
procedure ColonProc;
procedure EqualProc;
procedure EndTokenProc;
procedure GreaterProc;
procedure IdentProc;
procedure LFProc;
procedure LowerProc;
procedure MinusProc;
procedure ModSymbolProc;
procedure NotSymbolProc;
procedure NullProc;
procedure NumberProc;
procedure OrSymbolProc;
procedure PlusProc;
procedure PointProc;
procedure RoundCloseProc;
procedure RoundOpenProc;
procedure SemiColonProc;
procedure SlashProc;
procedure SpaceProc;
procedure StarProc;
procedure StringProc;
procedure UnknownProc;
procedure FoldValidProc;
procedure MakeMethodTables;
protected
function GetIdentChars: TSynIdentChars; override;
function GetSampleSource: 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;
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
function GetTokenAttribute: TSynHighLighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: integer; override;
procedure Next; override;
function GetRange: Pointer; override;
procedure SetRange(Value: Pointer); override;
procedure ReSetRange; override;
function GetDrawDivider(Index: integer): TSynDividerDrawConfigSetting; override;
property IdentChars;
class function GetLanguageName: string; override;
published
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 SymbolAttri: TSynHighLighterAttributes read fSymbolAttri write fSymbolAttri;
property AttribAttri: TSynHighLighterAttributes read fAttribAttri write fAttribAttri;
property ValueAttri: TSynHighLighterAttributes read fValueAttri write fValueAttri;
property HLWordsList: TStringList read FHLWordsList write SetHLWordsList;
end;
implementation
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 := I; //UpCase(I); In verilog the keywords are in lower case
case I in ['_', '0'..'9', 'A'..'Z', 'a'..'z'] of
True: mHashTable[I] := Ord(J)
else
mHashTable[I] := 0;
end;
end;
end;
function TSynJSONSyn.KeyComp(const aKey: string): boolean;
var
I: integer;
Temp: PChar;
begin
Temp := fToIdent; // Test from the second char +1
if Length(aKey) = fStringLen then
begin
Result := True;
for i := 1 to fStringLen do // Test from the second char := 2
begin
if mHashTable[Temp^] <> mHashTable[aKey[i]] then
begin
Result := False;
break;
end;
inc(Temp);
end;
end
else
Result := False;
end;
procedure TSynJSONSyn.SetHLWordsList(AValue: TStringList);
begin
if FHLWordsList=AValue then Exit;
FHLWordsList:=AValue;
end;
procedure TSynJSONSyn.IdentProc;
var i:integer;
begin
while Identifiers[fLine[Run]] do inc(Run);
fStringLen:=Run-fTokenPos;
fToIdent:=fLine + fTokenPos;
fTokenID := tkUnknown;
if FHLWordsList.Count>0 then for i:=0 to FHLWordsList.Count-1 do
begin
if KeyComp(FHLWordsList[i]) then fTokenID := tkString;
end;
//sba json
case Upcase(fToIdent^) of
'A':begin
if KeyComp('author')
then fTokenID := tkKey;
end;
'D':begin
if KeyComp('date') or
KeyComp('description')
then fTokenID := tkKey;
end;
'E':begin
if KeyComp('explibfiles') or
KeyComp('expmonolithic') or
KeyComp('exportpath')
then fTokenID := tkKey;
end;
'F':begin
if KeyComp('false')
then fTokenID := tkKey;
end;
'I':begin
if KeyComp('interface') or
KeyComp('ipcores')
then fTokenID := tkKey;
end;
'L':begin
if KeyComp('location')
then fTokenID := tkKey;
end;
'N':begin
if KeyComp('name') or
KeyComp('null')
then fTokenID := tkKey;
end;
'P':begin
if KeyComp('portname')
then fTokenID := tkKey;
//if KeyComp('process') or
// KeyComp('package') then begin fTokenID := tkKey; StartCodeFoldBlock(nil); end;
//if KeyComp('procedure') then begin fTokenID := tkKey; FoldValidProc; end;
end;
'T':begin
if KeyComp('title') or
KeyComp('true')
then fTokenID := tkKey;
end;
'U':begin
if KeyComp('userfiles')
then fTokenID := tkKey;
end;
'V':begin
if KeyComp('version') then fTokenID := tkKey;
end;
end;
end;
procedure TSynJSONSyn.MakeMethodTables;
var
I: char;
begin
for I := #0 to #255 do
case I of
#0 : fProcTable[I] := @NullProc;
'#','$','&','@' : fProcTable[I] := @SymbolsProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := @IdentProc;
'{': fProcTable[I] := @OpenObjectProc;
'}': fProcTable[I] := @CloseObjectProc;
'[': fProcTable[I] := @OpenArrayProc;
']': fProcTable[I] := @CloseArrayProc;
',': fProcTable[I] := @CommaProc;
':': fProcTable[I] := @ColonProc;
'=': fProcTable[I] := @EqualProc;
'>': fProcTable[I] := @GreaterProc;
#10: fProcTable[I] := @LFProc;
#13: fProcTable[I] := @CRProc;
'<': fProcTable[I] := @LowerProc;
'%': fProcTable[I] := @ModSymbolProc;
'!': fProcTable[I] := @NotSymbolProc;
'0'..'9','-': fProcTable[I] := @NumberProc;
'|': fProcTable[I] := @OrSymbolProc;
'+': fProcTable[I] := @PlusProc;
'*': fProcTable[I] := @StarProc;
'/': fProcTable[I] := @SlashProc;
'.': fProcTable[I] := @PointProc;
')': fProcTable[I] := @RoundCloseProc;
'(': fProcTable[I] := @RoundOpenProc;
';': fProcTable[I] := @SemiColonProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := @SpaceProc;
'"': fProcTable[I] := @StringProc; //" #34
else
fProcTable[I] := @UnknownProc;
end;
end;
constructor TSynJSONSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
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 := clRed;
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighLighterAttributes.Create(SYNS_AttrWhitespace);
AddAttribute(fSpaceAttri);
fSymbolAttri := TSynHighLighterAttributes.Create(SYNS_AttrSymbol);
fSymbolAttri.Foreground := clTeal;
AddAttribute(fSymbolAttri);
fAttribAttri := TSynHighLighterAttributes.Create(SYNS_AttrAttributeName);
fAttribAttri.Foreground := clPurple; // clMaroon;
AddAttribute(fAttribAttri);
FValueAttri := TSynHighlighterAttributes.Create(SYNS_AttrValue);
FValueAttri.Foreground := clNavy;
AddAttribute(FValueAttri);
SetAttributesOnChange(@DefHighlightChange);
MakeMethodTables;
fRange := rsUnknown;
fDefaultFilter := SYNS_FilterJSON;
fDivider.Color:=clNone;
FHLWordsList:=TStringList.Create;
end;
destructor TSynJSONSyn.Destroy;
begin
FreeAndNil(FHLWordsList);
inherited Destroy;
end;
procedure TSynJSONSyn.SetLine(const NewValue: String; LineNumber: Integer);
begin
inherited;
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynJSONSyn.CloseArrayProc;
begin
SymbolsProc;
FRange := rsUnknown;
end;
procedure TSynJSONSyn.CloseObjectProc;
begin
SymbolsProc;
FRange := rsUnknown;
end;
procedure TSynJSONSyn.ColonProc;
begin
SymbolsProc;
FRange := rsObjectValue;
end;
procedure TSynJSONSyn.CommaProc;
begin
SymbolsProc;
if FRange = rsObjectValue then
FRange := rsAttribute;
end;
procedure TSynJSONSyn.SymbolsProc;
begin
inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynJSONSyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run + 1] = #10 then Inc(Run);
end;
procedure TSynJSONSyn.EqualProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynJSONSyn.GreaterProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynJSONSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynJSONSyn.LowerProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynJSONSyn.MinusProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynJSONSyn.SlashProc;
begin
fTokenID := tkSymbol;
inc(Run);
end;
procedure TSynJSONSyn.ModSymbolProc;
begin
inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynJSONSyn.NotSymbolProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynJSONSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynJSONSyn.NumberProc;
begin
fTokenID := tkNumber;
while FLine[Run] in ['0'..'9','.','-','+','e','E'] do
inc(Run);
end;
procedure TSynJSONSyn.OpenArrayProc;
begin
SymbolsProc;
FRange := rsArrayValue;
end;
procedure TSynJSONSyn.OpenObjectProc;
begin
SymbolsProc;
FRange := rsAttribute;
end;
procedure TSynJSONSyn.OrSymbolProc;
begin
inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynJSONSyn.PlusProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynJSONSyn.PointProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynJSONSyn.RoundCloseProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynJSONSyn.RoundOpenProc;
begin
inc(Run);
FTokenID := tkSymbol;
end;
procedure TSynJSONSyn.SemiColonProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynJSONSyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
end;
procedure TSynJSONSyn.StarProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynJSONSyn.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 TSynJSONSyn.EndTokenProc;
begin
fTokenID := tkKey;
EndCodeFoldBlock();
end;
procedure TSynJSONSyn.UnknownProc;
begin
inc(Run);
while (fLine[Run] in [#128..#191]) OR // continued utf8 subcode
((fLine[Run]<>#0) and (fProcTable[fLine[Run]] = @UnknownProc)) do inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynJSONSyn.FoldValidProc;
var
tmp:integer;
found:boolean;
begin
tmp:=run;
found:=false;
while (not (fLine[tmp] in [#0, #10, #13])) do if fLine[tmp]=';' then
begin
found:=true;
break;
end else inc(tmp);
if not found then StartCodeFoldBlock(nil);
end;
procedure TSynJSONSyn.Next;
begin
fTokenPos := Run;
// if fRange = rsComment then CommentProc else
fProcTable[fLine[Run]];
end;
function TSynJSONSyn.GetDefaultAttribute(Index: integer): TSynHighLighterAttributes;
begin
case Index of
SYN_ATTR_IDENTIFIER: Result := fIdentifierAttri;
SYN_ATTR_KEYWORD: Result := fKeyAttri;
SYN_ATTR_STRING: Result := fValueAttri;
SYN_ATTR_WHITESPACE: Result := fSpaceAttri;
SYN_ATTR_SYMBOL: Result := fSymbolAttri;
else
Result := nil;
end;
end;
function TSynJSONSyn.GetEOL: boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynJSONSyn.GetToken: string;
var
Len: longint;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
procedure TSynJSONSyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
begin
TokenLength:=Run-fTokenPos;
TokenStart := fLine + fTokenPos;
end;
function TSynJSONSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynJSONSyn.GetTokenAttribute: TSynHighLighterAttributes;
begin
case GetTokenID of
tkString:
if FRange in [rsObjectValue, rsArrayValue] then
Result := FValueAttri
else
Result := fAttribAttri;
tkKey: Result := fKeyAttri;
tkNumber: Result := fNumberAttri;
tkSpace: Result := fSpaceAttri;
tkSymbol: Result := fSymbolAttri;
tkUnknown: Result := fIdentifierAttri;
else
Result := nil;
end;
end;
function TSynJSONSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynJSONSyn.GetTokenPos: integer;
begin
Result := fTokenPos;
end;
function TSynJSONSyn.GetRange: Pointer;
begin
// Result := Pointer(fRange);
CodeFoldRange.RangeType := Pointer(PtrInt(fRange));
Result := inherited;
end;
procedure TSynJSONSyn.ReSetRange;
begin
inherited;
fRange := rsUnknown;
end;
function TSynJSONSyn.GetDrawDivider(Index: integer
): TSynDividerDrawConfigSetting;
begin
Result:=fDivider;
end;
procedure TSynJSONSyn.SetRange(Value: Pointer);
begin
// fRange := TRangeState(Value);
inherited;
fRange := TRangeState(PtrUInt(CodeFoldRange.RangeType));
end;
function TSynJSONSyn.GetIdentChars: TSynIdentChars;
begin
Result := ['_', '0'..'9', 'a'..'z', 'A'..'Z'];
end;
class function TSynJSONSyn.GetLanguageName :string;
begin
Result := SYNS_LangJSON;
end;
function TSynJSONSyn.GetSampleSource: string;
begin
Result :=
'{"menu": {'+LineEnding+
' "id": "file",'+LineEnding+
' "value": "File",'+LineEnding+
' "popup": {'+LineEnding+
' "menuitem": ['+LineEnding+
' {"value": "New", "onclick": "CreateNewDoc()"},'+LineEnding+
' {"value": "Open", "onclick": "OpenDoc()"},'+LineEnding+
' {"value": "Close", "onclick": "CloseDoc()"}'+LineEnding+
' ]'+LineEnding+
' }'+LineEnding+
'}}';
end;
initialization
MakeIdentTable;
RegisterPlaceableHighlighter(TSynJSONSyn);
end.

View File

@ -27,7 +27,7 @@ replace them with the notice and other provisions required by the GPL.
If you do not delete the provisions above, a recipient may use your version
of this file under either the MPL or the GPL.
$Id: SynHighlighterTclTk.pas,v 1.19 2005/01/28 16:53:25 maelh Exp $
$Id: SynHighlighterTclTk.pas,v 1.20 2019/06/06 16:53:25 maelh Exp $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
@ -38,7 +38,7 @@ Known Issues:
@abstract(Provides a TCL/Tk highlighter for SynEdit)
@author(Igor Shitikov, converted to SynEdit by David Muir <dhm@dmsoftware.co.uk>)
@created(5 December 1999, converted to SynEdit April 18, 2000)
@lastmod(2000-06-23)
@lastmod(2019/06/06) MOD by M.A.R.C. for SBACreator
The SynHighlighterTclTk unit provides SynEdit with a TCL/Tk highlighter.
}
@ -62,6 +62,7 @@ uses
{$ELSE}
Graphics,
SynEditHighlighter,
SynEditHighlighterFoldBase,
{$ENDIF}
SysUtils,
Classes;
@ -70,12 +71,16 @@ type
TtkTokenKind = (tkComment, tkIdentifier, tkKey, tkNull, tkNumber, tkSecondKey,
tkSpace, tkString, tkSymbol, tkUnknown);
TRangeState = (rsUnknown, rsAnsi, rsPasStyle, rsCStyle);
TRangeState = (rsUnknown);
TProcTableProc = procedure of object;
TBlockID = (
BodyBlk
);
type
TSynTclTkSyn = class(TSynCustomHighlighter)
TSynTclTkSyn = class(TSynCustomFoldHighlighter)
private
fRange: TRangeState;
fLine: PChar;
@ -95,6 +100,7 @@ type
fKeyWords: TStrings;
fSecondKeys: TStrings;
procedure BraceOpenProc;
procedure BraceCloseProc;
procedure PointCommaProc;
procedure CRProc;
procedure IdentProc;
@ -102,14 +108,12 @@ type
procedure NullProc;
procedure NumberProc;
procedure RoundOpenProc;
procedure HashProc;
procedure SlashProc;
procedure SpaceProc;
procedure StringProc;
procedure UnknownProc;
procedure MakeMethodTables;
procedure AnsiProc;
procedure PasStyleProc;
procedure CStyleProc;
procedure SetKeyWords(const Value: TStrings);
procedure SetSecondKeys(const Value: TStrings);
function IsKeywordListStored: boolean;
@ -209,15 +213,15 @@ begin
for I := #0 to #255 do
begin
case I of
'_', '0'..'9', 'a'..'z', 'A'..'Z':
Identifiers[I] := True;
'_', '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;
case I in ['_', '0'..'9', 'A'..'Z', 'a'..'z'] of
True: mHashTable[I] := Ord(J)
else
mHashTable[I] := 0;
end;
end;
end;
@ -274,18 +278,19 @@ var
begin
for I := #0 to #255 do
case I of
'#': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} SlashProc;
'{': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} BraceOpenProc;
';': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} PointCommaProc;
#13: fProcTable[I] := {$IFDEF FPC}@{$ENDIF} CRProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} IdentProc;
#10: fProcTable[I] := {$IFDEF FPC}@{$ENDIF} LFProc;
#0: fProcTable[I] := {$IFDEF FPC}@{$ENDIF} NullProc;
'0'..'9': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} NumberProc;
'#': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} HashProc;
'{': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} BraceOpenProc;
'}': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} BraceCloseProc;
';': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} PointCommaProc;
'(': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} RoundOpenProc;
'"': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} StringProc;
'/': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} SlashProc;
#10: fProcTable[I] := {$IFDEF FPC}@{$ENDIF} LFProc;
#13: fProcTable[I] := {$IFDEF FPC}@{$ENDIF} CRProc;
'0'..'9': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} NumberProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := {$IFDEF FPC}@{$ENDIF} IdentProc;
#1..#9, #11, #12, #14..#32: fProcTable[I] := {$IFDEF FPC}@{$ENDIF} SpaceProc;
#34: fProcTable[I] := {$IFDEF FPC}@{$ENDIF} StringProc;
else
fProcTable[I] := {$IFDEF FPC}@{$ENDIF} UnknownProc;
end;
@ -348,129 +353,27 @@ end;
procedure TSynTclTkSyn.SetLine(const NewValue: String; LineNumber:Integer);
begin
inherited;
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end; { SetLine }
procedure TSynTclTkSyn.AnsiProc;
begin
fTokenID := tkComment;
case FLine[Run] of
#0:
begin
NullProc;
exit;
end;
#10:
begin
LFProc;
exit;
end;
#13:
begin
CRProc;
exit;
end;
end;
while fLine[Run] <> #0 do
case fLine[Run] of
'*':
if fLine[Run + 1] = ')' then
begin
fRange := rsUnKnown;
inc(Run, 2);
break;
end else inc(Run);
#10: break;
#13: break;
else inc(Run);
end;
end;
procedure TSynTclTkSyn.PasStyleProc;
begin
fTokenID := tkComment;
case FLine[Run] of
#0:
begin
NullProc;
exit;
end;
#10:
begin
LFProc;
exit;
end;
#13:
begin
CRProc;
exit;
end;
end;
while FLine[Run] <> #0 do
case FLine[Run] of
'}':
begin
fRange := rsUnKnown;
inc(Run);
break;
end;
#10: break;
#13: break;
else inc(Run);
end;
end;
procedure TSynTclTkSyn.CStyleProc;
begin
fTokenID := tkComment;
case FLine[Run] of
#0:
begin
NullProc;
exit;
end;
#10:
begin
LFProc;
exit;
end;
#13:
begin
CRProc;
exit;
end;
end;
while fLine[Run] <> #0 do
case fLine[Run] of
'*':
if fLine[Run + 1] = '/' then
begin
fRange := rsUnKnown;
inc(Run, 2);
break;
end else inc(Run);
#10: break;
#13: break;
else inc(Run);
end;
end;
procedure TSynTclTkSyn.BraceOpenProc;
begin
inc(Run);
fTokenID := tkSymbol;
StartCodeFoldBlock(Pointer(PtrUInt(BodyBlk)));
end;
procedure TSynTclTkSyn.BraceCloseProc;
var Blk:TBlockID;
begin
blk:=TBlockID(PtrUInt(TopCodeFoldBlockType));
if blk=BodyBlk then EndCodeFoldBlock();
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynTclTkSyn.PointCommaProc;
@ -482,10 +385,8 @@ end;
procedure TSynTclTkSyn.CRProc;
begin
fTokenID := tkSpace;
Case FLine[Run + 1] of
#10: inc(Run, 2);
else inc(Run);
end;
Inc(Run);
if fLine[Run + 1] = #10 then Inc(Run);
end;
procedure TSynTclTkSyn.IdentProc;
@ -494,8 +395,7 @@ begin
if IsKeyWord(GetToken) then begin
fTokenId := tkKey;
Exit;
end
else fTokenId := tkIdentifier;
end else fTokenId := tkIdentifier;
if IsSecondKeyWord(GetToken)
then fTokenId := tkSecondKey
else fTokenId := tkIdentifier;
@ -516,7 +416,7 @@ procedure TSynTclTkSyn.NumberProc;
begin
inc(Run);
fTokenID := tkNumber;
while FLine[Run] in ['0'..'9', '.', 'e', 'E'] do
while FLine[Run] in ['0'..'9', '.', 'a'..'f', 'A'..'F', 'x', 'X'] do
begin
case FLine[Run] of
'.':
@ -532,38 +432,22 @@ begin
fTokenId := tkSymbol;
end;
procedure TSynTclTkSyn.HashProc;
begin
fTokenID := tkComment;
while FLine[Run] <> #0 do
begin
case FLine[Run] of
#10, #13: break;
end;
inc(Run);
end;
end;
procedure TSynTclTkSyn.SlashProc;
begin
case FLine[Run + 1] of
'/':
begin
inc(Run, 2);
fTokenID := tkComment;
while FLine[Run] <> #0 do
begin
case FLine[Run] of
#10, #13: break;
end;
inc(Run);
end;
end;
'*':
begin
inc(Run);
fTokenId := tkSymbol;
end;
else
begin
fTokenID := tkComment;
while FLine[Run] <> #0 do
begin
case FLine[Run] of
#10, #13: break;
end;
inc(Run);
end;
end;
end;
fTokenID := tkSymbol;
end;
procedure TSynTclTkSyn.SpaceProc;
@ -594,20 +478,18 @@ begin
Inc(Run, 2)
else
{$ENDIF}
// inc(Run);
// fTokenID := tkUnKnown;
inc(Run);
fTokenID := tkUnKnown;
while (fLine[Run] in [#128..#191]) OR // continued utf8 subcode
((fLine[Run]<>#0) and (fProcTable[fLine[Run]] = @UnknownProc)) do inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynTclTkSyn.Next;
begin
fTokenPos := Run;
case fRange of
rsAnsi: AnsiProc;
rsPasStyle: PasStyleProc;
rsCStyle: CStyleProc;
else
fProcTable[fLine[Run]];
end;
end;
function TSynTclTkSyn.GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
@ -626,13 +508,13 @@ end;
function TSynTclTkSyn.GetEol: Boolean;
begin
Result := False;
if fTokenId = tkNull then Result := True;
Result := fTokenID = tkNull;
end;
function TSynTclTkSyn.GetRange: Pointer;
begin
Result := Pointer(PtrInt(fRange));
CodeFoldRange.RangeType := Pointer(PtrInt(fRange));
Result := inherited;
end;
function TSynTclTkSyn.GetToken: string;
@ -677,12 +559,15 @@ end;
procedure TSynTclTkSyn.ResetRange;
begin
inherited;
fRange := rsUnknown;
end;
procedure TSynTclTkSyn.SetRange(Value: Pointer);
begin
fRange := TRangeState(PtrUInt(Value));
// fRange := TRangeState(PtrUInt(Value));
inherited;
fRange := TRangeState(PtrUInt(CodeFoldRange.RangeType));
end;
procedure TSynTclTkSyn.SetKeyWords(const Value: TStrings);
@ -770,7 +655,8 @@ begin
iIndex := 0;
for cDefKey := Low(TclTkKeys) to High(TclTkKeys) do
begin
if not iKeys.Find( TclTkKeys[cDefKey], iIndex ) then
iIndex:=iKeys.IndexOf(TclTkKeys[cDefKey]);
if iIndex=-1 then
begin
Result := True;
Exit;

View File

@ -0,0 +1,985 @@
{-------------------------------------------------------------------------------
SynHighlighterVerilog v1.2
This unit provides a Verilog highlighter for SynEdit.
2015 (c) Miguel A. Risco-Castillo
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.
Some concepts in this unit are based in the Original Code of Zhou Kan and
"La Biblia del SynEdit" of Tito Hinostroza.
All Rights Reserved.
v1.2 2019/12/21
Adapted to extrasyn package
v1.1 2015
Add special list of highlighted words
-------------------------------------------------------------------------------}
unit synhighlighterverilog;
// extrasyn.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 extrasyn.inc}
{$H+}
interface
uses
SysUtils, Classes, Graphics, SynEditStrConstExtra, SynEditHighlighterFoldBase, SynEditHighlighter, SynEditTypes, SynEditStrConst;
type
TtkTokenKind = (tkSBA, tkIeee, tkComment, tkIdentifier, tkKey, tkNull,
tkNumber, tkSpace, tkString, tkSymbol, tkAttribute, tkUnknown);
TRangeState = (rsUnknown, rsComment);
TProcTableProc = procedure of object;
type
{ TSynVerilogSyn }
TSynVerilogSyn = class(TSynCustomFoldHighlighter)
private
FHLWordsList: TStringList;
fRange: TRangeState;
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;
fAttribAttri: TSynHighLighterAttributes;
FIeeeAttri: TSynHighLighterAttributes;
fSBAAttri: TSynHighLighterAttributes;
fDivider:TSynDividerDrawConfigSetting;
procedure CommentProc;
function KeyComp(const aKey: string): boolean;
procedure SetHLWordsList(AValue: TStringList);
procedure SymbolsProc;
procedure BraceCloseProc;
procedure BraceOpenProc;
procedure CRProc;
procedure ColonProc;
procedure EqualProc;
procedure EndTokenProc;
procedure GreaterProc;
procedure IdentProc;
procedure LFProc;
procedure LowerProc;
procedure MinusProc;
procedure ModSymbolProc;
procedure NotSymbolProc;
procedure NullProc;
procedure NumberProc;
procedure OrSymbolProc;
procedure PlusProc;
procedure PointProc;
procedure RoundCloseProc;
procedure RoundOpenProc;
procedure SemiColonProc;
procedure SlashProc;
procedure SpaceProc;
procedure SquareCloseProc;
procedure SquareOpenProc;
procedure StarProc;
procedure StringProc;
procedure TildeProc;
procedure AttribProc;
procedure XOrSymbolProc;
procedure UnknownProc;
procedure FoldValidProc;
procedure MakeMethodTables;
protected
function GetIdentChars: TSynIdentChars; override;
function GetSampleSource: 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;
procedure GetTokenEx(out TokenStart: PChar; out TokenLength: integer); override;
function GetTokenAttribute: TSynHighLighterAttributes; override;
function GetTokenKind: integer; override;
function GetTokenPos: integer; override;
procedure Next; override;
function GetRange: Pointer; override;
procedure SetRange(Value: Pointer); override;
procedure ReSetRange; override;
function GetDrawDivider(Index: integer): TSynDividerDrawConfigSetting; override;
property IdentChars;
class function GetLanguageName: string; override;
published
property CommentAttri: TSynHighLighterAttributes read fCommentAttri write fCommentAttri;
property IdentifierAttri: TSynHighLighterAttributes read fIdentifierAttri write fIdentifierAttri;
property KeyAttri: TSynHighLighterAttributes read fKeyAttri write fKeyAttri;
property NumberAttri: TSynHighLighterAttributes read fNumberAttri write fNumberAttri;
property SpaceAttri: TSynHighLighterAttributes read fSpaceAttri write fSpaceAttri;
property StringAttri: TSynHighLighterAttributes read fStringAttri write fStringAttri;
property SymbolAttri: TSynHighLighterAttributes read fSymbolAttri write fSymbolAttri;
property AttribAttri: TSynHighLighterAttributes read fAttribAttri write fAttribAttri;
property IeeeAttri: TSynHighLighterAttributes read fIeeeAttri write fIeeeAttri;
property SBAAttri: TSynHighLighterAttributes read fSBAAttri write fSBAAttri;
property HLWordsList: TStringList read FHLWordsList write SetHLWordsList;
end;
implementation
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 := I; //UpCase(I); In verilog the keywords are in lower case
case I in ['_', '0'..'9', 'A'..'Z', 'a'..'z'] of
True: mHashTable[I] := Ord(J)
else
mHashTable[I] := 0;
end;
end;
end;
function TSynVerilogSyn.KeyComp(const aKey: string): boolean;
var
I: integer;
Temp: PChar;
begin
Temp := fToIdent; // Test from the second char +1
if Length(aKey) = fStringLen then
begin
Result := True;
for i := 1 to fStringLen do // Test from the second char := 2
begin
if mHashTable[Temp^] <> mHashTable[aKey[i]] then
begin
Result := False;
break;
end;
inc(Temp);
end;
end
else
Result := False;
end;
procedure TSynVerilogSyn.SetHLWordsList(AValue: TStringList);
begin
if FHLWordsList=AValue then Exit;
FHLWordsList:=AValue;
end;
procedure TSynVerilogSyn.IdentProc;
var i:integer;
begin
while Identifiers[fLine[Run]] do inc(Run);
fStringLen:=Run-fTokenPos;
fToIdent:=fLine + fTokenPos;
fTokenID := tkUnknown;
if FHLWordsList.Count>0 then for i:=0 to FHLWordsList.Count-1 do
begin
if KeyComp(FHLWordsList[i]) then fTokenID := tkString;
end;
case Upcase(fToIdent^) of
'A':begin
//verilog
if KeyComp('always') or
KeyComp('and') or
KeyComp('assign') or
KeyComp('automatic')
then fTokenID := tkKey;
end;
'B':begin
//verilog
if KeyComp('begin') or
KeyComp('buf') or
KeyComp('bufif0') or
KeyComp('bufif1')
then fTokenID := tkKey;
if KeyComp('begin') then begin fTokenID := tkKey; StartCodeFoldBlock(nil); end;
end;
'C':begin
//verilog
if KeyComp('cell') or
KeyComp('cmos') or
KeyComp('config')
then fTokenID := tkKey;
if KeyComp('case') then begin fTokenID := tkKey; StartCodeFoldBlock(nil); end;
if KeyComp('casex') then begin fTokenID := tkKey; StartCodeFoldBlock(nil); end;
if KeyComp('casez') then begin fTokenID := tkKey; StartCodeFoldBlock(nil); end;
end;
'D':begin
//verilog
if KeyComp('deassign') or
KeyComp('default') or
KeyComp('defparam') or
KeyComp('design') or
KeyComp('disable') then fTokenID := tkKey;
end;
'E':begin
//verilog
if KeyComp('edge') or
KeyComp('else') or
KeyComp('event')
then fTokenID := tkKey;
if KeyComp('end') then endTokenProc;
if KeyComp('endcase') then endTokenProc;
if KeyComp('endconfig') then endTokenProc;
if KeyComp('endfunction') then endTokenProc;
if KeyComp('endgenerate') then endTokenProc;
if KeyComp('endmodule') then endTokenProc;
if KeyComp('endprimitive') then endTokenProc;
if KeyComp('endspecify') then endTokenProc;
if KeyComp('endtable') then endTokenProc;
if KeyComp('endtask') then endTokenProc;
end;
'F':begin
//verilog
if KeyComp('for') or
KeyComp('force') or
KeyComp('forever') or
KeyComp('fork') or
KeyComp('function')
then fTokenID := tkKey;
end;
'G':begin
//verilog
if KeyComp('generate') or
KeyComp('genvar')
then fTokenID := tkKey;
end;
'H':begin
//verilog
if KeyComp('highz0') or
KeyComp('highz1')
then fTokenID := tkKey;
end;
'I':begin
//verilog
if KeyComp('if') or
KeyComp('ifnone') or
KeyComp('incdir') or
KeyComp('include') or
KeyComp('initial') or
KeyComp('inout') or
KeyComp('input') or
KeyComp('instance') or
KeyComp('integer')
then fTokenID := tkKey;
end;
'J':begin
if KeyComp('join') then fTokenID := tkKey;
end;
'K':begin
end;
'L':begin
//verilog
if KeyComp('large') or
KeyComp('liblist') or
KeyComp('library') or
KeyComp('localparam')
then fTokenID := tkKey;
end;
'M':begin
//verilog
if KeyComp('macromodule') or
KeyComp('medium')
then fTokenID := tkKey;
if KeyComp('module') then begin fTokenID := tkKey; StartCodeFoldBlock(nil); end;
end;
'N':begin
//verilog
if KeyComp('nand') or
KeyComp('negedge') or
KeyComp('nmos') or
KeyComp('nor') or
KeyComp('noshowcancelled') or
KeyComp('not') or
KeyComp('notif0') or
KeyComp('notif1')
then fTokenID := tkKey;
end;
'O':begin
//verilog
if KeyComp('or') or
KeyComp('output')
then fTokenID := tkKey;
end;
'P':begin
//verilog
if KeyComp('parameter') or
KeyComp('pmos') or
KeyComp('posedge') or
KeyComp('primitive') or
KeyComp('pull0') or
KeyComp('pull1') or
KeyComp('pulldown') or
KeyComp('pullup') or
KeyComp('pulsestyle_oneventglitch') or
KeyComp('pulsestyle_ondetectglitch')
then fTokenID := tkKey;
//if KeyComp('process') or
// KeyComp('package') then begin fTokenID := tkKey; StartCodeFoldBlock(nil); end;
//if KeyComp('procedure') then begin fTokenID := tkKey; FoldValidProc; end;
end;
'Q':begin
end;
'R':begin
//verilog
if KeyComp('remos') or
KeyComp('real') or
KeyComp('realtime') or
KeyComp('reg') or
KeyComp('release') or
KeyComp('repeat') or
KeyComp('rnmos') or
KeyComp('rpmos') or
KeyComp('rtran') or
KeyComp('rtranif0') or
KeyComp('rtranif1')
then fTokenID := tkKey;
end;
'S':begin
//verilog
if KeyComp('scalared') or
KeyComp('showcancelled') or
KeyComp('signed') or
KeyComp('small') or
KeyComp('specify') or
KeyComp('specparam') or
KeyComp('strong0') or
KeyComp('strong1') or
KeyComp('supply0') or
KeyComp('supply1')
then fTokenID := tkKey;
//SBA
if KeyComp('sbaread') or
KeyComp('sbawrite') or
KeyComp('sba_config') or
KeyComp('sba_package') or
KeyComp('sba_typedef') or
KeyComp('sbacall') or
KeyComp('sbaret') or
KeyComp('sbajmp')
then fTokenID := tkSBA;
end;
'T':begin
//verilog
if KeyComp('table') or
KeyComp('task') or
KeyComp('time') or
KeyComp('tran') or
KeyComp('tranif0') or
KeyComp('tranif1') or
KeyComp('tri') or
KeyComp('tri0') or
KeyComp('tri1') or
KeyComp('triand') or
KeyComp('trior') or
KeyComp('trireg')
then fTokenID := tkKey;
end;
'U':begin
//verilog
if KeyComp('unsigned') or
KeyComp('use')
then fTokenID := tkKey;
end;
'V':begin
//verilog
if KeyComp('vectored') then fTokenID := tkKey;
end;
'W':begin
//verilog
if KeyComp('wait') or
KeyComp('wand') or
KeyComp('weak0') or
KeyComp('weak1') or
KeyComp('while') or
KeyComp('wire') or
KeyComp('wor')
then fTokenID := tkKey;
// if KeyComp('while') then begin fTokenID := tkKey; StartCodeFoldBlock(nil); end;
end;
'X':begin
//verilog
if KeyComp('xnor') or
KeyComp('xor')
then fTokenID := tkKey;
end;
'Y':begin
end;
end;
end;
procedure TSynVerilogSyn.MakeMethodTables;
var
I: char;
begin
for I := #0 to #255 do
case I of
#0 : fProcTable[I] := @NullProc;
'#','$','&','@' : fProcTable[I] := @SymbolsProc;
'}': fProcTable[I] := @BraceCloseProc;
'{': fProcTable[I] := @BraceOpenProc;
#13: fProcTable[I] := @CRProc;
':': fProcTable[I] := @ColonProc;
'=': fProcTable[I] := @EqualProc;
'>': fProcTable[I] := @GreaterProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := @IdentProc;
#10: fProcTable[I] := @LFProc;
'<': fProcTable[I] := @LowerProc;
'-': fProcTable[I] := @MinusProc;
'%': fProcTable[I] := @ModSymbolProc;
'!': fProcTable[I] := @NotSymbolProc;
'0'..'9': fProcTable[I] := @NumberProc;
'|': fProcTable[I] := @OrSymbolProc;
'+': 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] := @SquareCloseProc;
'[': fProcTable[I] := @SquareOpenProc;
'*': fProcTable[I] := @StarProc;
#34: fProcTable[I] := @StringProc; //"
'~': fProcTable[I] := @TildeProc;
#39: fProcTable[I] := @AttribProc; //'
#96: fProcTable[I] := @AttribProc; //`
'^': fProcTable[I] := @XOrSymbolProc;
else
fProcTable[I] := @UnknownProc;
end;
end;
constructor TSynVerilogSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCommentAttri := TSynHighLighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Foreground := clGreen;
AddAttribute(fCommentAttri);
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 := clRed;
AddAttribute(fNumberAttri);
fSpaceAttri := TSynHighLighterAttributes.Create(SYNS_AttrWhitespace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighLighterAttributes.Create(SYNS_AttrString);
fStringAttri.Foreground := clMaroon;
AddAttribute(fStringAttri);
fSymbolAttri := TSynHighLighterAttributes.Create(SYNS_AttrSymbol);
fSymbolAttri.Foreground := clTeal;
AddAttribute(fSymbolAttri);
fAttribAttri := TSynHighLighterAttributes.Create(SYNS_AttrAttributeName);
fAttribAttri.Foreground := $000080FF;
AddAttribute(fAttribAttri);
fIeeeAttri := TSynHighLighterAttributes.Create(SYNS_AttrSecondReservedWord);
fIeeeAttri.Foreground := $00804000;
AddAttribute(fIeeeAttri);
fSBAAttri := TSynHighLighterAttributes.Create(SYNS_AttrMiscellaneous);
fSBAAttri.Foreground := $00C08000;
AddAttribute(fSBAAttri);
SetAttributesOnChange(@DefHighlightChange);
MakeMethodTables;
fRange := rsUnknown;
fDefaultFilter := SYNS_FilterVerilog;
fDivider.Color:=clNone;
FHLWordsList:=TStringList.Create;
end;
destructor TSynVerilogSyn.Destroy;
begin
FreeAndNil(FHLWordsList);
inherited Destroy;
end;
procedure TSynVerilogSyn.SetLine(const NewValue: String; LineNumber: Integer);
begin
inherited;
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end;
procedure TSynVerilogSyn.SymbolsProc;
begin
inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynVerilogSyn.BraceCloseProc;
begin
inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynVerilogSyn.BraceOpenProc;
begin
inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynVerilogSyn.CRProc;
begin
fTokenID := tkSpace;
Inc(Run);
if fLine[Run + 1] = #10 then Inc(Run);
end;
procedure TSynVerilogSyn.ColonProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.EqualProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.GreaterProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynVerilogSyn.LowerProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.MinusProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.SlashProc;
begin
fTokenID := tkSymbol;
inc(Run);
if (FLine[Run] = '/') then
begin
if (FLine[Run+1] = ' ') and (FLine[Run+2] = '/') and
(FLine[Run+3] = 'L') and (FLine[Run+4] = ':') then
begin
fTokenID := tkSBA;
end else fTokenID := tkComment;
while not (FLine[Run] in [#0, #10, #13]) do inc(Run);
end else if (FLine[Run] = '*') then
begin
fRange := rsComment; //marca inicio de rango comentario
CommentProc; //Procesa en modo rango comentario
end;
end;
procedure TSynVerilogSyn.CommentProc;
begin
fTokenID := tkComment;
if (FLine[Run]=#0) then begin NullProc; exit; end; // Si fin de línea
while not (FLine[Run] in [#0, #10, #13]) do
begin
if (FLine[Run]='*') and (FLine[Run+1]='/') then
begin
fRange:=rsUnknown;
inc(Run,2);
break;
end else inc(Run);
end;
end;
procedure TSynVerilogSyn.ModSymbolProc;
begin
inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynVerilogSyn.NotSymbolProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynVerilogSyn.NumberProc;
begin
fTokenID := tkNumber;
while FLine[Run] in ['0'..'9', '.', 'u', 'U', 'l', 'L', 'x', 'X', 'e', 'E', 'f', 'F'] do
inc(Run);
end;
procedure TSynVerilogSyn.OrSymbolProc;
begin
inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynVerilogSyn.PlusProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.PointProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.RoundCloseProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.RoundOpenProc;
begin
inc(Run);
FTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.SemiColonProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
end;
procedure TSynVerilogSyn.SquareCloseProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.SquareOpenProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.StarProc;
begin
inc(Run);
fTokenID := tkSymbol;
end;
procedure TSynVerilogSyn.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 TSynVerilogSyn.TildeProc;
begin
inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynVerilogSyn.AttribProc;
var
tmp:integer;
c:char;
begin
fTokenID := tkSymbol;
inc(Run);
tmp:=Run;
c:=lowercase(fLine[Run]);
while fLine[tmp] in ['a'..'z','A'..'Z'] do inc(tmp);
fStringLen:=tmp-fTokenPos;
fToIdent:=fLine + fTokenPos;
if (c='b') or
(c='d') or
(c='h') or
keycomp('''include') or
keycomp('''ifdef') or
keycomp('''ifndef') or
keycomp('''define') or
keycomp('''endif') or
keycomp('''else') or
(c='o') then
begin
fTokenID := tkAttribute;
while fLine[Run] in ['a'..'z','A'..'Z'] do inc(Run);
end;
end;
procedure TSynVerilogSyn.XOrSymbolProc;
begin
inc(Run);
fTokenId := tkSymbol;
end;
procedure TSynVerilogSyn.EndTokenProc;
//var tmp:integer;
begin
fTokenID := tkKey;
//while fLine[Run]=' ' do inc(Run);
//tmp:=Run;
//while Identifiers[fLine[Run]] do inc(Run);
//fStringLen:=Run-tmp;
//fToIdent:=fLine + tmp;
//if not (
// keycomp('architecture') or
// keycomp('if') or
// keycomp('case') or
// keycomp('component') or
// keycomp('function') or
// keycomp('loop') or
// keycomp('package') or
// keycomp('procedure') or
// keycomp('process')
// ) then Run:=tmp;
EndCodeFoldBlock();
end;
procedure TSynVerilogSyn.UnknownProc;
begin
inc(Run);
while (fLine[Run] in [#128..#191]) OR // continued utf8 subcode
((fLine[Run]<>#0) and (fProcTable[fLine[Run]] = @UnknownProc)) do inc(Run);
fTokenID := tkUnknown;
end;
procedure TSynVerilogSyn.FoldValidProc;
var
tmp:integer;
found:boolean;
begin
tmp:=run;
found:=false;
while (not (fLine[tmp] in [#0, #10, #13])) do if fLine[tmp]=';' then
begin
found:=true;
break;
end else inc(tmp);
if not found then StartCodeFoldBlock(nil);
end;
procedure TSynVerilogSyn.Next;
begin
fTokenPos := Run;
if fRange = rsComment then CommentProc else fProcTable[fLine[Run]];
end;
function TSynVerilogSyn.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 TSynVerilogSyn.GetEOL: boolean;
begin
Result := fTokenID = tkNull;
end;
function TSynVerilogSyn.GetToken: string;
var
Len: longint;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
procedure TSynVerilogSyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
begin
TokenLength:=Run-fTokenPos;
TokenStart := fLine + fTokenPos;
//if TokenLength>0 then begin
// TokenStart:=@fLine[fTokenPos];
//end else begin
// TokenStart:=nil;
//end;
end;
function TSynVerilogSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynVerilogSyn.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;
tkAttribute: Result := fAttribAttri;
tkIeee: Result := fIeeeAttri;
tkSBA: Result := fSBAAttri;
tkUnknown: Result := fIdentifierAttri;
else
Result := nil;
end;
end;
function TSynVerilogSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynVerilogSyn.GetTokenPos: integer;
begin
Result := fTokenPos;
end;
function TSynVerilogSyn.GetRange: Pointer;
begin
// Result := Pointer(fRange);
CodeFoldRange.RangeType := Pointer(PtrInt(fRange));
Result := inherited;
end;
procedure TSynVerilogSyn.ReSetRange;
begin
inherited;
fRange := rsUnknown;
end;
function TSynVerilogSyn.GetDrawDivider(Index: integer
): TSynDividerDrawConfigSetting;
begin
Result:=fDivider;
end;
procedure TSynVerilogSyn.SetRange(Value: Pointer);
begin
// fRange := TRangeState(Value);
inherited;
fRange := TRangeState(PtrUInt(CodeFoldRange.RangeType));
end;
function TSynVerilogSyn.GetIdentChars: TSynIdentChars;
begin
Result := ['_', '0'..'9', 'a'..'z', 'A'..'Z'];
end;
class function TSynVerilogSyn.GetLanguageName :string;
begin
Result := SYNS_LangVerilog;
end;
function TSynVerilogSyn.GetSampleSource: string;
begin
Result :=
'// ----------------------------------------------------------'+LineEnding+
'// Module: verilogtest_2'+LineEnding+
'// ----------------------------------------------------------'+LineEnding+
''+LineEnding+
'`timescale 1ns / 100ps'+LineEnding+
''+LineEnding+
'module nc_test_2(Y, A, B, sel);'+LineEnding+
' output [15:0] Y;'+LineEnding+
' input [15:0] A, B;'+LineEnding+
' input sel;'+LineEnding+
' reg [15:0] Y;'+LineEnding+
' always @(A or B or sel)'+LineEnding+
' if (sel == 1''b0)'+LineEnding+
' Y = A;'+LineEnding+
' else'+LineEnding+
' Y = B;'+LineEnding+
'endmodule ';
end;
initialization
MakeIdentTable;
RegisterPlaceableHighlighter(TSynVerilogSyn);
end.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
object Form1: TForm1
Left = 366
Left = 641
Height = 449
Top = 155
Top = 230
Width = 742
Caption = 'Form1'
ClientHeight = 429
@ -9,7 +9,7 @@ object Form1: TForm1
Menu = MainMenu1
OnCreate = FormCreate
OnDestroy = FormDestroy
LCLVersion = '1.9.0.0'
LCLVersion = '2.3.0.0'
inline SynEdit1: TSynEdit
Left = 0
Height = 429
@ -19,7 +19,7 @@ object Form1: TForm1
Font.Height = -13
Font.Name = 'Courier New'
Font.Pitch = fpFixed
Font.Quality = fqNonAntialiased
Font.Quality = fqCleartype
ParentColor = False
ParentFont = False
TabOrder = 0
@ -649,8 +649,8 @@ object Form1: TForm1
end
end
object MainMenu1: TMainMenu
left = 152
top = 40
Left = 152
Top = 40
object MenuItem1: TMenuItem
Caption = 'Highlighter'
end

View File

@ -16,7 +16,7 @@ uses
SynHighlighterAsm, SynHighlighterDOT, SynHighlighterIDL, SynHighlighterKix, {SynHighlighterMsg,}
SynHighlighterSDD, SynHighlighterSml, SynHighlighterURI, SynHighlighterM3, SynHighlighterRC,
SynHighlighterST, SynHighlighter8051, SynHighlighterLua, SynHighlighterProlog, SynHighlighterCAC,
SynHighlighterAWK, SynHighlighterGnuplot;
SynHighlighterAWK, SynHighlighterGnuplot, SynHighlighterVHDL, SynHighlighterVerilog, SynHighlighterJSON;
// SynHighlighterGeneral;
@ -86,9 +86,13 @@ procedure TForm1.FormCreate(Sender: TObject);
var
i, c: Integer;
item: TMenuItem;
submenu: TMenuItem;
hl: TSynCustomHighlighter;
hlCap: String; // highlighter caption
lastChar: Char;
begin
Caption := FORM_CAPTION;
SynEdit1.Font.Quality := fqClearType;
FHighlighters := TFPList.Create;
@ -131,6 +135,9 @@ begin
FHighlighters.Add(TSynCACSyn.Create(Self));
FHighlighters.Add(TSynSTSyn.Create(self));
FHighlighters.Add(TSynGnuplotSyn.Create(self));
FHighlighters.Add(TSynVHDLSyn.Create(Self));
FHighlighters.Add(TSynVerilogSyn.Create(Self));
FHighlighters.Add(TSynJSONSyn.Create(Self));
// FHighlighters.Add(TSynCPMSyn.Create(self));
// FHighlighters.Add(TSynGeneralSyn.Create(self));
@ -140,9 +147,18 @@ begin
FHighlighters.Sort(@CompareHighlighters);
lastChar := #0;
for i:=0 to FHighlighters.Count-1 do begin
hl := TSynCustomHighlighter(FHighlighters[i]);
if Assigned(hl) then begin
hlCap := GetHighlighterCaption(hl);
if hlCap[1] <> lastChar then
begin
lastChar := hlCap[1];
subMenu := TMenuItem.Create(self);
subMenu.Caption := hlCap[1] + '...';
MenuItem1.Add(subMenu);
end;
SetDefaultColors(hl);
item := TMenuItem.Create(self);
item.Tag := i+1; //0 = unknown highlighter
@ -154,7 +170,7 @@ begin
end;
// item.Hint := hl.ClassName;
item.OnClick := @MenuClick;
MenuItem1.Add(item);
subMenu.Add(item);
end;
end;

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="4">
<Package Version="5">
<PathDelim Value="\"/>
<Name Value="ExtraHighlighters"/>
<Author Value="Various authors, see each highlighter source file for more info."/>
@ -19,8 +19,8 @@
</CompilerOptions>
<Description Value="Extra highlighters for synedit"/>
<License Value="MPL GPL dual license."/>
<Version Major="1"/>
<Files Count="40">
<Version Major="1" Minor="2"/>
<Files Count="43">
<Item1>
<Filename Value="SyneditHighlighters\syneditstrconstextra.pas"/>
<UnitName Value="SynEditStrConstExtra"/>
@ -182,7 +182,20 @@
<Filename Value="SyneditHighlighters\synhighlightergnuplot.pas"/>
<UnitName Value="synhighlightergnuplot"/>
</Item40>
<Item41>
<Filename Value="SyneditHighlighters\synhighlightervhdl.pas"/>
<UnitName Value="SynHighlighterVHDL"/>
</Item41>
<Item42>
<Filename Value="SyneditHighlighters\synhighlighterverilog.pas"/>
<UnitName Value="synhighlighterverilog"/>
</Item42>
<Item43>
<Filename Value="SyneditHighlighters\synhighlighterjson.pas"/>
<UnitName Value="SynHighlighterJSON"/>
</Item43>
</Files>
<CompatibilityMode Value="True"/>
<RequiredPkgs Count="2">
<Item1>
<PackageName Value="SynEdit"/>

View File

@ -20,7 +20,8 @@ uses
SynHighlighterRC, SynHighlighterRuby, SynHighlighterSDD, SynHighlighterSml,
SynHighlighterTclTk, SynHighlighterUnreal, SynHighlighterVBScript,
SynHighlighterVrml97, SynHighlighter8051, SynHighlighterURI,
SynHighlighterST, SynHighlighterGeneral, synhighlightergnuplot;
SynHighlighterST, SynHighlighterGeneral, synhighlightergnuplot,
SynHighlighterVHDL, synhighlighterverilog, SynHighlighterJSON;
implementation

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="4">
<Package Version="5">
<PathDelim Value="\"/>
<Name Value="ExtraHighlighters_Dsgn"/>
<Type Value="DesignTime"/>
@ -14,7 +14,7 @@
</CompilerOptions>
<Description Value="Extra highlighters for synedit"/>
<License Value="MPL, LGPL DUAL license."/>
<Version Major="1"/>
<Version Major="1" Minor="2"/>
<Files Count="1">
<Item1>
<Filename Value="uhighlighterreg.pas"/>
@ -22,6 +22,7 @@
<UnitName Value="uHighlighterReg"/>
</Item1>
</Files>
<CompatibilityMode Value="True"/>
<RequiredPkgs Count="2">
<Item1>
<PackageName Value="ExtraHighlighters"/>

View File

@ -115,3 +115,13 @@ tsynvbscriptsyn_200.png
tsynvrml97syn.png
tsynvrml97syn_150.png
tsynvrml97syn_200.png
tsynvhdlsyn.png
tsynvhdlsyn_150.png
tsynvhdlsyn_200.png
tsynverilogsyn.png
tsynverilogsyn_150.png
tsynverilogsyn_200.png
tsynjsonsyn.png
tsynjsonsyn_150.png
tsynjsonsyn_200.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 866 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1023 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 855 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 536 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

Binary file not shown.

View File

@ -28,6 +28,7 @@ uses
SynHighlighterHP48,
SynHighlighterIDL,
SynHighlighterInno,
SynHighlighterJSON,
SynHighlighterKix,
SynHighlighterLDraw,
SynHighlighterLua,
@ -42,6 +43,8 @@ uses
SynHighlighterTclTk,
SynHighlighterUnreal,
SynHighlighterVBScript,
SynHighlighterVerilog,
SynHighlighterVHDL,
SynHighlighterVrml97;
procedure Register;
@ -78,6 +81,7 @@ begin
TSynHP48Syn,
TSynIdlSyn,
TSynInnoSyn,
TSynJSONSyn,
TSynKixSyn,
TSynLDRSyn,
TSynLuaSyn,
@ -92,6 +96,8 @@ begin
TSynTclTkSyn,
TSynUnrealSyn,
TSynVBScriptSyn,
TSynVerilogSyn,
TSynVHDLSyn,
TSynVrml97Syn
]);
end;