From b229ecc7627cbca4317ea92f5cfca4cdc729cd80 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Tue, 8 Dec 2015 17:46:19 +0000 Subject: [PATCH] Update SynEdit component to https://github.com/SynEdit/SynEdit/commit/0470dcbf161c0d154002acbb654f1d6f7494ba91 from Sep 9, 2015 --- .../synedit/Packages/delphiXE5/SynEditR.dpk | 3 + .../synedit/Packages/delphiXE5/SynEditR.dproj | 2 + components/synedit/Source/Contributors.txt | 2 +- components/synedit/Source/Page.bmp | Bin 0 -> 32822 bytes .../synedit/Source/SynCompletionProposal.pas | 8 +- components/synedit/Source/SynEdit.inc | 163 ++++++ components/synedit/Source/SynEdit.pas | 68 ++- .../synedit/Source/SynEditDocumentManager.pas | 491 ++++++++++++++++ .../synedit/Source/SynEditHighlighter.pas | 19 +- components/synedit/Source/SynEditKeyCmds.pas | 4 +- components/synedit/Source/SynEditReg.pas | 9 +- components/synedit/Source/SynEditReg.res | Bin 0 -> 876 bytes components/synedit/Source/SynEditSearch.pas | 4 +- components/synedit/Source/SynEditStrConst.pas | 16 +- components/synedit/Source/SynEditTypes.pas | 35 ++ .../synedit/Source/SynHighlighterCss.pas | 257 ++++++-- .../synedit/Source/SynHighlighterDWS.pas | 345 ++++++----- .../synedit/Source/SynHighlighterJSON.pas | 547 ++++++++++++++++++ .../synedit/Source/SynHighlighterLLVM.pas | 13 +- .../synedit/Source/SynHighlighterMulti.pas | 16 +- .../synedit/Source/SynHighlighterPython.pas | 15 +- .../synedit/Source/SynHighlighterSQL.pas | 12 +- components/synedit/Source/SynRegExpr.pas | 2 - components/synedit/Source/SynUnicode.pas | 26 +- 24 files changed, 1797 insertions(+), 260 deletions(-) create mode 100644 components/synedit/Source/Page.bmp create mode 100644 components/synedit/Source/SynEditDocumentManager.pas create mode 100644 components/synedit/Source/SynEditReg.res create mode 100644 components/synedit/Source/SynHighlighterJSON.pas diff --git a/components/synedit/Packages/delphiXE5/SynEditR.dpk b/components/synedit/Packages/delphiXE5/SynEditR.dpk index 012267f3..8fbfea07 100644 --- a/components/synedit/Packages/delphiXE5/SynEditR.dpk +++ b/components/synedit/Packages/delphiXE5/SynEditR.dpk @@ -1,5 +1,6 @@ package SynEditR; +{$R *.res} {$IFDEF IMPLICITBUILDING This IFDEF should not be used by users} {$ALIGN 8} {$ASSERTIONS ON} @@ -42,6 +43,7 @@ contains SynDBEdit in '..\..\Source\SynDBEdit.pas', SynEdit in '..\..\Source\SynEdit.pas', SynEditAutoComplete in '..\..\Source\SynEditAutoComplete.pas', + SynEditDocumentManager in '..\..\Source\SynEditDocumentManager.pas', SynEditExport in '..\..\Source\SynEditExport.pas', SynEditHighlighter in '..\..\Source\SynEditHighlighter.pas', SynEditKbdHandler in '..\..\Source\SynEditKbdHandler.pas', @@ -98,6 +100,7 @@ contains SynHighlighterInno in '..\..\Source\SynHighlighterInno.pas', SynHighlighterJava in '..\..\Source\SynHighlighterJava.pas', SynHighlighterJScript in '..\..\Source\SynHighlighterJScript.pas', + SynHighlighterJSON in '..\..\Source\SynHighlighterJSON.pas', SynHighlighterKix in '..\..\Source\SynHighlighterKix.pas', SynHighlighterM3 in '..\..\Source\SynHighlighterM3.pas', SynHighlighterModelica in '..\..\Source\SynHighlighterModelica.pas', diff --git a/components/synedit/Packages/delphiXE5/SynEditR.dproj b/components/synedit/Packages/delphiXE5/SynEditR.dproj index 7d339b4c..0bd35e6c 100644 --- a/components/synedit/Packages/delphiXE5/SynEditR.dproj +++ b/components/synedit/Packages/delphiXE5/SynEditR.dproj @@ -101,6 +101,7 @@ + @@ -165,6 +166,7 @@ + diff --git a/components/synedit/Source/Contributors.txt b/components/synedit/Source/Contributors.txt index 4c9a4fce..aa92112d 100644 --- a/components/synedit/Source/Contributors.txt +++ b/components/synedit/Source/Contributors.txt @@ -9,7 +9,7 @@ Contributors to the SynEdit project: Mattias Gaertner, Michael Beck, Michael Hieke, Mike Gibbard, Morten J. Skovrup, Murad Kakabayev, Pieter Polak, Primoz Gabrijelcic, Roman Silin, Ruggero Bandera, Satya, Stefan van As, Steve Sutherland, - Sven Blankenberg, Tony De Buys, Woo Young Bum, Roman Kassebaum + Sven Blankenberg, Tony De Buys, Woo Young Bum Most of the files in the SynEdit package are based on mwEdit version 0.92a. diff --git a/components/synedit/Source/Page.bmp b/components/synedit/Source/Page.bmp new file mode 100644 index 0000000000000000000000000000000000000000..ee034600e3b6e81d20a0548727c09f085181d7b4 GIT binary patch literal 32822 zcmeI4y|v^v5{0RA){(QF#2SiV1CXzD92p!}-2D6h3bsm4iSY!UxV^ zX1%oZ@)f*??1PoB<OuYKCW%@S)2rS3a}6Gb z%xEKPUaGWl{WK3#f~StGEab1s;C6YK$)CL)yt5u$=g<6kpQcc8@2S6c^DqH^t9>@% zrpw>s&$sj96ZB2?y`ATFdAROAr|+``YSd-qgm>lg3HH^ARwIv$DCGBfV zC{;q>5o!AimMQXrn%J%~`@H@<49v~Id8lpHx0)7(OJ1mojOU6E@lbel7um_JwTKKs@xA7STB#Ruy$dx_vEPr>ZV7rq9W@;$sO?DFCSe>UxNo`;_Inb3HBIj`fj`(Iya`lLerHHF!b@ik*hnV_$-_ zl@zRlecV|N+7;}OOiNGwxj$3xv)AJ7v`^=G_$-V0%%7<0GfEER4ZOW>b3kKT^vCdG zLu(iAf>g8b0!5uFjQ4K)-qku|f9Ukac`@^+-gcc=)}bNvhu!B^hpH}-AHzF6ZSJy- zLS|pL_-R4$mIv8seR~Rih<(1lyH~gi(!G6NpsGv70bV-jbv~aD6c-PiqMA%nvL=T8m8{=ghK?cJ%RN zm3Z>EIU}j*77uA$Drh}q^@k}nUpI5TB7fSdg`+Q`C#@g2kU+A@vHnchkqsVg;-O%X zTdt7iG7|Jt(mXsWhO68$Ru|@WRz8j(M^#Cdkch~XkzOalRFh`b{i{zofAG$E;BVCV`vIcB+Gxxovivwsh%BE?f@{iVyBn0M1YD_!+5*U3v5>E*1O(x2-# zlIC~`F9l@RgO@pEbvx^>sK1rW`eyiZ?T_`{tlO*oS(!M84p!q;q^&?ITTlH}dT)bQ zktQS@gSXxX2yPkv^ajFkw3k&Qsr0DPUPgOKJuupfyfN#%e%@Ak&lq1udl~IT9?)s@ zhcDY7_|?oC$1}79eoDxf>Aqk7((yC!7@X(fjiFpsDY4I&_@)&0?ekn0B-82W(r2L2 zcLEzcy?7??wqu{`I?H1L;RL*6ZTqv2XDzR4AAEho{u#d#Fe(4Cz9LO`2dS2Q5NXyQ zc|jAfvJdL&JlECY;k|M%57;)(b+ve`8y=MsE6V&CoUp?)P4tHS`F#wf5g!#GqR!*% z_gVRI0Z-6AZX;Ht2|*fDnmm3n3z>=r>P7xp+ppy5eH_0es7V_{y6lqt?6AV@@=zo; zDzsMEcbdmGUoA1B`AvCZpXv{vpKRJ^x|;R{lgZ4E5H-WP#6AgCqzMT}i|1orMFXN3 zJ4=h|kM>D#MH=z0tHrbYRS((cALJ$Di|yUld9Leeo?18ji53O>fNhUwT|5++4y%+n z+81~TVFi(F?iJ$9>*8@X!w&}uw%5B(OyP>@ZK=SPkN#fP(s$>JCDJ;*4x9MKg^%$&jRcfVpH}& z{blpPCUR4@kH=T2`eA``QdwZzvfVuU;epaZ36{joame2O^PhZy?Jc4<_f znEgUBhgBd literal 0 HcmV?d00001 diff --git a/components/synedit/Source/SynCompletionProposal.pas b/components/synedit/Source/SynCompletionProposal.pas index bcefcd0b..9998c120 100644 --- a/components/synedit/Source/SynCompletionProposal.pas +++ b/components/synedit/Source/SynCompletionProposal.pas @@ -1577,6 +1577,7 @@ function TSynBaseCompletionProposalForm.CanResize(var NewWidth, NewHeight: Integ var NewLinesInWindow: Integer; BorderWidth: Integer; + tmpHeight : integer; begin Result := True; case FDisplayKind of @@ -1586,10 +1587,13 @@ begin if FEffectiveItemHeight <> 0 then begin - NewLinesInWindow := (NewHeight-FHeightBuffer) div FEffectiveItemHeight; + tmpHeight := NewHeight - BorderWidth; + NewLinesInWindow := (tmpHeight - FHeightBuffer) div FEffectiveItemHeight; + if NewLinesInWindow < 1 then NewLinesInWindow := 1; - end else + end + else NewLinesInWindow := 0; FLinesInWindow := NewLinesInWindow; diff --git a/components/synedit/Source/SynEdit.inc b/components/synedit/Source/SynEdit.inc index ec816111..466f9379 100644 --- a/components/synedit/Source/SynEdit.inc +++ b/components/synedit/Source/SynEdit.inc @@ -54,6 +54,12 @@ (* SYN_COMPILER_18_UP : Delphi XE4 or higher is the compiler. *) (* SYN_COMPILER_19 : Delphi XE5 is the compiler. *) (* SYN_COMPILER_19_UP : Delphi XE5 or higher is the compiler. *) +(* SYN_COMPILER_20 : Delphi XE6 is the compiler. *) +(* SYN_COMPILER_20_UP : Delphi XE6 or higher is the compiler. *) +(* SYN_COMPILER_21 : Delphi XE7 is the compiler. *) +(* SYN_COMPILER_21_UP : Delphi XE7 or higher is the compiler. *) +(* SYN_COMPILER_22 : Delphi XE8 is the compiler. *) +(* SYN_COMPILER_22_UP : Delphi XE8 or higher is the compiler. *) (* SYN_CPPB : Any version of C++Builder is being used. *) (* SYN_CPPB_1 : C++B v1.0x is being used. *) (* SYN_CPPB_3 : C++B v3.0x is being used. *) @@ -100,6 +106,10 @@ (* SYN_DELPHI_XE4_UP : Delphi XE4 or higher is being used. *) (* SYN_DELPHI_XE5 : Delphi XE5 is being used. *) (* SYN_DELPHI_XE5_UP : Delphi XE5 or higher is being used. *) +(* SYN_DELPHI_XE6 : Delphi XE6 is being used. *) +(* SYN_DELPHI_XE6_UP : Delphi XE6 or higher is being used. *) +(* SYN_DELPHI_XE7 : Delphi XE7 is being used. *) +(* SYN_DELPHI_XE7_UP : Delphi XE7 or higher is being used. *) (* SYN_KYLIX : Kylix 1.0 is being using. *) (* SYN_CLX : A CLX application is being created. *) (******************************************************************************) @@ -146,6 +156,24 @@ { VERXXX to SYN_COMPILERX, SYN_DELPHIX and SYN_CPPBX mappings } {------------------------------------------------------------------------------} +{$IFDEF VER290} + {$DEFINE SYN_COMPILER_22} + {$DEFINE SYN_DELPHI} + {$DEFINE SYN_DELPHI_XE8} +{$ENDIF} + +{$IFDEF VER280} + {$DEFINE SYN_COMPILER_21} + {$DEFINE SYN_DELPHI} + {$DEFINE SYN_DELPHI_XE7} +{$ENDIF} + +{$IFDEF VER270} + {$DEFINE SYN_COMPILER_20} + {$DEFINE SYN_DELPHI} + {$DEFINE SYN_DELPHI_XE6} +{$ENDIF} + {$IFDEF VER260} {$DEFINE SYN_COMPILER_19} {$DEFINE SYN_DELPHI} @@ -502,6 +530,75 @@ {$DEFINE SYN_COMPILER_19_UP} {$ENDIF} +{$IFDEF SYN_COMPILER_20} + {$DEFINE SYN_COMPILER_1_UP} + {$DEFINE SYN_COMPILER_2_UP} + {$DEFINE SYN_COMPILER_3_UP} + {$DEFINE SYN_COMPILER_4_UP} + {$DEFINE SYN_COMPILER_5_UP} + {$DEFINE SYN_COMPILER_6_UP} + {$DEFINE SYN_COMPILER_7_UP} + {$DEFINE SYN_COMPILER_8_UP} + {$DEFINE SYN_COMPILER_9_UP} + {$DEFINE SYN_COMPILER_10_UP} + {$DEFINE SYN_COMPILER_11_UP} + {$DEFINE SYN_COMPILER_12_UP} + {$DEFINE SYN_COMPILER_14_UP} + {$DEFINE SYN_COMPILER_15_UP} + {$DEFINE SYN_COMPILER_16_UP} + {$DEFINE SYN_COMPILER_17_UP} + {$DEFINE SYN_COMPILER_18_UP} + {$DEFINE SYN_COMPILER_19_UP} + {$DEFINE SYN_COMPILER_20_UP} +{$ENDIF} + +{$IFDEF SYN_COMPILER_21} + {$DEFINE SYN_COMPILER_1_UP} + {$DEFINE SYN_COMPILER_2_UP} + {$DEFINE SYN_COMPILER_3_UP} + {$DEFINE SYN_COMPILER_4_UP} + {$DEFINE SYN_COMPILER_5_UP} + {$DEFINE SYN_COMPILER_6_UP} + {$DEFINE SYN_COMPILER_7_UP} + {$DEFINE SYN_COMPILER_8_UP} + {$DEFINE SYN_COMPILER_9_UP} + {$DEFINE SYN_COMPILER_10_UP} + {$DEFINE SYN_COMPILER_11_UP} + {$DEFINE SYN_COMPILER_12_UP} + {$DEFINE SYN_COMPILER_14_UP} + {$DEFINE SYN_COMPILER_15_UP} + {$DEFINE SYN_COMPILER_16_UP} + {$DEFINE SYN_COMPILER_17_UP} + {$DEFINE SYN_COMPILER_18_UP} + {$DEFINE SYN_COMPILER_19_UP} + {$DEFINE SYN_COMPILER_20_UP} + {$DEFINE SYN_COMPILER_21_UP} +{$ENDIF} + +{$IFDEF SYN_COMPILER_22} + {$DEFINE SYN_COMPILER_1_UP} + {$DEFINE SYN_COMPILER_2_UP} + {$DEFINE SYN_COMPILER_3_UP} + {$DEFINE SYN_COMPILER_4_UP} + {$DEFINE SYN_COMPILER_5_UP} + {$DEFINE SYN_COMPILER_6_UP} + {$DEFINE SYN_COMPILER_7_UP} + {$DEFINE SYN_COMPILER_8_UP} + {$DEFINE SYN_COMPILER_9_UP} + {$DEFINE SYN_COMPILER_10_UP} + {$DEFINE SYN_COMPILER_11_UP} + {$DEFINE SYN_COMPILER_12_UP} + {$DEFINE SYN_COMPILER_14_UP} + {$DEFINE SYN_COMPILER_15_UP} + {$DEFINE SYN_COMPILER_16_UP} + {$DEFINE SYN_COMPILER_17_UP} + {$DEFINE SYN_COMPILER_18_UP} + {$DEFINE SYN_COMPILER_19_UP} + {$DEFINE SYN_COMPILER_20_UP} + {$DEFINE SYN_COMPILER_21_UP} + {$DEFINE SYN_COMPILER_22_UP} +{$ENDIF} + {$IFDEF SYN_DELPHI_2} {$DEFINE SYN_DELPHI_2_UP} {$ENDIF} @@ -706,6 +803,72 @@ {$DEFINE SYN_DELPHI_XE5_UP} {$ENDIF} +{$IFDEF SYN_DELPHI_XE6} + {$DEFINE SYN_DELPHI_2_UP} + {$DEFINE SYN_DELPHI_3_UP} + {$DEFINE SYN_DELPHI_4_UP} + {$DEFINE SYN_DELPHI_5_UP} + {$DEFINE SYN_DELPHI_6_UP} + {$DEFINE SYN_DELPHI_7_UP} + {$DEFINE SYN_DELPHI_8_UP} + {$DEFINE SYN_DELPHI_2005_UP} + {$DEFINE SYN_DELPHI_2006_UP} + {$DEFINE SYN_DELPHI_2007_UP} + {$DEFINE SYN_DELPHI_2009_UP} + {$DEFINE SYN_DELPHI_2010_UP} + {$DEFINE SYN_DELPHI_XE_UP} + {$DEFINE SYN_DELPHI_XE2_UP} + {$DEFINE SYN_DELPHI_XE3_UP} + {$DEFINE SYN_DELPHI_XE4_UP} + {$DEFINE SYN_DELPHI_XE5_UP} + {$DEFINE SYN_DELPHI_XE6_UP} +{$ENDIF} + +{$IFDEF SYN_DELPHI_XE7} + {$DEFINE SYN_DELPHI_2_UP} + {$DEFINE SYN_DELPHI_3_UP} + {$DEFINE SYN_DELPHI_4_UP} + {$DEFINE SYN_DELPHI_5_UP} + {$DEFINE SYN_DELPHI_6_UP} + {$DEFINE SYN_DELPHI_7_UP} + {$DEFINE SYN_DELPHI_8_UP} + {$DEFINE SYN_DELPHI_2005_UP} + {$DEFINE SYN_DELPHI_2006_UP} + {$DEFINE SYN_DELPHI_2007_UP} + {$DEFINE SYN_DELPHI_2009_UP} + {$DEFINE SYN_DELPHI_2010_UP} + {$DEFINE SYN_DELPHI_XE_UP} + {$DEFINE SYN_DELPHI_XE2_UP} + {$DEFINE SYN_DELPHI_XE3_UP} + {$DEFINE SYN_DELPHI_XE4_UP} + {$DEFINE SYN_DELPHI_XE5_UP} + {$DEFINE SYN_DELPHI_XE6_UP} + {$DEFINE SYN_DELPHI_XE7_UP} +{$ENDIF} + +{$IFDEF SYN_DELPHI_XE8} + {$DEFINE SYN_DELPHI_2_UP} + {$DEFINE SYN_DELPHI_3_UP} + {$DEFINE SYN_DELPHI_4_UP} + {$DEFINE SYN_DELPHI_5_UP} + {$DEFINE SYN_DELPHI_6_UP} + {$DEFINE SYN_DELPHI_7_UP} + {$DEFINE SYN_DELPHI_8_UP} + {$DEFINE SYN_DELPHI_2005_UP} + {$DEFINE SYN_DELPHI_2006_UP} + {$DEFINE SYN_DELPHI_2007_UP} + {$DEFINE SYN_DELPHI_2009_UP} + {$DEFINE SYN_DELPHI_2010_UP} + {$DEFINE SYN_DELPHI_XE_UP} + {$DEFINE SYN_DELPHI_XE2_UP} + {$DEFINE SYN_DELPHI_XE3_UP} + {$DEFINE SYN_DELPHI_XE4_UP} + {$DEFINE SYN_DELPHI_XE5_UP} + {$DEFINE SYN_DELPHI_XE6_UP} + {$DEFINE SYN_DELPHI_XE7_UP} + {$DEFINE SYN_DELPHI_XE8_UP} +{$ENDIF} + {$IFDEF SYN_CPPB_6} {$DEFINE SYN_CPPB_3_UP} {$DEFINE SYN_CPPB_4_UP} diff --git a/components/synedit/Source/SynEdit.pas b/components/synedit/Source/SynEdit.pas index 1a99df89..110c4908 100644 --- a/components/synedit/Source/SynEdit.pas +++ b/components/synedit/Source/SynEdit.pas @@ -135,8 +135,8 @@ var SynEditClipboardFormat: UINT; type - TBufferCoord = SynEditTypes.TBufferCoord; - TDisplayCoord = SynEditTypes.TDisplayCoord; + TBufferCoord = SynEditTypes.TBufferCoord; + TDisplayCoord = SynEditTypes.TDisplayCoord; {$IFDEF SYN_CLX} TSynBorderStyle = bsNone..bsSingle; @@ -178,7 +178,7 @@ type TGutterPaintEvent = procedure(Sender: TObject; aLine: Integer; X, Y: Integer) of object; - TSynEditCaretType = (ctVerticalLine, ctHorizontalLine, ctHalfBlock, ctBlock); + TSynEditCaretType = (ctVerticalLine, ctHorizontalLine, ctHalfBlock, ctBlock, ctVerticalLine2); TSynStateFlag = (sfCaretChanged, sfScrollbarChanged, sfLinesChanging, sfIgnoreNextChar, sfCaretVisible, sfDblClicked, sfPossibleGutterClick, @@ -6830,6 +6830,12 @@ begin ch := fTextHeight - 2; FCaretOffset := Point(0, 0); end; + ctVerticalLine2: + begin + cw := 2; + ch := fTextHeight + 1; + FCaretOffset := Point(0, 0); + end; else begin // ctVerticalLine cw := 2; @@ -7166,9 +7172,9 @@ begin MoveCaretAndSelection(CaretXY, CaretNew, Command = ecSelWordRight); end; ecSelWord: - begin - SetSelWord; - end; + begin + SetSelWord; + end; ecSelectAll: begin SelectAll; @@ -7202,11 +7208,11 @@ begin begin BackCounter := CaretY - 2; //It's better not to have if statement inside loop - if (eoTrimTrailingSpaces in Options) and (Len = 0) then + if (eoTrimTrailingSpaces in Options) then while BackCounter >= 0 do begin SpaceCount2 := LeftSpacesEx(Lines[BackCounter], True); - if SpaceCount2 < SpaceCount1 then + if (SpaceCount2 > 0) and (SpaceCount2 < SpaceCount1) then break; Dec(BackCounter); end @@ -7214,7 +7220,7 @@ begin while BackCounter >= 0 do begin SpaceCount2 := LeftSpaces(Lines[BackCounter]); - if SpaceCount2 < SpaceCount1 then + if (SpaceCount2 > 0) and (SpaceCount2 < SpaceCount1) then break; Dec(BackCounter); end; @@ -7260,13 +7266,23 @@ begin if SpaceCount1 > 0 then begin BackCounter := CaretY - 2; - while BackCounter >= 0 do - begin - SpaceCount2 := LeftSpaces(Lines[BackCounter]); - if SpaceCount2 < SpaceCount1 then - break; - Dec(BackCounter); - end; + //It's better not to have if statement inside loop + if (eoTrimTrailingSpaces in Options) then + while BackCounter >= 0 do + begin + SpaceCount2 := LeftSpacesEx(Lines[BackCounter], True); + if (SpaceCount2 > 0) and (SpaceCount2 < SpaceCount1) then + break; + Dec(BackCounter); + end + else + while BackCounter >= 0 do + begin + SpaceCount2 := LeftSpaces(Lines[BackCounter]); + if (SpaceCount2 > 0) and (SpaceCount2 < SpaceCount1) then + break; + Dec(BackCounter); + end; if (BackCounter = -1) and (SpaceCount2 > SpaceCount1) then SpaceCount2 := 0; end; @@ -7722,7 +7738,8 @@ begin ecTitleCase, ecUpperCaseBlock, ecLowerCaseBlock, - ecToggleCaseBlock: + ecToggleCaseBlock, + ecTitleCaseBlock: if not ReadOnly then DoCaseChange(Command); ecUndo: begin @@ -8332,7 +8349,7 @@ begin if csDesigning in ComponentState then exit; - Msg.Result := 1; + Msg.Result := 1; {$IFDEF SYN_COMPILER_4_UP} // In some occasions Windows will not properly initialize mouse wheel, but @@ -9002,12 +9019,21 @@ procedure TCustomSynEdit.DoCaseChange(const Cmd: TSynEditorCommand); end; end; + function TitleCase(const aStr: UnicodeString): UnicodeString; + var + i: Integer; + begin + Result:=SynWideLowerCase(aStr); + for i := 1 to Length(Result) do + if (i = 1) or IsWordBreakChar(Result[i-1]) then Result[i] := SynWideUpperCase(Result[i])[1]; + end; + var w: UnicodeString; oldCaret, oldBlockBegin, oldBlockEnd: TBufferCoord; bHadSel : Boolean; begin - Assert((Cmd >= ecUpperCase) and (Cmd <= ecToggleCaseBlock)); + Assert((Cmd >= ecUpperCase) and (Cmd <= ecTitleCaseBlock)); if SelAvail then begin bHadSel := True; @@ -9059,8 +9085,8 @@ begin w := SynWideLowerCase(w); ecToggleCase, ecToggleCaseBlock: w := ToggleCase(w); - ecTitleCase: - w := SynWideUpperCase(w[1]) + SynWideLowerCase(Copy(w, 2, Length(w))); + ecTitleCase, ecTitleCaseBlock: + w := TitleCase(w); end; BeginUndoBlock; try diff --git a/components/synedit/Source/SynEditDocumentManager.pas b/components/synedit/Source/SynEditDocumentManager.pas new file mode 100644 index 00000000..6c32d11e --- /dev/null +++ b/components/synedit/Source/SynEditDocumentManager.pas @@ -0,0 +1,491 @@ +unit SynEditDocumentManager; + +interface + +uses + classes, + messages, + ExtCtrls, + SynEditTypes, + SynEdit, + SynMemo, + SynEditTextBuffer, + SynEditHighlighter; + +type + ISynDocument = interface + ['{DC80C7CF-FC56-4FDE-9E3E-6A1C53D6EFCD}'] + procedure SetCaretXY(const value : TBufferCoord); + function GetCaretXY : TBufferCoord; + procedure SetLines(const value : TStrings); + function GetLines : TStrings; + function GetUndoList : TSynEditUndoList; + function GetRedoList : TSynEditUndoList; + function GetTopLine : integer; + procedure SetTopLine(const value : integer); + procedure SetModified(const value : boolean); + function GetModified : boolean; + function GetName : string; + function GetHighLighter : TSynCustomHighlighter; + procedure SetHighlighter(const value : TSynCustomHighlighter); + function GetDataIntf : IInterface; + procedure SetDataIntf(const value : IInterface); + function GetMarks : TSynEditMarkList; + + property CaretXY : TBufferCoord read GetCaretXY write SetCaretXY; + property Lines : TStrings read GetLines write SetLines; + property UndoList : TSynEditUndoList read GetUndoList; + property RedoList : TSynEditUndoList read GetRedoList; + property TopLine : integer read GetTopLine write SetTopLine; + property Modified : boolean read GetModified write SetModified; + property Name : string read GetName; + property Highlighter : TSynCustomHighlighter read GetHighlighter write SetHighLighter; + property DataIntf : IInterface read GetDataIntf write SetDataIntf; + property Marks : TSynEditMarkList read GetMarks; + //Line info allows us to store stuff like gutter icons, breakpoints etc. + end; + + TSynEditDocumentManager = class(TCOmponent) + private + FDocuments : IInterfaceList; + FCurrentDocumentIndex : integer; + FMemo : TSynMemo; + FMemoWndProc : TWndMethod; + FUpdateTimer : TTimer; + function GetCount: integer; + function GetCurrentDocument: ISynDocument; + protected + procedure MemoWndProc(var Msg: TMessage); + procedure SetMemo(const Value: TSynMemo); + function GetDocument(index: integer): ISynDocument; + function GetDocumentByName(index: string): ISynDocument; + procedure SetCurrentDocumentIndex(const Value: integer); + procedure UpdateTimerEvent(Sender : TObject); + + procedure Notification(AComponent: TComponent; Operation: TOperation); override; + public + constructor Create(AOwner : TComponent);override; + destructor Destroy;override; + procedure UpdateCurrentDocument; //saves editor to document + procedure ApplyCurrentDocument; //applies document to editor + function AddDocument(const AName : string; const ALines : TStrings; const AHighlighter : TSynCustomHighlighter) : ISynDocument; + procedure RemoveDocument(const index : integer);overload; + procedure RemoveDocument(const AName : string);overload; + procedure RemoveDocument(const ADocument : ISynDocument);overload; + procedure RemoveAll; + property Documents[index : integer] : ISynDocument read GetDocument; + property CurrentDocument : ISynDocument read GetCurrentDocument; + property DocumentsByName[index : string] : ISynDocument read GetDocumentByName; + property CurrentDocumentIndex : integer read FCurrentDocumentIndex write SetCurrentDocumentIndex; + property Count : integer read GetCount; + published + property Memo : TSynMemo read FMemo write SetMemo; + end; + +implementation + +uses + windows,SysUtils; +{ TSynEditDocumentManager } + +type + TSynDocument = class(TInterfacedObject,ISynDocument) + private + FName : string; + FLines : TStringList; + FCaretXY : TBufferCoord; + FModified : Boolean; + FRedoList : TSynEditUndoList; + FUndoList : TSynEditUndoList; + FTopLine : Integer; + FHighLighter : TSynCustomHighlighter; + FDataIntf : IInterface; + FMarks : TSynEditMarkList; + protected + function GetCaretXY : TBufferCoord; + function GetLines : TStrings; + function GetModified : Boolean; + function GetName : String; + function GetRedoList : TSynEditUndoList; + function GetTopLine : Integer; + function GetUndoList : TSynEditUndoList; + procedure SetCaretXY(const value: TBufferCoord); + procedure SetLines(const value: TStrings); + procedure SetModified(const value: Boolean); + procedure SetTopLine(const value: Integer); + function GetHighLighter : TSynCustomHighlighter; + procedure SetHighlighter(const value : TSynCustomHighlighter); + function GetDataIntf : IInterface; + procedure SetDataIntf(const value : IInterface); + function GetMarks : TSynEditMarkList; + public + constructor Create(const AName : string; ALines : TStrings); + destructor Destroy;override; + end; + + +function TSynEditDocumentManager.AddDocument(const AName: string; const ALines: TStrings; const AHighlighter : TSynCustomHighlighter): ISynDocument; +begin + result := GetDocumentByName(AName); + if result <> nil then + begin + result.Lines.Assign(ALines); + result.Highlighter := AHighlighter; + end + else + begin + result := TSynDocument.Create(AName,ALines); + result.Highlighter := AHighlighter; + FDocuments.Add(Result); +{ if CurrentDocumentIndex = -1 then + CurrentDocumentIndex := 0;} + end; + +end; + +constructor TSynEditDocumentManager.Create(AOwner: TComponent); +begin + inherited; + FDocuments := TInterfaceList.Create; + FCurrentDocumentIndex := -1; + FUpdateTimer := TTimer.Create(Self); + FUpdateTimer.enabled := False; + FUpdateTimer.Interval := 200; + FUpdateTimer.OnTimer := UpdateTimerEvent; +end; + +function TSynEditDocumentManager.GetDocument(index: integer): ISynDocument; +begin + if (index >= 0) and (index < FDocuments.Count) then + result := FDocuments.Items[index] as ISynDocument + else + result := nil; +end; + +function TSynEditDocumentManager.GetDocumentByName(index: string): ISynDocument; +var + i : integer; +begin + result := nil; + for i := 0 to FDocuments.Count -1 do + begin + result := GetDocument(i); + if CompareText(result.Name,index) = 0 then + break + else + result := nil; + end; +end; + +procedure TSynEditDocumentManager.RemoveDocument(const index: integer); +begin + FDocuments.Delete(index); + if FDocuments.Count = 0 then + FCurrentDocumentIndex := -1; +end; + +procedure TSynEditDocumentManager.RemoveDocument(const AName: string); +var + doc : ISynDocument; +begin + doc := GetDocumentByName(AName); + if doc <> nil then + FDocuments.Remove(doc); + if FDocuments.Count = 0 then + FCurrentDocumentIndex := -1; + +end; + +procedure TSynEditDocumentManager.MemoWndProc(var Msg: TMessage); +begin + if (Msg.Msg = WM_CHAR) then + begin + FUpdateTimer.Enabled := False; + FUpdateTimer.Enabled := True; + end; + if Assigned(FMemoWndProc) then + FMemoWndProc(Msg); +end; + +procedure TSynEditDocumentManager.RemoveDocument(const ADocument: ISynDocument); +begin + FDocuments.Remove(ADocument); + if FDocuments.Count = 0 then + FCurrentDocumentIndex := -1; +end; + +procedure TSynEditDocumentManager.SetCurrentDocumentIndex(const Value: integer); +begin + if FCurrentDocumentIndex <> Value then + begin + UpdateCurrentDocument; + if (Value >= 0) and (Value < FDocuments.Count) then + begin + FCurrentDocumentIndex := Value; + ApplyCurrentDocument; + end; + end; +end; + +procedure TSynEditDocumentManager.SetMemo(const Value: TSynMemo); +begin + if FMemo <> Value then + begin + if FMemo <> nil then + begin + FMemo.RemoveFreeNotification(Self); + if not (csDesigning in ComponentState) then + begin + if Assigned(FMemoWndProc) then + FMemo.WindowProc := FMemoWndProc; + end; + end; + FMemo := Value; + if FMemo <> nil then + begin + FMemo.FreeNotification(Self); + if not (csDesigning in ComponentState) then + begin + FMemoWndProc := FMemo.WindowProc; + FMemo.WindowProc := Self.MemoWndProc; + end; + end; + end; +end; + +procedure TSynEditDocumentManager.RemoveAll; +begin + FDocuments.Clear; + FCurrentDocumentIndex := -1; +end; + +function TSynEditDocumentManager.GetCount: integer; +begin + result := FDocuments.Count; +end; + +function TSynEditDocumentManager.GetCurrentDocument: ISynDocument; +begin + if FCurrentDocumentIndex <> -1 then + result := GetDocument(FCurrentDocumentIndex) + else + result := nil; +end; + +function CloneMark(const AOwner : TCustomSynEdit; const source : TSynEditMark) : TSynEditMark; +begin + result := TSynEditMark.Create(AOwner); + result.Line := source.Line; + Result.Char := source.Char; + result.ImageIndex := source.ImageIndex; + result.BookmarkNumber := source.BookmarkNumber; + result.InternalImage := source.InternalImage; + result.Visible := source.Visible; +end; + +procedure TSynEditDocumentManager.ApplyCurrentDocument; +var + doc : ISynDocument; + I: Integer; +begin + if FCurrentDocumentIndex <> -1 then + begin + if FMemo <> nil then + begin + doc := GetDocument(FCurrentDocumentIndex); + if doc <> nil then + begin + FMemo.Lines.Assign(doc.Lines); + FMemo.TopLine := doc.TopLine; + FMemo.CaretXY := doc.CaretXY; + FMemo.UndoList.Assign(doc.UndoList); + FMemo.RedoList.Assign(doc.RedoList); + FMemo.Highlighter := doc.Highlighter; + //can't do this because it av's now??? +// FMemo.Marks.Assign(doc.Marks); + FMemo.Marks.Clear; + for i := 0 to doc.Marks.Count - 1 do + begin + FMemo.Marks.Place(CloneMark(FMemo,doc.Marks.Items[i])); + end; + FMemo.Modified := doc.Modified; + FMemo.Refresh; + end; + end; + end; +end; + +{ TSynDocument } + +constructor TSynDocument.Create(const AName: string; ALines: TStrings); +begin + inherited Create; + FLines := TStringList.Create; + FRedoList := TSynEditUndoList.Create; + FUndoList := TSynEditUndoList.Create; + FName := AName; + FLines.Assign(ALines); + FModified := False; + FTopLine := 0; + FMarks := TSynEditMarkList.Create(nil); +end; + +destructor TSynDocument.Destroy; +begin + FLines.Free; + FRedoList.Free; + FUndoList.Free; + FMarks.Free; + inherited; +end; + +function TSynDocument.GetCaretXY: TBufferCoord; +begin + result := FCaretXY; +end; + +function TSynDocument.GetDataIntf: IInterface; +begin + result := FDataIntf; +end; + +function TSynDocument.GetHighLighter: TSynCustomHighlighter; +begin + result := FHighLighter; +end; + + +function TSynDocument.GetLines: TStrings; +begin + result := FLines; +end; + +function TSynDocument.GetMarks: TSynEditMarkList; +begin + result := FMarks; +end; + +function TSynDocument.GetModified: Boolean; +begin + result := FModified; +end; + +function TSynDocument.GetName: String; +begin + result := FName; +end; + +function TSynDocument.GetRedoList: TSynEditUndoList; +begin + result := FRedoList; +end; + +function TSynDocument.GetTopLine: Integer; +begin + result := FTopLine; +end; + +function TSynDocument.GetUndoList: TSynEditUndoList; +begin + result := FUndoList; +end; + +procedure TSynDocument.SetCaretXY(const value: TBufferCoord); +begin + FCaretXY := value; +end; + +procedure TSynDocument.SetDataIntf(const value: IInterface); +begin + FDataIntf := Value; +end; + +procedure TSynDocument.SetHighlighter(const value: TSynCustomHighlighter); +begin + FHighLighter := value; +end; + + +procedure TSynDocument.SetLines(const value: TStrings); +begin + FLines.Assign(value); +end; + +procedure TSynDocument.SetModified(const value: Boolean); +begin + FModified := Value; +end; + +procedure TSynDocument.SetTopLine(const value: Integer); +begin + FTopLine := Value; +end; + +procedure TSynEditDocumentManager.Notification(AComponent: TComponent; + Operation: TOperation); +begin + inherited; + if (AComponent = FMemo) and (Operation = opRemove) then + begin + SetMemo(nil); + end; +end; + +destructor TSynEditDocumentManager.Destroy; +begin + FUpdateTimer.Free; + inherited; +end; + +procedure TSynEditDocumentManager.UpdateTimerEvent(Sender: TObject); +var + doc : ISynDocument; +begin + FUpdateTimer.Enabled := False; + if FCurrentDocumentIndex <> -1 then + begin + if FMemo <> nil then + begin + doc := GetDocument(FCurrentDocumentIndex); + if doc <> nil then + begin + doc.Modified := FMemo.Modified; + doc.Lines.Assign(FMemo.Lines); + doc.TopLine := FMemo.TopLine; + doc.CaretXY := FMemo.CaretXY; + doc.UndoList.Assign(FMemo.UndoList); + doc.RedoList.Assign(FMemo.RedoList); + end; + end; + end; +end; + + +procedure TSynEditDocumentManager.UpdateCurrentDocument; +var + doc : ISynDocument; + i: Integer; +begin + if FCurrentDocumentIndex <> -1 then + begin + //save the state of the current document + if FMemo <> nil then + begin + doc := GetDocument(FCurrentDocumentIndex); + if doc <> nil then + begin + doc.Modified := FMemo.Modified; + doc.Lines.Assign(FMemo.Lines); + doc.TopLine := FMemo.TopLine; + doc.CaretXY := FMemo.CaretXY; + doc.UndoList.Assign(FMemo.UndoList); + doc.RedoList.Assign(FMemo.RedoList); + doc.Marks.Clear; + for i := 0 to FMemo.Marks.Count - 1 do + doc.Marks.Place(CloneMark(nil,FMemo.Marks.Items[i])); + FMemo.Highlighter := doc.Highlighter; + end; + end; + end; +end; +end. diff --git a/components/synedit/Source/SynEditHighlighter.pas b/components/synedit/Source/SynEditHighlighter.pas index 96198c45..fb14d85e 100644 --- a/components/synedit/Source/SynEditHighlighter.pas +++ b/components/synedit/Source/SynEditHighlighter.pas @@ -96,6 +96,7 @@ type function SaveToFile(Ini: TIniFile): Boolean; {$ENDIF} public + procedure SetColors(Foreground, Background: TColor); property FriendlyName: UnicodeString read fFriendlyName; property IntegerStyle: Integer read GetStyleFromInt write SetStyleFromInt; property Name: string read fName; @@ -647,6 +648,16 @@ begin end; end; +procedure TSynHighlighterAttributes.SetColors(Foreground, Background: TColor); +begin + if (fForeGround <> Foreground) or (fBackground <> Background) then + begin + fForeGround := Foreground; + fBackground := Background; + Changed; + end; +end; + procedure TSynHighlighterAttributes.SetForeground(Value: TColor); begin if fForeGround <> Value then @@ -1108,12 +1119,10 @@ end; function TSynCustomHighlighter.IsIdentChar(AChar: WideChar): Boolean; begin - case AChar of - '_', '0'..'9', 'A'..'Z', 'a'..'z': - Result := True; + if IsWordBreakChar(Achar) then + Result := False else - Result := False; - end; + Result := True; end; function TSynCustomHighlighter.IsKeyword(const AKeyword: UnicodeString): Boolean; diff --git a/components/synedit/Source/SynEditKeyCmds.pas b/components/synedit/Source/SynEditKeyCmds.pas index 250ad795..d356a0d0 100644 --- a/components/synedit/Source/SynEditKeyCmds.pas +++ b/components/synedit/Source/SynEditKeyCmds.pas @@ -201,6 +201,7 @@ const ecUpperCaseBlock = 625; // apply to current selection, or current char if no selection ecLowerCaseBlock = 626; ecToggleCaseBlock = 627; + ecTitleCaseBlock = 628; ecString = 630; //Insert a whole string @@ -318,7 +319,7 @@ type {$ENDIF} const - EditorCommandStrs: array[0..100] of TIdentMapEntry = ( + EditorCommandStrs: array[0..101] of TIdentMapEntry = ( (Value: ecNone; Name: 'ecNone'), (Value: ecLeft; Name: 'ecLeft'), (Value: ecRight; Name: 'ecRight'), @@ -419,6 +420,7 @@ const (Value: ecUpperCaseBlock; Name: 'ecUpperCaseBlock'), (Value: ecLowerCaseBlock; Name: 'ecLowerCaseBlock'), (Value: ecToggleCaseBlock; Name: 'ecToggleCaseBlock'), + (Value: ecTitleCaseBlock; Name: 'ecTitleCaseBlock'), (Value: ecString; Name:'ecString')); procedure GetEditorCommandValues(Proc: TGetStrProc); diff --git a/components/synedit/Source/SynEditReg.pas b/components/synedit/Source/SynEditReg.pas index b87755cf..e3c8078e 100644 --- a/components/synedit/Source/SynEditReg.pas +++ b/components/synedit/Source/SynEditReg.pas @@ -127,6 +127,7 @@ uses // SynEdit components SynEdit, SynMemo, + SynEditDocumentManager, {$IFNDEF SYN_DELPHI_PE} SynDBEdit, {$ENDIF} @@ -137,7 +138,7 @@ uses SynEditExport, SynExportHTML, SynExportRTF, - SynExportTeX, + SynExportTeX, SynHighlighterMulti, SynCompletionProposal, SynEditPythonBehaviour, @@ -181,6 +182,7 @@ uses SynHighlighterInno, SynHighlighterJava, SynHighlighterJScript, + SynHighlighterJSON, SynHighlighterKix, SynHighlighterModelica, SynHighlighterM3, @@ -248,7 +250,8 @@ begin TSynExporterTeX, TSynEditPythonBehaviour, TSynMultiSyn, TSynCompletionProposal, TSynAutoComplete, TSynMacroRecorder, TSynEditPrint, TSynEditPrintPreview, TSynAutoCorrect, - TSynEditSearch, TSynEditRegexSearch, TSynEditOptionsDialog, TSynURIOpener, TSynHotKey]); + TSynEditSearch, TSynEditRegexSearch, TSynEditOptionsDialog, TSynURIOpener, TSynHotKey, + TSynEditDocumentManager]); {$IFDEF SYN_COMPILER_4_UP} RegisterComponents(SYNS_ComponentsPage, [TSynHighlighterManager]); {$ENDIF} @@ -260,7 +263,7 @@ begin TSynM3Syn, TSynPasSyn, TSynVBSyn, TSynCobolSyn, TSynCSSyn, // internet TSynCssSyn, TSynHTMLSyn, TSynJScriptSyn, TSynPHPSyn, TSynVBScriptSyn, - TSynXMLSyn, TSynVrml97Syn, + TSynXMLSyn, TSynJSONSyn, TSynVrml97Syn, //interpreted TSynAWKSyn, TSynBATSyn, {$ifdef SYN_DELPHI_2009_UP} diff --git a/components/synedit/Source/SynEditReg.res b/components/synedit/Source/SynEditReg.res new file mode 100644 index 0000000000000000000000000000000000000000..80b90468eb34208f54c4b6cbb7c4ce53eb679d72 GIT binary patch literal 876 zcmbtTu};G<6udN*qAa9H>||u@MmIoA48Sk2(XkSPvtg-HlaV#b!f!-f@+ln|BX!A8 z^>Mc2Hbvcd$;G~R_nxiD27r_hap3eMenwso=?SbhnM7l6y5S@x?uh_>nl5g4u)_#0~tqeK8qzYPHHc_14X97xa+N=kJ};NB$pO`B<2K3Rz)-Ny~G1 z*>MFZv5vy7Z#JYPHzw;RwTZ0A7u)>9$SzT2$t+X1j0!Ti5WmOLRaa9?|!4JdBuK_RXb#0tl> literal 0 HcmV?d00001 diff --git a/components/synedit/Source/SynEditSearch.pas b/components/synedit/Source/SynEditSearch.pas index 80f7a027..84fc5c7b 100644 --- a/components/synedit/Source/SynEditSearch.pas +++ b/components/synedit/Source/SynEditSearch.pas @@ -207,9 +207,7 @@ begin begin if I = PatLen then begin - case fWhole of - True: if not TestWholeWord then break; - end; + if fWhole and not TestWholeWord then break; inc(fCount); Result := Run - Origin - Patlen + 2; exit; diff --git a/components/synedit/Source/SynEditStrConst.pas b/components/synedit/Source/SynEditStrConst.pas index fd4c43b0..81e9a926 100644 --- a/components/synedit/Source/SynEditStrConst.pas +++ b/components/synedit/Source/SynEditStrConst.pas @@ -74,6 +74,7 @@ const SYNS_AttrCharacter = 'Character'; SYNS_AttrClass = 'Class'; SYNS_AttrColor = 'ColorValue'; + SYNS_AttrConstant = 'Constant'; SYNS_AttrComment = 'Comment'; SYNS_AttrCondition = 'Condition'; SYNS_AttrConditionalComment = 'ConditionalComment'; @@ -105,6 +106,7 @@ const SYNS_AttrInclude = 'Include'; SYNS_AttrIndicator = 'IndicatorArea'; SYNS_AttrIndirect = 'Indirect'; + SYNS_AttrInstructions = 'Instructions'; SYNS_AttrInvalidSymbol = 'InvalidSymbol'; SYNS_AttrInternalFunction = 'InternalFunction'; SYNS_AttrKey = 'Key'; @@ -231,6 +233,7 @@ const SYNS_LangCache = 'CacheObjectScript'; SYNS_LangCSS = 'CascadingStyleSheet'; SYNS_LangJScript = 'JavaScript'; + SYNS_LangJSON = 'JSON'; SYNS_LangKIX = 'KiXtart'; SYNS_LangBaan = 'Baan_4GL'; SYNS_LangFoxpro = 'Foxpro'; @@ -255,6 +258,7 @@ const SYNS_LangDOT = 'DOT_Graph_Drawing_Description_language'; SYNS_LangEiffel = 'Eiffel'; SYNS_LangLDraw = 'LEGO_LDraw'; + SYNS_LangLLVMIR = 'LLVM IR'; SYNS_LangUnknown = ''; SYNS_LangURI = 'URI'; SYNS_LangVrml97 = 'Vrml97'; @@ -285,6 +289,7 @@ resourcestring SYNS_FriendlyAttrComment = 'Comment'; SYNS_FriendlyAttrCondition = 'Condition'; SYNS_FriendlyAttrConditionalComment = 'Conditional Comment'; + SYNS_FriendlyAttrConstant = 'Constant'; SYNS_FriendlyAttrDataType = 'Data Type'; SYNS_FriendlyAttrDebugLines = 'Debugging Lines'; SYNS_FriendlyAttrDefaultPackage = 'Default Packages'; @@ -313,8 +318,9 @@ resourcestring SYNS_FriendlyAttrInclude = 'Include'; SYNS_FriendlyAttrIndicator = 'Indicator Area'; SYNS_FriendlyAttrIndirect = 'Indirect'; - SYNS_FriendlyAttrInvalidSymbol = 'Invalid Symbol'; + SYNS_FriendlyAttrInstructions = 'Instructions'; SYNS_FriendlyAttrInternalFunction = 'Internal Function'; + SYNS_FriendlyAttrInvalidSymbol = 'Invalid Symbol'; SYNS_FriendlyAttrKey = 'Key'; SYNS_FriendlyAttrLabel = 'Label'; SYNS_FriendlyAttrLace = 'Lace'; @@ -334,7 +340,7 @@ resourcestring SYNS_FriendlyAttrOperatorAndSymbols = 'Operator And Symbols'; SYNS_FriendlyAttrOpLine = 'OpLine'; SYNS_FriendlyAttrOptions = 'Options'; - SYNS_FriendlyAttrPath = 'Pathname'; + SYNS_FriendlyAttrPath = 'Pathname'; SYNS_FriendlyAttrPLSQL = 'PL/SQL Reserved Word'; SYNS_FriendlyAttrPragma = 'Pragma'; SYNS_FriendlyAttrPredefined = 'Predefined'; @@ -458,6 +464,7 @@ resourcestring SYNS_FilterCache = 'Cache Files (*.mac;*.inc;*.int)|*.mac;*.inc;*.int'; SYNS_FilterCSS = 'Cascading Stylesheets (*.css)|*.css'; SYNS_FilterJScript = 'Javascript Files (*.js)|*.js'; + SYNS_FilterJSON = 'JSON Files (*.json)|*.json'; SYNS_FilterKIX = 'KiXtart Scripts (*.kix)|*.kix'; SYNS_FilterBaan = 'Baan 4GL Files (*.cln)|*.cln'; SYNS_FilterFoxpro = 'Foxpro Files (*.prg)|*.prg'; @@ -481,6 +488,7 @@ resourcestring SYNS_FilterDOT = 'DOT Graph Drawing Description (*.dot)|*.dot'; SYNS_FilterEiffel = 'Eiffel (*.e;*.ace)|*.e;*.ace'; SYNS_FilterLDraw = 'LEGO LDraw Files (*.ldr)|*.ldr'; + SYNS_FilterLLVMIR = 'LLVM IR files (*.ll)|*.ll'; SYNS_FilterURI = 'All Files (*.*)|*.*'; SYNS_FilterVrml97 = 'Vrml97/X3D World (*.wrl;*.wrml;*.vrl;*.vrml;*.x3d)|*.wrl;*.wrml;*.vrl;*.vrml;*.x3d'; @@ -516,6 +524,7 @@ resourcestring SYNS_FriendlyLangCache = 'Cache Object Script'; SYNS_FriendlyLangCSS = 'Cascading Style Sheet'; SYNS_FriendlyLangJScript = 'JavaScript'; + SYNS_FriendlyLangJSON = 'JSON'; SYNS_FriendlyLangKIX = 'KiXtart'; SYNS_FriendlyLangBaan = 'Baan 4GL'; SYNS_FriendlyLangFoxpro = 'Foxpro'; @@ -540,7 +549,8 @@ resourcestring SYNS_FriendlyLangDOT = 'DOT Graph Drawing Description language'; SYNS_FriendlyLangEiffel = 'Eiffel'; SYNS_FriendlyLangLDraw = 'LEGO LDraw'; - SYNS_FriendlyLangUnknown = ''; + SYNS_FriendlyLangLLVMIR = 'LLVM Intermediate Representation'; + SYNS_FriendlyLangUnknown = ''; SYNS_FriendlyLangURI = 'URI'; SYNS_FriendlyLangVrml97 = 'Vrml97'; diff --git a/components/synedit/Source/SynEditTypes.pas b/components/synedit/Source/SynEditTypes.pas index 6677f460..a8a79b7a 100644 --- a/components/synedit/Source/SynEditTypes.pas +++ b/components/synedit/Source/SynEditTypes.pas @@ -81,6 +81,9 @@ type TBufferCoord = record Char: integer; Line: integer; + {$IFDEF SYN_COMPILER_10_UP} + class operator Equal(a, b: TBufferCoord): Boolean; + {$ENDIF} end; // Codehunter patch: added TBufferBlock @@ -89,11 +92,17 @@ type BeginChar, EndLine, EndChar: Integer; + {$IFDEF SYN_COMPILER_10_UP} + class operator Equal(a, b: TBufferBlock): Boolean; + {$ENDIF} end; TDisplayCoord = record Column: integer; Row: integer; + {$IFDEF SYN_COMPILER_10_UP} + class operator Equal(a, b: TDisplayCoord): Boolean; + {$ENDIF} end; function DisplayCoord(AColumn, ARow: Integer): TDisplayCoord; @@ -113,4 +122,30 @@ begin Result.Line := ALine; end; +{$IFDEF SYN_COMPILER_10_UP} + +{ TBufferCoord } + +class operator TBufferCoord.Equal(a, b: TBufferCoord): Boolean; +begin + Result := (a.Char = b.Char) and (a.Line = b.Line); +end; + +{ TBufferBlock } + +class operator TBufferBlock.Equal(a, b: TBufferBlock): Boolean; +begin + Result := (a.BeginLine = b.BeginLine) and (a.BeginChar = b.BeginChar) and + (a.EndLine = b.EndLine) and (a.EndChar = b.EndChar); +end; + +{ TDisplayCoord } + +class operator TDisplayCoord.Equal(a, b: TDisplayCoord): Boolean; +begin + Result := (a.Row = b.Row) and (a.Column = b.Column); +end; + +{$ENDIF} + end. diff --git a/components/synedit/Source/SynHighlighterCss.pas b/components/synedit/Source/SynHighlighterCss.pas index 6809e7b1..f0cadabe 100644 --- a/components/synedit/Source/SynHighlighterCss.pas +++ b/components/synedit/Source/SynHighlighterCss.pas @@ -77,19 +77,23 @@ uses Classes; type - TtkTokenKind = (tkComment, tkProperty, tkKey, tkNull, tkSpace, tkString, - tkSymbol, tkText, tkUndefProperty, tkValue, tkColor, tkNumber, tkImportant); + TtkTokenKind = (tkComment, tkProperty, tkSelector, tkSelectorAttrib, tkNull, + tkSpace, tkString, tkSymbol, tkText, tkUndefProperty, tkValue, tkColor, + tkNumber, tkImportant); - TRangeState = (rsComment, rsKey, rsParam, rsText, rsUnKnown, rsValue); + TRangeState = (rsComment, rsSelector, rsDeclaration, rsUnknown, rsProperty, + rsValue, rsAttrib, rsParameter); TSynCssSyn = class(TSynCustomHighlighter) private fRange: TRangeState; fCommentRange: TRangeState; + fParameterRange: TRangeState; fTokenID: TtkTokenKind; fCommentAttri: TSynHighlighterAttributes; fPropertyAttri: TSynHighlighterAttributes; - fKeyAttri: TSynHighlighterAttributes; + fAttributeAttri: TSynHighlighterAttributes; + fSelectorAttri: TSynHighlighterAttributes; fSpaceAttri: TSynHighlighterAttributes; fStringAttri: TSynHighlighterAttributes; fColorAttri: TSynHighlighterAttributes; @@ -103,10 +107,15 @@ type procedure DoAddKeyword(AKeyword: UnicodeString; AKind: integer); function HashKey(Str: PWideChar): Integer; function IdentKind(MayBe: PWideChar): TtkTokenKind; - procedure TextProc; + procedure SelectorProc; + procedure AttributeProc; procedure CommentProc; procedure BraceCloseProc; procedure BraceOpenProc; + procedure ParenOpenProc; + procedure ParenCloseProc; + procedure BracketOpenProc; + procedure BracketCloseProc; procedure CRProc; procedure SemiProc; procedure StartValProc; @@ -118,11 +127,16 @@ type procedure StringProc; procedure HashProc; procedure SlashProc; + procedure GreaterProc; + procedure PlusProc; + procedure TildeProc; + procedure PipeProc; + procedure EqualProc; procedure ExclamProc; protected function GetSampleSource: UnicodeString; override; function IsFilterStored: Boolean; override; - procedure NextProcedure; + procedure NextDeclaration; public class function GetLanguageName: string; override; class function GetFriendlyLanguageName: UnicodeString; override; @@ -148,7 +162,10 @@ type write fColorAttri; property NumberAttri: TSynHighlighterAttributes read fNumberAttri write fNumberAttri; - property KeyAttri: TSynHighlighterAttributes read fKeyAttri write fKeyAttri; + property SelectorAttri: TSynHighlighterAttributes read fSelectorAttri + write fSelectorAttri; + property AttributeAttri: TSynHighlighterAttributes read fAttributeAttri + write fAttributeAttri; property SpaceAttri: TSynHighlighterAttributes read fSpaceAttri write fSpaceAttri; property StringAttri: TSynHighlighterAttributes read fStringAttri @@ -295,13 +312,18 @@ const +',volume'; Properties_CSS3 : UnicodeString = '@font-face' + +',@font-feature-values' +',@keyframes' + +',align-content' + +',align-items' + +',align-self' +',alignment-adjust' +',alignment-baseline' +',animation' +',animation-delay' +',animation-direction' +',animation-duration' + +',animation-fill-mode' +',animation-iteration-count' +',animation-name' +',animation-play-state' @@ -337,6 +359,9 @@ const +',box-pack' +',box-shadow' +',box-sizing' + +',break-after' + +',break-before' + +',break-inside' +',color-profile' +',column-count' +',column-fill' @@ -356,10 +381,28 @@ const +',drop-initial-before-align' +',drop-initial-size' +',drop-initial-value' + +',filter' +',fit' +',fit-position' +',float-offset' + +',flex' + +',flex-basis' + +',flex-direction' + +',flex-flow' + +',flex-grow' + +',flex-shrink' + +',flex-wrap' +',font-size-adjust' + +',font-feature-setting' + +',font-kerning' + +',font-language-override' + +',font-synthesis' + +',font-variant-alternates' + +',font-variant-caps' + +',font-variant-east-asian' + +',font-variant-ligatures' + +',font-variant-numeric' + +',font-variant-position' +',font-stretch' +',grid-columns' +',grid-rows' @@ -372,8 +415,12 @@ const +',hyphens' +',icon' +',image-orientation' + +',image-rendering' +',image-resolution' + +',ime-mode' + +',justify-content' +',inline-box-align' + +',line-break' +',line-stacking' +',line-stacking-ruby' +',line-stacking-shift' @@ -386,17 +433,23 @@ const +',marquee-play-count' +',marquee-speed' +',marquee-style' + +',mask' + +',mask-type' +',move-to' +',nav-down' +',nav-index' +',nav-left' +',nav-right' +',nav-up' + +',object-fit' + +',object-position' +',opacity' + +',order' +',outline-offset' +',overflow-style' +',overflow-x' +',overflow-y' + +',overflow-wrap' +',page' +',page-policy' +',perspective' @@ -416,16 +469,23 @@ const +',ruby-span' +',size' +',string-set' + +',tab-size' +',target' +',target-name' +',target-new' +',target-position' +',text-align-last' + +',text-combine-horizontal' + +',text-decoration-color' + +',text-decoration-line' + +',text-decoration-style' +',text-height' +',text-justify' + +',text-orientation' +',text-outline' +',text-overflow' +',text-shadow' + +',text-underline-position' +',text-wrap' +',transform' +',transform-origin' @@ -443,8 +503,8 @@ const +',voice-stress' +',voice-volume' +',word-break' - +',word-wrap'; - + +',word-wrap' + +',writing-mode'; { TSynCssSyn } @@ -514,10 +574,15 @@ begin fPropertyAttri.Style := [fsBold]; AddAttribute(fPropertyAttri); - fKeyAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord, SYNS_FriendlyAttrReservedWord); - fKeyAttri.Style := [fsBold]; - fKeyAttri.Foreground := $00ff0080; - AddAttribute(fKeyAttri); + fSelectorAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord, SYNS_FriendlyAttrReservedWord); + fSelectorAttri.Style := [fsBold]; + fSelectorAttri.Foreground := $00ff0080; + AddAttribute(fSelectorAttri); + + fAttributeAttri := TSynHighlighterAttributes.Create(SYNS_AttrAttribute, SYNS_FriendlyAttrAttribute); + fAttributeAttri.Style := []; + fAttributeAttri.Foreground := $00ff0080; + AddAttribute(fAttributeAttri); fUndefPropertyAttri := TSynHighlighterAttributes.Create( SYNS_AttrUndefinedProperty, SYNS_FriendlyAttrUndefinedProperty); @@ -561,7 +626,7 @@ begin EnumerateKeywords(Ord(tkProperty), Properties_CSS2_Aural, IsIdentChar, DoAddKeyword); EnumerateKeywords(Ord(tkProperty), Properties_CSS3, IsIdentChar, DoAddKeyword); - fRange := rsText; + fRange := rsSelector; fDefaultFilter := SYNS_FilterCSS; end; @@ -571,13 +636,64 @@ begin inherited Destroy; end; +procedure TSynCssSyn.AttributeProc; + + function IsStopChar: Boolean; + begin + case fLine[Run] of + #0..#31, ']', '~', '^', '$', '*', '|', '=': + Result := True; + else + Result := False; + end; + end; + +begin + if IsStopChar then + begin + case fLine[Run] of + #0..#31, '{', '/': NextDeclaration; + ']': BracketCloseProc; + '~': TildeProc; + '|': PipeProc; + '=': EqualProc; + end; + Exit; + end; + + fTokenID := tkSelectorAttrib; + while not IsStopChar do + Inc(Run); +end; + procedure TSynCssSyn.BraceCloseProc; begin - fRange := rsText; + fRange := rsSelector; fTokenId := tkSymbol; Inc(Run); end; +procedure TSynCssSyn.BraceOpenProc; +begin + Inc(Run); + fRange := rsDeclaration; + fTokenID := tkSymbol; +end; + +procedure TSynCssSyn.BracketCloseProc; +begin + fTokenID := tkSymbol; + fRange := rsSelector; + Inc(Run); +end; + +procedure TSynCssSyn.BracketOpenProc; +begin + Inc(Run); + fRange := rsAttrib; + fTokenID := tkSymbol; +end; + procedure TSynCssSyn.CommentProc; begin if fLine[Run] = #0 then @@ -597,13 +713,6 @@ begin end; end; -procedure TSynCssSyn.BraceOpenProc; -begin - Inc(Run); - fRange := rsParam; - fTokenID := tkSymbol; -end; - procedure TSynCssSyn.CRProc; begin fTokenID := tkSpace; @@ -644,27 +753,58 @@ begin end; end; +procedure TSynCssSyn.ParenCloseProc; +begin + fRange := fParameterRange; + fTokenID := tkSymbol; + Inc(Run); +end; + +procedure TSynCssSyn.ParenOpenProc; +begin + Inc(Run); + fParameterRange := fRange; + fRange := rsParameter; + fTokenID := tkSymbol; +end; + +procedure TSynCssSyn.PipeProc; +begin + Inc(Run); + if fLine[Run] = '=' then + begin + Inc(Run); + fTokenID := tkSymbol; + end; +end; + +procedure TSynCssSyn.PlusProc; +begin + Inc(Run); + fTokenID := tkSymbol; +end; + procedure TSynCssSyn.IdentProc; begin case fRange of - rsKey: + rsProperty: begin - fRange := rsParam; - fTokenID := tkKey; + fRange := rsDeclaration; + fTokenID := tkSelector; Inc(Run, fStringLen); end; - rsValue: + rsValue, rsParameter: begin fTokenID := tkValue; while not IsLineEnd(Run) and - not CharInSet(fLine[Run], ['}', ';', ',', ' ']) do + not CharInSet(fLine[Run], ['(', ')', '}', ';', ',', ' ']) do begin Inc(Run); end; if IsLineEnd(Run) or CharInSet(fLine[Run], ['}', ';']) then - fRange := rsParam; + fRange := rsDeclaration; end; else fTokenID := IdentKind((fLine + Run)); @@ -686,12 +826,12 @@ begin inc(Run); end; -procedure TSynCssSyn.TextProc; +procedure TSynCssSyn.SelectorProc; function IsStopChar: Boolean; begin case fLine[Run] of - #0..#31, '{', '/': + #0..#31, '{', '/', '[', ']', '>', '+', '~': Result := True; else Result := False; @@ -701,12 +841,30 @@ procedure TSynCssSyn.TextProc; begin if IsStopChar then begin - NextProcedure; - exit; + case fLine[Run] of + #0..#31, '{', '/': NextDeclaration; + '[': BracketOpenProc; + ']': BracketCloseProc; + '>': GreaterProc; + '+': PlusProc; + '~': TildeProc; + end; + Exit; end; - fTokenID := tkKey; - while not IsStopChar do Inc(Run); + fTokenID := tkSelector; + while not IsStopChar do + Inc(Run); +end; + +procedure TSynCssSyn.TildeProc; +begin + Inc(Run); + if fLine[Run] = '=' then + begin + Inc(Run); + fTokenID := tkSymbol; + end; end; procedure TSynCssSyn.SpaceProc; @@ -742,6 +900,12 @@ begin while IsHexChar do Inc(Run); end; +procedure TSynCssSyn.EqualProc; +begin + Inc(Run); + fTokenID := tkSymbol; +end; + procedure TSynCssSyn.ExclamProc; begin if (fLine[Run + 1] = 'i') and @@ -781,17 +945,19 @@ procedure TSynCssSyn.Next; begin fTokenPos := Run; case fRange of - rsText: - TextProc; + rsSelector: + SelectorProc; + rsAttrib: + AttributeProc; rsComment: CommentProc; else - NextProcedure; + NextDeclaration; end; inherited; end; -procedure TSynCssSyn.NextProcedure; +procedure TSynCssSyn.NextDeclaration; begin case fLine[Run] of #0: NullProc; @@ -802,6 +968,8 @@ begin '#': HashProc; '{': BraceOpenProc; '}': BraceCloseProc; + '(': ParenOpenProc; + ')': ParenCloseProc; ':', ',': StartValProc; ';': SemiProc; '0'..'9', '-', '.': NumberProc; @@ -815,7 +983,7 @@ function TSynCssSyn.GetDefaultAttribute(Index: integer): TSynHighlighterAttribut begin case Index of SYN_ATTR_COMMENT: Result := fCommentAttri; - SYN_ATTR_KEYWORD: Result := fKeyAttri; + SYN_ATTR_KEYWORD: Result := fSelectorAttri; SYN_ATTR_WHITESPACE: Result := fSpaceAttri; SYN_ATTR_STRING: Result := fStringAttri; else Result := nil; @@ -837,7 +1005,8 @@ begin case fTokenID of tkComment: Result := fCommentAttri; tkProperty: Result := fPropertyAttri; - tkKey: Result := fKeyAttri; + tkSelector: Result := fSelectorAttri; + tkSelectorAttrib: Result := fAttributeAttri; tkSpace: Result := fSpaceAttri; tkString: Result := fStringAttri; tkSymbol: Result := fSymbolAttri; @@ -856,6 +1025,12 @@ begin Result := Ord(fTokenId); end; +procedure TSynCssSyn.GreaterProc; +begin + Inc(Run); + fTokenID := tkSymbol; +end; + function TSynCssSyn.GetRange: Pointer; begin Result := Pointer(fRange); @@ -868,7 +1043,7 @@ end; procedure TSynCssSyn.ResetRange; begin - fRange:= rsText; + fRange:= rsSelector; end; function TSynCssSyn.GetSampleSource: UnicodeString; diff --git a/components/synedit/Source/SynHighlighterDWS.pas b/components/synedit/Source/SynHighlighterDWS.pas index 06c95737..099b4d39 100644 --- a/components/synedit/Source/SynHighlighterDWS.pas +++ b/components/synedit/Source/SynHighlighterDWS.pas @@ -59,7 +59,8 @@ type tkSpace, tkString, tkSymbol, tkUnknown, tkFloat, tkHex, tkDirec, tkChar); TRangeState = (rsANil, rsAnsi, rsAnsiAsm, rsAsm, rsBor, rsBorAsm, rsProperty, - rsExports, rsDirective, rsDirectiveAsm, rsHereDocSingle, rsHereDocDouble, rsUnKnown); + rsExports, rsDirective, rsDirectiveAsm, rsHereDocSingle, rsHereDocDouble, + rsType, rsUnknown); PIdentFuncTableFunc = ^TIdentFuncTableFunc; TIdentFuncTableFunc = function : TtkTokenKind of object; @@ -76,8 +77,9 @@ type fRange: TRangeState; fCommentClose : Char; fIdentFuncTable: array[0..388] of TIdentFuncTableFunc; - fKeyWords : TAnsiStringList; - fKeyWords_PropertyScoped : TAnsiStringList; + fKeywords: TAnsiStringList; + fKeywordsPropertyScoped: TAnsiStringList; + fKeywordsTypeScoped: TAnsiStringList; fTokenID: TtkTokenKind; fStringAttri: TSynHighlighterAttributes; fCharAttri: TSynHighlighterAttributes; @@ -92,11 +94,13 @@ type fIdentifierAttri: TSynHighlighterAttributes; fSpaceAttri: TSynHighlighterAttributes; function AltFunc: TtkTokenKind; - function KeyWordFunc: TtkTokenKind; + function KeywordFunc: TtkTokenKind; function FuncAsm: TtkTokenKind; function FuncEnd: TtkTokenKind; function FuncPropertyScoped: TtkTokenKind; function FuncProperty: TtkTokenKind; + function FuncTypeScoped: TtkTokenKind; + function FuncType: TtkTokenKind; function HashKey(Str: PWideChar): Cardinal; function IdentKind(MayBe: PWideChar): TtkTokenKind; procedure InitIdent; @@ -186,10 +190,10 @@ uses const // if the language is case-insensitive keywords *must* be in lowercase - cKeyWords: array[1..95] of UnicodeString = ( + cKeywords: array[1..94] of UnicodeString = ( 'abstract', 'and', 'array', 'as', 'asm', 'begin', 'break', 'case', 'cdecl', 'class', 'const', 'constructor', - 'contains', 'continue', 'deprecated', 'destructor', + 'continue', 'deprecated', 'destructor', 'div', 'do', 'downto', 'else', 'end', 'ensure', 'except', 'exit', 'export', 'exports', 'external', 'final', 'finalization', 'finally', 'for', 'forward', 'function', 'helper', 'if', @@ -204,125 +208,20 @@ const 'then', 'to', 'try', 'type', 'unit', 'until', 'uses', 'var', 'virtual', 'while', 'xor' ); - cKeyWords_PropertyScoped: array [0..4] of UnicodeString = ( + cKeywordsPropertyScoped: array [0..4] of UnicodeString = ( 'default', 'index', 'read', 'stored', 'write' ); + cKeywordsTypeScoped: array [0..1] of UnicodeString = ( + 'enum', 'flag' + ); function TAnsiStringList.CompareStrings(const S1, S2: string): Integer; begin - Result:=CompareText(S1, S2); + Result := CompareText(S1, S2); end; -function TSynDWSSyn.HashKey(Str: PWideChar): Cardinal; -var - c : Word; -begin - Result:=0; - while IsIdentChar(Str^) do begin - c:=Ord(Str^); - if c in [Ord('A')..Ord('Z')] then - c := c + (Ord('a')-Ord('A')); - Result := Result * 692 + c * 171; - inc(Str); - end; - fStringLen := Str - fToIdent; - Result := Result mod Cardinal(Length(fIdentFuncTable)); -end; -function TSynDWSSyn.IdentKind(MayBe: PWideChar): TtkTokenKind; -var - Key: Cardinal; -begin - fToIdent := MayBe; - Key := HashKey(MayBe); - if Key <= High(fIdentFuncTable) then - Result := fIdentFuncTable[Key] - else - Result := tkIdentifier; -end; - -procedure TSynDWSSyn.InitIdent; - - procedure SetIdentFunc(h : Integer; const func : TIdentFuncTableFunc); - begin - fIdentFuncTable[h]:=func; - end; - -var - i : Integer; -begin - for i:=Low(cKeyWords) to High(cKeyWords) do begin - SetIdentFunc(HashKey(@cKeyWords[i][1]), KeyWordFunc); - fKeyWords.Add(cKeyWords[i]); - end; - - for i:=0 to High(cKeyWords_PropertyScoped) do begin - SetIdentFunc(HashKey(@cKeyWords_PropertyScoped[i][1]), FuncPropertyScoped); - fKeyWords_PropertyScoped.Add(cKeyWords_PropertyScoped[i]); - end; - - for i := Low(fIdentFuncTable) to High(fIdentFuncTable) do - if @fIdentFuncTable[i] = nil then - fIdentFuncTable[i] := AltFunc; - - SetIdentFunc(HashKey('asm'), FuncAsm); - SetIdentFunc(HashKey('end'), FuncEnd); - SetIdentFunc(HashKey('property'), FuncProperty); - - fKeyWords.Sorted:=True; -end; - -function TSynDWSSyn.AltFunc: TtkTokenKind; -begin - Result := tkIdentifier -end; - -function TSynDWSSyn.KeyWordFunc: TtkTokenKind; -var - buf : String; -begin - SetString(buf, fToIdent, fStringLen); - if (fKeyWords.IndexOf(buf)>=0) and (FLine[Run - 1] <> '&') then - Result := tkKey - else Result := tkIdentifier -end; - -function TSynDWSSyn.FuncAsm: TtkTokenKind; -begin - if IsCurrentToken('asm') then begin - Result := tkKey; - fRange := rsAsm; - fAsmStart := True; - end else Result:=KeyWordFunc; -end; - -function TSynDWSSyn.FuncEnd: TtkTokenKind; -begin - if IsCurrentToken('end') then begin - Result := tkKey; - fRange := rsUnknown; - end else Result:=KeyWordFunc; -end; - -// FuncPropertyScoped -// -function TSynDWSSyn.FuncPropertyScoped: TtkTokenKind; -var - buf : String; -begin - SetString(buf, fToIdent, fStringLen); - if (fRange = rsProperty) and (fKeyWords_PropertyScoped.IndexOf(buf)>=0) then - Result:=tkKey - else Result:=KeyWordFunc; -end; - -function TSynDWSSyn.FuncProperty: TtkTokenKind; -begin - if IsCurrentToken('property') then begin - Result := tkKey; - fRange := rsProperty; - end else Result:=KeyWordFunc; -end; +{ TSynDWSSyn } constructor TSynDWSSyn.Create(AOwner: TComponent); begin @@ -330,17 +229,17 @@ begin fCaseSensitive := True; // bypass automatic lowercase, we handle it here fAsmAttri := TSynHighlighterAttributes.Create(SYNS_AttrAssembler, SYNS_FriendlyAttrAssembler); - fAsmAttri.Foreground:=RGB(128, 0, 0); + fAsmAttri.Foreground := RGB(128, 0, 0); AddAttribute(fAsmAttri); fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment, SYNS_FriendlyAttrComment); - fCommentAttri.Foreground:=clGreen; - fCommentAttri.Style:= [fsItalic]; + fCommentAttri.Foreground := clGreen; + fCommentAttri.Style := [fsItalic]; AddAttribute(fCommentAttri); fDirecAttri := TSynHighlighterAttributes.Create(SYNS_AttrPreprocessor, SYNS_FriendlyAttrPreprocessor); fDirecAttri.Foreground := TColor($808000); - fDirecAttri.Style:= [fsItalic]; + fDirecAttri.Style := [fsItalic]; AddAttribute(fDirecAttri); fIdentifierAttri := TSynHighlighterAttributes.Create(SYNS_AttrIdentifier, SYNS_FriendlyAttrIdentifier); @@ -378,8 +277,9 @@ begin AddAttribute(fSymbolAttri); SetAttributesOnChange(DefHighlightChange); - fKeyWords:=TAnsiStringList.Create; - fKeyWords_PropertyScoped:=TAnsiStringList.Create; + fKeywords := TAnsiStringList.Create; + fKeywordsPropertyScoped := TAnsiStringList.Create; + fKeywordsTypeScoped := TAnsiStringList.Create; InitIdent; fRange := rsUnknown; @@ -391,9 +291,152 @@ end; // destructor TSynDWSSyn.Destroy; begin - inherited; - fKeyWords.Free; - fKeyWords_PropertyScoped.Free; + inherited; + fKeywords.Free; + fKeywordsPropertyScoped.Free; + fKeywordsTypeScoped.Free; +end; + +function TSynDWSSyn.HashKey(Str: PWideChar): Cardinal; +var + c : Word; +begin + Result := 0; + while IsIdentChar(Str^) do begin + c := Ord(Str^); + if c in [Ord('A')..Ord('Z')] then + c := c + (Ord('a') - Ord('A')); + Result := Result * 692 + c * 171; + inc(Str); + end; + fStringLen := Str - fToIdent; + Result := Result mod Cardinal(Length(fIdentFuncTable)); +end; + +function TSynDWSSyn.IdentKind(MayBe: PWideChar): TtkTokenKind; +var + Key: Cardinal; +begin + fToIdent := MayBe; + Key := HashKey(MayBe); + if Key <= High(fIdentFuncTable) then + Result := fIdentFuncTable[Key] + else + Result := tkIdentifier; +end; + +procedure TSynDWSSyn.InitIdent; + + procedure SetIdentFunc(h : Integer; const func : TIdentFuncTableFunc); + begin + fIdentFuncTable[h] := func; + end; + +var + i : Integer; +begin + for i := Low(cKeywords) to High(cKeywords) do + begin + SetIdentFunc(HashKey(@cKeywords[i][1]), KeywordFunc); + fKeywords.Add(cKeywords[i]); + end; + + for i := 0 to High(cKeywordsPropertyScoped) do + begin + SetIdentFunc(HashKey(@cKeywordsPropertyScoped[i][1]), FuncPropertyScoped); + fKeywordsPropertyScoped.Add(cKeywordsPropertyScoped[i]); + end; + + for i := 0 to High(cKeywordsTypeScoped) do + begin + SetIdentFunc(HashKey(@cKeywordsTypeScoped[i][1]), FuncTypeScoped); + fKeywordsTypeScoped.Add(cKeywordsTypeScoped[i]); + end; + + for i := Low(fIdentFuncTable) to High(fIdentFuncTable) do + if @fIdentFuncTable[i] = nil then + fIdentFuncTable[i] := AltFunc; + + SetIdentFunc(HashKey('asm'), FuncAsm); + SetIdentFunc(HashKey('end'), FuncEnd); + SetIdentFunc(HashKey('property'), FuncProperty); + SetIdentFunc(HashKey('type'), FuncType); + + fKeywords.Sorted := True; +end; + +function TSynDWSSyn.AltFunc: TtkTokenKind; +begin + Result := tkIdentifier +end; + +function TSynDWSSyn.KeywordFunc: TtkTokenKind; +var + buf : String; +begin + SetString(buf, fToIdent, fStringLen); + if (fKeywords.IndexOf(buf)>=0) and (FLine[Run - 1] <> '&') then + Result := tkKey + else Result := tkIdentifier +end; + +function TSynDWSSyn.FuncAsm: TtkTokenKind; +begin + if IsCurrentToken('asm') then begin + Result := tkKey; + fRange := rsAsm; + fAsmStart := True; + end else Result := KeywordFunc; +end; + +function TSynDWSSyn.FuncEnd: TtkTokenKind; +begin + if IsCurrentToken('end') then begin + Result := tkKey; + fRange := rsUnknown; + end else Result := KeywordFunc; +end; + +function TSynDWSSyn.FuncTypeScoped: TtkTokenKind; +var + buf: String; +begin + SetString(buf, fToIdent, fStringLen); + if (fRange = rsType) and (fKeywordsTypeScoped.IndexOf(buf) >= 0) then + Result := tkKey + else + Result := KeywordFunc; +end; + +function TSynDWSSyn.FuncType: TtkTokenKind; +begin + if IsCurrentToken('type') then + begin + Result := tkKey; + fRange := rsType; + end else Result := KeywordFunc; +end; + +function TSynDWSSyn.FuncPropertyScoped: TtkTokenKind; +var + buf: String; +begin + SetString(buf, fToIdent, fStringLen); + if (fRange = rsProperty) and (fKeywordsPropertyScoped.IndexOf(buf) >= 0) then + Result := tkKey + else + Result := KeywordFunc; +end; + +function TSynDWSSyn.FuncProperty: TtkTokenKind; +begin + if IsCurrentToken('property') then + begin + Result := tkKey; + fRange := rsProperty; + end + else + Result := KeywordFunc; end; procedure TSynDWSSyn.AddressOpProc; @@ -523,23 +566,22 @@ end; procedure TSynDWSSyn.LoadDelphiStyle; - - procedure AddKeyword( const AName : string ); + procedure AddKeyword(const AName : string); var I : integer; begin I := HashKey( @AName[1] ); - fIdentFuncTable[I]:= KeyWordFunc; - fKeyWords.Add(AName); + fIdentFuncTable[I] := KeywordFunc; + fKeywords.Add(AName); end; - procedure RemoveKeyword( const AName : string ); + procedure RemoveKeyword(const AName : string); var I : integer; begin - I := fKeyWords.IndexOf(AName); + I := fKeywords.IndexOf(AName); if I <> -1 then - fKeywords.Delete( I ); + fKeywords.Delete(I); end; const @@ -563,12 +605,12 @@ begin CommentAttri.Foreground := clComment; // These are keywords highlighted in Delphi but not in TSynDWSSyn .. - for i:=Low(cKeywordsToAdd) to High(cKeywordsToAdd) do - AddKeyword( cKeywordsToAdd[i] ); + for i := Low(cKeywordsToAdd) to High(cKeywordsToAdd) do + AddKeyword(cKeywordsToAdd[i]); // These are keywords highlighted in TSynDWSSyn but not in Delphi... - for i:=Low(cKeywordsToRemove) to High(cKeywordsToRemove) do - RemoveKeyword( cKeywordsToRemove[i] ); + for i := Low(cKeywordsToRemove) to High(cKeywordsToRemove) do + RemoveKeyword(cKeywordsToRemove[i]); end; procedure TSynDWSSyn.LowerProc; @@ -737,15 +779,17 @@ end; procedure TSynDWSSyn.StringAposMultiProc; begin fTokenID := tkString; - Inc(Run); + if (Run>0) or IsLineEnd(Run+1) then + Inc(Run); fRange := rsHereDocSingle; while not IsLineEnd(Run) do begin if fLine[Run] = '''' then begin Inc(Run); - if fLine[Run] <> '''' then + if fLine[Run] <> '''' then begin fRange := rsUnknown; break; + end; end; Inc(Run); end; @@ -754,15 +798,29 @@ end; procedure TSynDWSSyn.StringQuoteProc; begin fTokenID := tkString; - Inc(Run); - fRange := rsHereDocDouble; + if fRange <> rsHereDocDouble then + begin + fRange := rsHereDocDouble; + Inc(Run); + end else + begin + if IsLineEnd(Run) then + begin + Inc(Run); + Exit; + end; + end; + while not IsLineEnd(Run) do begin - if fLine[Run] = '"' then begin + if fLine[Run] = '"' then + begin Inc(Run); if fLine[Run] <> '"' then + begin fRange := rsUnknown; break; + end; end; Inc(Run); end; @@ -898,7 +956,7 @@ end; procedure TSynDWSSyn.ResetRange; begin - fRange:= rsUnknown; + fRange := rsUnknown; end; function TSynDWSSyn.GetSampleSource: UnicodeString; @@ -986,4 +1044,3 @@ initialization {$ENDIF} end. - diff --git a/components/synedit/Source/SynHighlighterJSON.pas b/components/synedit/Source/SynHighlighterJSON.pas new file mode 100644 index 00000000..9c0d0e0d --- /dev/null +++ b/components/synedit/Source/SynHighlighterJSON.pas @@ -0,0 +1,547 @@ +{------------------------------------------------------------------------------- +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: SynHighlighterJSON.pas, released 2015-01-14. +The Initial Author of this file is Christian-W. Budde. +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. + +You may retrieve the latest version of this file at the SynEdit home page, +located at http://SynEdit.SourceForge.net +} + +{$IFNDEF QSYNHIGHLIGHTERJSON} +unit SynHighlighterJSON; +{$ENDIF} + +{$I SynEdit.Inc} + +interface + +uses +{$IFDEF SYN_CLX} + QGraphics, + QSynEditTypes, + QSynEditHighlighter, + QSynUnicode, +{$ELSE} + Graphics, + Registry, + SynEditTypes, + SynEditHighlighter, + SynUnicode, +{$ENDIF} + SysUtils, Classes; + +type + TtkTokenKind = (tkString, tkReserved, tkNull, tkNumber, tkSpace, + tkSymbol, tkUnknown); + + TRangeState = (rsUnknown, rsAttribute, rsObjectValue, rsArrayValue); + +type + TSynJSONSyn = class(TSynCustomHighLighter) + private + FRange: TRangeState; + FTokenID: TtkTokenKind; + FReservedAttri: TSynHighlighterAttributes; + FAttributeAttri: TSynHighlighterAttributes; + FValueAttri: TSynHighlighterAttributes; + FNumberAttri: TSynHighlighterAttributes; + FSpaceAttri: TSynHighlighterAttributes; + FSymbolAttri: TSynHighlighterAttributes; + procedure CloseArrayProc; + procedure CloseObjectProc; + procedure ColonProc; + procedure CommaProc; + procedure CRProc; + procedure LFProc; + procedure NullProc; + procedure NumberProc; + procedure OpenArrayProc; + procedure OpenObjectProc; + procedure ReservedWordProc; + procedure SpaceProc; + procedure StringProc; + procedure SymbolProc; + procedure UnknownProc; + protected + function GetSampleSource: UnicodeString; override; + function IsFilterStored: Boolean; override; + public + class function GetLanguageName: string; override; + class function GetFriendlyLanguageName: UnicodeString; override; + public + constructor Create(AOwner: TComponent); override; + function GetDefaultAttribute(Index: integer): TSynHighlighterAttributes; + override; + function GetEol: Boolean; override; + function GetRange: Pointer; override; + function GetTokenID: TtkTokenKind; + function GetTokenAttribute: TSynHighlighterAttributes; override; + function GetTokenKind: integer; override; + procedure Next; override; + procedure SetRange(Value: Pointer); override; + procedure ResetRange; override; + published + property AttributeAttri: TSynHighlighterAttributes read FAttributeAttri + write FAttributeAttri; + property ReservedAttri: TSynHighlighterAttributes read FReservedAttri + write FReservedAttri; + property NumberAttri: TSynHighlighterAttributes read FNumberAttri + write FNumberAttri; + property SpaceAttri: TSynHighlighterAttributes read FSpaceAttri + write FSpaceAttri; + property SymbolAttri: TSynHighlighterAttributes read FSymbolAttri + write FSymbolAttri; + property ValueAttri: TSynHighlighterAttributes read FValueAttri + write FValueAttri; + end; + +implementation + +uses +{$IFDEF SYN_CLX} + QSynEditStrConst, Variants; +{$ELSE} + SynEditStrConst; +{$ENDIF} + + +{ TSynJSONSyn } + +constructor TSynJSONSyn.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + + FCaseSensitive := True; + + // Attribute + FAttributeAttri := TSynHighlighterAttributes.Create(SYNS_AttrAttribute, + SYNS_FriendlyAttrAttribute); + FAttributeAttri.Foreground := clNavy; + AddAttribute(FAttributeAttri); + + // reserved words ("true", "false", "null") + FReservedAttri := TSynHighlighterAttributes.Create(SYNS_AttrReservedWord, + SYNS_FriendlyAttrReservedWord); + FReservedAttri.Style := [fsBold]; + AddAttribute(FReservedAttri); + + // numbers + FNumberAttri := TSynHighlighterAttributes.Create(SYNS_AttrNumber, + SYNS_FriendlyAttrNumber); + FNumberAttri.Foreground := clRed; + AddAttribute(FNumberAttri); + + // spaces + FSpaceAttri := TSynHighlighterAttributes.Create(SYNS_AttrSpace, + SYNS_FriendlyAttrSpace); + AddAttribute(FSpaceAttri); + + // symbols + FSymbolAttri := TSynHighlighterAttributes.Create(SYNS_AttrSymbol, + SYNS_FriendlyAttrSymbol); + FSymbolAttri.Foreground := clGreen; + AddAttribute(FSymbolAttri); + + // Value + FValueAttri := TSynHighlighterAttributes.Create(SYNS_AttrValue, + SYNS_FriendlyAttrValue); + FValueAttri.Foreground := clBlue; + AddAttribute(FValueAttri); + + SetAttributesOnChange(DefHighlightChange); + FDefaultFilter := SYNS_FilterJSON; + FRange := rsUnknown; +end; + +procedure TSynJSONSyn.CloseArrayProc; +begin + SymbolProc; + FRange := rsUnknown; +end; + +procedure TSynJSONSyn.CloseObjectProc; +begin + SymbolProc; + FRange := rsUnknown; +end; + +procedure TSynJSONSyn.ColonProc; +begin + SymbolProc; + FRange := rsObjectValue; +end; + +procedure TSynJSONSyn.CommaProc; +begin + SymbolProc; + if FRange = rsObjectValue then + FRange := rsAttribute; +end; + +procedure TSynJSONSyn.CRProc; +begin + FTokenID := tkSpace; + Inc(Run); + if FLine[Run] = #10 then Inc(Run); +end; + +procedure TSynJSONSyn.LFProc; +begin + FTokenID := tkSpace; + Inc(Run); +end; + +procedure TSynJSONSyn.NullProc; +begin + FTokenID := tkNull; + Inc(Run); +end; + +procedure TSynJSONSyn.NumberProc; + + function ExpectDigit: Boolean; + begin + Result := CharInSet(FLine[Run], ['0'..'9']); + while CharInSet(FLine[Run], ['0'..'9']) do + Inc(Run); + end; + +begin + FTokenID := tkNumber; + + if FLine[Run] = '-' then + Inc(Run); + + // ensure that a zero is followed by a dot + if FLine[Run] = '0' then + if FLine[Run + 1] <> '.' then + begin + FTokenID := tkUnknown; + while (FLine[Run] <> #32) and not IsLineEnd(Run) do Inc(Run); + Exit; + end; + + // at least any digit must appear here + if not ExpectDigit then + begin + FTokenID := tkUnknown; + while (FLine[Run] <> #32) and not IsLineEnd(Run) do Inc(Run); + Exit; + end; + + // check for dot + if FLine[Run] = '.' then + begin + // advance + Inc(Run); + + // at least any digit must appear after a dot! + if not ExpectDigit then + begin + FTokenID := tkUnknown; + while (FLine[Run] <> #32) and not IsLineEnd(Run) do Inc(Run); + Exit; + end; + end; + + // check for an exponent + if CharInSet(FLine[Run], ['e', 'E']) then + begin + Inc(Run); + + // allow +/- here + if CharInSet(FLine[Run], ['+', '-']) then + Inc(Run); + + // at least any digit must appear here + if not ExpectDigit then + begin + FTokenID := tkUnknown; + while (FLine[Run] <> #32) and not IsLineEnd(Run) do Inc(Run); + Exit; + end; + end; +end; + +procedure TSynJSONSyn.OpenArrayProc; +begin + SymbolProc; + FRange := rsArrayValue; +end; + +procedure TSynJSONSyn.OpenObjectProc; +begin + SymbolProc; + FRange := rsAttribute; +end; + +procedure TSynJSONSyn.ReservedWordProc; + + procedure SkipToken; + begin + while (FLine[Run] <> #32) and (FLine[Run] <> ',') and not IsLineEnd(Run) do + Inc(Run); + end; + +begin + FTokenID := tkUnknown; + case FLine[Run] of + 'n': + if (FLine[Run + 1] = 'u') and + (FLine[Run + 2] = 'l') and + (FLine[Run + 3] = 'l') then + begin + FTokenID := tkReserved; + Inc(Run, 4); + end + else + SkipToken; + 't': + if (FLine[Run + 1] = 'r') and + (FLine[Run + 2] = 'u') and + (FLine[Run + 3] = 'e') then + begin + FTokenID := tkReserved; + Inc(Run, 4); + end + else + SkipToken; + 'f': + if (FLine[Run + 1] = 'a') and + (FLine[Run + 2] = 'l') and + (FLine[Run + 3] = 's') and + (FLine[Run + 4] = 'e') then + begin + FTokenID := tkReserved; + Inc(Run, 5); + end + else + SkipToken; + else + SkipToken; + end; +end; + +procedure TSynJSONSyn.SpaceProc; +begin + Inc(Run); + FTokenID := tkSpace; + while (FLine[Run] <= #32) and not IsLineEnd(Run) do Inc(Run); +end; + +procedure TSynJSONSyn.StringProc; + + function IsHex(Digit: AnsiChar): Boolean; overload; + begin + Result := CharInSet(Digit, ['0'..'9', 'A'..'F', 'a'..'f']); + end; + + function IsHex(Digit: WideChar): Boolean; overload; + begin + Result := CharInSet(Digit, ['0'..'9', 'A'..'F', 'a'..'f']); + end; + +begin + FTokenID := tkString; + + repeat + Inc(Run); + case FLine[Run] of + '"': + begin + Inc(Run); + Break; + end; + '\': + case FLine[Run + 1] of + '"', '/', '\', 'b', 'f', 'n', 'r', 't': + Inc(Run); + 'u': + begin + Inc(Run); + if not (IsHex(FLine[Run + 1]) and IsHex(FLine[Run + 2]) and + IsHex(FLine[Run + 3]) and IsHex(FLine[Run + 4])) then + begin + // a 4 hex digit is expected + FTokenID := tkUnknown; + while not CharInSet(FLine[Run], [#32, '"']) and not IsLineEnd(Run) do + Inc(Run); + Exit; + end; + Inc(Run, 4); + end; + end; + end; + until IsLineEnd(Run); +end; + +procedure TSynJSONSyn.SymbolProc; +begin + Inc(Run); + FTokenID := tkSymbol; +end; + +procedure TSynJSONSyn.UnknownProc; +begin + Inc(Run); + FTokenID := tkUnknown; +end; + +procedure TSynJSONSyn.Next; +begin + fTokenPos := Run; + case FLine[Run] of + #0: NullProc; + #1..#9, #11, #12, #14..#32: SpaceProc; + #10: LFProc; + #13: CRProc; + '0'..'9', '-': NumberProc; + 't', + 'f', + 'n' : ReservedWordProc; + '"': StringProc; + ':': ColonProc; + '{': OpenObjectProc; + '[': OpenArrayProc; + '}': CloseObjectProc; + ']': CloseArrayProc; + ',' : CommaProc; + else UnknownProc; + end; + + inherited; +end; + +function TSynJSONSyn.GetDefaultAttribute(Index: integer): TSynHighlighterAttributes; +begin + case Index of + SYN_ATTR_KEYWORD: Result := FReservedAttri; + SYN_ATTR_IDENTIFIER: Result := FAttributeAttri; + SYN_ATTR_WHITESPACE: Result := FSpaceAttri; + SYN_ATTR_SYMBOL: Result := FSymbolAttri; + SYN_ATTR_STRING: Result := FValueAttri; + else + Result := nil; + end; +end; + +function TSynJSONSyn.GetEol: Boolean; +begin + Result := Run = fLineLen + 1; +end; + +function TSynJSONSyn.GetRange: Pointer; +begin + Result := Pointer(FRange); +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 := FAttributeAttri; + tkReserved: Result := FReservedAttri; + tkNumber: Result := FNumberAttri; + tkSpace: Result := FSpaceAttri; + tkSymbol: Result := FSymbolAttri; + tkUnknown: Result := FAttributeAttri; + else Result := nil; + end; +end; + +function TSynJSONSyn.GetTokenKind: integer; +begin + Result := Ord(FTokenID); +end; + +procedure TSynJSONSyn.ResetRange; +begin + FRange := rsUnknown; +end; + +procedure TSynJSONSyn.SetRange(Value: Pointer); +begin + FRange := TRangeState(Value); +end; + +function TSynJSONSyn.IsFilterStored: Boolean; +begin + Result := FDefaultFilter <> SYNS_FilterJSON; +end; + +class function TSynJSONSyn.GetLanguageName: string; +begin + Result := SYNS_LangJSON; +end; + +function TSynJSONSyn.GetSampleSource: UnicodeString; +begin + Result := + '{'#13#10 + + ' "firstName": "John",'#13#10 + + ' "lastName": "Smith",'#13#10 + + ' "isAlive": true,'#13#10 + + ' "age": 25,'#13#10 + + ' "height_cm": 167.6,'#13#10 + + ' "address": {'#13#10 + + ' "streetAddress": "21 2nd Street",'#13#10 + + ' "city": "New York",'#13#10 + + ' "state": "NY",'#13#10 + + ' "postalCode": "10021-3100"'#13#10 + + ' },'#13#10 + + ' "phoneNumbers": ['#13#10 + + ' {'#13#10 + + ' "type": "home",'#13#10 + + ' "number": "212 555-1234"'#13#10 + + ' },'#13#10 + + ' {'#13#10 + + ' "type": "office",'#13#10 + + ' "number": "646 555-4567"'#13#10 + + ' }'#13#10 + + ' ],'#13#10 + + ' "face": "\uD83D\uDE02",'#13#10 + + ' "children": [],'#13#10 + + ' "spouse": null'#13#10 + + '}'; +end; + +class function TSynJSONSyn.GetFriendlyLanguageName: UnicodeString; +begin + Result := SYNS_FriendlyLangJSON; +end; + +initialization +{$IFNDEF SYN_CPPB_1} + RegisterPlaceableHighlighter(TSynJSONSyn); +{$ENDIF} +end. diff --git a/components/synedit/Source/SynHighlighterLLVM.pas b/components/synedit/Source/SynHighlighterLLVM.pas index 83b4954e..660d75c0 100644 --- a/components/synedit/Source/SynHighlighterLLVM.pas +++ b/components/synedit/Source/SynHighlighterLLVM.pas @@ -9,9 +9,9 @@ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Code template generated with SynGen. -The original code is: C:\Users\Public\Code\SynEdit\SynGen\LLVM_IR.pas, released 2013-03-30. +The original code is: SynHighlighterLLVM.pas, released 2013-03-30. Description: Syntax Parser/Highlighter -The initial author of this file is Christian. +The initial author of this file is Christian-W. Budde. Copyright (c) 2013, all rights reserved. Contributors to the SynEdit and mwEdit projects are listed in the @@ -165,15 +165,6 @@ uses SynEditStrConst; {$ENDIF} -resourcestring - SYNS_FilterLLVMIR = 'LLVM IR files (*.ll)|*.ll'; - SYNS_LangLLVMIR = 'LLVM IR'; - SYNS_FriendlyLangLLVMIR = 'LLVM Intermediate Representation'; - SYNS_AttrConstant = 'Constant'; - SYNS_FriendlyAttrConstant = 'Constant'; - SYNS_AttrInstructions = 'Instructions'; - SYNS_FriendlyAttrInstructions = 'Instructions'; - const // as this language is case-insensitive keywords *must* be in lowercase KeyWords: array[0..216] of UnicodeString = ( diff --git a/components/synedit/Source/SynHighlighterMulti.pas b/components/synedit/Source/SynHighlighterMulti.pas index 74fb1c47..af5b3eaa 100644 --- a/components/synedit/Source/SynHighlighterMulti.pas +++ b/components/synedit/Source/SynHighlighterMulti.pas @@ -66,7 +66,7 @@ uses type TOnCheckMarker = procedure (Sender: TObject; var StartPos, MarkerLen: Integer; - var MarkerText: UnicodeString; Line: Integer) of object; + var MarkerText: UnicodeString; Line: Integer; const LineStr: string) of object; TScheme = class(TCollectionItem) private @@ -200,7 +200,8 @@ type function GetMarkers(Index: Integer): TMarker; property Markers[Index: Integer]: TMarker read GetMarkers; procedure DoCheckMarker(Scheme:TScheme; StartPos, MarkerLen: Integer; - const MarkerText: UnicodeString; Start: Boolean; Line: Integer); + const MarkerText: UnicodeString; Start: Boolean; Line: Integer; + const LineStr: string); procedure SetOnCustomRange(const Value: TCustomRangeEvent); protected fSchemes: TSchemes; @@ -662,7 +663,8 @@ begin end; procedure TSynMultiSyn.DoCheckMarker(Scheme:TScheme; StartPos, MarkerLen: Integer; - const MarkerText: UnicodeString; Start: Boolean; Line: Integer); + const MarkerText: UnicodeString; Start: Boolean; Line: Integer; + const LineStr: string); var aStartPos: Integer; aMarkerLen: Integer; @@ -672,9 +674,9 @@ begin aMarkerLen := MarkerLen; aMarkerText := MarkerText; if Start and Assigned(Scheme.OnCheckStartMarker) then - Scheme.OnCheckStartMarker(Self, aStartPos, aMarkerLen, aMarkerText, Line) + Scheme.OnCheckStartMarker(Self, aStartPos, aMarkerLen, aMarkerText, Line, LineStr) else if not Start and Assigned(Scheme.OnCheckEndMarker) then - Scheme.OnCheckEndMarker(Self, aStartPos, aMarkerLen, aMarkerText, Line); + Scheme.OnCheckEndMarker(Self, aStartPos, aMarkerLen, aMarkerText, Line, LineStr); if (aMarkerText <> '') and (aMarkerLen > 0) then begin fMarkers.Add(TMarker.Create(Scheme.Index, aStartPos, aMarkerLen, Start, @@ -907,7 +909,7 @@ begin begin iExpr := Copy(Value, iParser.MatchPos[0] + iEaten, iParser.MatchLen[0]); DoCheckMarker(iScheme, iParser.MatchPos[0] + iEaten, iParser.MatchLen[0], - iExpr, False, LineNumber); + iExpr, False, LineNumber, Value); Delete(iLine, 1, iParser.MatchPos[0] - 1 + iParser.MatchLen[0]); Inc(iEaten, iParser.MatchPos[0] - 1 + iParser.MatchLen[0]); iScheme := nil; @@ -930,7 +932,7 @@ begin if iParser.Exec(iLine) then begin iExpr := Copy(Value, iParser.MatchPos[0] + iEaten, iParser.MatchLen[0]); DoCheckMarker(iScheme, iParser.MatchPos[0] + iEaten, iParser.MatchLen[0], - iExpr, True, LineNumber); + iExpr, True, LineNumber, Value); Delete(iLine, 1, iParser.MatchPos[0] - 1 + iParser.MatchLen[0]); Inc(iEaten, iParser.MatchPos[0] - 1 + iParser.MatchLen[0]); break; diff --git a/components/synedit/Source/SynHighlighterPython.pas b/components/synedit/Source/SynHighlighterPython.pas index 76449617..62dd0323 100644 --- a/components/synedit/Source/SynHighlighterPython.pas +++ b/components/synedit/Source/SynHighlighterPython.pas @@ -1,4 +1,4 @@ -{------------------------------------------------------------------------------- +{------------------------------------------------------------------------------- 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 @@ -13,7 +13,7 @@ The Original Code is based on the odPySyn.pas file from the mwEdit component suite by Martin Waldenburg and other developers, the Initial Author of this file is Olivier Deckmyn. Portions created by M.Utku Karatas and Dennis Chuah. -Unicode translation by Maël Hörz. +Unicode translation by Maël Hörz. All Rights Reserved. Contributors to the SynEdit and mwEdit projects are listed in the @@ -186,10 +186,11 @@ const // No need to localise keywords! // List of keywords - KEYWORDCOUNT = 29; + KEYWORDCOUNT = 32; KEYWORDS: array [1..KEYWORDCOUNT] of UnicodeString = ( 'and', + 'as', 'assert', 'break', 'class', @@ -209,6 +210,7 @@ const 'in', 'is', 'lambda', + 'nonlocal', 'not', 'or', 'pass', @@ -217,6 +219,7 @@ const 'return', 'try', 'while', + 'with', 'yield' ); @@ -342,6 +345,10 @@ begin (MayBe[fStringLen - 3] <> '_') then Result := tkSystemDefined + // Check for names of class and functions - not optimal + else if ( (WideCompareStr(Trim(Copy(fLine, 0, Length(fLine) - Length(fToIdent))), 'def')=0) or (WideCompareStr(Trim(Copy(fLine, 0, Length(fLine) - Length(fToIdent))), 'class')=0) ) then + Result := tkSystemDefined + // Else, hey, it is an ordinary run-of-the-mill identifier! else Result := tkIdentifier; @@ -357,6 +364,8 @@ begin FKeywords.Sorted := True; FKeywords.Duplicates := dupError; FKeywords.Assign (GetKeywordIdentifiers); + if not FKeywords.Sorted then + FKeywords.Sort; fRange := rsUnknown; fCommentAttri := TSynHighlighterAttributes.Create(SYNS_AttrComment, SYNS_FriendlyAttrComment); diff --git a/components/synedit/Source/SynHighlighterSQL.pas b/components/synedit/Source/SynHighlighterSQL.pas index f71745c0..fcd81e4e 100644 --- a/components/synedit/Source/SynHighlighterSQL.pas +++ b/components/synedit/Source/SynHighlighterSQL.pas @@ -1320,8 +1320,6 @@ begin end; procedure TSynSQLSyn.AsciiCharProc; -var - IsEsc: Boolean; begin // Oracle SQL allows strings to go over multiple lines if fLine[Run] = #0 then @@ -1346,18 +1344,12 @@ begin end else begin - IsEsc := False; if (Run > 0) or (fRange <> rsString) or ((fLine[Run] <> #39) and (fLine[Run - 1] <> '\')) then begin fRange := rsString; repeat - if fLine[Run] = '\' then - IsEsc := not IsEsc - else - IsEsc := False; - - if (not IsEsc) and (fLine[Run + 1] = #39) then + if (fLine[Run] <> '\') and (fLine[Run + 1] = #39) then begin Inc(Run); break; @@ -1365,7 +1357,7 @@ begin Inc(Run); until IsLineEnd(Run); end; - if (fLine[Run] = #39) and (not IsEsc) then + if (fLine[Run] = #39) and not(fLine[Run-1] = '\') then begin Inc(Run); fRange := rsUnknown; diff --git a/components/synedit/Source/SynRegExpr.pas b/components/synedit/Source/SynRegExpr.pas index e528b638..00097008 100644 --- a/components/synedit/Source/SynRegExpr.pas +++ b/components/synedit/Source/SynRegExpr.pas @@ -1296,9 +1296,7 @@ var AModifiersInt : integer) : boolean; begin Result := true; IsOn := true; -{$IFDEF CPUX86} Mask := 0; // prevent compiler warning -{$ENDIF} for i := 1 to length (AModifiers) do if AModifiers [i] = '-' then IsOn := false diff --git a/components/synedit/Source/SynUnicode.pas b/components/synedit/Source/SynUnicode.pas index 603e0957..fa8be136 100644 --- a/components/synedit/Source/SynUnicode.pas +++ b/components/synedit/Source/SynUnicode.pas @@ -954,7 +954,15 @@ begin System.Move(ByteOrderMask[0], SA[1], BytesRead); // max 6 bytes = 6 chars if Size > BytesRead then Stream.Read(SA[7], Size - BytesRead); // first 6 chars were copied by System.Move + SW := UTF8Decode(SA); + if SW <> '' then + begin + FSaveFormat := sfUTF8; + SetTextStr(SW); + Loaded := True; + end; end; + if not Loaded then SetTextStr(SA); end; finally @@ -1003,6 +1011,18 @@ begin end; end; +procedure TUnicodeStrings.SaveToFile(const FileName: TFileName; WithBOM: Boolean); +var + Stream: TStream; +begin + Stream := TFileStream.Create(FileName, fmCreate); + try + SaveToStream(Stream, WithBOM); + finally + Stream.Free; + end; +end; + procedure TUnicodeStrings.SaveToStream(Stream: TStream; WithBOM: Boolean = True); // Saves the currently loaded text into the given stream. WithBOM determines whether to write a // byte order mark or not. Note: when saved as ANSI text there will never be a BOM. @@ -3162,7 +3182,7 @@ var if (Length(BOM) <> Length(UTF8BOM)) or not CompareMem(@BOM[0], @UTF8BOM[0], Length(UTF8BOM)) then - Stream.Seek(-Length(BOM), soCurrent) + Stream.Seek(-Length(BOM), soFromCurrent) else Result := True; end; @@ -3173,7 +3193,7 @@ var if (Length(BOM) <> Length(UTF16BOMLE)) or not CompareMem(@BOM[0], @UTF16BOMLE[0], Length(UTF16BOMLE)) then - Stream.Seek(-Length(BOM), soCurrent) + Stream.Seek(-Length(BOM), soFromCurrent) else Result := True; end; @@ -3184,7 +3204,7 @@ var if (Length(BOM) <> Length(UTF16BOMBE)) or not CompareMem(@BOM[0], @UTF16BOMBE[0], Length(UTF16BOMBE)) then - Stream.Seek(-Length(BOM), soCurrent) + Stream.Seek(-Length(BOM), soFromCurrent) else Result := True; end;