IDE starting on po highlighter

git-svn-id: trunk@34300 -
This commit is contained in:
martin 2011-12-19 23:37:41 +00:00
parent 3f6db54739
commit d4efb55fc4
5 changed files with 484 additions and 27 deletions

1
.gitattributes vendored
View File

@ -2389,6 +2389,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/synhighlighterpo.pp svneol=native#text/pascal
components/synedit/synhighlighterposition.pas svneol=native#text/pascal
components/synedit/synhighlighterpython.pas svneol=native#text/pascal
components/synedit/synhighlightersql.pas svneol=native#text/pascal

View File

@ -7,29 +7,26 @@ unit allsynedit;
interface
uses
SynBeautifier, SynCompletion, SynDesignStringConstants, SynEdit,
SynEditAutoComplete, SynEditExport, SynEditFoldedView, SynEditHighlighter,
SynEditHighlighterFoldBase, SynEditHighlighterXMLBase, SynEditKeyCmds,
SynEditLazDsgn, SynEditLines, SynEditMarks, SynEditMarkup,
SynEditMarkupBracket, SynEditMarkupCtrlMouseLink, SynEditMarkupHighAll,
SynBeautifier, SynCompletion, SynDesignStringConstants, SynEdit, SynEditAutoComplete,
SynEditExport, SynEditFoldedView, SynEditHighlighter, SynEditHighlighterFoldBase,
SynEditHighlighterXMLBase, SynEditKeyCmds, SynEditLazDsgn, SynEditLines, SynEditMarks,
SynEditMarkup, SynEditMarkupBracket, SynEditMarkupCtrlMouseLink, SynEditMarkupHighAll,
SynEditMarkupSelection, SynEditMarkupSpecialLine, SynEditMarkupWordGroup,
SynEditMiscClasses, SynEditMiscProcs, SynEditMouseCmds, SynEditPlugins,
SynEditPointClasses, SynEditRegexSearch, SynEditSearch, SynEditStrConst,
SynEditTextBase, SynEditTextBuffer, SynEditTextDoubleWidthChars,
SynEditTextTabExpander, SynEditTextTrimmer, SynEditTypes, SynExportHTML,
SynGutter, SynGutterBase, SynGutterChanges, SynGutterCodeFolding,
SynGutterLineNumber, SynGutterLineOverview, SynGutterMarks,
SynEditPointClasses, SynEditRegexSearch, SynEditSearch, SynEditStrConst, SynEditTextBase,
SynEditTextBuffer, SynEditTextDoubleWidthChars, SynEditTextTabExpander, SynEditTextTrimmer,
SynEditTypes, SynExportHTML, SynGutter, SynGutterBase, SynGutterChanges,
SynGutterCodeFolding, SynGutterLineNumber, SynGutterLineOverview, SynGutterMarks,
SynHighlighterAny, SynHighlighterCpp, SynHighlighterCss, SynHighlighterDiff,
SynHighlighterHashEntries, SynHighlighterHTML, SynHighlighterJava,
SynHighlighterJScript, SynHighlighterLFM, SynHighlighterMulti,
SynHighlighterPas, SynHighlighterPerl, SynHighlighterPHP,
SynHighlighterPosition, SynHighlighterPython, SynHighlighterSQL,
SynHighlighterTeX, synhighlighterunixshellscript, SynHighlighterVB,
SynHighlighterXML, SynMacroRecorder, SynMemo, SynPluginSyncroEdit,
SynPluginSyncronizedEditBase, SynPluginTemplateEdit,
SynPropertyEditObjectList, SynRegExpr, SynTextDrawer,
SynEditMarkupGutterMark, SynHighlighterBat, SynHighlighterIni,
SynEditMarkupSpecialChar, LazarusPackageIntf;
SynHighlighterHashEntries, SynHighlighterHTML, SynHighlighterJava, SynHighlighterJScript,
SynHighlighterLFM, SynHighlighterMulti, SynHighlighterPas, SynHighlighterPerl,
SynHighlighterPHP, SynHighlighterPosition, SynHighlighterPython, SynHighlighterSQL,
SynHighlighterTeX, synhighlighterunixshellscript, SynHighlighterVB, SynHighlighterXML,
SynMacroRecorder, SynMemo, SynPluginSyncroEdit, SynPluginSyncronizedEditBase,
SynPluginTemplateEdit, SynPropertyEditObjectList, SynRegExpr, SynTextDrawer,
SynEditMarkupGutterMark, SynHighlighterBat, SynHighlighterIni, SynEditMarkupSpecialChar,
LazSynEditText, LazSynTextArea, LazSynEditMouseCmdsTypes, SynHighlighterPo,
LazarusPackageIntf;
implementation

View File

@ -151,6 +151,8 @@ resourcestring
SYNS_AttrLineRemoved = 'Diff Removed Line';
SYNS_AttrLineChanged = 'Diff Changed Line';
SYNS_AttrLineContext = 'Diff Context Line';
SYNS_AttrPrevValue = 'Previous value';
SYNS_AttrFlags = 'Flags';
(* End of Attribute Names *)
const
@ -261,6 +263,8 @@ const
SYNS_XML_AttrLineRemoved = 'Diff Removed Line';
SYNS_XML_AttrLineChanged = 'Diff Changed Line';
SYNS_XML_AttrLineContext = 'Diff Context Line';
SYNS_XML_AttrPrevValue = 'Previous value';
SYNS_XML_AttrFlags = 'Flags';
(* End of Stored Attribute Names *)
resourcestring
@ -326,6 +330,7 @@ resourcestring
SYNS_FilterSynGenMsgfiles = 'Msg files (*.msg)|*.msg';
SYNS_FilterUNIXShellScript = 'UNIX Shell Scripts (*.sh)|*.sh';
SYNS_FilterTeX = 'TeX Files (*.tex)|*.tex';
SYNS_FilterPo = 'Po Files (*.po)|*.po';
{$IFDEF SYN_LAZARUS}
// Currently the language names are used to identify the language
@ -380,6 +385,7 @@ const
SYNS_LangSynGenMsgfiles = 'SynGen Msg files';
SYNS_LangUnreal = 'Unreal';
SYNS_LangTeX = 'TeX';
SYNS_LangPo = 'po language files';
resourcestring

View File

@ -0,0 +1,419 @@
{-------------------------------------------------------------------------------
The contents of this file may be used under the terms of the
GNU General Public License Version 2 or later (the "GPL")
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: SynHighlighterPo.pp, released 2011-12-17.
Author: Bart Broersma
All Rights Reserved.
Contributors to the SynEdit and mwEdit projects are listed in the
Contributors.txt file.
$Id: SynHighlighterPo.pp,v 0.0.1 bbroersma Exp $
Known Issues:
-------------------------------------------------------------------------------}
{
@abstract(Provides a po-files highlighter for SynEdit)
@author(Bart Broersma)
@created(2011-12-17)
@lastmod(2011-12-18)
The SynHighlighterPo unit provides SynEdit with an po-files highlighter.
}
unit SynHighlighterPo;
{$I SynEdit.inc}
interface
uses
Classes, SysUtils,
{$IFDEF SYN_CLX}
QGraphics,
{$ELSE}
Graphics,
{$ENDIF}
SynEditTypes, SynEditHighlighter, SynEditStrConst;
type
TtkTokenKind = (tkComment, tkText, tkKey, tkNull, tkSpace, tkString,
tkIdentifier, tkPrevValue, tkFlags, tkUnknown);
TProcTableProc = procedure of object;
type
{ TSynPoSyn }
TSynPoSyn = class(TSynCustomHighlighter)
private
fLine: PChar;
fLineNumber: Integer;
fProcTable: array[#0..#255] of TProcTableProc;
Run: LongInt;
fTokenPos: Integer;
FTokenID: TtkTokenKind;
fCommentAttri: TSynHighlighterAttributes;
fTextAttri: TSynHighlighterAttributes;
fKeyAttri: TSynHighlighterAttributes;
fSpaceAttri: TSynHighlighterAttributes;
fStringAttri: TSynHighlighterAttributes;
fIdentAttri: TSynHighlighterAttributes;
fPrevAttri: TSynHighlighterAttributes;
fFlagAttri: TSynHighlighterAttributes;
procedure IdentProc;
procedure KeyProc;
procedure CRProc;
procedure TextProc;
procedure LFProc;
procedure NullProc;
procedure HashProc;
procedure SpaceProc;
procedure StringProc;
procedure MakeMethodTables;
protected
{General Stuff}
function GetIdentChars: TSynIdentChars; override;
function GetSampleSource: String; override;
public
{$IFNDEF SYN_CPPB_1} class {$ENDIF} //mh 2000-07-14
function GetLanguageName: string; override;
function IsKeyword(const AKeyword: string): boolean; override;
public
constructor Create(AOwner: TComponent); override;
function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
override;
function GetEol: Boolean; override;
function GetTokenID: TtkTokenKind;
procedure SetLine({$IFDEF FPC}const {$ENDIF}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;
published
property CommentAttri: TSynHighlighterAttributes read fCommentAttri
write fCommentAttri;
property TextAttri : TSynHighlighterAttributes read fTextAttri
write fTextAttri;
property KeyAttri : TSynHighlighterAttributes read fKeyAttri
write fKeyAttri;
property SpaceAttri : TSynHighlighterAttributes read fSpaceAttri
write fSpaceAttri;
end;
implementation
const
PoKeysCount = 3;
PoKeys: array[1..PoKeysCount] of string = (
'msgid', 'msgstr', 'msgctxt');
procedure TSynPoSyn.MakeMethodTables;
var
i: Char;
begin
for i := #0 to #255 do
case i of
#0 : fProcTable[i] := @NullProc;
#10 {LF}: fProcTable[i] := @LFProc;
#13 {CR}: fProcTable[i] := @CRProc;
#34 {"} : fProcTable[i] := @StringProc;
'A'..'Z', 'a'..'z', '_': fProcTable[I] := @IdentProc;
'#' {#} : fProcTable[i] := @HashProc;
#1..#9, #11, #12, #14..#32: fProcTable[i] := @SpaceProc;
else
fProcTable[i] := @TextProc;
end;
end;
constructor TSynPoSyn.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment);
fCommentAttri.Style := [fsItalic];
fCommentAttri.Foreground := clGreen;
AddAttribute(fCommentAttri);
fTextAttri := TSynHighlighterAttributes.Create(SYNS_AttrText);
AddAttribute(fTextAttri);
fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrKey);
fKeyAttri.Foreground := clBlue;
fKeyAttri.Style := [fsBold];
AddAttribute(fKeyAttri);
fIdentAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier, SYNS_XML_AttrIdentifier);
fIdentAttri.Foreground := clGreen;
fIdentAttri.Style := [fsBold];
AddAttribute(fIdentAttri);
fPrevAttri := TSynHighlighterAttributes.Create(SYNS_AttrPrevValue, SYNS_XML_AttrPrevValue);
fPrevAttri.Foreground := clOlive;
fPrevAttri.Style := [fsItalic];
AddAttribute(fPrevAttri);
fFlagAttri := TSynHighlighterAttributes.Create(SYNS_AttrFlags, SYNS_XML_AttrFlags);
fFlagAttri.Foreground := clTeal;
AddAttribute(fFlagAttri);
fSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace, SYNS_XML_AttrSpace);
AddAttribute(fSpaceAttri);
fStringAttri := TSynHighlighterAttributes.Create(SYNS_AttrString, SYNS_XML_AttrString);
fStringAttri.Foreground := clFuchsia;
AddAttribute(fStringAttri);
SetAttributesOnChange(@DefHighlightChange);
fDefaultFilter := SYNS_FilterPo;
MakeMethodTables;
end; { Create }
procedure TSynPoSyn.SetLine({$IFDEF FPC}const {$ENDIF}NewValue: String; LineNumber:Integer);
begin
inherited;
fLine := PChar(NewValue);
Run := 0;
fLineNumber := LineNumber;
Next;
end; { SetLine }
procedure TSynPoSyn.IdentProc;
begin
while fLine[Run] in GetIdentChars {['A'..'Z','a'..'z']} do inc(Run);
if IsKeyWord(GetToken) then begin
fTokenId := tkKey;
Exit;
end
else fTokenId := tkUnknown;
end;
procedure TSynPoSyn.CRProc;
begin
fTokenID := tkSpace;
Case FLine[Run + 1] of
#10: inc(Run, 2);
else inc(Run);
end;
end;
procedure TSynPoSyn.KeyProc;
begin
fTokenID := tkKey;
inc(Run);
while FLine[Run] <> #0 do
case FLine[Run] of
#32: break;
#10: break;
#13: break;
else inc(Run);
end;
end;
procedure TSynPoSyn.TextProc;
begin
if Run = 0 then
IdentProc
else begin
inc(Run);
{$IFDEF SYN_LAZARUS}
while (fLine[Run] in [#128..#191]) OR // continued utf8 subcode
((fLine[Run]<>#0) and (fProcTable[fLine[Run]] = @TextProc)) do inc(Run);
{$ENDIF}
fTokenID := tkText;
end;
end;
procedure TSynPoSyn.LFProc;
begin
fTokenID := tkSpace;
inc(Run);
end;
procedure TSynPoSyn.NullProc;
begin
fTokenID := tkNull;
end;
procedure TSynPoSyn.SpaceProc;
begin
inc(Run);
fTokenID := tkSpace;
while FLine[Run] in [#1..#9, #11, #12, #14..#32] do inc(Run);
end;
procedure TSynPoSyn.StringProc;
begin
fTokenID := tkString;
repeat
case FLine[Run] of
#0, #10, #13: break;
'\': if FLine[Run + 1] = #34 then Inc(Run); { \" means a literal " in the line}
end;
inc(Run);
until FLine[Run] = #34;
if FLine[Run] <> #0 then inc(Run);
end;
procedure TSynPoSyn.HashProc;
begin
// if it is not column 0 mark as tkText and get out of here
if Run > 0 then
begin
fTokenID := tkText;
inc(Run);
Exit;
end;
// this is column 0 --> ok
fTokenID := tkComment;
while FLine[Run] <> #0 do
case FLine[Run] of
#10: break;
#13: break;
':': begin if (Run = 1) then fTokenId := tkIdentifier; Inc(Run) end;
',': begin if (Run = 1) then fTokenId := tkFlags; Inc(Run) end;
'|': begin if (Run = 1) then fTokenId := tkPrevValue; Inc(Run) end;
else inc(Run);
end;
end;
procedure TSynPoSyn.Next;
begin
fTokenPos := Run;
fProcTable[fLine[Run]];
end;
function TSynPoSyn.GetDefaultAttribute(Index: integer): TSynHighlighterAttributes;
begin
case Index of
SYN_ATTR_COMMENT: Result := fCommentAttri;
SYN_ATTR_KEYWORD: Result := fKeyAttri;
SYN_ATTR_STRING: Result := fStringAttri;
SYN_ATTR_WHITESPACE: Result := fSpaceAttri;
else
Result := nil;
end;
end;
function TSynPoSyn.GetEol: Boolean;
begin
Result := fTokenId = tkNull;
end;
function TSynPoSyn.GetToken: String;
var
Len: LongInt;
begin
Len := Run - fTokenPos;
SetString(Result, (FLine + fTokenPos), Len);
end;
procedure TSynPoSyn.GetTokenEx(out TokenStart: PChar; out TokenLength: integer);
begin
TokenLength := Run - fTokenPos;
TokenStart := FLine + fTokenPos;
end;
function TSynPoSyn.GetTokenID: TtkTokenKind;
begin
Result := fTokenId;
end;
function TSynPoSyn.GetTokenAttribute: TSynHighlighterAttributes;
begin
case fTokenID of
tkComment: Result := fCommentAttri;
tkText : Result := fTextAttri;
tkKey : Result := fKeyAttri;
tkSpace : Result := fSpaceAttri;
tkString : Result := fStringAttri;
tkIdentifier: Result := fIdentAttri;
tkFlags: Result := fFlagAttri;
tkPrevValue: Result := fPrevAttri;
tkUnknown: Result := fTextAttri;
else Result := nil;
end;
end;
function TSynPoSyn.GetTokenKind: integer;
begin
Result := Ord(fTokenId);
end;
function TSynPoSyn.GetTokenPos: Integer;
begin
Result := fTokenPos;
end;
function TSynPoSyn.GetIdentChars: TSynIdentChars;
begin
Result := inherited GetIdentChars; //TSynValidStringChars;
end;
{$IFNDEF SYN_CPPB_1} class {$ENDIF} //mh 2000-07-14
function TSynPoSyn.GetLanguageName: string;
begin
Result := SYNS_LangPo;
end;
{$IFNDEF SYN_CPPB_1} //mh 2000-07-14
function TSynPoSyn.GetSampleSource: String;
begin
Result := '"Project-Id-Version: \n"' + LineEnding +
'"POT-Creation-Date: \n"' + LineEnding +
'"MIME-Version: 1.0\n"' + LineEnding +
'"Content-Type: text/plain; charset=UTF-8\n"' + LineEnding +
'"Content-Transfer-Encoding: 8bit\n"' + LineEnding +
LineEnding +
'#: lazarusidestrconsts.dlgcochecks' + LineEnding +
'#, fuzzy' + LineEnding +
'#| msgid "Checks:"' + LineEnding +
'msgid "Checks"' + LineEnding +
'msgstr "Controleert:"' + LineEnding +
LineEnding +
'#: lazarusidestrconsts.listemplateeditparamcellhelp' + LineEnding +
'msgid ""' + LineEnding +
'"Inserts an editable Cell, with a default value\n"' + LineEnding +
'"\"\",Sync=n (,S=n), to Sync with a previous cell (n=1 to highest prev cell\n"' + LineEnding +
'"\"default\",Sync, to Sync with a previous cell of equal default\n"' + LineEnding +
'msgstr ""';
end;
function TSynPoSyn.IsKeyword(const AKeyword: string): boolean;
var
Token: String;
i: Integer;
begin
//There are only 3 keywords, so no need to make a hashtable
Token := LowerCase(AKeyWord);
for i := 1 to PoKeysCount do if (PoKeys[i] = Token) then
begin
Exit(True);
end;
Result := False;
end;
initialization
RegisterPlaceableHighlighter(TSynPoSyn);
{$ENDIF}
end.

View File

@ -52,6 +52,7 @@ uses
SynHighlighterPas, SynHighlighterPerl, SynHighlighterPHP, SynHighlighterSQL,
SynHighlighterPython, SynHighlighterUNIXShellScript, SynHighlighterXML,
SynHighlighterJScript, SynHighlighterDiff, SynHighlighterBat, SynHighlighterIni,
SynHighlighterPo,
// codetools
LinkScanner, CodeToolManager, Laz_XMLCfg,
// IDEIntf
@ -78,7 +79,7 @@ type
TLazSyntaxHighlighter =
(lshNone, lshText, lshFreePascal, lshDelphi, lshLFM, lshXML, lshHTML,
lshCPP, lshPerl, lshJava, lshBash, lshPython, lshPHP, lshSQL, lshJScript,
lshDiff, lshBat, lshIni);
lshDiff, lshBat, lshIni, lshPo);
TAdditionalHilightAttribute =
(ahaNone, ahaTextBlock, ahaExecutionPoint,
@ -374,7 +375,8 @@ const
(Count: 0; Info: nil), // jscript
(Count: 0; Info: nil), // Diff
(Count: 0; Info: nil), // Ini
(Count: 0; Info: nil) // Bat
(Count: 0; Info: nil), // Bat
(Count: 0; Info: nil) // PO
);
type
@ -570,7 +572,8 @@ const
(Count: 0; Info: nil), // jscript
(Count: 3; Info: {$IFDEF FPC}@{$ENDIF}EditorOptionsFoldInfoDiff[0]), // Diff
(Count: 0; Info: nil), // Bat
(Count: 0; Info: nil) // Ini
(Count: 0; Info: nil), // Ini
(Count: 0; Info: nil) // PO
);
const
@ -590,7 +593,7 @@ const
(nil, nil, TIDESynFreePasSyn, TIDESynPasSyn, TSynLFMSyn, TSynXMLSyn,
TSynHTMLSyn, TSynCPPSyn, TSynPerlSyn, TSynJavaSyn, TSynUNIXShellScriptSyn,
TSynPythonSyn, TSynPHPSyn, TSynSQLSyn, TSynJScriptSyn, TSynDiffSyn,
TSynBatSyn, TSynIniSyn);
TSynBatSyn, TSynIniSyn, TSynPoSyn);
{ Comments }
@ -613,7 +616,8 @@ const
comtCPP, // lshJScript
comtNone, // Diff
comtNone, // Bat
comtNone // Ini
comtNone, // Ini
comtNone // po
);
const
@ -1427,7 +1431,8 @@ const
'JScript',
'Diff',
'Bat',
'Ini'
'Ini',
'PO'
);
var
@ -1474,7 +1479,8 @@ const
lshJScript,
lshDiff,
lshBat,
lshIni
lshIni,
lshPo
);
var
@ -2381,6 +2387,34 @@ begin
CaretXY := Point(1,1);
end;
Add(NewInfo);
// create info for PO
NewInfo := TEditOptLanguageInfo.Create;
with NewInfo do
begin
TheType := lshPo;
DefaultCommentType := DefaultCommentTypes[TheType];
SynClass := LazSyntaxHighlighterClasses[TheType];
SetBothFilextensions('po');
SampleSource :=
'#: foo.bar'#13#10 +
'#, fuzzy'#13#10 +
'#| msgid "abc"'#13#10 +
'msgid "abc"'#13#10 +
'msgstr "123"'#13#10;
//MappedAttributes := TStringList.Create;
//with MappedAttributes do
//begin
// Add('Comment=Comment');
// Add('Key=Key');
// Add('Identifier=Identifier');
// Add('Space=Space');
// Add('String=String');
//end;
CaretXY := Point(3,1);
end;
Add(NewInfo);
end;
destructor TEditOptLangList.Destroy;