synedit and ide: Adds Pike syntax highlighter

git-svn-id: trunk@48339 -
This commit is contained in:
sekelsenmat 2015-03-14 10:42:05 +00:00
parent b5ef5a6a06
commit 467c7ec4c5
7 changed files with 474 additions and 16 deletions

1
.gitattributes vendored
View File

@ -3496,6 +3496,7 @@ components/synedit/synhighlightermulti.pas svneol=native#text/pascal
components/synedit/synhighlighterpas.pp svneol=native#text/pascal
components/synedit/synhighlighterperl.pas svneol=native#text/pascal
components/synedit/synhighlighterphp.pas svneol=native#text/pascal
components/synedit/synhighlighterpike.pas svneol=native#text/plain
components/synedit/synhighlighterpo.pp svneol=native#text/pascal
components/synedit/synhighlighterposition.pas svneol=native#text/pascal
components/synedit/synhighlighterpython.pas svneol=native#text/pascal

View File

@ -30,7 +30,7 @@ uses
LazSynTextArea, SynRegExpr, SynTextDrawer, SynEditMarkupGutterMark,
SynHighlighterBat, SynHighlighterIni, SynEditMarkupSpecialChar,
SynEditTextDoubleWidthChars, SynEditTextSystemCharWidth, SynEditMarkupIfDef,
SynPluginMultiCaret, LazarusPackageIntf;
SynPluginMultiCaret, synhighlighterpike, LazarusPackageIntf;
implementation

View File

@ -37,7 +37,7 @@ Alternatively, the contents of these files may be used under the terms of the GN
If you wish to allow use of your version of these files only under the terms of the GPL and not to allow others to use your version of this file under the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under either the MPL or the GPL.
"/>
<Version Major="1"/>
<Files Count="82">
<Files Count="83">
<Item1>
<Filename Value="synbeautifier.pas"/>
<UnitName Value="SynBeautifier"/>
@ -369,6 +369,10 @@ If you wish to allow use of your version of these files only under the terms of
<Filename Value="synpluginmulticaret.pp"/>
<UnitName Value="SynPluginMultiCaret"/>
</Item82>
<Item83>
<Filename Value="synhighlighterpike.pas"/>
<UnitName Value="synhighlighterpike"/>
</Item83>
</Files>
<LazDoc Paths="docs\xml"/>
<i18n>

View File

@ -393,7 +393,8 @@ const
SYNS_LangSynGenMsgfiles = 'SynGen Msg files';
SYNS_LangUnreal = 'Unreal';
SYNS_LangTeX = 'TeX';
SYNS_LangPo = 'po language files';
SYNS_LangPo = 'po language files';
SYNS_LangPike = 'Pike';
resourcestring

View File

@ -88,7 +88,6 @@ type
FTokenID: TtkTokenKind;
FExtTokenID: TxtkTokenKind;
fEol: Boolean;
fIdentFuncTable: array[0..172] of TIdentFuncTableFunc;
fLineNumber: Integer;
fCommentAttri: TSynHighlighterAttributes;
fDocumentAttri: TSynHighlighterAttributes;
@ -100,8 +99,6 @@ type
fStringAttri: TSynHighlighterAttributes;
fSymbolAttri: TSynHighlighterAttributes;
fAnnotationAttri: TSynHighlighterAttributes;
function KeyHash(ToHash: PChar): Integer;
function KeyComp(const aKey: String): Boolean;
function Func17: TtkTokenKind;
function Func21: TtkTokenKind;
function Func32: TtkTokenKind;
@ -183,11 +180,14 @@ type
procedure TildeProc;
procedure XOrSymbolProc;
procedure UnknownProc;
function AltFunc: TtkTokenKind;
procedure InitIdent;
function IdentKind(MayBe: PChar): TtkTokenKind;
procedure MakeMethodTables;
protected
fIdentFuncTable: array[0..172] of TIdentFuncTableFunc;
function AltFunc: TtkTokenKind;
function KeyHash(ToHash: PChar): Integer;
function KeyComp(const aKey: String): Boolean;
procedure InitIdent; virtual;
function GetIdentChars: TSynIdentChars; override;
function GetSampleSource: string; override;
function GetExtTokenID: TxtkTokenKind;

View File

@ -0,0 +1,421 @@
{-------------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: SynHighlighterJava.pas, released 2000-04-10.
The Original Code is based on the DcjSynJava.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Michael Trier.
All Rights Reserved.
Contributors to the SynEdit and mwEdit projects are listed in the
Contributors.txt file.
Alternatively, the contents of this file may be used under the terms of the
GNU General Public License Version 2 or later (the "GPL"), in which case
the provisions of the GPL are applicable instead of those above.
If you wish to allow use of your version of this file only under the terms
of the GPL and not to allow others to use your version of this file
under the MPL, indicate your decision by deleting the provisions above and
replace them with the notice and other provisions required by the GPL.
If you do not delete the provisions above, a recipient may use your version
of this file under either the MPL or the GPL.
$Id: synhighlighterjava.pas 46388 2014-09-30 23:57:55Z martin $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
Known Issues:
-------------------------------------------------------------------------------}
{
@abstract(Provides a Pike highlighter for SynEdit)
@author(Felipe Monteiro de Carvalho)
@created(March 2015)
@lastmod(2015-03-14)
The SynHighlighterPike unit provides SynEdit with a Pike source (.pike) highlighter.
}
unit synhighlighterpike;
{$I SynEdit.inc}
interface
uses
SysUtils, Classes,
LCLIntf, LCLType, Graphics,
SynEditTypes, SynEditHighlighter, synhighlighterjava;
type
TSynPikeSyn = class(TSynJavaSyn)
private
function Func17: TtkTokenKind;
function Func21: TtkTokenKind;
function Func32: TtkTokenKind;
function Func34: TtkTokenKind;
function Func39: TtkTokenKind;
function Func40: TtkTokenKind;
function Func42: TtkTokenKind;
function Func45: TtkTokenKind;
function Func46: TtkTokenKind;
function Func47: TtkTokenKind;
function Func48: TtkTokenKind;
function Func54: TtkTokenKind;
function Func55: TtkTokenKind;
function Func57: TtkTokenKind;
function Func59: TtkTokenKind;
function Func60: TtkTokenKind;
function Func61: TtkTokenKind;
function Func62: TtkTokenKind;
function Func63: TtkTokenKind;
function Func66: TtkTokenKind;
function Func68: TtkTokenKind;
function Func69: TtkTokenKind;
function Func76: TtkTokenKind;
function Func78: TtkTokenKind;
function Func79: TtkTokenKind;
function Func83: TtkTokenKind;
function Func86: TtkTokenKind;
function Func88: TtkTokenKind;
function Func89: TtkTokenKind;
function Func90: TtkTokenKind;
function Func92: TtkTokenKind;
function Func93: TtkTokenKind;
function Func95: TtkTokenKind;
function Func97: TtkTokenKind;
function Func98: TtkTokenKind;
function Func102: TtkTokenKind;
function Func109: TtkTokenKind;
function Func110: TtkTokenKind;
function Func114: TtkTokenKind;
function Func115: TtkTokenKind;
function Func119: TtkTokenKind;
function Func127: TtkTokenKind;
function Func136: TtkTokenKind;
function Func172: TtkTokenKind;
protected
procedure InitIdent; override;
function GetSampleSource: string; override;
public
class function Pike_GetSampleSource: string;
class function GetLanguageName: string; override;
end;
implementation
uses
SynEditStrConst;
procedure TSynPikeSyn.InitIdent;
var
I: Integer;
begin
for I := 0 to 172 do
Case I of
17: fIdentFuncTable[I] := @Func17;
21: fIdentFuncTable[I] := @Func21;
32: fIdentFuncTable[I] := @Func32;
34: fIdentFuncTable[I] := @Func34;
39: fIdentFuncTable[I] := @Func39;
40: fIdentFuncTable[I] := @Func40;
42: fIdentFuncTable[I] := @Func42;
45: fIdentFuncTable[I] := @Func45;
46: fIdentFuncTable[I] := @Func46;
47: fIdentFuncTable[I] := @Func47;
48: fIdentFuncTable[I] := @Func48;
54: fIdentFuncTable[I] := @Func54;
55: fIdentFuncTable[I] := @Func55;
57: fIdentFuncTable[I] := @Func57;
59: fIdentFuncTable[I] := @Func59;
60: fIdentFuncTable[I] := @Func60;
61: fIdentFuncTable[I] := @Func61;
62: fIdentFuncTable[I] := @Func62;
63: fIdentFuncTable[I] := @Func63;
66: fIdentFuncTable[I] := @Func66;
68: fIdentFuncTable[I] := @Func68;
69: fIdentFuncTable[I] := @Func69;
76: fIdentFuncTable[I] := @Func76;
78: fIdentFuncTable[I] := @Func78;
79: fIdentFuncTable[I] := @Func79;
83: fIdentFuncTable[I] := @Func83;
86: fIdentFuncTable[I] := @Func86;
88: fIdentFuncTable[I] := @Func88;
89: fIdentFuncTable[I] := @Func89;
90: fIdentFuncTable[I] := @Func90;
92: fIdentFuncTable[I] := @Func92;
93: fIdentFuncTable[I] := @Func93;
95: fIdentFuncTable[I] := @Func95;
97: fIdentFuncTable[I] := @Func97;
98: fIdentFuncTable[I] := @Func98;
102: fIdentFuncTable[I] := @Func102;
109: fIdentFuncTable[I] := @Func109;
110: fIdentFuncTable[I] := @Func110;
114: fIdentFuncTable[I] := @Func114;
115: fIdentFuncTable[I] := @Func115;
119: fIdentFuncTable[I] := @Func119;
127: fIdentFuncTable[I] := @Func127;
136: fIdentFuncTable[I] := @Func136;
172: fIdentFuncTable[I] := @Func172;
else fIdentFuncTable[I] := @AltFunc;
end;
end;
function TSynPikeSyn.Func17: TtkTokenKind;
begin
if KeyComp('if') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func21: TtkTokenKind;
begin
if KeyComp('do') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func32: TtkTokenKind;
begin
if KeyComp('case') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func34: TtkTokenKind;
begin
if KeyComp('char') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func39: TtkTokenKind;
begin
if KeyComp('lambda') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func40: TtkTokenKind;
begin
if KeyComp('catch') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func42: TtkTokenKind;
begin
if KeyComp('for') then Result := tkKey else
if KeyComp('break') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func45: TtkTokenKind;
begin
if KeyComp('else') or KeyComp('bool') or KeyComp('new') then
Result := tkKey
else Result := tkIdentifier;
end;
function TSynPikeSyn.Func46: TtkTokenKind;
begin
if KeyComp('int') or KeyComp('gauge') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func47: TtkTokenKind;
begin
if KeyComp('final') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func48: TtkTokenKind;
begin
if KeyComp('false') or KeyComp('local') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func54: TtkTokenKind;
begin
if KeyComp('void') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func55: TtkTokenKind;
begin
if KeyComp('global') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func57: TtkTokenKind;
begin
if KeyComp('enum') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func59: TtkTokenKind;
begin
if KeyComp('class') or KeyComp('float') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func60: TtkTokenKind;
begin
if KeyComp('this') or KeyComp('mixed') or KeyComp('prefed') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func61: TtkTokenKind;
begin
if KeyComp('goto') or KeyComp('object') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func62: TtkTokenKind;
begin
if KeyComp('while') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func63: TtkTokenKind;
begin
if KeyComp('null') or KeyComp('foreach') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func66: TtkTokenKind;
begin
if KeyComp('try') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func68: TtkTokenKind;
begin
if KeyComp('true') or KeyComp('array') or KeyComp('sscanf') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func69: TtkTokenKind;
begin
if KeyComp('public') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func76: TtkTokenKind;
begin
if KeyComp('default') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func78: TtkTokenKind;
begin
if KeyComp('static') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func79: TtkTokenKind;
begin
if KeyComp('nomask') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func83: TtkTokenKind;
begin
if KeyComp('mapping') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func86: TtkTokenKind;
begin
if KeyComp('finally') or KeyComp('sizeof') or KeyComp('inline') then
Result := tkKey
else Result := tkIdentifier;
end;
function TSynPikeSyn.Func88: TtkTokenKind;
begin
if KeyComp('switch') or KeyComp('typedef') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func89: TtkTokenKind;
begin
if KeyComp('throw') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func90: TtkTokenKind;
begin
if KeyComp('inherit') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func92: TtkTokenKind;
begin
if KeyComp('variant') or KeyComp('extern') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func93: TtkTokenKind;
begin
if KeyComp('string') or KeyComp('typeof') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func95: TtkTokenKind;
begin
if KeyComp('program') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func97: TtkTokenKind;
begin
if KeyComp('import') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func98: TtkTokenKind;
begin
if KeyComp('private') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func102: TtkTokenKind;
begin
if KeyComp('return') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func109: TtkTokenKind;
begin
if KeyComp('continue') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func110: TtkTokenKind;
begin
if KeyComp('function') or KeyComp('optional') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func114: TtkTokenKind;
begin
if KeyComp('constant') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func115: TtkTokenKind;
begin
if KeyComp('protected') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func119: TtkTokenKind;
begin
if KeyComp('strictfp') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func127: TtkTokenKind;
begin
if KeyComp('multiset') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func136: TtkTokenKind;
begin
if KeyComp('implements') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.Func172: TtkTokenKind;
begin
if KeyComp('synchronized') then Result := tkKey else Result := tkIdentifier;
end;
function TSynPikeSyn.GetSampleSource: string;
begin
Result := Pike_GetSampleSource();
end;
class function TSynPikeSyn.Pike_GetSampleSource: string;
begin
Result := '/* Pike syntax highlighting */'#13#10 +
'int main()'#13#10 +
'{'#13#10 +
' array(string) words = ({ "first", "second" });'#13#10 +
' foreach(words, string cur_word)'#13#10 +
' write("%O\n", cur_word);'#13#10 +
' return 0;'#13#10 +
'}'#13#10 +
'/* Text Block */'#13#10 + #13#10;
end;
class function TSynPikeSyn.GetLanguageName: string;
begin
Result := SYNS_LangPike;
end;
initialization
RegisterPlaceableHighlighter(TSynPikeSyn);
end.

View File

@ -59,7 +59,7 @@ uses
SynHighlighterPas, SynHighlighterPerl, SynHighlighterPHP, SynHighlighterSQL,
SynHighlighterPython, SynHighlighterUNIXShellScript, SynHighlighterXML,
SynHighlighterJScript, SynHighlighterDiff, SynHighlighterBat, SynHighlighterIni,
SynHighlighterPo, SynPluginMultiCaret,
SynHighlighterPo, SynHighlighterPike, SynPluginMultiCaret,
// codetools
LinkScanner, CodeToolManager,
// IDEIntf
@ -86,7 +86,7 @@ type
TLazSyntaxHighlighter =
(lshNone, lshText, lshFreePascal, lshDelphi, lshLFM, lshXML, lshHTML,
lshCPP, lshPerl, lshJava, lshBash, lshPython, lshPHP, lshSQL, lshJScript,
lshDiff, lshBat, lshIni, lshPo);
lshDiff, lshBat, lshIni, lshPo, lshPike);
TColorSchemeAttributeFeature =
( hafBackColor, hafForeColor, hafFrameColor, hafAlpha, hafPrior,
@ -399,7 +399,8 @@ const
(Count: 0; Info: nil), // Diff
(Count: 0; Info: nil), // Ini
(Count: 0; Info: nil), // Bat
(Count: 0; Info: nil) // PO
(Count: 0; Info: nil), // PO
(Count: 0; Info: nil) // Pike
);
type
@ -599,7 +600,8 @@ const
(Count: 3; Info: @EditorOptionsFoldInfoDiff[0]), // Diff
(Count: 0; Info: nil), // Bat
(Count: 0; Info: nil), // Ini
(Count: 0; Info: nil) // PO
(Count: 0; Info: nil), // PO
(Count: 0; Info: nil) // Pike
);
const
@ -631,7 +633,7 @@ const
(nil, nil, TIDESynFreePasSyn, TIDESynPasSyn, TSynLFMSyn, TSynXMLSyn,
TSynHTMLSyn, TSynCPPSyn, TSynPerlSyn, TSynJavaSyn, TSynUNIXShellScriptSyn,
TSynPythonSyn, TSynPHPSyn, TSynSQLSyn, TSynJScriptSyn, TSynDiffSyn,
TSynBatSyn, TSynIniSyn, TSynPoSyn);
TSynBatSyn, TSynIniSyn, TSynPoSyn, TSynPikeSyn);
{ Comments }
@ -655,7 +657,8 @@ const
comtNone, // Diff
comtNone, // Bat
comtNone, // Ini
comtNone // po
comtNone, // po
comtCPP // lshPike
);
const
@ -1689,7 +1692,8 @@ const
'Diff',
'Bat',
'Ini',
'PO'
'PO',
'Pike'
);
var
@ -1739,7 +1743,8 @@ const
lshDiff,
lshBat,
lshIni,
lshPo
lshPo,
lshPike
);
var
@ -3141,6 +3146,32 @@ begin
end;
Add(NewInfo);
// create info for Pike
NewInfo := TEditOptLanguageInfo.Create;
NewInfo.TheType := lshPike;
NewInfo.DefaultCommentType := DefaultCommentTypes[NewInfo.TheType];
NewInfo.SynClass := LazSyntaxHighlighterClasses[NewInfo.TheType];
NewInfo.SetBothFilextensions('pike;pmod');
NewInfo.SampleSource := TSynPikeSyn.Pike_GetSampleSource();
with NewInfo do
begin
AddAttrSampleLines[ahaTextBlock] := 12;
MappedAttributes := TStringList.Create;
with MappedAttributes do
begin
Add('Comment=Comment');
Add('Documentation=Comment');
Add('Identifier=Identifier');
Add('Reserved_word=Reserved_word');
Add('Number=Number');
Add('Space=Space');
Add('String=String');
Add('Symbol=Symbol');
end;
CaretXY := Point(1,1);
end;
Add(NewInfo);
end;
destructor TEditOptLangList.Destroy;