diff --git a/components/extrasyn/SyneditHighlighters/syneditstrconstextra.pas b/components/extrasyn/SyneditHighlighters/syneditstrconstextra.pas index 88ae442a4..67da0a989 100644 --- a/components/extrasyn/SyneditHighlighters/syneditstrconstextra.pas +++ b/components/extrasyn/SyneditHighlighters/syneditstrconstextra.pas @@ -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'; diff --git a/components/extrasyn/SyneditHighlighters/synhighlighterjson.pas b/components/extrasyn/SyneditHighlighters/synhighlighterjson.pas new file mode 100644 index 000000000..0a72c915e --- /dev/null +++ b/components/extrasyn/SyneditHighlighters/synhighlighterjson.pas @@ -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. + diff --git a/components/extrasyn/SyneditHighlighters/synhighlightertcltk.pas b/components/extrasyn/SyneditHighlighters/synhighlightertcltk.pas index 3545db56e..479a4c3b2 100644 --- a/components/extrasyn/SyneditHighlighters/synhighlightertcltk.pas +++ b/components/extrasyn/SyneditHighlighters/synhighlightertcltk.pas @@ -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 ) @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; + inc(Run); + 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; + fProcTable[fLine[Run]]; 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; diff --git a/components/extrasyn/SyneditHighlighters/synhighlighterverilog.pas b/components/extrasyn/SyneditHighlighters/synhighlighterverilog.pas new file mode 100644 index 000000000..40cba58a2 --- /dev/null +++ b/components/extrasyn/SyneditHighlighters/synhighlighterverilog.pas @@ -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. + diff --git a/components/extrasyn/SyneditHighlighters/synhighlightervhdl.pas b/components/extrasyn/SyneditHighlighters/synhighlightervhdl.pas new file mode 100644 index 000000000..d1a5b0502 --- /dev/null +++ b/components/extrasyn/SyneditHighlighters/synhighlightervhdl.pas @@ -0,0 +1,1120 @@ +{------------------------------------------------------------------------------- +SynHighlighterVHDL v1.3 + +This unit provides a SBA VHDL highlighter for SynEdit. + +2018 (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.3 2019/12/21 +Adapted to extrasyn package + +v1.2 2018/04/25 +Add SBAsector Attribute for highlight sections of SBA code + +v1.1 +Add special list of highlighted words +-------------------------------------------------------------------------------} + +{$IFNDEF QSYNHIGHLIGHTERVHDL} +unit SynHighlighterVHDL; +{$ENDIF} + +// 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, tkSBAsector, tkIeee, tkComment, tkIdentifier, tkKey, tkNull, + tkNumber, tkSpace, tkString, tkSymbol, tkAttribute, tkUnknown); + + TRangeState = (rsUnknown); + + TProcTableProc = procedure of object; + + TBlockID = ( + PackageBlk, // Package block + EntityBlk, + ArchBlk, // Declarative + ArchImplBlk, // Implementation + CompBlk, + EntCompBlk, + MapBlk, + RecordBlk, + ProcessBlk, + CaseBlk, + ForBlk, + IfBlk, + WhileBlk, + FuncProcBlk + ); + +type + + { TSynVHDLSyn } + + TSynVHDLSyn = 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; + fSBAsectorAttri: TSynHighLighterAttributes; + fDivider:TSynDividerDrawConfigSetting; + 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 GetSampleSource: string; override; + function GetIdentChars: TSynIdentChars; 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 SBAsectorAttrib:TSynHighlighterAttributes read fSBAsectorAttri write fSBAsectorAttri; + 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 := UpCase(I); + case I in ['_', '0'..'9', 'A'..'Z', 'a'..'z'] of + True: mHashTable[I] := Ord(J) + else + mHashTable[I] := 0; + end; + end; +end; + +function TSynVHDLSyn.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 TSynVHDLSyn.SetHLWordsList(AValue: TStringList); +begin + if FHLWordsList=AValue then Exit; + if assigned(FHLWordsList) then FHLWordsList.Free; + FHLWordsList:=AValue; +end; + +procedure TSynVHDLSyn.IdentProc; +var + i:integer; + blk:TBlockID; +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; + blk:=TBlockID(PtrUInt(TopCodeFoldBlockType)); + case Upcase(fToIdent^) of + 'A':begin + //vhdl + if KeyComp('abs') or + KeyComp('access') or + KeyComp('after') or + KeyComp('alias') or + KeyComp('all') or + KeyComp('and') or + KeyComp('array') or + KeyComp('assert') or + KeyComp('attribute') + then fTokenID := tkKey; + if KeyComp('architecture') then begin fTokenID := tkKey; StartCodeFoldBlock(Pointer(PtrUInt(ArchBlk))); end; + //ieee + if KeyComp('add_unsigned') or + KeyComp('and_table') or + KeyComp('append_mode') + then fTokenID := tkIeee; + end; + 'B':begin + //vhdl + if KeyComp('begin') or + KeyComp('block') or + KeyComp('body') or + KeyComp('buffer') or + KeyComp('bus') + then fTokenID := tkKey; +// if KeyComp('begin') then begin fTokenID := tkKey; StartCodeFoldBlock(nil); end; + //ieee + if KeyComp('bit_vector') or + KeyComp('bit') or + KeyComp('bitwise_eql') or + KeyComp('bitwise_neq') or + KeyComp('boolean') + then fTokenID := tkIeee; + end; + 'C':begin + //vhdl + if KeyComp('configuration') or + KeyComp('constant') + then fTokenID := tkKey; + if KeyComp('case') then begin fTokenID := tkKey; StartCodeFoldBlock(Pointer(PtrUInt(CaseBlk))); end; + if KeyComp('component') then begin + fTokenID := tkKey; + if (Blk=ArchBlk) then StartCodeFoldBlock(Pointer(PtrUInt(CompBlk))); + end; + //ieee + if KeyComp('character') then fTokenID := tkIeee; + end; + 'D':begin + //vhdl + if KeyComp('disconnect') or + KeyComp('downto') then fTokenID := tkKey; + //ieee + if KeyComp('delay_length') then fTokenID := tkieee; + end; + 'E':begin + //vhdl + if KeyComp('else') or + KeyComp('elsif') or + KeyComp('exit') + then fTokenID := tkKey; + if KeyComp('entity') then + begin + fTokenID := tkKey; + if (Blk<>ArchBlk) then StartCodeFoldBlock(Pointer(PtrUInt(EntityBlk))) else StartCodeFoldBlock(Pointer(PtrUInt(EntCompBlk))); + end; + if KeyComp('end') then endTokenProc; + end; + 'F':begin + //vhdl + if KeyComp('file') then fTokenID := tkKey; + if KeyComp('for') then fTokenID := tkKey; + if KeyComp('function')then begin fTokenID := tkKey; FoldValidProc; end; + //ieee + if KeyComp('falling_edge') or + KeyComp('false') or + KeyComp('fs') + then fTokenID := tkIeee; + end; + 'G':begin + //vhdl + if KeyComp('generate') or + KeyComp('generic') or + KeyComp('group') or + KeyComp('guarded') + then fTokenID := tkKey; + end; + 'H':begin + //ieee + if KeyComp('hr') then fTokenID := tkIeee; + end; + 'I':begin + //vhdl + if KeyComp('if') then begin fTokenID := tkKey; StartCodeFoldBlock(Pointer(PtrUInt(IfBlk))); end; + if KeyComp('impure') or + KeyComp('in') or + KeyComp('inertial') or + KeyComp('inout') or + KeyComp('is') + then fTokenID := tkKey; + //ieee + if KeyComp('ieee') or + KeyComp('image') or + KeyComp('input') or + KeyComp('integer') or + KeyComp('is_x') + then fTokenID := tkIeee; + end; + 'J':begin + end; + 'K':begin + end; + 'L':begin + //vhdl + if KeyComp('label') or + KeyComp('library') or + KeyComp('linkage') or + KeyComp('literal') + then fTokenID := tkKey; + if KeyComp('loop') then begin fTokenID := tkKey; StartCodeFoldBlock(Pointer(PtrUInt(ForBlk))); end; + end; + 'M':begin + //vhdl + if KeyComp('map') then begin fTokenID := tkKey; end; //StartCodeFoldBlock(Pointer(PtrUInt(MapBlk))); end; + if KeyComp('mod') then fTokenID := tkKey; + //ieee + if KeyComp('math_real') or + KeyComp('min') or + KeyComp('ms') + then fTokenID := tkIeee; + end; + 'N':begin + //vhdl + if KeyComp('nand') or + KeyComp('new') or + KeyComp('next') or + KeyComp('nor') or + KeyComp('not') or + KeyComp('null') + then fTokenID := tkKey; + //ieee + if KeyComp('natural') or + KeyComp('ns') or + KeyComp('numeric_bit') or + KeyComp('numeric_std') + then fTokenID := tkIeee; + end; + 'O':begin + //vhdl + if KeyComp('of') or + KeyComp('on') or + KeyComp('open') or + KeyComp('or') or + KeyComp('others') or + KeyComp('out') + then fTokenID := tkKey; + //ieee + if KeyComp('output') then fTokenID := tkIeee; + end; + 'P':begin + //vhdl + if KeyComp('port') or + KeyComp('postponed') or + KeyComp('pure') + then fTokenID := tkKey; + if KeyComp('process') or + KeyComp('package') then begin fTokenID := tkKey; StartCodeFoldBlock(Pointer(PtrUInt(PackageBlk))); end; + if KeyComp('procedure') then begin fTokenID := tkKey; FoldValidProc; end; + //ieee + if KeyComp('positive') or + KeyComp('pos') or + KeyComp('ps') + then fTokenID := tkIeee; + end; + 'Q':begin + end; + 'R':begin + //vhdl + if KeyComp('range') or + KeyComp('register') or + KeyComp('reject') or + KeyComp('rem') or + KeyComp('report') or + KeyComp('return') or + KeyComp('rol') or + KeyComp('ror') + then fTokenID := tkKey; + if KeyComp('record') then begin fTokenID := tkKey; StartCodeFoldBlock(Pointer(PtrUInt(RecordBlk))); end; + //ieee + if KeyComp('real') or + KeyComp('resize') or + KeyComp('rising_edge') or + KeyComp('rotate_left') or + KeyComp('rotate_right') + then fTokenID := tkIeee; + end; + 'S':begin + //vhdl + if KeyComp('select') or + KeyComp('severity') or + KeyComp('signal') or + KeyComp('shared') or + KeyComp('sla') or + KeyComp('sll') or + KeyComp('sra') or + KeyComp('srl') or + KeyComp('subtype') + then fTokenID := tkKey; + //ieee + if KeyComp('severity_level') or + KeyComp('sec') or + KeyComp('shift_left') or + KeyComp('shift_right') or + KeyComp('shl') or + KeyComp('shr') or + KeyComp('signed_equal') or + KeyComp('signed_less_or_equal') or + KeyComp('signed_less') or + KeyComp('signed_num_bits') or + KeyComp('signed_return_boolean') or + KeyComp('signed') or + KeyComp('small_int') or + KeyComp('sqrt') or + KeyComp('standard') or + KeyComp('status_error') or + KeyComp('std_logic_1164') or + KeyComp('std_logic_arith') or + KeyComp('std_logic_signed') or + KeyComp('std_logic_unsigned') or + KeyComp('std_logic_vector') or + KeyComp('std_logic') or + KeyComp('std_match') or + KeyComp('std_ulogic_vector') or + KeyComp('std_ulogic') or + KeyComp('string') + then fTokenID := tkIeee; + //SBA + if KeyComp('sbacall') or + KeyComp('sbaconfig') or + KeyComp('sbainte') or + KeyComp('sbajump') or + KeyComp('sbapackage') or + KeyComp('sbaread') or + KeyComp('sbaret') or + KeyComp('sbareti') or + KeyComp('sbawait') or + KeyComp('sbawrite') + then fTokenID := tkSBA; + end; + 'T':begin + //vhdl + if KeyComp('then') or + KeyComp('to') or + KeyComp('transport') or + KeyComp('type') + then fTokenID := tkKey; + //ieee + if KeyComp('text') or + KeyComp('textio') or + KeyComp('time') or + KeyComp('to_01') or + KeyComp('to_bit') or + KeyComp('to_bitvector') or + KeyComp('to_integer') or + KeyComp('to_signed') or + KeyComp('to_stdlogicvector') or + KeyComp('to_stdulogic') or + KeyComp('to_stdulogicvector') or + KeyComp('to_unsigned') or + KeyComp('true') + then fTokenID := tkIeee; + end; + 'U':begin + //vhdl + if KeyComp('unaffected') or + KeyComp('units') or + KeyComp('until') or + KeyComp('use') + then fTokenID := tkKey; + //ieee + if KeyComp('unsigned') or + KeyComp('us') + then fTokenID := tkIeee; + end; + 'V':begin + //vhdl + if KeyComp('variable') then fTokenID := tkKey; + //ieee + if KeyComp('val') then fTokenID := tkIeee; + end; + 'W':begin + //vhdl + if KeyComp('wait') or + KeyComp('when') or + KeyComp('with') + then fTokenID := tkKey; + if KeyComp('while') then begin fTokenID := tkKey; StartCodeFoldBlock(Pointer(PtrUInt(WhileBlk))); end; + //ieee + if KeyComp('work') then fTokenID := tkIeee; + end; + 'X':begin + //vhdl + if KeyComp('xnor') or + KeyComp('xor') + then fTokenID := tkKey; + //ieee + if KeyComp('xrol') or + KeyComp('xror') or + KeyComp('xsll') or + KeyComp('xsra') or + KeyComp('xsrl') + then fTokenID := tkIeee; + end; + 'Y':begin + end; + 'Z':begin + end; + end; +end; + +procedure TSynVHDLSyn.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] := @RoundOpenProc; + ')': fProcTable[I] := @RoundCloseProc; + ';': 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; //' + '^': fProcTable[I] := @XOrSymbolProc; + else + fProcTable[I] := @UnknownProc; + end; +end; + +constructor TSynVHDLSyn.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); + + fSBAsectorAttri := TSynHighLighterAttributes.Create(SYNS_AttrLabel); + fSBAsectorAttri.Foreground := $00C08000; + fSBAsectorAttri.Style:=[fsBold]; + AddAttribute(fSBAsectorAttri); + + SetAttributesOnChange(@DefHighlightChange); + MakeMethodTables; + fRange := rsUnknown; + fDefaultFilter := SYNS_FilterVHDL; + + fDivider.Color:=clNone; + + FHLWordsList:=TStringList.Create; +end; + +destructor TSynVHDLSyn.Destroy; +begin + FreeAndNil(FHLWordsList); + inherited Destroy; +end; + +procedure TSynVHDLSyn.SetLine(const NewValue: String; LineNumber: Integer); +begin + inherited; + fLine := PChar(NewValue); + Run := 0; + fLineNumber := LineNumber; + Next; +end; + +procedure TSynVHDLSyn.SymbolsProc; +begin + inc(Run); + fTokenId := tkSymbol; +end; + +procedure TSynVHDLSyn.BraceCloseProc; +begin + inc(Run); + fTokenId := tkSymbol; +end; + +procedure TSynVHDLSyn.BraceOpenProc; +begin + inc(Run); + fTokenId := tkSymbol; +end; + +procedure TSynVHDLSyn.CRProc; +begin + fTokenID := tkSpace; + Inc(Run); + if fLine[Run + 1] = #10 then Inc(Run); +end; + +procedure TSynVHDLSyn.ColonProc; +begin + inc(Run); + fTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.EqualProc; +begin + inc(Run); + fTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.GreaterProc; +begin + inc(Run); + fTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.LFProc; +begin + fTokenID := tkSpace; + inc(Run); +end; + +procedure TSynVHDLSyn.LowerProc; +begin + inc(Run); + fTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.MinusProc; +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] = ':')) or + ((FLine[Run+3] = 'S') and (FLine[Run+4] = 'B') and (FLine[Run+5] = 'A') and (FLine[Run+6] = ':'))) + then + begin + fTokenID := tkSBASector; + end else fTokenID := tkComment; + while not (FLine[Run] in [#0, #10, #13]) do inc(Run); + end; +end; + +procedure TSynVHDLSyn.ModSymbolProc; +begin + inc(Run); + fTokenId := tkSymbol; +end; + +procedure TSynVHDLSyn.NotSymbolProc; +begin + inc(Run); + fTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.NullProc; +begin + fTokenID := tkNull; +end; + +procedure TSynVHDLSyn.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 TSynVHDLSyn.OrSymbolProc; +begin + inc(Run); + fTokenId := tkSymbol; +end; + +procedure TSynVHDLSyn.PlusProc; +begin + inc(Run); + fTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.PointProc; +begin + inc(Run); + fTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.RoundCloseProc; +var Blk:TBlockID; +begin + blk:=TBlockID(PtrUInt(TopCodeFoldBlockType)); + if blk=MapBlk then EndCodeFoldBlock(); + inc(Run); + fTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.RoundOpenProc; +begin + inc(Run); + FTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.SemiColonProc; +var Blk:TBlockID; +begin + blk:=TBlockID(PtrUInt(TopCodeFoldBlockType)); + if blk=EntCompBlk then EndCodeFoldBlock(); + inc(Run); + fTokenID := tkSymbol; +end; + + +procedure TSynVHDLSyn.SlashProc; +begin + inc(Run); + fTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.SpaceProc; +begin + inc(Run); + fTokenID := tkSpace; + while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run); +end; + +procedure TSynVHDLSyn.SquareCloseProc; +begin + inc(Run); + fTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.SquareOpenProc; +begin + inc(Run); + fTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.StarProc; +begin + inc(Run); + fTokenID := tkSymbol; +end; + +procedure TSynVHDLSyn.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 TSynVHDLSyn.TildeProc; +begin + inc(Run); + fTokenId := tkSymbol; +end; + +procedure TSynVHDLSyn.AttribProc; +var tmp:integer; +begin + fTokenID := tkSymbol; + inc(Run); + tmp:=Run; + while Identifiers[fLine[tmp]] do inc(tmp); + fStringLen:=tmp-fTokenPos; + fToIdent:=fLine + fTokenPos; + + if keycomp('''ascending') or + keycomp('''base') or + keycomp('''delayed') or + keycomp('''driving') or + keycomp('''driving_value') or + keycomp('''event') or + keycomp('''high') or + keycomp('''image') or + keycomp('''instance_name') or + keycomp('''last_active') or + keycomp('''last_event') or + keycomp('''last_value') or + keycomp('''left') or + keycomp('''leftof') or + keycomp('''length') or + keycomp('''low') or + keycomp('''path_name') or + keycomp('''pos') or + keycomp('''pred') or + keycomp('''quiet') or + keycomp('''range') or + keycomp('''reverse_range') or + keycomp('''right') or + keycomp('''rightof') or + keycomp('''simple_name') or + keycomp('''stable') or + keycomp('''succ') or + keycomp('''transaction') or + keycomp('''val') or + keycomp('''value') then + begin + fTokenID := tkAttribute; + while Identifiers[fLine[Run]] do inc(Run); + end; +end; + +procedure TSynVHDLSyn.XOrSymbolProc; +begin + inc(Run); + fTokenId := tkSymbol; +end; + +procedure TSynVHDLSyn.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') or + keycomp('record') + ) then Run:=tmp; + EndCodeFoldBlock(); +end; + +procedure TSynVHDLSyn.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 TSynVHDLSyn.FoldValidProc; +var + tmp:integer; + found:boolean; + inRoundbracket:boolean=false; +begin + tmp:=run; + found:=false; + while (not (fLine[tmp] in [#0, #10, #13])) do + begin + if (fLine[tmp]='(') then inRoundbracket:=true; + if (fLine[tmp]=')') then inRoundbracket:=false; + if (fLine[tmp]=';') and not inRoundbracket then + begin + found:=true; + break; + end else inc(tmp); + end; + if not found then StartCodeFoldBlock(Pointer(PtrUInt(FuncProcBlk))); +end; + +procedure TSynVHDLSyn.Next; +begin + fTokenPos := Run; + fProcTable[fLine[Run]]; +end; + +function TSynVHDLSyn.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 TSynVHDLSyn.GetEOL: boolean; +begin + Result := fTokenID = tkNull; +end; + +function TSynVHDLSyn.GetToken: string; +var + Len: longint; +begin + Len := Run - fTokenPos; + SetString(Result, (FLine + fTokenPos), Len); +end; + +procedure TSynVHDLSyn.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 TSynVHDLSyn.GetTokenID: TtkTokenKind; +begin + Result := fTokenId; +end; + +function TSynVHDLSyn.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; + tkSBAsector: Result := fSBAsectorAttri; + tkUnknown: Result := fIdentifierAttri; + else + Result := nil; + end; +end; + +function TSynVHDLSyn.GetTokenKind: integer; +begin + Result := Ord(fTokenId); +end; + +function TSynVHDLSyn.GetTokenPos: integer; +begin + Result := fTokenPos; +end; + +function TSynVHDLSyn.GetRange: Pointer; +begin +// Result := Pointer(fRange); + CodeFoldRange.RangeType := Pointer(PtrInt(fRange)); + Result := inherited; +end; + +procedure TSynVHDLSyn.ReSetRange; +begin + inherited; + fRange := rsUnknown; +end; + +function TSynVHDLSyn.GetDrawDivider(Index: integer + ): TSynDividerDrawConfigSetting; +begin + Result:=fDivider; +end; + +procedure TSynVHDLSyn.SetRange(Value: Pointer); +begin + // fRange := TRangeState(Value); + inherited; + fRange := TRangeState(PtrUInt(CodeFoldRange.RangeType)); +end; + +function TSynVHDLSyn.GetIdentChars: TSynIdentChars; +begin + Result := ['_', '0'..'9', 'a'..'z', 'A'..'Z']; +end; + +class function TSynVHDLSyn.GetLanguageName :string; +begin + Result := SYNS_LangVHDL; +end; + +function TSynVHDLSyn.GetSampleSource: string; +begin + Result := + 'entity DEMO is'+LineEnding+ + 'generic('+LineEnding+ + ' debug:positive:=1;'+LineEnding+ + ' sysfreq:positive:=25E6'+LineEnding+ + ');'+LineEnding+ + 'port('+LineEnding+ + '-- SBA Bus Interface'+LineEnding+ + ' RST_I : in std_logic; -- active high reset'+LineEnding+ + ' CLK_I : in std_logic; -- Main clock'+LineEnding+ + ' STB_I : in std_logic; -- Strobe/ChipSelect, active high'+LineEnding+ + ' WE_I : in std_logic; -- Write enable: active high, Read: active low'+LineEnding+ + ' ADR_I : in std_logic_vector;-- Address bus'+LineEnding+ + ' DAT_I : in std_logic_vector;-- Data in bus'+LineEnding+ + ' DAT_O : out std_logic_vector;-- Data Out bus'+LineEnding+ + ' INT_O : out std_logic; -- Interrupt request output'+LineEnding+ + '-- Aditional Interface'+LineEnding+ + ' P_O : out std_logic_vector(7 downto 0);'+LineEnding+ + ' P_I : in std_logic_vector(7 downto 0)'+LineEnding+ + ');'+LineEnding+ + 'end DEMO;'; +end; + +initialization + MakeIdentTable; + RegisterPlaceableHighlighter(TSynVHDLSyn); +end. + diff --git a/components/extrasyn/TestHighlighters/TestSynHighlighter.lpi b/components/extrasyn/TestHighlighters/TestSynHighlighter.lpi index b5e3fee59..07b8a9797 100644 --- a/components/extrasyn/TestHighlighters/TestSynHighlighter.lpi +++ b/components/extrasyn/TestHighlighters/TestSynHighlighter.lpi @@ -1,10 +1,12 @@ - + - + + + @@ -12,15 +14,16 @@ - - + + + - + @@ -39,12 +42,12 @@ - + - + @@ -55,12 +58,12 @@ - - - - + + + + - + @@ -69,141 +72,141 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -211,7 +214,7 @@ - + @@ -219,29 +222,30 @@ - + - + - - - - + + + + + - + @@ -249,31 +253,30 @@ - + - + - - - - + + + + - + - - + @@ -281,7 +284,7 @@ - + @@ -289,15 +292,15 @@ - + - - + + - + @@ -305,21 +308,23 @@ - + - + - + - - - + + + + + @@ -327,11 +332,11 @@ - + - + @@ -339,22 +344,22 @@ - + - + - + - + @@ -363,35 +368,35 @@ - + - + - + - + - + @@ -399,19 +404,19 @@ - + - + - + @@ -419,24 +424,22 @@ - + - + - - + - + - - + @@ -444,14 +447,14 @@ - + - + @@ -459,14 +462,14 @@ - + - + @@ -474,7 +477,7 @@ - + @@ -482,21 +485,21 @@ - + - + - + @@ -504,21 +507,21 @@ - + - + - + @@ -526,7 +529,7 @@ - + @@ -534,7 +537,7 @@ - + @@ -542,19 +545,19 @@ - + - + - + @@ -562,118 +565,118 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + + @@ -681,78 +684,76 @@ - + - + - + - + - - + - + - + - + - + - + - + - + - - + - + @@ -761,7 +762,7 @@ - + @@ -769,7 +770,7 @@ - + @@ -777,164 +778,177 @@ - + - + - - + - + - - + - + - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/extrasyn/TestHighlighters/unit1.lfm b/components/extrasyn/TestHighlighters/unit1.lfm index da0665f2e..9f6971f33 100644 --- a/components/extrasyn/TestHighlighters/unit1.lfm +++ b/components/extrasyn/TestHighlighters/unit1.lfm @@ -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 diff --git a/components/extrasyn/TestHighlighters/unit1.pas b/components/extrasyn/TestHighlighters/unit1.pas index b59dbda35..e4a784660 100644 --- a/components/extrasyn/TestHighlighters/unit1.pas +++ b/components/extrasyn/TestHighlighters/unit1.pas @@ -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; diff --git a/components/extrasyn/extrahighlighters.lpk b/components/extrasyn/extrahighlighters.lpk index f61215e97..d636bec67 100644 --- a/components/extrasyn/extrahighlighters.lpk +++ b/components/extrasyn/extrahighlighters.lpk @@ -1,6 +1,6 @@ - + @@ -19,8 +19,8 @@ - - + + @@ -182,7 +182,20 @@ + + + + + + + + + + + + + diff --git a/components/extrasyn/extrahighlighters.pas b/components/extrasyn/extrahighlighters.pas index a8c1f9962..8bab9d5fd 100644 --- a/components/extrasyn/extrahighlighters.pas +++ b/components/extrasyn/extrahighlighters.pas @@ -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 diff --git a/components/extrasyn/extrahighlighters_dsgn.lpk b/components/extrasyn/extrahighlighters_dsgn.lpk index 4b4fb4e56..ee32704d3 100644 --- a/components/extrasyn/extrahighlighters_dsgn.lpk +++ b/components/extrasyn/extrahighlighters_dsgn.lpk @@ -1,6 +1,6 @@ - + @@ -14,7 +14,7 @@ - + @@ -22,6 +22,7 @@ + diff --git a/components/extrasyn/icons/iconlist.txt b/components/extrasyn/icons/iconlist.txt index bb62f6b62..74171ae61 100644 --- a/components/extrasyn/icons/iconlist.txt +++ b/components/extrasyn/icons/iconlist.txt @@ -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 + diff --git a/components/extrasyn/icons/tsynjsonsyn.png b/components/extrasyn/icons/tsynjsonsyn.png new file mode 100644 index 000000000..b0928578b Binary files /dev/null and b/components/extrasyn/icons/tsynjsonsyn.png differ diff --git a/components/extrasyn/icons/tsynjsonsyn_150.png b/components/extrasyn/icons/tsynjsonsyn_150.png new file mode 100644 index 000000000..9421dda6e Binary files /dev/null and b/components/extrasyn/icons/tsynjsonsyn_150.png differ diff --git a/components/extrasyn/icons/tsynjsonsyn_200.png b/components/extrasyn/icons/tsynjsonsyn_200.png new file mode 100644 index 000000000..89053c353 Binary files /dev/null and b/components/extrasyn/icons/tsynjsonsyn_200.png differ diff --git a/components/extrasyn/icons/tsynverilogsyn.png b/components/extrasyn/icons/tsynverilogsyn.png new file mode 100644 index 000000000..975b4e801 Binary files /dev/null and b/components/extrasyn/icons/tsynverilogsyn.png differ diff --git a/components/extrasyn/icons/tsynverilogsyn_150.png b/components/extrasyn/icons/tsynverilogsyn_150.png new file mode 100644 index 000000000..1d18c8209 Binary files /dev/null and b/components/extrasyn/icons/tsynverilogsyn_150.png differ diff --git a/components/extrasyn/icons/tsynverilogsyn_200.png b/components/extrasyn/icons/tsynverilogsyn_200.png new file mode 100644 index 000000000..bf44c0a3c Binary files /dev/null and b/components/extrasyn/icons/tsynverilogsyn_200.png differ diff --git a/components/extrasyn/icons/tsynvhdlsyn.png b/components/extrasyn/icons/tsynvhdlsyn.png new file mode 100644 index 000000000..a6548d3dc Binary files /dev/null and b/components/extrasyn/icons/tsynvhdlsyn.png differ diff --git a/components/extrasyn/icons/tsynvhdlsyn_150.png b/components/extrasyn/icons/tsynvhdlsyn_150.png new file mode 100644 index 000000000..1b3ccadeb Binary files /dev/null and b/components/extrasyn/icons/tsynvhdlsyn_150.png differ diff --git a/components/extrasyn/icons/tsynvhdlsyn_200.png b/components/extrasyn/icons/tsynvhdlsyn_200.png new file mode 100644 index 000000000..66afab002 Binary files /dev/null and b/components/extrasyn/icons/tsynvhdlsyn_200.png differ diff --git a/components/extrasyn/images.res b/components/extrasyn/images.res index fbb52a928..05cd5cb8c 100644 Binary files a/components/extrasyn/images.res and b/components/extrasyn/images.res differ diff --git a/components/extrasyn/uhighlighterreg.pas b/components/extrasyn/uhighlighterreg.pas index 84decfbaf..5a2a39390 100644 --- a/components/extrasyn/uhighlighterreg.pas +++ b/components/extrasyn/uhighlighterreg.pas @@ -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;