diff --git a/components/synedit/Packages/Delphi10.4/SynEdit_R.dpk b/components/synedit/Packages/Delphi10.4/SynEdit_R.dpk index 7b260063..47a8dfb8 100644 --- a/components/synedit/Packages/Delphi10.4/SynEdit_R.dpk +++ b/components/synedit/Packages/Delphi10.4/SynEdit_R.dpk @@ -90,6 +90,7 @@ contains SynHighlighterDml in '..\..\Source\SynHighlighterDml.pas', SynHighlighterDOT in '..\..\Source\SynHighlighterDOT.pas', SynHighlighterDWS in '..\..\Source\SynHighlighterDWS.pas', + SynHighlighterECMAScript in '..\..\Source\SynHighlighterECMAScript.pas', SynHighlighterEiffel in '..\..\Source\SynHighlighterEiffel.pas', SynHighlighterFortran in '..\..\Source\SynHighlighterFortran.pas', SynHighlighterFoxpro in '..\..\Source\SynHighlighterFoxpro.pas', diff --git a/components/synedit/Packages/Delphi10.4/SynEdit_R.dproj b/components/synedit/Packages/Delphi10.4/SynEdit_R.dproj index 23a9074e..fabb0199 100644 --- a/components/synedit/Packages/Delphi10.4/SynEdit_R.dproj +++ b/components/synedit/Packages/Delphi10.4/SynEdit_R.dproj @@ -156,6 +156,7 @@ + diff --git a/components/synedit/Source/SynCompletionProposal.pas b/components/synedit/Source/SynCompletionProposal.pas index 8d6bdf2c..1fa39cd5 100644 --- a/components/synedit/Source/SynCompletionProposal.pas +++ b/components/synedit/Source/SynCompletionProposal.pas @@ -45,7 +45,7 @@ Known Issues: unit SynCompletionProposal; {$ENDIF} -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynEdit.pas b/components/synedit/Source/SynEdit.pas index 82ea79ea..38593381 100644 --- a/components/synedit/Source/SynEdit.pas +++ b/components/synedit/Source/SynEdit.pas @@ -110,6 +110,21 @@ const SYNEDIT_CLIPBOARD_FORMAT = 'SynEdit Control Block Type'; + // Reconversion string. + IMR_COMPOSITIONWINDOW = $0001; + IMR_CANDIDATEWINDOW = $0002; + IMR_COMPOSITIONFONT = $0003; + IMR_RECONVERTSTRING = $0004; + IMR_CONFIRMRECONVERTSTRING = $0005; + IMR_QUERYCHARPOSITION = $0006; + IMR_DOCUMENTFEED = $0007; + + SCS_SETSTR = GCS_COMPREADSTR or GCS_COMPSTR; + SCS_CHANGEATTR = GCS_COMPREADATTR or GCS_COMPATTR; + SCS_CHANGECLAUSE = GCS_COMPREADCLAUSE or GCS_COMPCLAUSE; + SCS_SETRECONVERTSTRING = $00010000; + SCS_QUERYRECONVERTSTRING = $00020000; + var SynEditClipboardFormat: UINT; @@ -342,6 +357,20 @@ type FindText: UnicodeString) of object; {$ENDIF} + // Reconversion string. + PReconvertString = ^TReconvertString; + TReconvertString = record + dwSize: DWord; + dwVersion: DWord; + dwStrLen: DWord; + dwStrOffset: DWord; + dwCompStrLen: DWord; + dwCompStrOffset: DWord; + dwTargetStrLen: DWord; + dwTargetStrOffset: DWord; + end; + + TCustomSynEdit = class(TCustomControl) private procedure CMHintShow(var Msg: TMessage); message CM_HINTSHOW; @@ -363,6 +392,7 @@ type procedure WMImeChar(var Msg: TMessage); message WM_IME_CHAR; procedure WMImeComposition(var Msg: TMessage); message WM_IME_COMPOSITION; procedure WMImeNotify(var Msg: TMessage); message WM_IME_NOTIFY; + procedure WMImeRequest(var Message: TMessage); message WM_IME_REQUEST; procedure WMKillFocus(var Msg: TWMKillFocus); message WM_KILLFOCUS; procedure WMSetCursor(var Msg: TWMSetCursor); message WM_SETCURSOR; procedure WMSetFocus(var Msg: TWMSetFocus); message WM_SETFOCUS; @@ -4925,6 +4955,7 @@ var vCaretDisplay: TDisplayCoord; vCaretPix: TPoint; cf: TCompositionForm; + vSelStartPix: TPoint; begin if (PaintLock <> 0) or not (Focused or FAlwaysShowCaret) then Include(FStateFlags, sfCaretChanged) @@ -4950,9 +4981,17 @@ begin SetCaretPos(CX, CY); HideCaret; end; - cf.dwStyle := CFS_POINT; - cf.ptCurrentPos := Point(CX, CY); - ImmSetCompositionWindow(ImmGetContext(Handle), @cf); + if (Self.SelAvail = False) then + begin + cf.dwStyle := CFS_POINT; + cf.ptCurrentPos := Point(CX, CY); + ImmSetCompositionWindow(ImmGetContext(Handle), @cf); + end + else + begin + vSelStartPix := Self.RowColumnToPixels(BufferToDisplayPos(Self.BlockBegin)); + Self.SetImeCompositionWindow(Self.Font, vSelStartPix.X, vSelStartPix.Y); + end; end; end; @@ -5434,6 +5473,113 @@ begin inherited; end; +procedure TCustomSynEdit.WMImeRequest(var Message: TMessage); +var + pReconvert: PReconvertString; + TargetText: string; + TargetByteLength: Integer; + pTarget: PChar; + H: HIMC; +begin + case Message.WParam of + IMR_RECONVERTSTRING: + begin + // Reconversion string + if (Self.SelLength <> 0) then + begin + TargetText := Self.SelText; + end + else + begin + if (Self.Lines.Count >= Self.CaretY - 1) then + TargetText := Self.Lines[Self.CaretY - 1] + else + TargetText := ''; + end; + TargetByteLength := Length(TargetText) * sizeof(Char); + + if (Message.LParam = 0) then + begin + // 1st time (get buffer size (bytes)) + // Select only one row + if (Self.BlockBegin.Line = Self.BlockEnd.Line) then + Message.Result := Sizeof(TReconvertString) + TargetByteLength + else + Message.Result := 0; + end + else + begin + // 2nd time + pReconvert := Pointer(Message.LParam); + pReconvert.dwSize := Sizeof(TReconvertString); + pReconvert.dwVersion := 0; + pReconvert.dwStrLen := Length(TargetText); + pReconvert.dwStrOffset := Sizeof(TReconvertString); + + pTarget := Pointer(Message.LParam + Sizeof(TReconvertString)); + move(TargetText[1], pTarget^, TargetByteLength); + + if (Self.SelLength <> 0) then + begin + pReconvert.dwTargetStrLen := 0; + pReconvert.dwTargetStrOffset := 0; + pReconvert.dwCompStrLen := Length(TargetText); + pReconvert.dwCompStrOffset := 0; + end + else + begin + pReconvert.dwTargetStrLen := 0; + pReconvert.dwTargetStrOffset := (Self.CaretX - 1) * sizeof(Char); + H := Imm32GetContext(Handle); + try + ImmSetCompositionString(H, SCS_QUERYRECONVERTSTRING, pReconvert, Sizeof(TReconvertString) + TargetByteLength, nil, 0); + if (pReconvert.dwCompStrLen <> 0) then + begin + Self.CaretX := pReconvert.dwCompStrOffset div sizeof(Char) + 1; + Self.SelStart := RowColToCharIndex(Self.CaretXY); + Self.SelLength := pReconvert.dwCompStrLen; + end; + finally + Imm32ReleaseContext(Handle, H); + end; + end; + Message.Result := Sizeof(TReconvertString) + TargetByteLength; + end; + end; + IMR_DOCUMENTFEED: + begin + // Notifies an application when the selected IME needs the converted string from the application. + if (Self.Lines.Count >= Self.CaretY) then + TargetText := Self.Lines[Self.CaretY] + else + TargetText := ''; + if (Message.LParam = 0) then + begin + // 1st time (get line size (bytes)) + Message.Result := Sizeof(TReconvertString) + Length(TargetText) * sizeof(Char); + end + else + begin + // 2nd time + pReconvert := Pointer(Message.LParam); + pReconvert.dwSize := Sizeof(TReconvertString); + pReconvert.dwVersion := 0; + pReconvert.dwStrLen := Length(TargetText); + pReconvert.dwStrOffset := Sizeof(TReconvertString); + pReconvert.dwCompStrLen := 0; + pReconvert.dwCompStrOffset := 0; + pReconvert.dwTargetStrLen := 0; + pReconvert.dwTargetStrOffset := (Self.CaretX - 1) * sizeof(Char); + + pTarget := Pointer(Message.LParam + Sizeof(TReconvertString)); + move(TargetText[1], pTarget^, Length(TargetText) * sizeof(Char)); + + Message.Result := Sizeof(TReconvertString) + Length(TargetText) * sizeof(Char); + end; + end; + end; +end; + procedure TCustomSynEdit.WMKillFocus(var Msg: TWMKillFocus); begin inherited; @@ -8172,11 +8318,13 @@ begin begin BeginUndoBlock; try - FUndoList.AddChange(crDelete, FBlockBegin, FBlockEnd, Helper, + FUndoList.AddChange(crDelete, FBlockBegin, FBlockEnd, SelText, smNormal); - StartOfBlock := FBlockBegin; + StartOfBlock := BlockBegin; + EndOfBlock.Line := BlockBegin.Line; + EndOfBlock.Char := BlockBegin.Char + Length(s); SetSelTextPrimitive(s); - FUndoList.AddChange(crInsert, FBlockBegin, FBlockEnd, Helper, + FUndoList.AddChange(crInsert, StartOfBlock, EndOfBlock, '', smNormal); finally EndUndoBlock; diff --git a/components/synedit/Source/SynEditCodeFolding.pas b/components/synedit/Source/SynEditCodeFolding.pas index f19038d9..e9228bed 100644 --- a/components/synedit/Source/SynEditCodeFolding.pas +++ b/components/synedit/Source/SynEditCodeFolding.pas @@ -106,7 +106,7 @@ unit SynEditCodeFolding; } interface -{$I SynEdit.Inc} +{$I SynEdit.inc} uses Graphics, diff --git a/components/synedit/Source/SynEditHighlighter.pas b/components/synedit/Source/SynEditHighlighter.pas index 112b9db8..b74ebcf4 100644 --- a/components/synedit/Source/SynEditHighlighter.pas +++ b/components/synedit/Source/SynEditHighlighter.pas @@ -29,7 +29,7 @@ Known Issues: unit SynEditHighlighter; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynEditKbdHandler.pas b/components/synedit/Source/SynEditKbdHandler.pas index c78c0e51..ed8711e8 100644 --- a/components/synedit/Source/SynEditKbdHandler.pas +++ b/components/synedit/Source/SynEditKbdHandler.pas @@ -161,6 +161,8 @@ end; constructor TSynEditKbdHandler.Create; begin + inherited; + { Elements to handle KeyDown-Events } FKeyDownChain := TMethodList.Create; @@ -355,12 +357,16 @@ end; constructor TMethodList.Create; begin + inherited; + FData := TList.Create; end; destructor TMethodList.Destroy; begin FData.Free; + + inherited; end; function TMethodList.GetCount: Integer; diff --git a/components/synedit/Source/SynEditOptionsDialog.pas b/components/synedit/Source/SynEditOptionsDialog.pas index 1648314c..680c0335 100644 --- a/components/synedit/Source/SynEditOptionsDialog.pas +++ b/components/synedit/Source/SynEditOptionsDialog.pas @@ -40,7 +40,7 @@ Known Issues: unit SynEditOptionsDialog; {$ENDIF} -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynEditPrint.pas b/components/synedit/Source/SynEditPrint.pas index 485729d7..4f69680c 100644 --- a/components/synedit/Source/SynEditPrint.pas +++ b/components/synedit/Source/SynEditPrint.pas @@ -87,7 +87,7 @@ unit SynEditPrint; {$ENDIF} {$M+} -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynEditReg.dcr b/components/synedit/Source/SynEditReg.dcr index 71104456..b5f15015 100644 Binary files a/components/synedit/Source/SynEditReg.dcr and b/components/synedit/Source/SynEditReg.dcr differ diff --git a/components/synedit/Source/SynEditReg.pas b/components/synedit/Source/SynEditReg.pas index 3466c10e..6b054cfe 100644 --- a/components/synedit/Source/SynEditReg.pas +++ b/components/synedit/Source/SynEditReg.pas @@ -87,6 +87,7 @@ uses {$ifdef SYN_DELPHI_2009_UP} SynHighlighterDWS, {$endif} + SynHighlighterECMAScript, SynHighlighterEiffel, SynHighlighterFortran, SynHighlighterFoxpro, @@ -182,7 +183,7 @@ begin TSynM3Syn, TSynPasSyn, TSynVBSyn, TSynCobolSyn, TSynCSSyn, TSynGoSyn, // internet TSynCssSyn, TSynHTMLSyn, TSynJScriptSyn, TSynPHPSyn, TSynVBScriptSyn, - TSynXMLSyn, TSynJSONSyn, TSynVrml97Syn, + TSynXMLSyn, TSynJSONSyn, TSynVrml97Syn, TSynECMAScriptSyn, //interpreted TSynAWKSyn, TSynBATSyn, {$ifdef SYN_DELPHI_2009_UP} diff --git a/components/synedit/Source/SynEditSearch.pas b/components/synedit/Source/SynEditSearch.pas index b27bd807..4d2613b6 100644 --- a/components/synedit/Source/SynEditSearch.pas +++ b/components/synedit/Source/SynEditSearch.pas @@ -40,7 +40,7 @@ Known Issues: unit SynEditSearch; {$ENDIF} -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynEditStrConst.pas b/components/synedit/Source/SynEditStrConst.pas index 8e342d0c..441e6e9b 100644 --- a/components/synedit/Source/SynEditStrConst.pas +++ b/components/synedit/Source/SynEditStrConst.pas @@ -219,6 +219,7 @@ const SYNS_LangCSS = 'CascadingStyleSheet'; SYNS_LangDfm = 'BorlandForms'; SYNS_LangDOT = 'DOT_Graph_Drawing_Description_language'; + SYNS_LangECMAScript = 'ECMAScript'; SYNS_LangEiffel = 'Eiffel'; SYNS_LangFortran = 'Fortran'; SYNS_LangFoxpro = 'Foxpro'; @@ -459,6 +460,7 @@ resourcestring SYNS_FilterDFM = 'Borland Form Files (*.dfm;*.xfm)|*.dfm;*.xfm'; SYNS_FilterDOT = 'DOT Graph Drawing Description (*.dot)|*.dot'; SYNS_FilterDWS = 'DWScript Files (*.dws;*.pas;*.inc)|*.dws;*.pas;*.inc'; + SYNS_FilterEcmaScript = 'Javascript Files (*.js)|*.js'; SYNS_FilterEiffel = 'Eiffel (*.e;*.ace)|*.e;*.ace'; SYNS_FilterFortran = 'Fortran Files (*.for)|*.for'; SYNS_FilterFoxpro = 'Foxpro Files (*.prg)|*.prg'; @@ -519,6 +521,7 @@ resourcestring SYNS_FriendlyLangCSS = 'Cascading Style Sheet'; SYNS_FriendlyLangDfm = 'Borland Forms'; SYNS_FriendlyLangDOT = 'DOT Graph Drawing Description language'; + SYNS_FriendlyLangEcmaScript = 'ECMA Script'; SYNS_FriendlyLangEiffel = 'Eiffel'; SYNS_FriendlyLangFortran = 'Fortran'; SYNS_FriendlyLangFoxpro = 'Foxpro'; @@ -535,6 +538,7 @@ resourcestring SYNS_FriendlyLangINI = 'INI'; SYNS_FriendlyLangInno = 'Inno Setup Script'; SYNS_FriendlyLangJava = 'Java'; + SYNS_FriendlyLangJavaScript = 'JavaScript'; SYNS_FriendlyLangJScript = 'JavaScript'; SYNS_FriendlyLangJSON = 'JSON'; SYNS_FriendlyLangKIX = 'KiXtart'; diff --git a/components/synedit/Source/SynHighlighterADSP21xx.pas b/components/synedit/Source/SynHighlighterADSP21xx.pas index c5596a39..8d0ea515 100644 --- a/components/synedit/Source/SynHighlighterADSP21xx.pas +++ b/components/synedit/Source/SynHighlighterADSP21xx.pas @@ -45,7 +45,7 @@ The SynHighlighterADSP21xx unit provides a ADSP21xx DSP assembler highlighter fo unit SynHighlighterADSP21xx; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterAWK.pas b/components/synedit/Source/SynHighlighterAWK.pas index 9e02104c..6cfe3c31 100644 --- a/components/synedit/Source/SynHighlighterAWK.pas +++ b/components/synedit/Source/SynHighlighterAWK.pas @@ -47,7 +47,7 @@ unit SynHighlighterAWK; interface -{$I SynEdit.Inc} +{$I SynEdit.inc} uses Graphics, diff --git a/components/synedit/Source/SynHighlighterAsm.pas b/components/synedit/Source/SynHighlighterAsm.pas index 085ca6d9..c2d54e3a 100644 --- a/components/synedit/Source/SynHighlighterAsm.pas +++ b/components/synedit/Source/SynHighlighterAsm.pas @@ -47,7 +47,7 @@ Thanks to Martin Waldenburg, Hideo Koiso. unit SynHighlighterAsm; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterAsmMASM.pas b/components/synedit/Source/SynHighlighterAsmMASM.pas index 250bba32..80cdf42a 100644 --- a/components/synedit/Source/SynHighlighterAsmMASM.pas +++ b/components/synedit/Source/SynHighlighterAsmMASM.pas @@ -49,7 +49,7 @@ compile externally until I move the API functions externally into JSON file. unit SynHighlighterAsmMASM; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterBaan.pas b/components/synedit/Source/SynHighlighterBaan.pas index 241e8cfb..ca20bf31 100644 --- a/components/synedit/Source/SynHighlighterBaan.pas +++ b/components/synedit/Source/SynHighlighterBaan.pas @@ -46,7 +46,7 @@ Thanks to Martin Waldenburg. unit SynHighlighterBaan; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterBat.pas b/components/synedit/Source/SynHighlighterBat.pas index 2a00ed8d..83dc21b9 100644 --- a/components/synedit/Source/SynHighlighterBat.pas +++ b/components/synedit/Source/SynHighlighterBat.pas @@ -46,7 +46,7 @@ The highlighter supports the formatting of keywords and parameters (batch file a unit SynHighlighterBat; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterCAC.pas b/components/synedit/Source/SynHighlighterCAC.pas index 914cb868..d111af34 100644 --- a/components/synedit/Source/SynHighlighterCAC.pas +++ b/components/synedit/Source/SynHighlighterCAC.pas @@ -46,7 +46,7 @@ Thanks to Primoz Gabrijelcic, Andy Jeffries. unit SynHighlighterCAC; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterCPM.pas b/components/synedit/Source/SynHighlighterCPM.pas index 2ae66898..079ede1d 100644 --- a/components/synedit/Source/SynHighlighterCPM.pas +++ b/components/synedit/Source/SynHighlighterCPM.pas @@ -35,7 +35,7 @@ located at http://SynEdit.SourceForge.net unit SynHighlighterCPM; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterCS.pas b/components/synedit/Source/SynHighlighterCS.pas index 8ae9c64b..1a9a7adb 100644 --- a/components/synedit/Source/SynHighlighterCS.pas +++ b/components/synedit/Source/SynHighlighterCS.pas @@ -51,7 +51,7 @@ Based on SynHighlighterCpp.pas unit SynHighlighterCS; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterCache.pas b/components/synedit/Source/SynHighlighterCache.pas index 3db98c28..003e5af2 100644 --- a/components/synedit/Source/SynHighlighterCache.pas +++ b/components/synedit/Source/SynHighlighterCache.pas @@ -46,7 +46,7 @@ Thanks to Martin Waldenburg. unit SynHighlighterCache; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterCobol.pas b/components/synedit/Source/SynHighlighterCobol.pas index ae3723a5..7156a7f2 100644 --- a/components/synedit/Source/SynHighlighterCobol.pas +++ b/components/synedit/Source/SynHighlighterCobol.pas @@ -38,7 +38,7 @@ located at http://SynEdit.SourceForge.net unit SynHighlighterCobol; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterCpp.pas b/components/synedit/Source/SynHighlighterCpp.pas index 1503103c..3ff4f3e2 100644 --- a/components/synedit/Source/SynHighlighterCpp.pas +++ b/components/synedit/Source/SynHighlighterCpp.pas @@ -46,7 +46,7 @@ Thanks to Martin Waldenburg. unit SynHighlighterCpp; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterCss.pas b/components/synedit/Source/SynHighlighterCss.pas index 444a1280..d0a41711 100644 --- a/components/synedit/Source/SynHighlighterCss.pas +++ b/components/synedit/Source/SynHighlighterCss.pas @@ -53,7 +53,7 @@ ashley@ashleybrown.co.uk unit SynHighlighterCSS; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterDOT.pas b/components/synedit/Source/SynHighlighterDOT.pas index 1cba7ab2..72d8b59e 100644 --- a/components/synedit/Source/SynHighlighterDOT.pas +++ b/components/synedit/Source/SynHighlighterDOT.pas @@ -45,7 +45,7 @@ The highlighter formats DOT source code ref.: http://www.research.att.com/sw/too unit SynHighlighterDOT; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterDfm.pas b/components/synedit/Source/SynHighlighterDfm.pas index c75b6ee8..2e2d1409 100644 --- a/components/synedit/Source/SynHighlighterDfm.pas +++ b/components/synedit/Source/SynHighlighterDfm.pas @@ -46,7 +46,7 @@ The highlighter formats form source code similar to when forms are viewed as tex unit SynHighlighterDfm; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterDml.pas b/components/synedit/Source/SynHighlighterDml.pas index 3601f9d6..505ae200 100644 --- a/components/synedit/Source/SynHighlighterDml.pas +++ b/components/synedit/Source/SynHighlighterDml.pas @@ -46,7 +46,7 @@ The SynHighlighterDml unit provides SynEdit with a Dml highlighter. unit SynHighlighterDml; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterEiffel.pas b/components/synedit/Source/SynHighlighterEiffel.pas index a40202a9..46ba345b 100644 --- a/components/synedit/Source/SynHighlighterEiffel.pas +++ b/components/synedit/Source/SynHighlighterEiffel.pas @@ -44,7 +44,7 @@ The SynHighlighterEiffel unit provides SynEdit with an Eiffel highlighter. unit SynHighlighterEiffel; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterFortran.pas b/components/synedit/Source/SynHighlighterFortran.pas index 2cc4e7cd..e27f727a 100644 --- a/components/synedit/Source/SynHighlighterFortran.pas +++ b/components/synedit/Source/SynHighlighterFortran.pas @@ -46,7 +46,7 @@ Thanks to Martin Waldenburg. unit SynHighlighterFortran; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterFoxpro.pas b/components/synedit/Source/SynHighlighterFoxpro.pas index 7fd76f7c..fc5dc0ab 100644 --- a/components/synedit/Source/SynHighlighterFoxpro.pas +++ b/components/synedit/Source/SynHighlighterFoxpro.pas @@ -46,7 +46,7 @@ Thanks to Martin Waldenburg. unit SynHighlighterFoxpro; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterGLSL.pas b/components/synedit/Source/SynHighlighterGLSL.pas index b62f7f66..18312258 100644 --- a/components/synedit/Source/SynHighlighterGLSL.pas +++ b/components/synedit/Source/SynHighlighterGLSL.pas @@ -46,7 +46,7 @@ Thanks to Martin Waldenburg. unit SynHighlighterGLSL; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterGWS.pas b/components/synedit/Source/SynHighlighterGWS.pas index e54341f2..94335ca5 100644 --- a/components/synedit/Source/SynHighlighterGWS.pas +++ b/components/synedit/Source/SynHighlighterGWS.pas @@ -39,7 +39,7 @@ unit SynHighlighterGWS; { This unit provides a syntax highlighter for GW-TEL Scripts } -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterGalaxy.pas b/components/synedit/Source/SynHighlighterGalaxy.pas index dae1cd88..5ea4ecf6 100644 --- a/components/synedit/Source/SynHighlighterGalaxy.pas +++ b/components/synedit/Source/SynHighlighterGalaxy.pas @@ -47,7 +47,7 @@ The keywords in the string list KeyWords have to be in lowercase and sorted. unit SynHighlighterGalaxy; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterGeneral.pas b/components/synedit/Source/SynHighlighterGeneral.pas index 2e5d2b85..4eb6666f 100644 --- a/components/synedit/Source/SynHighlighterGeneral.pas +++ b/components/synedit/Source/SynHighlighterGeneral.pas @@ -46,7 +46,7 @@ The SynHighlighterGeneral unit provides a customizable highlighter for SynEdit. unit SynHighlighterGeneral; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterHC11.pas b/components/synedit/Source/SynHighlighterHC11.pas index c9904fed..1aae4ab6 100644 --- a/components/synedit/Source/SynHighlighterHC11.pas +++ b/components/synedit/Source/SynHighlighterHC11.pas @@ -47,7 +47,7 @@ Thanks to Martin Waldenburg, David Muir, Hideo Koiso and Nick Hoddinott. unit SynHighlighterHC11; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterHP48.pas b/components/synedit/Source/SynHighlighterHP48.pas index 5f756eb7..688eb1ed 100644 --- a/components/synedit/Source/SynHighlighterHP48.pas +++ b/components/synedit/Source/SynHighlighterHP48.pas @@ -45,7 +45,7 @@ The unit SynHighlighterHP48 provides SynEdit with a HP48 assembler highlighter. unit SynHighlighterHP48; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterHaskell.pas b/components/synedit/Source/SynHighlighterHaskell.pas index d1ddeda5..ce173269 100644 --- a/components/synedit/Source/SynHighlighterHaskell.pas +++ b/components/synedit/Source/SynHighlighterHaskell.pas @@ -51,7 +51,7 @@ ashley@ashleybrown.co.uk unit SynHighlighterHaskell; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterHtml.pas b/components/synedit/Source/SynHighlighterHtml.pas index 4a4b9905..76dc679b 100644 --- a/components/synedit/Source/SynHighlighterHtml.pas +++ b/components/synedit/Source/SynHighlighterHtml.pas @@ -48,7 +48,7 @@ unit SynHighlighterHtml; interface -{$I SynEdit.Inc} +{$I SynEdit.inc} uses {$IFDEF UNICODE} diff --git a/components/synedit/Source/SynHighlighterIDL.pas b/components/synedit/Source/SynHighlighterIDL.pas index 21c7c0bb..d311048b 100644 --- a/components/synedit/Source/SynHighlighterIDL.pas +++ b/components/synedit/Source/SynHighlighterIDL.pas @@ -37,7 +37,7 @@ located at http://SynEdit.SourceForge.net unit SynHighlighterIDL; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterIni.pas b/components/synedit/Source/SynHighlighterIni.pas index f747bce8..d4fbbe0c 100644 --- a/components/synedit/Source/SynHighlighterIni.pas +++ b/components/synedit/Source/SynHighlighterIni.pas @@ -46,7 +46,7 @@ Thanks to Primoz Gabrijelcic, Martin Waldenburg and Michael Hieke. unit SynHighlighterIni; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterInno.pas b/components/synedit/Source/SynHighlighterInno.pas index 87fbea22..985d96de 100644 --- a/components/synedit/Source/SynHighlighterInno.pas +++ b/components/synedit/Source/SynHighlighterInno.pas @@ -45,7 +45,7 @@ and http://www.wintax.nl/isx/ for My Inno Setup Extensions. unit SynHighlighterInno; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterJSON.pas b/components/synedit/Source/SynHighlighterJSON.pas index 197e2e7b..7cee7f56 100644 --- a/components/synedit/Source/SynHighlighterJSON.pas +++ b/components/synedit/Source/SynHighlighterJSON.pas @@ -31,7 +31,7 @@ located at http://SynEdit.SourceForge.net unit SynHighlighterJSON; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterJScript.pas b/components/synedit/Source/SynHighlighterJScript.pas index 9497dec0..07718603 100644 --- a/components/synedit/Source/SynHighlighterJScript.pas +++ b/components/synedit/Source/SynHighlighterJScript.pas @@ -46,7 +46,7 @@ The highlighter formats JavaScript source code highlighting keywords, strings, n unit SynHighlighterJScript; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterJava.pas b/components/synedit/Source/SynHighlighterJava.pas index 6da2098e..98a6e357 100644 --- a/components/synedit/Source/SynHighlighterJava.pas +++ b/components/synedit/Source/SynHighlighterJava.pas @@ -45,7 +45,7 @@ The SynHighlighterJava unit provides SynEdit with a Java source (.java) highligh unit SynHighlighterJava; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterKix.pas b/components/synedit/Source/SynHighlighterKix.pas index 0634984f..941e7e6e 100644 --- a/components/synedit/Source/SynHighlighterKix.pas +++ b/components/synedit/Source/SynHighlighterKix.pas @@ -45,7 +45,7 @@ The SynHighlighterKix unit provides SynEdit with a Kix script file syntax highli unit SynHighlighterKix; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterLDraw.pas b/components/synedit/Source/SynHighlighterLDraw.pas index 09b311f7..f5ccdc16 100644 --- a/components/synedit/Source/SynHighlighterLDraw.pas +++ b/components/synedit/Source/SynHighlighterLDraw.pas @@ -44,7 +44,7 @@ The SynHighlighterLDraw unit provides SynEdit with a LEGO LDraw (.ldr / .dat) hi unit SynHighlighterLDraw; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterM3.pas b/components/synedit/Source/SynHighlighterM3.pas index 4d7f7d6e..70cd2727 100644 --- a/components/synedit/Source/SynHighlighterM3.pas +++ b/components/synedit/Source/SynHighlighterM3.pas @@ -41,7 +41,7 @@ The SynHighlighterM3 unit provides SynEdit with a Modula-3 (.m3) highlighter. unit SynHighlighterM3; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterModelica.pas b/components/synedit/Source/SynHighlighterModelica.pas index 22bbf0dc..1579478a 100644 --- a/components/synedit/Source/SynHighlighterModelica.pas +++ b/components/synedit/Source/SynHighlighterModelica.pas @@ -36,7 +36,7 @@ Known Issues: unit SynHighlighterModelica; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterMsg.pas b/components/synedit/Source/SynHighlighterMsg.pas index 762e7a4e..948e0399 100644 --- a/components/synedit/Source/SynHighlighterMsg.pas +++ b/components/synedit/Source/SynHighlighterMsg.pas @@ -37,7 +37,7 @@ located at http://SynEdit.SourceForge.net unit SynHighlighterMsg; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterPHP.pas b/components/synedit/Source/SynHighlighterPHP.pas index 57a5a68c..013724af 100644 --- a/components/synedit/Source/SynHighlighterPHP.pas +++ b/components/synedit/Source/SynHighlighterPHP.pas @@ -48,7 +48,7 @@ Thanks to Martin Waldenburg. unit SynHighlighterPHP; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterPerl.pas b/components/synedit/Source/SynHighlighterPerl.pas index 7933c402..d9dc77e6 100644 --- a/components/synedit/Source/SynHighlighterPerl.pas +++ b/components/synedit/Source/SynHighlighterPerl.pas @@ -48,7 +48,7 @@ The SynHighlighterPerl unit provides SynEdit with a Perl syntax highlighter. unit SynHighlighterPerl; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterProgress.pas b/components/synedit/Source/SynHighlighterProgress.pas index 98c4f50b..907c26f0 100644 --- a/components/synedit/Source/SynHighlighterProgress.pas +++ b/components/synedit/Source/SynHighlighterProgress.pas @@ -47,7 +47,7 @@ highlighter is based. unit SynHighlighterProgress; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterPython.pas b/components/synedit/Source/SynHighlighterPython.pas index 711b0cbc..e008075f 100644 --- a/components/synedit/Source/SynHighlighterPython.pas +++ b/components/synedit/Source/SynHighlighterPython.pas @@ -46,7 +46,7 @@ The SynHighlighterPython implements a highlighter for Python for the SynEdit pro unit SynHighlighterPython; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterRC.pas b/components/synedit/Source/SynHighlighterRC.pas index d949a3e3..41400a66 100644 --- a/components/synedit/Source/SynHighlighterRC.pas +++ b/components/synedit/Source/SynHighlighterRC.pas @@ -34,7 +34,7 @@ located at http://SynEdit.SourceForge.net unit SynHighlighterRC; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterRuby.pas b/components/synedit/Source/SynHighlighterRuby.pas index 526a1abf..cf5a1915 100644 --- a/components/synedit/Source/SynHighlighterRuby.pas +++ b/components/synedit/Source/SynHighlighterRuby.pas @@ -45,7 +45,7 @@ The SynHighlighterVisualLisp unit provides SynEdit with a Ruby highlighter. unit SynHighlighterRuby; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterSDD.pas b/components/synedit/Source/SynHighlighterSDD.pas index 1422c88e..39894022 100644 --- a/components/synedit/Source/SynHighlighterSDD.pas +++ b/components/synedit/Source/SynHighlighterSDD.pas @@ -35,7 +35,7 @@ located at http://SynEdit.SourceForge.net unit SynHighlighterSDD; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterSQL.pas b/components/synedit/Source/SynHighlighterSQL.pas index 45cb8eb9..dd698f4d 100644 --- a/components/synedit/Source/SynHighlighterSQL.pas +++ b/components/synedit/Source/SynHighlighterSQL.pas @@ -49,7 +49,7 @@ Different SQL dialects can be selected via the Dialect property. unit SynHighlighterSQL; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterST.pas b/components/synedit/Source/SynHighlighterST.pas index 1f034952..8bda85fe 100644 --- a/components/synedit/Source/SynHighlighterST.pas +++ b/components/synedit/Source/SynHighlighterST.pas @@ -39,7 +39,7 @@ Known Issues: unit SynHighlighterST; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterSml.pas b/components/synedit/Source/SynHighlighterSml.pas index 33746e9b..8bd6082c 100644 --- a/components/synedit/Source/SynHighlighterSml.pas +++ b/components/synedit/Source/SynHighlighterSml.pas @@ -47,7 +47,7 @@ be disabled for backwards compatibility with older ML compilers that do not have unit SynHighlighterSml; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterTclTk.pas b/components/synedit/Source/SynHighlighterTclTk.pas index 43bb074a..c577ca7c 100644 --- a/components/synedit/Source/SynHighlighterTclTk.pas +++ b/components/synedit/Source/SynHighlighterTclTk.pas @@ -45,7 +45,7 @@ The SynHighlighterTclTk unit provides SynEdit with a TCL/Tk highlighter. unit SynHighlighterTclTk; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterTeX.pas b/components/synedit/Source/SynHighlighterTeX.pas index eeeb0a17..fddc2309 100644 --- a/components/synedit/Source/SynHighlighterTeX.pas +++ b/components/synedit/Source/SynHighlighterTeX.pas @@ -37,7 +37,7 @@ Known Issues: unit SynHighlighterTeX; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterUNIXShellScript.pas b/components/synedit/Source/SynHighlighterUNIXShellScript.pas index 05f4ba0d..557adee1 100644 --- a/components/synedit/Source/SynHighlighterUNIXShellScript.pas +++ b/components/synedit/Source/SynHighlighterUNIXShellScript.pas @@ -45,7 +45,7 @@ The SynHighlighterUNIXShellScript unit provides SynEdit with a UNIX Shell Script unit SynHighlighterUNIXShellScript; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterURI.pas b/components/synedit/Source/SynHighlighterURI.pas index 7f5506b8..afd076ad 100644 --- a/components/synedit/Source/SynHighlighterURI.pas +++ b/components/synedit/Source/SynHighlighterURI.pas @@ -68,7 +68,7 @@ www.host.org unit SynHighlighterURI; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterUnreal.pas b/components/synedit/Source/SynHighlighterUnreal.pas index ba851c27..2d222795 100644 --- a/components/synedit/Source/SynHighlighterUnreal.pas +++ b/components/synedit/Source/SynHighlighterUnreal.pas @@ -43,7 +43,7 @@ Known Issues: unit SynHighlighterUnreal; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterVB.pas b/components/synedit/Source/SynHighlighterVB.pas index 45254c02..45e26314 100644 --- a/components/synedit/Source/SynHighlighterVB.pas +++ b/components/synedit/Source/SynHighlighterVB.pas @@ -45,7 +45,7 @@ The SynHighlighterVB unit provides SynEdit with a Visual Basic (.bas) highlighte unit SynHighlighterVB; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterVBScript.pas b/components/synedit/Source/SynHighlighterVBScript.pas index e653269a..f1c79677 100644 --- a/components/synedit/Source/SynHighlighterVBScript.pas +++ b/components/synedit/Source/SynHighlighterVBScript.pas @@ -46,7 +46,7 @@ Thanks to Primoz Gabrijelcic and Martin Waldenburg. unit SynHighlighterVBScript; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterVrml97.pas b/components/synedit/Source/SynHighlighterVrml97.pas index 76782402..ad815a11 100644 --- a/components/synedit/Source/SynHighlighterVrml97.pas +++ b/components/synedit/Source/SynHighlighterVrml97.pas @@ -68,7 +68,7 @@ The highlighter formats Vrml97/X3D source code highlighting keywords, strings, n unit SynHighlighterVrml97; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/Source/SynHighlighterXML.pas b/components/synedit/Source/SynHighlighterXML.pas index 55820ac6..818cff49 100644 --- a/components/synedit/Source/SynHighlighterXML.pas +++ b/components/synedit/Source/SynHighlighterXML.pas @@ -53,7 +53,7 @@ unit SynHighlighterXML; interface -{$I SynEdit.Inc} +{$I SynEdit.inc} uses Windows, Messages, Controls, Graphics, Registry, @@ -830,7 +830,6 @@ procedure TSynXMLSyn.ScanForFoldRanges(FoldRanges: TSynFoldRanges; LinesToScan: TStrings; FromLine, ToLine: Integer); var Line: Integer; - TagStartPos: Integer; CurLine: string; RunPos: Integer; IsClosing: Boolean; diff --git a/components/synedit/Source/SynMemo.pas b/components/synedit/Source/SynMemo.pas index d5263c9e..47cf022b 100644 --- a/components/synedit/Source/SynMemo.pas +++ b/components/synedit/Source/SynMemo.pas @@ -40,7 +40,7 @@ Known Issues: unit SynMemo; -{$I SynEdit.Inc} +{$I SynEdit.inc} interface diff --git a/components/synedit/SynGen/SynGen.dpr b/components/synedit/SynGen/SynGen.dpr index 77c7792b..b5558e89 100644 --- a/components/synedit/SynGen/SynGen.dpr +++ b/components/synedit/SynGen/SynGen.dpr @@ -41,7 +41,7 @@ program SynGen; uses Forms, - SynGenUnit in 'SynGenUnit.pas' {FrmMain}, + SynGenUnit in 'SynGenUnit.pas' {FormMain}, GenLex in 'GenLex.pas', HashTableGen in 'HashTableGen.pas' {FrmHashTableGen}; @@ -50,7 +50,7 @@ uses begin Application.Initialize; Application.Title := 'SynGen'; - Application.CreateForm(TFrmMain, FrmMain); + Application.CreateForm(TFormMain, FormMain); Application.CreateForm(TFrmHashTableGen, FrmHashTableGen); Application.Run; end. diff --git a/components/synedit/SynGen/SynGen.dproj b/components/synedit/SynGen/SynGen.dproj index b8fed138..5b2cb8d4 100644 --- a/components/synedit/SynGen/SynGen.dproj +++ b/components/synedit/SynGen/SynGen.dproj @@ -8,7 +8,7 @@ 1 Application VCL - 16.1 + 18.4 Win32 @@ -34,6 +34,12 @@ Base true + + true + Cfg_2 + true + true + 1031 Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;Winapi;System.Win;$(DCC_Namespace) @@ -52,10 +58,16 @@ $(BDS)\bin\default_app.manifest 1033 true - Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + true + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png $(BDS)\bin\default_app.manifest + true + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png false @@ -66,12 +78,15 @@ DEBUG;$(DCC_Define) + + Debug + MainSource -
FrmMain
+
FormMain
diff --git a/components/synedit/SynGen/SynGenUnit.dfm b/components/synedit/SynGen/SynGenUnit.dfm index 676e75e7..5be357cd 100644 --- a/components/synedit/SynGen/SynGenUnit.dfm +++ b/components/synedit/SynGen/SynGenUnit.dfm @@ -1,343 +1,338 @@ -object FrmMain: TFrmMain - Left = 379 - Top = 238 - ActiveControl = BtnStart - BorderIcons = [biSystemMenu, biMinimize] - BorderStyle = bsSingle - Caption = 'SynGen' - ClientHeight = 288 - ClientWidth = 368 - Color = clBtnFace - Font.Charset = DEFAULT_CHARSET - Font.Color = clWindowText - Font.Height = -11 - Font.Name = 'MS Sans Serif' - Font.Style = [] - Menu = MainMenu - OldCreateOrder = False - OnClose = FormClose - OnCreate = FormCreate - OnDestroy = FormDestroy - PixelsPerInch = 96 - TextHeight = 13 - object PageControl: TPageControl - Left = 8 - Top = 8 - Width = 353 - Height = 241 - ActivePage = TabHighlighter - TabOrder = 1 - TabWidth = 80 - object TabHighlighter: TTabSheet - Caption = 'Highlighter' - object LblAuthor: TLabel - Left = 8 - Top = 20 - Width = 34 - Height = 13 - Caption = 'Author:' - end - object LblDescription: TLabel - Left = 8 - Top = 52 - Width = 56 - Height = 13 - Caption = 'Description:' - end - object LblVersion: TLabel - Left = 8 - Top = 84 - Width = 38 - Height = 13 - Caption = 'Version:' - end - object EditAuthor: TEdit - Left = 80 - Top = 16 - Width = 257 - Height = 21 - TabOrder = 0 - end - object EditDescription: TEdit - Left = 80 - Top = 48 - Width = 257 - Height = 21 - TabOrder = 1 - end - object EditVersion: TEdit - Left = 80 - Top = 80 - Width = 257 - Height = 21 - TabOrder = 2 - end - object ChkGetKeyWords: TCheckBox - Left = 8 - Top = 188 - Width = 249 - Height = 17 - Caption = 'Include optional GetKeyWords public method' - Checked = True - State = cbChecked - TabOrder = 4 - end - object ChkGPLHeader: TCheckBox - Left = 8 - Top = 168 - Width = 249 - Height = 17 - Caption = 'Use SynEdit standard GPL comment header' - Checked = True - State = cbChecked - TabOrder = 3 - end - end - object TabLanguage: TTabSheet - Caption = 'Language' - object LblFilter: TLabel - Left = 8 - Top = 20 - Width = 59 - Height = 13 - Caption = 'Default filter:' - end - object LblLangName: TLabel - Left = 8 - Top = 52 - Width = 80 - Height = 13 - Caption = 'Language name:' - end - object CboFilter: TComboBox - Left = 96 - Top = 16 - Width = 241 - Height = 21 - ItemHeight = 13 - TabOrder = 0 - Text = 'All files (*.*)|*.*' - OnChange = CboLangNameChange - Items.Strings = ( - 'Pascal files (*.pas,*.dpr,*.dpk,*.inc)|*.pas;*.dpr;*.dpk;*.inc' - 'HP48 files (*.s,*.sou,*.a,*.hp)|*.s;*.sou;*.a;*.hp' - 'CA-Clipper files (*.prg, *.ch, *.inc)|*.prg;*.ch;*.inc' - 'C++ files (*.cpp,*.h,*.hpp)|*.cpp;*.h;*.hpp' - 'Java files (*.java)|*.java' - 'Perl files (*.pl,*.pm,*.cgi)|*.pl;*.pm;*.cgi' - 'AWK Script (*.awk)|*.awk' - 'HTML Document (*.htm,*.html)|*.htm;*.html' - 'VBScript files (*.vbs)|*.vbs' - 'Galaxy files (*.gtv,*.galrep,*.txt)|*.gtv;*.galrep;*.txt' - 'Python files (*.py)|*.py' - 'SQL files (*.sql)|*.sql' - 'HP48 files (*.s,*.sou,*.a,*.hp)|*.s;*.sou;*.a;*.hp' - 'Tcl/Tk files (*.tcl)|*.tcl' - 'Rich Text Format (*.rtf)|*.rtf' - 'MS-DOS Batch Files (*.bat)|*.bat' - 'Delphi/C++ Builder Form Files (*.dfm)|*.dfm' - 'x86 Assembly Files (*.asm)|*.asm' - 'GEMBASE files (*.dml,*.gem)|*.dml;*.gem' - 'INI Files (*.ini)|*.ini' - 'Standard ML Files (*.sml)|*.sml' - 'Visual Basic files (*.bas)|*.bas' - 'DSP files (*.dsp,*.inc)|*.dsp;*.inc' - - 'PHP files (*.php,*.php3,*.phtml,*.inc)|*.php;*.php3;*.phtml;*.in' + - 'c' - 'Cache files (*.mac,*.inc,*.int)|*.mac;*.inc;*.int' - 'Cascading Stylesheets (*.css)|*.css' - 'Javascript files (*.js)|*.js' - 'Kix Scripts (*.kix)|*.kix' - 'Baan 4GL files (*.cln)|*.cln' - 'Foxpro Files (*.prg)|*.prg' - 'Fortran Files (*.for)|*.for' - '68HC11 Assembler files (*.hc11,*.asm,*.asc)|*.hc11;*.asm;*.asc') - end - object CboLangName: TComboBox - Left = 96 - Top = 48 - Width = 241 - Height = 21 - ItemHeight = 13 - TabOrder = 1 - OnChange = CboLangNameChange - Items.Strings = ( - 'HP48' - 'CA-Clipper' - 'C++' - 'Java' - 'Perl' - 'MS-DOS Batch Language' - 'Delphi/C++ Builder Form Definitions' - 'AWK Script' - 'HTML Document' - 'MS VBScript' - 'Galaxy' - 'General' - 'ObjectPascal' - 'x86 Assembly Language' - 'Python' - 'Tcl/Tk' - 'SQL' - 'Gembase' - 'INI files' - 'Standard ML' - 'Visual Basic' - 'ADSP21xx' - 'PHP' - 'Sybase SQL' - 'General Multi-Highlighter' - 'Cache object script' - 'Cascading Stylesheets' - 'Javascript' - 'KIX32' - 'Baan 4GL' - 'Foxpro' - 'Fortran' - '68HC11 Assembler') - end - end - object TabAttributes: TTabSheet - Caption = 'Attributes' - object LblUnknownTokenAttr: TLabel - Left = 8 - Top = 120 - Width = 164 - Height = 13 - Caption = 'Assign unknown token to attribute:' - end - object GrpAttrNames: TGroupBox - Left = 8 - Top = 8 - Width = 329 - Height = 96 - Caption = 'Attribute names' - TabOrder = 0 - object LblIdentifier: TLabel - Left = 16 - Top = 32 - Width = 43 - Height = 13 - Caption = 'Identifier:' - end - object LblReservedWord: TLabel - Left = 16 - Top = 64 - Width = 75 - Height = 13 - Caption = 'Reserved word:' - end - object CboAttrIdentifier: TComboBox - Left = 104 - Top = 28 - Width = 209 - Height = 21 - Style = csDropDownList - ItemHeight = 13 - TabOrder = 0 - end - object CboAttrReservedWord: TComboBox - Left = 104 - Top = 60 - Width = 209 - Height = 21 - Style = csDropDownList - ItemHeight = 13 - TabOrder = 1 - end - end - object CboUnknownTokenAttr: TComboBox - Left = 184 - Top = 116 - Width = 153 - Height = 21 - Style = csDropDownList - ItemHeight = 13 - TabOrder = 1 - Items.Strings = ( - 'Identifier' - 'Symbol' - 'Miscellaneous') - end - end - object TabFields: TTabSheet - Caption = 'Private Fields' - object ListBoxFields: TListBox - Left = 8 - Top = 40 - Width = 249 - Height = 161 - ItemHeight = 13 - Sorted = True - TabOrder = 3 - OnClick = ListBoxFieldsClick - end - object BtnAdd: TButton - Left = 264 - Top = 8 - Width = 73 - Height = 23 - Caption = 'Add' - Enabled = False - TabOrder = 0 - OnClick = BtnAddClick - end - object BtnDelete: TButton - Left = 264 - Top = 40 - Width = 73 - Height = 23 - Caption = 'Delete' - Enabled = False - TabOrder = 1 - OnClick = BtnDeleteClick - end - object EditAddField: TEdit - Left = 8 - Top = 8 - Width = 249 - Height = 21 - TabOrder = 2 - OnChange = EditAddFieldChange - OnKeyPress = EditAddFieldKeyPress - end - end - end - object BtnStart: TButton - Left = 288 - Top = 257 - Width = 75 - Height = 23 - Caption = 'Start!' - Default = True - TabOrder = 0 - OnClick = BtnStartClick - end - object OpenDialog: TOpenDialog - Filter = 'Grammar file (*.msg)|*.msg' - Left = 320 - Top = 184 - end - object MainMenu: TMainMenu - Left = 288 - Top = 184 - object MnuFile: TMenuItem - Caption = '&File' - object MnuOpen: TMenuItem - Caption = '&Open...' - ShortCut = 16463 - OnClick = MnuOpenClick - end - object MnuExit: TMenuItem - Caption = 'E&xit' - ShortCut = 32883 - OnClick = MnuExitClick - end - end - object MnuStart: TMenuItem - Caption = '&Start!' - OnClick = BtnStartClick - end - end -end +object FormMain: TFormMain + Left = 379 + Top = 238 + ActiveControl = ButtonStart + BorderIcons = [biSystemMenu, biMinimize] + BorderStyle = bsSingle + Caption = 'SynGen' + ClientHeight = 288 + ClientWidth = 368 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'MS Sans Serif' + Font.Style = [] + Menu = MainMenu + OldCreateOrder = False + OnClose = FormClose + OnCreate = FormCreate + OnDestroy = FormDestroy + PixelsPerInch = 96 + TextHeight = 13 + object PageControl: TPageControl + Left = 8 + Top = 8 + Width = 353 + Height = 241 + ActivePage = TabHighlighter + TabOrder = 1 + TabWidth = 80 + object TabHighlighter: TTabSheet + Caption = 'Highlighter' + object LabelAuthor: TLabel + Left = 8 + Top = 20 + Width = 34 + Height = 13 + Caption = 'Author:' + end + object LabelDescription: TLabel + Left = 8 + Top = 52 + Width = 56 + Height = 13 + Caption = 'Description:' + end + object LabelVersion: TLabel + Left = 8 + Top = 84 + Width = 38 + Height = 13 + Caption = 'Version:' + end + object EditAuthor: TEdit + Left = 80 + Top = 16 + Width = 257 + Height = 21 + TabOrder = 0 + end + object EditDescription: TEdit + Left = 80 + Top = 48 + Width = 257 + Height = 21 + TabOrder = 1 + end + object EditVersion: TEdit + Left = 80 + Top = 80 + Width = 257 + Height = 21 + TabOrder = 2 + end + object CheckBoxGetKeyWords: TCheckBox + Left = 8 + Top = 188 + Width = 249 + Height = 17 + Caption = 'Include optional GetKeyWords public method' + Checked = True + State = cbChecked + TabOrder = 4 + end + object CheckBoxGPLHeader: TCheckBox + Left = 8 + Top = 168 + Width = 249 + Height = 17 + Caption = 'Use SynEdit standard GPL comment header' + Checked = True + State = cbChecked + TabOrder = 3 + end + end + object TabLanguage: TTabSheet + Caption = 'Language' + object LabelFilter: TLabel + Left = 8 + Top = 20 + Width = 59 + Height = 13 + Caption = 'Default filter:' + end + object LabelLangName: TLabel + Left = 8 + Top = 52 + Width = 80 + Height = 13 + Caption = 'Language name:' + end + object ComboBoxFilter: TComboBox + Left = 96 + Top = 16 + Width = 241 + Height = 21 + TabOrder = 0 + Text = 'All files (*.*)|*.*' + OnChange = ComboBoxLangNameChange + Items.Strings = ( + 'Pascal files (*.pas,*.dpr,*.dpk,*.inc)|*.pas;*.dpr;*.dpk;*.inc' + 'HP48 files (*.s,*.sou,*.a,*.hp)|*.s;*.sou;*.a;*.hp' + 'CA-Clipper files (*.prg, *.ch, *.inc)|*.prg;*.ch;*.inc' + 'C++ files (*.cpp,*.h,*.hpp)|*.cpp;*.h;*.hpp' + 'Java files (*.java)|*.java' + 'Perl files (*.pl,*.pm,*.cgi)|*.pl;*.pm;*.cgi' + 'AWK Script (*.awk)|*.awk' + 'HTML Document (*.htm,*.html)|*.htm;*.html' + 'VBScript files (*.vbs)|*.vbs' + 'Galaxy files (*.gtv,*.galrep,*.txt)|*.gtv;*.galrep;*.txt' + 'Python files (*.py)|*.py' + 'SQL files (*.sql)|*.sql' + 'HP48 files (*.s,*.sou,*.a,*.hp)|*.s;*.sou;*.a;*.hp' + 'Tcl/Tk files (*.tcl)|*.tcl' + 'Rich Text Format (*.rtf)|*.rtf' + 'MS-DOS Batch Files (*.bat)|*.bat' + 'Delphi/C++ Builder Form Files (*.dfm)|*.dfm' + 'x86 Assembly Files (*.asm)|*.asm' + 'GEMBASE files (*.dml,*.gem)|*.dml;*.gem' + 'INI Files (*.ini)|*.ini' + 'Standard ML Files (*.sml)|*.sml' + 'Visual Basic files (*.bas)|*.bas' + 'DSP files (*.dsp,*.inc)|*.dsp;*.inc' + + 'PHP files (*.php,*.php3,*.phtml,*.inc)|*.php;*.php3;*.phtml;*.in' + + 'c' + 'Cache files (*.mac,*.inc,*.int)|*.mac;*.inc;*.int' + 'Cascading Stylesheets (*.css)|*.css' + 'Javascript files (*.js)|*.js' + 'Kix Scripts (*.kix)|*.kix' + 'Baan 4GL files (*.cln)|*.cln' + 'Foxpro Files (*.prg)|*.prg' + 'Fortran Files (*.for)|*.for' + '68HC11 Assembler files (*.hc11,*.asm,*.asc)|*.hc11;*.asm;*.asc') + end + object ComboBoxLangName: TComboBox + Left = 96 + Top = 48 + Width = 241 + Height = 21 + TabOrder = 1 + OnChange = ComboBoxLangNameChange + Items.Strings = ( + 'HP48' + 'CA-Clipper' + 'C++' + 'Java' + 'Perl' + 'MS-DOS Batch Language' + 'Delphi/C++ Builder Form Definitions' + 'AWK Script' + 'HTML Document' + 'MS VBScript' + 'Galaxy' + 'General' + 'ObjectPascal' + 'x86 Assembly Language' + 'Python' + 'Tcl/Tk' + 'SQL' + 'Gembase' + 'INI files' + 'Standard ML' + 'Visual Basic' + 'ADSP21xx' + 'PHP' + 'Sybase SQL' + 'General Multi-Highlighter' + 'Cache object script' + 'Cascading Stylesheets' + 'Javascript' + 'KIX32' + 'Baan 4GL' + 'Foxpro' + 'Fortran' + '68HC11 Assembler') + end + end + object TabAttributes: TTabSheet + Caption = 'Attributes' + object LabelUnknownTokenAttr: TLabel + Left = 8 + Top = 120 + Width = 164 + Height = 13 + Caption = 'Assign unknown token to attribute:' + end + object GrpAttrNames: TGroupBox + Left = 8 + Top = 8 + Width = 329 + Height = 96 + Caption = 'Attribute names' + TabOrder = 0 + object LabelIdentifier: TLabel + Left = 16 + Top = 32 + Width = 43 + Height = 13 + Caption = 'Identifier:' + end + object LabelReservedWord: TLabel + Left = 16 + Top = 64 + Width = 75 + Height = 13 + Caption = 'Reserved word:' + end + object ComboBoxAttrIdentifier: TComboBox + Left = 104 + Top = 28 + Width = 209 + Height = 21 + Style = csDropDownList + TabOrder = 0 + end + object ComboBoxAttrReservedWord: TComboBox + Left = 104 + Top = 60 + Width = 209 + Height = 21 + Style = csDropDownList + TabOrder = 1 + end + end + object ComboBoxUnknownTokenAttr: TComboBox + Left = 184 + Top = 116 + Width = 153 + Height = 21 + Style = csDropDownList + TabOrder = 1 + Items.Strings = ( + 'Identifier' + 'Symbol' + 'Miscellaneous') + end + end + object TabFields: TTabSheet + Caption = 'Private Fields' + object ListBoxFields: TListBox + Left = 8 + Top = 40 + Width = 249 + Height = 161 + ItemHeight = 13 + Sorted = True + TabOrder = 3 + OnClick = ListBoxFieldsClick + end + object ButtonAdd: TButton + Left = 264 + Top = 8 + Width = 73 + Height = 23 + Caption = 'Add' + Enabled = False + TabOrder = 0 + OnClick = ButtonAddClick + end + object ButtonDelete: TButton + Left = 264 + Top = 40 + Width = 73 + Height = 23 + Caption = 'Delete' + Enabled = False + TabOrder = 1 + OnClick = ButtonDeleteClick + end + object EditAddField: TEdit + Left = 8 + Top = 8 + Width = 249 + Height = 21 + TabOrder = 2 + OnChange = EditAddFieldChange + OnKeyPress = EditAddFieldKeyPress + end + end + end + object ButtonStart: TButton + Left = 288 + Top = 257 + Width = 75 + Height = 23 + Caption = 'Start!' + Default = True + TabOrder = 0 + OnClick = ButtonStartClick + end + object OpenDialog: TOpenDialog + Filter = 'Grammar file (*.msg)|*.msg' + Left = 320 + Top = 184 + end + object MainMenu: TMainMenu + Left = 288 + Top = 184 + object MenuItemFile: TMenuItem + Caption = '&File' + object MenuItemOpen: TMenuItem + Caption = '&Open...' + ShortCut = 16463 + OnClick = MenuItemOpenClick + end + object MenuItemExit: TMenuItem + Caption = 'E&xit' + ShortCut = 32883 + OnClick = MenuItemExitClick + end + end + object MenuItemStart: TMenuItem + Caption = '&Start!' + OnClick = ButtonStartClick + end + end +end diff --git a/components/synedit/SynGen/SynGenUnit.pas b/components/synedit/SynGen/SynGenUnit.pas index 71f88c03..ced7069d 100644 --- a/components/synedit/SynGen/SynGenUnit.pas +++ b/components/synedit/SynGen/SynGenUnit.pas @@ -1,1938 +1,1926 @@ -{------------------------------------------------------------------------------- -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: SynGenUnit.pas, released 2000-04-19. -Description: Generator for skeletons of HighLighters to use in SynEdit, -drived by a simple grammar. - -The Original Code is based on SynGenU.pas by Martin Waldenburg, part of -the mwEdit component suite. -Portions created by Martin Waldenburg are Copyright (C) 1998 Martin Waldenburg. -Portions created by Pieter Polak are Copyright (C) 2001 Pieter Polak. -Unicode translation by Maël Hörz. -All Rights Reserved. - -Contributors to the SynEdit and mwEdit projects are listed in the -Contributors.txt file. - -Alternatively, the contents of this file may be used under the terms of the -GNU General Public License Version 2 or later (the "GPL"), in which case -the provisions of the GPL are applicable instead of those above. -If you wish to allow use of your version of this file only under the terms -of the GPL and not to allow others to use your version of this file -under the MPL, indicate your decision by deleting the provisions above and -replace them with the notice and other provisions required by the GPL. -If you do not delete the provisions above, a recipient may use your version -of this file under either the MPL or the GPL. - -$Id: SynGenUnit.pas,v 1.18.2.11 2008/10/25 23:30:31 maelh Exp $ - -You may retrieve the latest version of this file at the SynEdit home page, -located at http://SynEdit.SourceForge.net - -Todo: - - Remember the last opened MSG file - - Double-click a MSG file opens SynGen - - Add user-defined default attributes to TSynXXXSyn.Create - - SynEdit to edit the MSG file (using the highlighter for MSG files) - - Store language names list and attribute names list in INI file - - SynEdit with Pascal highlighter to preview the created highlighter source - - Allow to define different type of keywords in MSG file - -Known Issues: --------------------------------------------------------------------------------} - -unit SynGenUnit; - -{$I SynEdit.inc} - -interface - -uses - Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, - StdCtrls, GenLex, ComCtrls, Menus, SynUnicode; - -var - mKeyHashTable: array[#0..#255] of Integer; - mSKeyHashTable: array[#0..#255] of Integer; - -type - TLexKeys = class - public - KeyName: string; - Key: Cardinal; - TokenType: string; - end; - - TLexCharsets = class - public - SetName: string; - Charset: string; - ProcData: string; - FuncData: string; - end; - - TLexEnclosedBy = class - public - TokenName: string; - ProcName: string; - StartsWith: string; - EndsWith: string; - MultiLine: Boolean; - constructor Create; - end; - - TLexDefaultAttri = class - public - Style: string; - Foreground: string; - Background: string; - constructor Create; - end; - - TFrmMain = class(TForm) - BtnStart: TButton; - OpenDialog: TOpenDialog; - PageControl: TPageControl; - TabLanguage: TTabSheet; - LblFilter: TLabel; - CboFilter: TComboBox; - LblLangName: TLabel; - CboLangName: TComboBox; - TabAttributes: TTabSheet; - GrpAttrNames: TGroupBox; - LblIdentifier: TLabel; - LblReservedWord: TLabel; - CboAttrIdentifier: TComboBox; - CboAttrReservedWord: TComboBox; - LblUnknownTokenAttr: TLabel; - CboUnknownTokenAttr: TComboBox; - TabFields: TTabSheet; - BtnAdd: TButton; - BtnDelete: TButton; - EditAddField: TEdit; - ListBoxFields: TListBox; - MainMenu: TMainMenu; - MnuFile: TMenuItem; - MnuOpen: TMenuItem; - MnuExit: TMenuItem; - TabHighlighter: TTabSheet; - LblAuthor: TLabel; - LblDescription: TLabel; - LblVersion: TLabel; - EditAuthor: TEdit; - EditDescription: TEdit; - EditVersion: TEdit; - MnuStart: TMenuItem; - ChkGetKeyWords: TCheckBox; - ChkGPLHeader: TCheckBox; - procedure BtnStartClick(Sender: TObject); - procedure FormCreate(Sender: TObject); - procedure FormDestroy(Sender: TObject); - procedure CboLangNameChange(Sender: TObject); - procedure ListBoxFieldsClick(Sender: TObject); - procedure BtnAddClick(Sender: TObject); - procedure BtnDeleteClick(Sender: TObject); - procedure EditAddFieldChange(Sender: TObject); - procedure EditAddFieldKeyPress(Sender: TObject; var Key: Char); - procedure MnuExitClick(Sender: TObject); - procedure MnuOpenClick(Sender: TObject); - procedure FormClose(Sender: TObject; var Action: TCloseAction); - private - LexName: string; - IdentPre: string; - IdentStart: string; - IdentContent: string; - FFileName: string; - IniFile: string; - OutFile: TextFile; - Sensitivity: Boolean; - LexFileContents: UnicodeString; - Lex: TGenLex; - KeyList: TList; - SetList: TList; - EnclosedList: TList; - SampleSourceList: TStringList; - IdentList: TStringList; - procedure ClearAll; - function GetFilterName: string; - function GetLangName: string; - function FilterInvalidChars(const Value: string): string; - procedure MakeHashTable; - procedure MakeSensitiveHashTable; - procedure FillKeyList; - procedure FillTokenTypeList; - procedure OutFileCreate(InName: string); - procedure ParseCharsets; - procedure ParseEnclosedBy; - procedure ParseSampleSource; - procedure RetrieveCharset; - procedure RetrieveEnclosedBy; - procedure RetrieveSampleSource; - procedure WriteSettings; - function PerformFileOpen: Boolean; - procedure WriteRest; - function KeywordsAreAllAlphaNumAndDifferent: Boolean; - function GetFriendlyLangName: string; - public - end; - -var - FrmMain: TFrmMain; - -implementation - -{$R *.DFM} - -uses -{$IFDEF SYN_COMPILER_6_UP} - StrUtils, -{$ENDIF} - Registry, HashTableGen; - -const - BoolStrs: array[Boolean] of string = ('False', 'True'); // Do not localize - -function CompareKeys(Item1, Item2: Pointer): Integer; -begin - Result := AnsiCompareStr(TLexKeys(Item1).KeyName, TLexKeys(Item2).KeyName); -end; - -function CompareSets(Item1, Item2: Pointer): Integer; -begin - Result := 0; - if TLexCharsets(Item1).SetName < TLexCharsets(Item2).SetName then - Result := -1 - else if TLexCharsets(Item1).SetName > TLexCharsets(Item2).SetName then - Result := 1; -end; - -function AddInt(const aValue: Integer): string; -begin - if (aValue < 0) then - Result := ' - ' + IntToStr(Abs(aValue)) - else if (aValue > 0) then - Result := ' + ' + IntToStr(aValue) - else - Result := ''; -end; - -function StuffString(const Value: UnicodeString): UnicodeString; -var - i: Integer; -begin - Result := ''; - for i := 1 to Length(Value) do - begin - if (Value[i] = '''') then - Result := Result + '''''' - else - Result := Result + Value[i]; - end; -end; - -function FirstLetterCap(S: UnicodeString): UnicodeString; -begin - Result := SynWideLowerCase(S); - if Length(Result) > 0 then - Result[1] := SynWideUpperCase(S[1])[1]; -end; - -{$IFNDEF SYN_COMPILER_6_UP} -function AnsiReplaceStr(const AText, AFromText, AToText: string): string; -begin - Result := StringReplace(AText, AFromText, AToText, [rfReplaceAll]); -end; -{$ENDIF} - -function ToAlphaNum(S: UnicodeString): UnicodeString; -var - c: Char; -begin - for c := #33 to #47 do - S := AnsiReplaceStr(S, c, IntToStr(Ord(c))); - - for c := #58 to #64 do - S := AnsiReplaceStr(S, c, IntToStr(Ord(c))); - - for c := #91 to #96 do - S := AnsiReplaceStr(S, c, IntToStr(Ord(c))); - - for c := #123 to #191 do - S := AnsiReplaceStr(S, c, IntToStr(Ord(c))); - - Result := S; -end; - -function IsASCIIAlphaNum(S: UnicodeString): Boolean; -var - i: Integer; -begin - Result := True; - - S := ToAlphaNum(S); - - for i := 1 to Length(S) do - case S[i] of - 'a'..'z', 'A'..'Z', '0'..'9', '_': ; - else - begin - Result := False; - Exit; - end; - end; -end; - -constructor TLexEnclosedBy.Create; -begin - inherited Create; - TokenName := ''; - ProcName := ''; - StartsWith := ''; - EndsWith := ''; - MultiLine := False; -end; - -constructor TLexDefaultAttri.Create; -begin - inherited Create; - Style := ''; - Foreground := ''; - Background := ''; -end; - -procedure TFrmMain.MakeSensitiveHashTable; -var - I: Char; -begin - for I := #0 to #255 do - begin - case CharInSet(I, ['_', 'A'..'Z', 'a'..'z']) of - True: - begin - if (I > #64) and (I < #91) then - mSKeyHashTable[I] := Ord(I) - 64 - else if (I > #96) then - mSKeyHashTable[I] := Ord(I) - 95; - end; - else - mSKeyHashTable[I] := 0; - end; - end; -end; - -procedure TFrmMain.MakeHashTable; -var - I, J: Char; -begin - for I := #0 to #255 do - begin - J := UpperCase(I)[1]; - case CharInSet(I, ['_', 'A'..'Z', 'a'..'z']) of - True: mKeyHashTable[I] := Ord(J) - 64; - else - mKeyHashTable[I] := 0; - end; - end; -end; - -procedure TFrmMain.WriteSettings; -begin - with TRegIniFile.Create(IniFile) do - try - WriteString('General', 'OpenDir', OpenDialog.InitialDir); - WriteBool(FFileName, 'GetKeyWords', ChkGetKeyWords.Checked); - WriteBool(FFileName, 'ChkGPLHeader', ChkGPLHeader.Checked); - WriteString(FFileName, 'Author', EditAuthor.Text); - WriteString(FFileName, 'Description', EditDescription.Text); - WriteString(FFileName, 'Version', EditVersion.Text); - WriteString(FFileName, 'Filter', CboFilter.Text); - WriteString(FFileName, 'Language', CboLangName.Text); - WriteString(FFileName, 'AttrIdentifier', CboAttrIdentifier.Text); - WriteString(FFileName, 'AttrReservedWord', CboAttrReservedWord.Text); - WriteString(FFileName, 'UnknownTokenAttr', CboUnknownTokenAttr.Text); - WriteString(FFileName, 'Fields', ListBoxFields.Items.CommaText); - finally - Free; - end; -end; - -function TFrmMain.PerformFileOpen: Boolean; -var - UserName: PChar; -{$IFDEF SYN_COMPILER_5_UP} - Count: Cardinal; -{$ELSE} - Count: Integer; -{$ENDIF} -begin - if OpenDialog.Execute then - begin - Count := 0; - Result := True; - FFileName := ExtractFileName(OpenDialog.FileName); - Caption := 'SynGen - ' + FFileName; - Application.Title := Caption; - OpenDialog.InitialDir := ExtractFilePath(OpenDialog.FileName); - GetUserName(nil, Count); - // retrieve the required size of the user name buffer - UserName := StrAlloc(Count); // allocate memory for the user name - GetUserName(UserName, Count); // retrieve the user name - with TRegIniFile.Create(IniFile) do - try - EditAuthor.Text := ReadString(FFileName, 'Author', StrPas(UserName)); - EditDescription.Text := ReadString(FFileName, 'Description', - 'Syntax Parser/Highlighter'); - EditVersion.Text := ReadString(FFileName, 'Version', '0.1'); - CboFilter.Text := ReadString(FFileName, 'Filter', 'All files (*.*)|*.*'); - CboLangName.Text := ReadString(FFileName, 'Language', ''); - ChkGetKeyWords.Checked := ReadBool(FFileName, 'GetKeyWords', True); - ChkGPLHeader.Checked := ReadBool(FFileName, 'ChkGPLHeader', True); - CboAttrIdentifier.ItemIndex := CboAttrIdentifier.Items.IndexOf - (ReadString(FFileName, 'AttrIdentifier', 'SYNS_AttrIdentifier')); - CboAttrReservedWord.ItemIndex := CboAttrReservedWord.Items.IndexOf - (ReadString(FFileName, 'AttrReservedWord', 'SYNS_AttrReservedWord')); - CboUnknownTokenAttr.ItemIndex := CboUnknownTokenAttr.Items.IndexOf - (ReadString(FFileName, 'UnknownTokenAttr', 'Identifier')); - ListBoxFields.Items.CommaText := ReadString(FFileName, 'Fields', ''); - finally - Free; - end; - StrDispose(UserName); - CboLangNameChange(Self); - end - else - Result := False; -end; - -procedure TFrmMain.FormCreate(Sender: TObject); -var - i: Integer; -begin - for i := FrmMain.ComponentCount - 1 downto 0 do - if FrmMain.Components[i] is TComboBox then - if TComboBox(FrmMain.Components[i]).Parent = GrpAttrNames then - begin - TComboBox(FrmMain.Components[i]).Items.Clear; - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrAsm'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrAsmComment'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrAsmKey'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrASP'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrAssembler'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrBlock'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrBrackets'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrCharacter'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrClass'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrComment'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrCondition'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrDir'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrDirective'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrDocumentation'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrEmbedSQL'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrEmbedText'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrEscapeAmpersand'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrForm'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrFunction'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrIcon'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrIdentifier'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrIllegalChar'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrIndirect'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrInvalidSymbol'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrInternalFunction'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrKey'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrLabel'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrMacro'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrMarker'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrMessage'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrMiscellaneous'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrNull'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrNumber'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrOperator'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrPragma'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrPreprocessor'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrQualifier'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrRegister'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrReservedWord'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrRpl'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrRplKey'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrRplComment'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrSASM'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrSASMComment'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrSASMKey'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrSecondReservedWord'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrSection'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrSpace'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrSpecialVariable'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrString'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrSymbol'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrSyntaxError'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrSystem'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrSystemValue'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrText'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrUnknownWord'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrUser'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrUserFunction'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrValue'); - TComboBox(FrmMain.Components[i]).Items.Add('SYNS_AttrVariable'); - end; - PageControl.ActivePage := PageControl.Pages[0]; - Lex := TGenLex.Create; - KeyList := TList.Create; - SetList := TList.Create; - EnclosedList := TList.Create; - SampleSourceList := TStringList.Create; - IdentList := TStringList.Create; - // read ini file - IniFile := Copy(ExtractFileName(Application.ExeName), 0, - Length(ExtractFileName(Application.ExeName)) - - Length(ExtractFileExt(Application.ExeName))) + '.ini'; - with TRegIniFile.Create(IniFile) do - try - OpenDialog.InitialDir := ReadString('General', 'OpenDir', - ExtractFilePath(Application.ExeName)); - finally - Free; - end; - - { Move form off the screen, but show already, to activate it correctly when - OpenFileDialog is closed with OK. } - Left := -10000; - Show; - if PerformFileOpen then - begin - MakeHashTable; - MakeSensitiveHashTable; - Position := poScreenCenter; // move form on the screen ("make visible") - end - else - Application.Terminate -end; - -procedure TFrmMain.ClearAll; -var - I: Integer; -begin - // Clear the contents of KeyList - for I := 0 to (KeyList.Count - 1) do - TObject(KeyList[I]).Free; - KeyList.Clear; - // Clear the contents of SetList - for I := 0 to (SetList.Count - 1) do - TObject(SetList[I]).Free; - SetList.Clear; - // Clear the contents of EnclosedList - for I := 0 to (EnclosedList.Count - 1) do - TObject(EnclosedList[I]).Free; - EnclosedList.Clear; - // Clear the contents of IdentList - for I := 0 to (IdentList.Count - 1) do - begin - if Assigned(IdentList.Objects[I]) then - TObject(IdentList.Objects[I]).Free; - end; - IdentList.Clear; - // Clear the contents of SampleSourceList - SampleSourceList.Clear; -end; - -procedure TFrmMain.FormDestroy(Sender: TObject); -begin - ClearAll; - Lex.Free; - IdentList.Free; - KeyList.Free; - SetList.Free; - EnclosedList.Free; -end; - -procedure TFrmMain.BtnStartClick(Sender: TObject); -var - LexFileLines: TUnicodeStringList; -begin - ClearAll; - - Screen.Cursor := crHourGlass; - - LexFileLines := TUnicodeStringList.Create; - try - LexFileLines.LoadFromFile(OpenDialog.FileName); - LexFileContents := LexFileLines.Text; - finally - LexFileLines.Free; - end; - Lex.Origin := PWideChar(LexFileContents); - Lex.Tokenize; - - while Lex.RunId <> IDIdentifier do - Lex.Next; - LexName := Lex.RunToken; - - Lex.Next; - while Lex.RunId <> IDIdentifier do - Lex.Next; - IdentPre := Lex.RunToken; - - OutFileCreate(OpenDialog.FileName); - try - while not (Lex.RunId in [IdSensitive, IdIdentStart]) do - Lex.Next; - - if Lex.RunId = IdSensitive then - Sensitivity := True - else - Sensitivity := False; - Lex.Next; - - while Lex.RunId <> IDCharSet do - Lex.Next; - IdentStart := Lex.RunToken; - Lex.Next; - - while Lex.RunId <> IDNull do - begin - case Lex.RunId of - IDCharSet: IdentContent := Lex.RunToken; - IDKeys: FillKeyList; - IDTokenTypes: FillTokenTypeList; - IDChars: ParseCharSets; - IDEnclosedBy: ParseEnclosedBy; - IDSampleSource: ParseSampleSource; - end; - Lex.Next; - end; - - if (KeyList.Count = 0) then - raise Exception.Create('You should specify at least 1 keyword!'); - if (IdentList.Count = 0) then - raise Exception.Create('You should specify at least 1 token type'); - if not KeywordsAreAllAlphaNumAndDifferent then - raise Exception.Create('One or more keywords contain unhandable characters'); - - FrmHashTableGen.AssignKeyWords(KeyList, Sensitivity); - FrmHashTableGen.ShowModal; - - WriteRest; - while (Lex.RunId <> IdNull) do - begin - Lex.Next; - end; - finally - Screen.Cursor := crDefault; - CloseFile(OutFile); - end; - MessageDlg(LexName + ' created on ' + DateTimeToStr(Now), mtInformation, - [mbOk], 0); -end; - -procedure TFrmMain.FillKeyList; -var - aLexKey: TLexKeys; - aString: string; - aTokenType: string; -begin - Lex.Next; - - aTokenType := ''; - while Lex.RunId <> IdCRLF do - begin - if not (Lex.RunId in [IdSpace, IdBraceOpen]) then - aTokenType := aTokenType + Lex.RunToken; - Lex.Next; - end; - - if (aTokenType = '') then - aTokenType := 'Key'; - - while Lex.RunId <> IdStop do - begin - while Lex.RunId in [IdSpace, IdBraceOpen, IdCRLF] do - Lex.Next; - if Lex.RunId <> IdStop then - begin - aString := ''; - while not (Lex.RunId in [IdSpace, IdBraceOpen, IdCRLF]) do - begin - aString := aString + Lex.RunToken; - Lex.Next; - end; - aLexKey := TLexKeys.Create; - aLexKey.TokenType := aTokenType; - aLexKey.KeyName := aString; - KeyList.Add(aLexKey); - end - else - Break; - Lex.Next; - end; - KeyList.Sort(CompareKeys); -end; - -procedure TFrmMain.FillTokenTypeList; -var - i: Integer; - List: TStringList; - sIdent: string; - sLine: string; - DefAttri: TLexDefaultAttri; -begin - Lex.Next; - IdentList.Add(IdentPre + 'Unknown'); - IdentList.Add(IdentPre + 'Null'); - while (Lex.RunId <> IdStop) do - begin - while Lex.RunId in [IdSpace, IdBraceOpen, IdCRLF, IDUnknown] do - Lex.Next; - if (Lex.RunId <> IdStop) then - begin - sIdent := IdentPre + Lex.RunToken; - if not IsValidIdent(sIdent) then - raise Exception.Create('Invalid identifier for token type: ' + sIdent); - - if (IdentList.IndexOf(sIdent) < 0) then - IdentList.Add(sIdent); - Lex.Next; - - sLine := ''; - while (Lex.RunId = IdSpace) do - Lex.Next; - while not (Lex.RunId in [IdStop, IdCRLF]) do - begin { is there more data on this line? } - sLine := sLine + Lex.RunToken; - Lex.Next; - end; - - if (sLine <> '') then { The Msg file specifies default attributes } - begin - List := TStringList.Create; - try - while (sLine <> '') do - begin - i := Pos('|', sLine); - if (i > 0) then - begin - List.Add(Copy(sLine, 1, i - 1)); - Delete(sLine, 1, i); - end - else - begin - List.Add(sLine); - sLine := ''; - end; - end; - - i := IdentList.IndexOf(sIdent); - if (i >= 0) then - begin - DefAttri := TLexDefaultAttri.Create; - DefAttri.Style := List.Values['Style']; - DefAttri.Foreground := List.Values['Foreground']; - DefAttri.Background := List.Values['Background']; - IdentList.Objects[i] := DefAttri; - end; - finally - List.Free; - end; - end; - end - else - Break; - end; -end; - -procedure TFrmMain.OutFileCreate(InName: string); -var - OutName, UName: string; - sysTime: TSystemTime; - ISODate: string; -begin - OutName := ChangeFileExt(InName, '.pas'); - Uname := ExtractFileName(ChangeFileExt(InName, '')); - AssignFile(OutFile, OutName); - rewrite(OutFile); - GetSystemTime(sysTime); - ISODate := Format('%.4d-%.2d-%.2d', [sysTime.wYear, sysTime.wMonth, - sysTime.wDay]); - if ChkGPLHeader.Checked then - begin - Writeln(OutFile, - '{-------------------------------------------------------------------------------'); - Writeln(OutFile, - 'The contents of this file are subject to the Mozilla Public License'); - Writeln(OutFile, - 'Version 1.1 (the "License"); you may not use this file except in compliance'); - Writeln(OutFile, - 'with the License. You may obtain a copy of the License at'); - Writeln(OutFile, 'http://www.mozilla.org/MPL/'); - Writeln(OutFile); - Writeln(OutFile, - 'Software distributed under the License is distributed on an "AS IS" basis,'); - Writeln(OutFile, - 'WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for'); - Writeln(OutFile, - 'the specific language governing rights and limitations under the License.'); - Writeln(OutFile); - Writeln(OutFile, 'Code template generated with SynGen.'); - Writeln(OutFile, 'The original code is: ' + OutName + ', released ' + ISODate - + '.'); - Writeln(OutFile, 'Description: ' + EditDescription.Text); - Writeln(OutFile, 'The initial author of this file is ' + EditAuthor.Text + - '.'); - Writeln(OutFile, 'Copyright (c) ' + Format('%d', [sysTime.wYear]) + - ', all rights reserved.'); - Writeln(OutFile); - Writeln(OutFile, - 'Contributors to the SynEdit and mwEdit projects are listed in the'); - Writeln(OutFile, 'Contributors.txt file.'); - Writeln(OutFile); - Writeln(OutFile, - 'Alternatively, the contents of this file may be used under the terms of the'); - Writeln(OutFile, - 'GNU General Public License Version 2 or later (the "GPL"), in which case'); - Writeln(OutFile, - 'the provisions of the GPL are applicable instead of those above.'); - Writeln(OutFile, - 'If you wish to allow use of your version of this file only under the terms'); - Writeln(OutFile, - 'of the GPL and not to allow others to use your version of this file'); - Writeln(OutFile, - 'under the MPL, indicate your decision by deleting the provisions above and'); - Writeln(OutFile, - 'replace them with the notice and other provisions required by the GPL.'); - Writeln(OutFile, - 'If you do not delete the provisions above, a recipient may use your version'); - Writeln(OutFile, 'of this file under either the MPL or the GPL.'); - Writeln(OutFile); - Writeln(OutFile, '$' + 'Id: ' + '$'); - Writeln(OutFile); - Writeln(OutFile, - 'You may retrieve the latest version of this file at the SynEdit home page,'); - Writeln(OutFile, 'located at http://SynEdit.SourceForge.net'); - Writeln(OutFile); - Writeln(OutFile, - '-------------------------------------------------------------------------------}'); - end - else - begin - Writeln(OutFile, - '{+-----------------------------------------------------------------------------+'); - Writeln(OutFile, ' | Class: ' + LexName); - Writeln(OutFile, ' | Created: ' + ISODate); - Writeln(OutFile, ' | Last change: ' + ISODate); - Writeln(OutFile, ' | Author: ' + EditAuthor.Text); - Writeln(OutFile, ' | Description: ' + EditDescription.Text); - Writeln(OutFile, ' | Version: ' + EditVersion.Text); - Writeln(OutFile, ' |'); - Writeln(OutFile, ' | Copyright (c) ' + Format('%d', [sysTime.wYear]) + #32 + - EditAuthor.Text + '. All rights reserved.'); - Writeln(OutFile, ' |'); - Writeln(OutFile, ' | Generated with SynGen.'); - Writeln(OutFile, - ' +----------------------------------------------------------------------------+}'); - end; - Writeln(OutFile); - Writeln(OutFile, '{$IFNDEF Q' + UpperCase(Uname) + '}'); - Writeln(OutFile, 'unit ' + Uname + ';'); - Writeln(OutFile, '{$ENDIF}'); - Writeln(OutFile); - Writeln(OutFile, '{$I SynEdit.inc}'); - Writeln(OutFile); - Writeln(OutFile, 'interface'); - Writeln(OutFile); - Writeln(OutFile, 'uses'); - Writeln(OutFile, '{$IFDEF SYN_CLX}'); - Writeln(OutFile, ' QGraphics,'); - Writeln(OutFile, ' QSynEditTypes,'); - Writeln(OutFile, ' QSynEditHighlighter,'); - Writeln(OutFile, ' QSynUnicode,'); - Writeln(OutFile, '{$ELSE}'); - Writeln(OutFile, ' Graphics,'); - Writeln(OutFile, ' SynEditTypes,'); - Writeln(OutFile, ' SynEditHighlighter,'); - Writeln(OutFile, ' SynUnicode,'); - Writeln(OutFile, '{$ENDIF}'); - Writeln(OutFile, ' SysUtils,'); - Writeln(OutFile, ' Classes;'); - Writeln(OutFile); - Writeln(OutFile, 'type'); - Writeln(OutFile, ' T' + IdentPre + 'TokenKind = ('); -end; - -procedure TFrmMain.ParseCharsets; -begin - Lex.Next; - while Lex.RunId <> IdStop do - begin - case Lex.RunId of - IdCharset: RetrieveCharset; - else - Lex.Next; - end; - end; -end; - -procedure TFrmMain.ParseEnclosedBy; -begin - Lex.Next; - while not (Lex.RunId in [IdStop, IdNull]) do - RetrieveEnclosedBy; -end; - -procedure TFrmMain.ParseSampleSource; -begin - Lex.Next; - if (Lex.RunId = IdCRLF) then - Lex.Next; - - while not (Lex.RunId in [IdStop, IdNull]) do - RetrieveSampleSource; -end; - -procedure TFrmMain.RetrieveCharset; -var - aSet: TLexCharsets; -begin - aSet := TLexCharsets.Create; - aSet.Charset := Lex.RunToken; - while Lex.RunId <> IDIdentifier do - Lex.Next; - aSet.SetName := Lex.RunToken; - while Lex.RunId <> IDBeginProc do - Lex.Next; - Lex.Next; - while Lex.RunId in [IdCRLF, IdSpace] do - Lex.Next; - while not (Lex.RunId = IdEndProc) do - begin - aSet.ProcData := aSet.ProcData + Lex.RunToken; - Lex.Next; - end; - SetList.Add(aSet); - Lex.Next; -end; - -procedure TFrmMain.RetrieveSampleSource; -var - sLine: string; -begin - sLine := ''; - while not (Lex.RunId in [IdCRLF, IdNull, IdStop]) do - begin - sLine := sLine + Lex.RunToken; - Lex.Next; - end; - if (Lex.RunId = IdCRLF) then - Lex.Next; - - SampleSourceList.Add(sLine); -end; - -procedure TFrmMain.RetrieveEnclosedBy; -var - aThing: TLexEnclosedBy; - sLine: string; - iPos: Integer; -begin - while Lex.RunId in [IdCRLF, IdSpace] do - Lex.Next; - - sLine := ''; - while not (Lex.RunId in [IdCRLF, IdNull, IdStop]) do - begin - sLine := sLine + Lex.RunToken; - Lex.Next; - end; - - if (sLine <> '') then - begin - aThing := TLexEnclosedBy.Create; - - iPos := Pos(',', sLine); - aThing.TokenName := Copy(sLine, 1, iPos - 1); - Delete(sLine, 1, iPos); - - iPos := Pos(',', sLine); - aThing.ProcName := Copy(sLine, 1, iPos - 1); - Delete(sLine, 1, iPos); - - iPos := Pos(',', sLine); - aThing.StartsWith := Copy(sLine, 1, iPos - 1); - Delete(sLine, 1, iPos); - - iPos := Pos(',', sLine); - if (iPos > 0) then - begin - aThing.EndsWith := Copy(sLine, 1, iPos - 1); - Delete(sLine, 1, iPos); - if (Pos('MULTILINE', UpperCase(sLine)) = 1) then - aThing.MultiLine := True; - end - else - aThing.EndsWith := sLine; - - EnclosedList.Add(aThing); - end - else if (Lex.RunId <> IdStop) then - Lex.Next; -end; { RetrieveEnclosedBy } - -function TFrmMain.FilterInvalidChars(const Value: string): string; -var - i: Integer; -begin - Result := ''; - for i := 1 to Length(Value) do - begin - if IsValidIdent(Result + Value[i]) then - Result := Result + Value[i]; - end; -end; { FilterInvalidChars } - -function TFrmMain.GetFilterName: string; -var - FilterName: string; -begin - FilterName := ''; - case CboFilter.ItemIndex of - -1: FilterName := 'SYNS_Filter' + FilterInvalidChars(CboLangName.Text); - 0: FilterName := 'SYNS_FilterPascal'; - 1: FilterName := 'SYNS_FilterHP48'; - 2: FilterName := 'SYNS_FilterCAClipper'; - 3: FilterName := 'SYNS_FilterCPP'; - 4: FilterName := 'SYNS_FilterJava'; - 5: FilterName := 'SYNS_FilterPerl'; - 6: FilterName := 'SYNS_FilterAWK'; - 7: FilterName := 'SYNS_FilterHTML'; - 8: FilterName := 'SYNS_FilterVBScript'; - 9: FilterName := 'SYNS_FilterGalaxy'; - 10: FilterName := 'SYNS_FilterPython'; - 11: FilterName := 'SYNS_FilterSQL'; - 12: FilterName := 'SYNS_FilterTclTk'; - 13: FilterName := 'SYNS_FilterRTF'; - 14: FilterName := 'SYNS_FilterBatch'; - 15: FilterName := 'SYNS_FilterDFM'; - 16: FilterName := 'SYNS_FilterX86Asm'; - 17: FilterName := 'SYNS_FilterGembase'; - 18: FilterName := 'SYNS_FilterINI'; - 19: FilterName := 'SYNS_FilterML'; - 20: FilterName := 'SYNS_FilterVisualBASIC'; - 21: FilterName := 'SYNS_FilterADSP21xx'; - 22: FilterName := 'SYNS_FilterPHP'; - 23: FilterName := 'SYNS_FilterCache'; - 24: FilterName := 'SYNS_FilterCSS'; - 25: FilterName := 'SYNS_FilterJScript'; - 26: FilterName := 'SYNS_FilterKIX'; - 27: FilterName := 'SYNS_FilterBaan'; - 28: FilterName := 'SYNS_FilterFoxpro'; - 29: FilterName := 'SYNS_FilterFortran'; - 30: FilterName := 'SYNS_FilterAsm68HC11'; - end; - Result := FilterName; -end; - -function TFrmMain.GetFriendlyLangName: string; -var - LangName: string; -begin - case CboLangName.ItemIndex of - -1: LangName := 'SYNS_FriendlyLang' + FilterInvalidChars(CboLangName.Text); - 0: LangName := 'SYNS_FriendlyLangHP48'; - 1: LangName := 'SYNS_FriendlyLangCAClipper'; - 2: LangName := 'SYNS_FriendlyLangCPP'; - 3: LangName := 'SYNS_FriendlyLangJava'; - 4: LangName := 'SYNS_FriendlyLangPerl'; - 5: LangName := 'SYNS_FriendlyLangBatch'; - 6: LangName := 'SYNS_FriendlyLangDfm'; - 7: LangName := 'SYNS_FriendlyLangAWK'; - 8: LangName := 'SYNS_FriendlyLangHTML'; - 9: LangName := 'SYNS_FriendlyLangVBSScript'; - 10: LangName := 'SYNS_FriendlyLangGalaxy'; - 11: LangName := 'SYNS_FriendlyLangGeneral'; - 12: LangName := 'SYNS_FriendlyLangPascal'; - 13: LangName := 'SYNS_FriendlyLangX86Asm'; - 14: LangName := 'SYNS_FriendlyLangPython'; - 15: LangName := 'SYNS_FriendlyLangTclTk'; - 16: LangName := 'SYNS_FriendlyLangSQL'; - 17: LangName := 'SYNS_FriendlyLangGembase'; - 18: LangName := 'SYNS_FriendlyLangINI'; - 19: LangName := 'SYNS_FriendlyLangML'; - 20: LangName := 'SYNS_FriendlyLangVisualBASIC'; - 21: LangName := 'SYNS_FriendlyLangADSP21xx'; - 22: LangName := 'SYNS_FriendlyLangPHP'; - 23: LangName := 'SYNS_FriendlyLangSybaseSQL'; - 24: LangName := 'SYNS_FriendlyLangGeneralMulti'; - 25: LangName := 'SYNS_FriendlyLangCache'; - 26: LangName := 'SYNS_FriendlyLangCSS'; - 27: LangName := 'SYNS_FriendlyLangJScript'; - 28: LangName := 'SYNS_FriendlyLangKIX'; - 29: LangName := 'SYNS_FriendlyLangBaan'; - 30: LangName := 'SYNS_FriendlyLangFoxpro'; - 31: LangName := 'SYNS_FriendlyLangFortran'; - 32: LangName := 'SYNS_FriendlyLang68HC11'; - end; - Result := LangName; -end; - -function TFrmMain.GetLangName: string; -var - LangName: string; -begin - case CboLangName.ItemIndex of - -1: LangName := 'SYNS_Lang' + FilterInvalidChars(CboLangName.Text); - 0: LangName := 'SYNS_LangHP48'; - 1: LangName := 'SYNS_LangCAClipper'; - 2: LangName := 'SYNS_LangCPP'; - 3: LangName := 'SYNS_LangJava'; - 4: LangName := 'SYNS_LangPerl'; - 5: LangName := 'SYNS_LangBatch'; - 6: LangName := 'SYNS_LangDfm'; - 7: LangName := 'SYNS_LangAWK'; - 8: LangName := 'SYNS_LangHTML'; - 9: LangName := 'SYNS_LangVBSScript'; - 10: LangName := 'SYNS_LangGalaxy'; - 11: LangName := 'SYNS_LangGeneral'; - 12: LangName := 'SYNS_LangPascal'; - 13: LangName := 'SYNS_LangX86Asm'; - 14: LangName := 'SYNS_LangPython'; - 15: LangName := 'SYNS_LangTclTk'; - 16: LangName := 'SYNS_LangSQL'; - 17: LangName := 'SYNS_LangGembase'; - 18: LangName := 'SYNS_LangINI'; - 19: LangName := 'SYNS_LangML'; - 20: LangName := 'SYNS_LangVisualBASIC'; - 21: LangName := 'SYNS_LangADSP21xx'; - 22: LangName := 'SYNS_LangPHP'; - 23: LangName := 'SYNS_LangSybaseSQL'; - 24: LangName := 'SYNS_LangGeneralMulti'; - 25: LangName := 'SYNS_LangCache'; - 26: LangName := 'SYNS_LangCSS'; - 27: LangName := 'SYNS_LangJScript'; - 28: LangName := 'SYNS_LangKIX'; - 29: LangName := 'SYNS_LangBaan'; - 30: LangName := 'SYNS_LangFoxpro'; - 31: LangName := 'SYNS_LangFortran'; - 32: LangName := 'SYNS_Lang68HC11'; - end; - Result := LangName; -end; - -procedure TFrmMain.WriteRest; -var - I, J: Integer; - LineLength: Integer; - KeyString: string; - AttrName: string; - FriendlyAttrName: string; - AttrTemp: string; - TempStringList: TStringList; - sPrefix: string; - DefAttri: TLexDefaultAttri; -begin - IdentList.Sort; - SetList.Sort(CompareSets); - I := 0; - while I < IdentList.Count - 1 do - begin - Writeln(OutFile, ' ' + IdentList[I] + ','); - inc(I); - end; - Writeln(OutFile, ' ' + IdentList[I] + ');'); - Writeln(OutFile); - Write(OutFile, ' TRangeState = (rsUnKnown'); - for I := 0 to (EnclosedList.Count - 1) do - Write(OutFile, ', rs' + TLexEnclosedBy(EnclosedList[I]).ProcName); - Writeln(OutFile, ');'); - Writeln(OutFile); - Writeln(OutFile, ' TProcTableProc = procedure of object;'); - Writeln(OutFile); - Writeln(OutFile, ' PIdentFuncTableFunc = ^TIdentFuncTableFunc;'); - Writeln(OutFile, ' TIdentFuncTableFunc = function (Index: Integer): T' + IdentPre + - 'TokenKind of object;'); - Writeln(OutFile); - - Writeln(OutFile, 'type'); - Writeln(OutFile, ' ' + LexName + ' = class(TSynCustomHighlighter)'); - Writeln(OutFile, ' private'); - Writeln(OutFile, ' fRange: TRangeState;'); - - if ListBoxFields.Items.Count > 0 then - for i := 0 to ListBoxFields.Items.Count - 1 do - Writeln(OutFile, ' ' + ListBoxFields.Items[i] + ';'); - - Writeln(OutFile, ' fTokenID: TtkTokenKind;'); - Writeln(OutFile, - ' fIdentFuncTable: array[0..' + - IntToStr(FrmHashTableGen.KeyIndicesCount - 1) + ']' + - ' of TIdentFuncTableFunc;'); - - I := 0; - while I < IdentList.Count do - begin - if (IdentList[I] <> IdentPre + 'Null') and (IdentList[I] <> IdentPre + - 'Unknown') then - Writeln(OutFile, ' f' + Copy(IdentList[I], Length(IdentPre) + 1, - Length(IdentList[I])) + 'Attri: TSynHighlighterAttributes;'); - inc(I); - end; - - Writeln(OutFile, ' function HashKey(Str: PWideChar): Cardinal;'); - - I := 0; - while I < KeyList.Count do - begin - Writeln(OutFile, AnsiString(' function Func' + - ToAlphaNum(FirstLetterCap(TLexKeys(KeyList[I]).KeyName)) + - '(Index: Integer): T' + IdentPre + 'TokenKind;')); - inc(I); - end; - - I := 0; - while I < SetList.Count do - begin - Writeln(OutFile, ' procedure ' + TLexCharsets(SetList[I]).SetName + - 'Proc;'); - inc(I); - end; - - Writeln(OutFile, ' procedure UnknownProc;'); - Writeln(OutFile, ' function AltFunc(Index: Integer): T' + IdentPre + 'TokenKind;'); - Writeln(OutFile, ' procedure InitIdent;'); - Writeln(OutFile, ' function IdentKind(MayBe: PWideChar): T' + IdentPre + - 'TokenKind;'); - Writeln(OutFile, ' procedure NullProc;'); - if (IdentList.IndexOf(IdentPre + 'Space') >= 0) then - Writeln(OutFile, ' procedure SpaceProc;'); - Writeln(OutFile, ' procedure CRProc;'); - Writeln(OutFile, ' procedure LFProc;'); - for I := 0 to (EnclosedList.Count - 1) do - begin - Writeln(OutFile, ' procedure ' + TLexEnclosedBy(EnclosedList[I]).ProcName - + 'OpenProc;'); - Writeln(OutFile, ' procedure ' + TLexEnclosedBy(EnclosedList[I]).ProcName - + 'Proc;'); - end; - Writeln(OutFile, ' protected'); - Writeln(OutFile, ' function GetSampleSource: UnicodeString; override;'); - Writeln(OutFile, ' function IsFilterStored: Boolean; override;'); - Writeln(OutFile, ' public'); - Writeln(OutFile, ' constructor Create(AOwner: TComponent); override;'); - Writeln(OutFile, ' class function GetFriendlyLanguageName: UnicodeString; override;'); - Writeln(OutFile, ' class function GetLanguageName: string; override;'); - Writeln(OutFile, ' function GetRange: Pointer; override;'); - Writeln(OutFile, ' procedure ResetRange; override;'); - Writeln(OutFile, ' procedure SetRange(Value: Pointer); override;'); - Writeln(OutFile, - ' function GetDefaultAttribute(Index: Integer): TSynHighlighterAttributes; override;'); - Writeln(OutFile, ' function GetEol: Boolean; override;'); - if ChkGetKeyWords.Checked then - Writeln(OutFile, ' function GetKeyWords(TokenKind: Integer): UnicodeString; override;'); - Writeln(OutFile, ' function GetTokenID: TtkTokenKind;'); - Writeln(OutFile, - ' function GetTokenAttribute: TSynHighlighterAttributes; override;'); - Writeln(OutFile, ' function GetTokenKind: Integer; override;'); - Writeln(OutFile, ' function IsIdentChar(AChar: WideChar): Boolean; override;'); - Writeln(OutFile, ' procedure Next; override;'); - Writeln(OutFile, ' published'); - - I := 0; - while I < IdentList.Count do - begin - if (IdentList[I] <> IdentPre + 'Null') and (IdentList[I] <> IdentPre + - 'Unknown') then - Writeln(OutFile, ' property ' + Copy(IdentList[I], Length(IdentPre) + - 1, Length(IdentList[I])) - + 'Attri: TSynHighlighterAttributes read f' + Copy(IdentList[I], - Length(IdentPre) + 1, Length(IdentList[I])) + - 'Attri write f' + Copy(IdentList[I], Length(IdentPre) + 1, - Length(IdentList[I])) + 'Attri;'); - inc(I); - end; - - Writeln(OutFile, ' end;'); - Writeln(OutFile); - Writeln(OutFile, 'implementation'); - Writeln(OutFile); - Writeln(OutFile, 'uses'); - Writeln(OutFile, '{$IFDEF SYN_CLX}'); - Writeln(OutFile, ' QSynEditStrConst;'); - Writeln(OutFile, '{$ELSE}'); - Writeln(OutFile, ' SynEditStrConst;'); - Writeln(OutFile, '{$ENDIF}'); - Writeln(OutFile); - if (CboFilter.ItemIndex = -1) or (CboLangName.ItemIndex = -1) then - begin - Writeln(OutFile, 'resourcestring'); - if (CboFilter.ItemIndex = -1) then - Writeln(OutFile, ' SYNS_Filter' + FilterInvalidChars(CboLangName.Text) + - ' = ''' + CboFilter.Text + ''';'); - if (CboLangName.ItemIndex = -1) then - begin - Writeln(OutFile, ' SYNS_Lang' + FilterInvalidChars(CboLangName.Text) + - ' = ''' + CboLangName.Text + ''';'); - - Writeln(OutFile, ' SYNS_FriendlyLang' + FilterInvalidChars(CboLangName.Text) + - ' = ''' + CboLangName.Text + ''';'); - end; - - I := 0; - while I < IdentList.Count do - begin - AttrTemp := Copy(IdentList[I], Length(IdentPre) + 1, - Length(IdentList[I])); - if (CboAttrIdentifier.Items.IndexOf('SYNS_Attr' + AttrTemp) < 0) and - (AttrTemp <> 'Unknown') then - begin - Writeln(OutFile, ' SYNS_Attr' + FilterInvalidChars(AttrTemp) + ' = ''' - + AttrTemp + ''';'); - Writeln(OutFile, ' SYNS_FriendlyAttr' + FilterInvalidChars(AttrTemp) + ' = ''' - + AttrTemp + ''';'); - end; - Inc(i); - end; - Writeln(OutFile); - end; - - Writeln(OutFile, 'const'); - Write(OutFile, FrmHashTableGen.GetKeyWordConstantsSource(Sensitivity)); - Writeln(OutFile); - - Writeln(OutFile, 'procedure ' + LexName + '.InitIdent;'); - Writeln(OutFile, 'var'); - Writeln(OutFile, ' i: Integer;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' for i := Low(fIdentFuncTable) to High(fIdentFuncTable) do'); - Writeln(OutFile, ' if KeyIndices[i] = -1 then'); - Writeln(OutFile, ' fIdentFuncTable[i] := AltFunc;'); - Writeln(OutFile, ''); - - I := 0; - while I < KeyList.Count do - begin - if I < KeyList.Count - 1 then - while TLexKeys(KeyList[I]).Key = TLexKeys(KeyList[I + 1]).Key do - begin - inc(I); - if I >= KeyList.Count - 1 then - break; - end; - KeyString := IntToStr(TLexKeys(KeyList[I]).Key); - Writeln(OutFile, ' fIdentFuncTable[' + KeyString + '] := Func' + - ToAlphaNum(FirstLetterCap(TLexKeys(KeyList[I]).KeyName)) + ';'); - inc(I); - end; - - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Write(OutFile, FrmHashTableGen.GetHashKeyFunctionSource(LexName)); - Writeln(OutFile); - - I := 0; - while I < KeyList.Count do - begin - KeyString := ToAlphaNum(FirstLetterCap(TLexKeys(KeyList[I]).KeyName)); - Writeln(OutFile, 'function ' + LexName + '.Func' + KeyString + '(Index: Integer): T' + - IdentPre + 'TokenKind;'); - Writeln(OutFile, 'begin'); - if I < KeyList.Count - 1 then - while TLexKeys(KeyList[I]).Key = TLexKeys(KeyList[I + 1]).Key do - begin - Writeln(OutFile, ' if IsCurrentToken(KeyWords[Index]) then'); - Writeln(OutFile, ' Result := ' + IdentPre + TLexKeys(KeyList[I]).TokenType); - Writeln(OutFile, ' else'); - inc(I); - if I >= KeyList.Count - 1 then - break; - end; - Writeln(OutFile, ' if IsCurrentToken(KeyWords[Index]) then'); - Writeln(OutFile, ' Result := ' + IdentPre + TLexKeys(KeyList[I]).TokenType); - Writeln(OutFile, ' else'); - Writeln(OutFile, ' Result := ' + IdentPre + 'Identifier;'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - inc(I); - end; - - Writeln(OutFile, 'function ' + LexName + '.AltFunc(Index: Integer): T' + IdentPre + - 'TokenKind;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' Result := ' + IdentPre + 'Identifier;'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'function ' + LexName + '.IdentKind(MayBe: PWideChar): T' + - IdentPre + 'TokenKind;'); - Writeln(OutFile, 'var'); - Writeln(OutFile, ' Key: Cardinal;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' fToIdent := MayBe;'); - Writeln(OutFile, ' Key := HashKey(MayBe);'); - Writeln(OutFile, ' if Key <= High(fIdentFuncTable) then'); - Writeln(OutFile, ' Result := fIdentFuncTable[Key](KeyIndices[Key])'); - Writeln(OutFile, ' else'); - Writeln(OutFile, ' Result := ' + IdentPre + 'Identifier;'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - if (IdentList.IndexOf(IdentPre + 'Space') >= 0) then - begin - Writeln(OutFile, 'procedure ' + LexName + '.SpaceProc;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' inc(Run);'); - Writeln(OutFile, ' fTokenID := ' + IdentPre + 'Space;'); - Writeln(OutFile, ' while (FLine[Run] <= #32) and not IsLineEnd(Run) do inc(Run);'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - end; - - Writeln(OutFile, 'procedure ' + LexName + '.NullProc;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' fTokenID := ' + IdentPre + 'Null;'); - Writeln(OutFile, ' inc(Run);'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'procedure ' + LexName + '.CRProc;'); - Writeln(OutFile, 'begin'); - if (IdentList.IndexOf(IdentPre + 'Space') >= 0) then - Writeln(OutFile, ' fTokenID := ' + IdentPre + 'Space;') - else - Writeln(OutFile, ' fTokenID := ' + IdentPre + 'Unknown;'); - Writeln(OutFile, ' inc(Run);'); - Writeln(OutFile, ' if fLine[Run] = #10 then'); - Writeln(OutFile, ' inc(Run);'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'procedure ' + LexName + '.LFProc;'); - Writeln(OutFile, 'begin'); - if (IdentList.IndexOf(IdentPre + 'Space') >= 0) then - Writeln(OutFile, ' fTokenID := ' + IdentPre + 'Space;') - else - Writeln(OutFile, ' fTokenID := ' + IdentPre + 'Unknown;'); - Writeln(OutFile, ' inc(Run);'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - for I := 0 to (EnclosedList.Count - 1) do - begin - Writeln(OutFile, 'procedure ' + LexName + '.' + - TLexEnclosedBy(EnclosedList[I]).ProcName + 'OpenProc;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' Inc(Run);'); - if (Length(TLexEnclosedBy(EnclosedList[I]).StartsWith) > 1) then - begin - Write(OutFile, ' if '); - for J := 2 to Length(TLexEnclosedBy(EnclosedList[I]).StartsWith) do - begin - if (J > 2) then - begin - Writeln(OutFile, ' and'); - Write(OutFile, ' '); - end; - Write(OutFile, '(fLine[Run' + AddInt(J - 2) + '] = ''' + - StuffString(TLexEnclosedBy(EnclosedList[I]).StartsWith[J]) + ''')'); - end; - Writeln(OutFile, ' then'); - Writeln(OutFile, ' begin'); - Writeln(OutFile, ' Inc(Run, ' + - IntToStr(Length(TLexEnclosedBy(EnclosedList[I]).StartsWith)-1) + ');'); - Writeln(OutFile, ' fRange := rs' + - TLexEnclosedBy(EnclosedList[I]).ProcName + ';'); - if not TLexEnclosedBy(EnclosedList[I]).MultiLine then - begin - Writeln(OutFile, ' ' + TLexEnclosedBy(EnclosedList[I]).ProcName + - 'Proc;'); - end; - Writeln(OutFile, ' fTokenID := ' + IdentPre + - TLexEnclosedBy(EnclosedList[I]).TokenName + ';'); - Writeln(OutFile, ' end'); - Writeln(OutFile, ' else'); - if (IdentList.IndexOf(IdentPre + 'Symbol') >= 0) then - Writeln(OutFile, ' fTokenID := ' + IdentPre + 'Symbol;') - else - Writeln(OutFile, ' fTokenID := ' + IdentPre + 'Identifier;'); - end - else - begin - Writeln(OutFile, ' fRange := rs' + - TLexEnclosedBy(EnclosedList[I]).ProcName + ';'); - if not TLexEnclosedBy(EnclosedList[I]).MultiLine then - begin - Writeln(OutFile, ' ' + TLexEnclosedBy(EnclosedList[I]).ProcName + - 'Proc;'); - end; - Writeln(OutFile, ' fTokenID := ' + IdentPre + - TLexEnclosedBy(EnclosedList[I]).TokenName + ';'); - end; - Writeln(OutFile, 'end;'); - Writeln(OutFile); - Writeln(OutFile, 'procedure ' + LexName + '.' + - TLexEnclosedBy(EnclosedList[I]).ProcName + 'Proc;'); - Writeln(OutFile, 'begin'); - if TLexEnclosedBy(EnclosedList[I]).MultiLine then - begin - Writeln(OutFile, ' case fLine[Run] of'); - Writeln(OutFile, ' #0: NullProc;'); - Writeln(OutFile, ' #10: LFProc;'); - Writeln(OutFile, ' #13: CRProc;'); - Writeln(OutFile, ' else'); - Writeln(OutFile, ' begin'); - sPrefix := ' '; - end - else - sPrefix := ''; - Writeln(OutFile, sPrefix, ' fTokenID := ' + IdentPre + - TLexEnclosedBy(EnclosedList[I]).TokenName + ';'); - Writeln(OutFile, sPrefix, ' repeat'); - Write(OutFile, sPrefix, ' if '); - for J := 1 to Length(TLexEnclosedBy(EnclosedList[I]).EndsWith) do - begin - if (J > 1) then - begin - Writeln(OutFile, ' and'); - Write(OutFile, sPrefix, ' '); - end; - Write(OutFile, '(fLine[Run' + AddInt(J - 1) + '] = ''' + - StuffString(TLexEnclosedBy(EnclosedList[I]).EndsWith[J]) + ''')'); - end; - Writeln(OutFile, ' then'); - Writeln(OutFile, sPrefix, ' begin'); - Writeln(OutFile, sPrefix, ' Inc(Run, ' + - IntToStr(Length(TLexEnclosedBy(EnclosedList[I]).EndsWith)) + ');'); - Writeln(OutFile, sPrefix, ' fRange := rsUnKnown;'); - Writeln(OutFile, sPrefix, ' Break;'); - Writeln(OutFile, sPrefix, ' end;'); - Writeln(OutFile, sPrefix, ' if not IsLineEnd(Run) then'); - Writeln(OutFile, sPrefix, ' Inc(Run);'); - Writeln(OutFile, sPrefix, ' until IsLineEnd(Run);'); - Writeln(OutFile, sPrefix, 'end;'); - if TLexEnclosedBy(EnclosedList[I]).MultiLine then - begin - Writeln(OutFile, ' end;'); - Writeln(OutFile, 'end;'); - end; - Writeln(OutFile); - end; - - Writeln(OutFile, 'constructor ' + LexName + '.Create(AOwner: TComponent);'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' inherited Create(AOwner);'); - Writeln(OutFile, ' fCaseSensitive := ' + BoolStrs[Sensitivity] + ';'); - Writeln(OutFile); - - I := 0; - while I < IdentList.Count do - begin - AttrTemp := Copy(IdentList[I], Length(IdentPre) + 1, Length(IdentList[I])); - if AttrTemp = 'Key' then - AttrName := CboAttrReservedWord.Text - else if AttrTemp = 'Identifier' then - AttrName := CboAttrIdentifier.Text - else - AttrName := 'SYNS_Attr' + FilterInvalidChars(AttrTemp); - - if Pos('SYNS_', AttrName) = 1 then - begin - FriendlyAttrName := AttrName; - Insert('Friendly', FriendlyAttrName, Length('SYNS_') + 1) - end - else - FriendlyAttrName := 'Friendly' + AttrName; - - if (IdentList[I] <> IdentPre + 'Null') and (IdentList[I] <> IdentPre + - 'Unknown') then - begin - AttrTemp := 'f' + AttrTemp + 'Attri'; - Writeln(OutFile, ' ' + AttrTemp + ' := TSynHighLighterAttributes.Create(' - + AttrName + ', ' + FriendlyAttrName + ');'); - if Assigned(IdentList.Objects[i]) then - begin - DefAttri := TLexDefaultAttri(IdentList.Objects[i]); - if (DefAttri.Style <> '') then - Writeln(OutFile, ' ' + AttrTemp + '.Style := ' + DefAttri.Style + - ';'); - if (DefAttri.Foreground <> '') then - Writeln(OutFile, ' ' + AttrTemp + '.Foreground := ' + - DefAttri.Foreground + ';'); - if (DefAttri.Background <> '') then - Writeln(OutFile, ' ' + AttrTemp + '.Background := ' + - DefAttri.Background + ';'); - end - else if (IdentList[I] = IdentPre + 'Key') then - Writeln(OutFile, ' ' + AttrTemp + '.Style := [fsBold];') - else if (IdentList[I] = IdentPre + 'Comment') then - begin - Writeln(OutFile, ' ' + AttrTemp + '.Style := [fsItalic];'); - Writeln(OutFile, ' ' + AttrTemp + '.Foreground := clNavy;'); - end; - Writeln(OutFile, ' AddAttribute(' + AttrTemp + ');'); - Writeln(OutFile); - end; - Inc(I); - end; - - Writeln(OutFile, ' SetAttributesOnChange(DefHighlightChange);'); - Writeln(OutFile, ' InitIdent;'); - - Writeln(OutFile, ' fDefaultFilter := ' + GetFilterName + ';'); - Writeln(OutFile, ' fRange := rsUnknown;'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - I := 0; - while I < SetList.Count do - begin - Writeln(OutFile, 'procedure ' + LexName + '.' + - TLexCharsets(SetList[I]).SetName + 'Proc;'); - Writeln(OutFile, 'begin'); - Write(OutFile, ' ' + TLexCharsets(SetList[I]).ProcData); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - inc(I); - end; - - Writeln(OutFile, 'procedure ' + LexName + '.UnknownProc;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' inc(Run);'); - Writeln(OutFile, ' fTokenID := ' + IdentPre + 'Unknown;'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'procedure ' + LexName + '.Next;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' fTokenPos := Run;'); - if (EnclosedList.Count > 0) then - begin - Writeln(OutFile, ' case fRange of'); - for I := 0 to (EnclosedList.Count - 1) do - begin - if TLexEnclosedBy(EnclosedList[I]).MultiLine then - begin - Writeln(OutFile, ' rs' + TLexEnclosedBy(EnclosedList[I]).ProcName + - ': ' + TLexEnclosedBy(EnclosedList[I]).ProcName + 'Proc;'); - end; - end; - Writeln(OutFile, ' else'); - Writeln(OutFile, ' case fLine[Run] of'); - Writeln(OutFile, ' #0: NullProc;'); - Writeln(OutFile, ' #10: LFProc;'); - Writeln(OutFile, ' #13: CRProc;'); - - for I := 0 to (EnclosedList.Count - 1) do - begin - if (TLexEnclosedBy(EnclosedList[I]).StartsWith <> '') then - begin - Writeln(OutFile, ' ''' + - StuffString(TLexEnclosedBy(EnclosedList[I]).StartsWith[1]) + - ''': ' + TLexEnclosedBy(EnclosedList[I]).ProcName + 'OpenProc;'); - end; - end; - if (IdentList.IndexOf(IdentPre + 'Space') >= 0) then - Writeln(OutFile, ' #1..#9, #11, #12, #14..#32: SpaceProc;'); - I := 0; - while I < SetList.Count do - begin - Writeln(OutFile, ' ' + TLexCharsets(SetList[I]).Charset + - ': ' + TLexCharsets(SetList[I]).SetName + 'Proc;'); - Inc(I); - end; - - Writeln(OutFile, ' else'); - Writeln(OutFile, ' UnknownProc;'); - Writeln(OutFile, ' end;'); - Writeln(OutFile, ' end;'); - end - else - begin - Writeln(OutFile, ' case fLine[Run] of'); - Writeln(OutFile, ' #0: NullProc;'); - Writeln(OutFile, ' #10: LFProc;'); - Writeln(OutFile, ' #13: CRProc;'); - - if (IdentList.IndexOf(IdentPre + 'Space') >= 0) then - Writeln(OutFile, ' #1..#9, #11, #12, #14..#32: SpaceProc;'); - I := 0; - while I < SetList.Count do - begin - Writeln(OutFile, ' ' + TLexCharsets(SetList[I]).Charset + - ': ' + TLexCharsets(SetList[I]).SetName + 'Proc;'); - Inc(I); - end; - - Writeln(OutFile, ' else'); - Writeln(OutFile, ' UnknownProc;'); - Writeln(OutFile, ' end;'); - end; - Writeln(OutFile, ' inherited;'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'function ' + LexName + - '.GetDefaultAttribute(Index: Integer): TSynHighLighterAttributes;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' case Index of'); - if (IdentList.IndexOf(IdentPre + 'Comment') >= 0) then - Writeln(OutFile, ' SYN_ATTR_COMMENT: Result := fCommentAttri;'); - if (IdentList.IndexOf(IdentPre + 'Identifier') >= 0) then - Writeln(OutFile, ' SYN_ATTR_IDENTIFIER: Result := fIdentifierAttri;'); - if (IdentList.IndexOf(IdentPre + 'Key') >= 0) then - Writeln(OutFile, ' SYN_ATTR_KEYWORD: Result := fKeyAttri;'); - if (IdentList.IndexOf(IdentPre + 'String') >= 0) then - Writeln(OutFile, ' SYN_ATTR_STRING: Result := fStringAttri;'); - if (IdentList.IndexOf(IdentPre + 'Space') >= 0) then - Writeln(OutFile, ' SYN_ATTR_WHITESPACE: Result := fSpaceAttri;'); - if (IdentList.IndexOf(IdentPre + 'Symbol') >= 0) then - Writeln(OutFile, ' SYN_ATTR_SYMBOL: Result := fSymbolAttri;'); - Writeln(OutFile, ' else'); - Writeln(OutFile, ' Result := nil;'); - Writeln(OutFile, ' end;'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'function ' + LexName + '.GetEol: Boolean;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' Result := Run = fLineLen + 1;'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - if ChkGetKeyWords.Checked then - begin - Writeln(OutFile, 'function ' + LexName + '.GetKeyWords(TokenKind: Integer): UnicodeString;'); - Writeln(OutFile, 'begin'); - TempStringList := TStringList.Create; - try - TempStringList.Sorted := True; - for I := 0 to KeyList.Count - 1 do - TempStringList.Add(TLexKeys(KeyList[I]).KeyName); - if TempStringList.Count > 0 then - begin - Writeln(OutFile, ' Result := '); - for I := 0 to Trunc(Int(Length(TempStringList.CommaText) div 70)) - 1 do - begin - if I = 0 then - LineLength := 69 - else - LineLength := 70; - Writeln(OutFile, ' ' + #39 + Copy(TempStringList.CommaText, - I * 70, LineLength) + #39 + #32 + #43); - end; - I := Trunc(Int(Length(TempStringList.CommaText) div 70)); - Writeln(OutFile, ' ' + #39 + Copy(TempStringList.CommaText, - I * 70, Length(TempStringList.CommaText)) + #39 + ';') - end - else - Writeln(OutFile, ' Result := ' + #39 + #39 + ';'); - finally - TempStringList.Free; - end; - Writeln(OutFile, 'end;'); - Writeln(OutFile); - end; - - Writeln(OutFile, 'function ' + LexName + '.GetTokenID: TtkTokenKind;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' Result := fTokenId;'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'function ' + LexName + - '.GetTokenAttribute: TSynHighLighterAttributes;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' case GetTokenID of'); - - I := 0; - while I < IdentList.Count do - begin - if (IdentList[I] <> IdentPre + 'Null') and (IdentList[I] <> IdentPre + - 'Unknown') then - Writeln(OutFile, ' ' + IdentList[I] + ': Result := f' + - Copy(IdentList[I], Length(IdentPre) + 1, Length(IdentList[I])) + - 'Attri;'); - inc(I); - end; - Writeln(OutFile, ' ' + IdentPre + 'Unknown: Result := f' + - CboUnknownTokenAttr.Text + 'Attri;'); - - Writeln(OutFile, ' else'); - Writeln(OutFile, ' Result := nil;'); - Writeln(OutFile, ' end;'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'function ' + LexName + '.GetTokenKind: Integer;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' Result := Ord(fTokenId);'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'function ' + LexName + '.IsIdentChar(AChar: WideChar): Boolean;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' case AChar of'); - Writeln(OutFile, ' ' + IdentContent + ':'); - Writeln(OutFile, ' Result := True;'); - Writeln(OutFile, ' else'); - Writeln(OutFile, ' Result := False;'); - Writeln(OutFile, ' end;'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'function ' + LexName + '.GetSampleSource: UnicodeString;'); - Writeln(OutFile, 'begin'); - if (SampleSourceList.Count = 0) then - begin - Writeln(OutFile, ' Result := '); - Writeln(OutFile, ' ''Sample source for: ''#13#10 +'); - Writeln(OutFile, ' ''' + EditDescription.Text + ''';'); - end - else - begin - Writeln(OutFile, ' Result := '); - for i := 0 to SampleSourceList.Count - 1 do - begin - if (i > 0) and (i < SampleSourceList.Count - 1) then - Writeln(OutFile, '#13#10 +'); - if (i < SampleSourceList.Count - 1) then - Write(OutFile, ' '); - if SampleSourceList[i] <> '' then - Write(OutFile, '''', StuffString(SampleSourceList[i]), ''''); - end; - Writeln(OutFile, ';'); - end; - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'function ' + LexName + '.IsFilterStored: Boolean;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' Result := fDefaultFilter <> ' + GetFilterName + ';'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'class function ' + LexName + '.GetFriendlyLanguageName: UnicodeString;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' Result := ' + GetFriendlyLangName + ';'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'class function ' + LexName + '.GetLanguageName: string;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' Result := ' + GetLangName + ';'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'procedure ' + LexName + '.ResetRange;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' fRange := rsUnknown;'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'procedure ' + LexName + '.SetRange(Value: Pointer);'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' fRange := TRangeState(Value);'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'function ' + LexName + '.GetRange: Pointer;'); - Writeln(OutFile, 'begin'); - Writeln(OutFile, ' Result := Pointer(fRange);'); - Writeln(OutFile, 'end;'); - Writeln(OutFile); - - Writeln(OutFile, 'initialization'); - Writeln(OutFile, '{$IFNDEF SYN_CPPB_1}'); - Writeln(OutFile, ' RegisterPlaceableHighlighter(' + LexName + ');'); - Writeln(OutFile, '{$ENDIF}'); - Writeln(OutFile, 'end.'); -end; - -procedure TFrmMain.CboLangNameChange(Sender: TObject); -begin - if (CboLangName.Text <> '') and (CboFilter.Text <> '') then - BtnStart.Enabled := True - else - BtnStart.Enabled := False; -end; - -procedure TFrmMain.ListBoxFieldsClick(Sender: TObject); -begin - BtnDelete.Enabled := True; -end; - -procedure TFrmMain.BtnAddClick(Sender: TObject); -begin - ListBoxFields.Items.Add(EditAddField.Text); - EditAddField.Clear; -end; - -procedure TFrmMain.BtnDeleteClick(Sender: TObject); -begin - BtnDelete.Enabled := False; - ListBoxFields.Items.Delete(ListBoxFields.ItemIndex); -end; - -procedure TFrmMain.EditAddFieldChange(Sender: TObject); -begin - BtnAdd.Enabled := EditAddField.Text <> ''; -end; - -procedure TFrmMain.EditAddFieldKeyPress(Sender: TObject; var Key: Char); -begin - if (Key = ';') or (Key = #32) then - Key := #0; -end; - -procedure TFrmMain.MnuExitClick(Sender: TObject); -begin - Close; -end; - -procedure TFrmMain.MnuOpenClick(Sender: TObject); -begin - WriteSettings; - PerformFileOpen; -end; - -procedure TFrmMain.FormClose(Sender: TObject; var Action: TCloseAction); -begin - WriteSettings; -end; - -function TFrmMain.KeywordsAreAllAlphaNumAndDifferent: Boolean; -var - i: Integer; - KeyWordList: TStringList; -begin - Result := True; - - KeyWordList := TStringList.Create; - try - KeyWordList.Sorted := True; - KeyWordList.Duplicates := dupError; - - try - for i := 0 to KeyList.Count - 1 do - KeyWordList.Add(TLexKeys(KeyList[i]).KeyName); - except - Result := False; - Exit; - end; - finally - KeyWordList.Free; - end; - - for i := 0 to KeyList.Count - 1 do - if not IsASCIIAlphaNum(TLexKeys(KeyList[i]).KeyName) then - begin - Result := False; - Exit; - end; -end; - -end. - +{------------------------------------------------------------------------------- +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: SynGenUnit.pas, released 2000-04-19. +Description: Generator for skeletons of HighLighters to use in SynEdit, +drived by a simple grammar. + +The Original Code is based on SynGenU.pas by Martin Waldenburg, part of +the mwEdit component suite. +Portions created by Martin Waldenburg are Copyright (C) 1998 Martin Waldenburg. +Portions created by Pieter Polak are Copyright (C) 2001 Pieter Polak. +Unicode translation by Maël Hörz. +All Rights Reserved. + +Contributors to the SynEdit and mwEdit projects are listed in the +Contributors.txt file. + +Alternatively, the contents of this file may be used under the terms of the +GNU General Public License Version 2 or later (the "GPL"), in which case +the provisions of the GPL are applicable instead of those above. +If you wish to allow use of your version of this file only under the terms +of the GPL and not to allow others to use your version of this file +under the MPL, indicate your decision by deleting the provisions above and +replace them with the notice and other provisions required by the GPL. +If you do not delete the provisions above, a recipient may use your version +of this file under either the MPL or the GPL. + +$Id: SynGenUnit.pas,v 1.18.2.11 2008/10/25 23:30:31 maelh Exp $ + +You may retrieve the latest version of this file at the SynEdit home page, +located at http://SynEdit.SourceForge.net + +Todo: + - Remember the last opened MSG file + - Double-click a MSG file opens SynGen + - Add user-defined default attributes to TSynXXXSyn.Create + - SynEdit to edit the MSG file (using the highlighter for MSG files) + - Store language names list and attribute names list in INI file + - SynEdit with Pascal highlighter to preview the created highlighter source + - Allow to define different type of keywords in MSG file + +Known Issues: +-------------------------------------------------------------------------------} + +unit SynGenUnit; + +{$I SynEdit.inc} + +interface + +uses + Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, + StdCtrls, GenLex, ComCtrls, Menus, SynUnicode; + +var + mKeyHashTable: array[#0..#255] of Integer; + mSKeyHashTable: array[#0..#255] of Integer; + +type + TLexKeys = class + public + KeyName: string; + Key: Cardinal; + TokenType: string; + end; + + TLexCharsets = class + public + SetName: string; + Charset: string; + ProcData: string; + FuncData: string; + end; + + TLexEnclosedBy = class + public + TokenName: string; + ProcName: string; + StartsWith: string; + EndsWith: string; + MultiLine: Boolean; + constructor Create; + end; + + TLexDefaultAttri = class + public + Style: string; + Foreground: string; + Background: string; + constructor Create; + end; + + TFormMain = class(TForm) + ButtonAdd: TButton; + ButtonDelete: TButton; + ButtonStart: TButton; + ComboBoxAttrIdentifier: TComboBox; + ComboBoxAttrReservedWord: TComboBox; + ComboBoxFilter: TComboBox; + ComboBoxLangName: TComboBox; + ComboBoxUnknownTokenAttr: TComboBox; + CheckBoxGetKeyWords: TCheckBox; + CheckBoxGPLHeader: TCheckBox; + EditAddField: TEdit; + EditAuthor: TEdit; + EditDescription: TEdit; + EditVersion: TEdit; + GrpAttrNames: TGroupBox; + LabelAuthor: TLabel; + LabelDescription: TLabel; + LabelFilter: TLabel; + LabelIdentifier: TLabel; + LabelLangName: TLabel; + LabelReservedWord: TLabel; + LabelUnknownTokenAttr: TLabel; + LabelVersion: TLabel; + ListBoxFields: TListBox; + MainMenu: TMainMenu; + MenuItemExit: TMenuItem; + MenuItemFile: TMenuItem; + MenuItemOpen: TMenuItem; + MenuItemStart: TMenuItem; + OpenDialog: TOpenDialog; + PageControl: TPageControl; + TabAttributes: TTabSheet; + TabFields: TTabSheet; + TabHighlighter: TTabSheet; + TabLanguage: TTabSheet; + procedure ButtonStartClick(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure FormDestroy(Sender: TObject); + procedure ComboBoxLangNameChange(Sender: TObject); + procedure ListBoxFieldsClick(Sender: TObject); + procedure ButtonAddClick(Sender: TObject); + procedure ButtonDeleteClick(Sender: TObject); + procedure EditAddFieldChange(Sender: TObject); + procedure EditAddFieldKeyPress(Sender: TObject; var Key: Char); + procedure MenuItemExitClick(Sender: TObject); + procedure MenuItemOpenClick(Sender: TObject); + procedure FormClose(Sender: TObject; var Action: TCloseAction); + private + FLexName: string; + FIdentPre: string; + FIdentStart: string; + FIdentContent: string; + FFileName: string; + FIniFile: string; + FOutFile: TextFile; + FSensitivity: Boolean; + FLexFileContents: UnicodeString; + FLex: TGenLex; + FKeyList: TList; + FSetList: TList; + FEnclosedList: TList; + FSampleSourceList: TStringList; + FIdentList: TStringList; + procedure ClearAll; + function GetFilterName: string; + function GetLangName: string; + function FilterInvalidChars(const Value: string): string; + procedure MakeHashTable; + procedure MakeSensitiveHashTable; + procedure FillKeyList; + procedure FillTokenTypeList; + procedure OutFileCreate(InName: string); + procedure ParseCharsets; + procedure ParseEnclosedBy; + procedure ParseSampleSource; + procedure RetrieveCharset; + procedure RetrieveEnclosedBy; + procedure RetrieveSampleSource; + procedure WriteSettings; + function PerformFileOpen: Boolean; + procedure WriteRest; + function KeywordsAreAllAlphaNumAndDifferent: Boolean; + function GetFriendlyLangName: string; + public + end; + +var + FormMain: TFormMain; + +implementation + +{$R *.DFM} + +uses +{$IFDEF SYN_COMPILER_6_UP} + StrUtils, +{$ENDIF} + Registry, HashTableGen; + +const + BoolStrs: array[Boolean] of string = ('False', 'True'); // Do not localize + +function CompareKeys(Item1, Item2: Pointer): Integer; +begin + Result := AnsiCompareStr(TLexKeys(Item1).KeyName, TLexKeys(Item2).KeyName); +end; + +function CompareSets(Item1, Item2: Pointer): Integer; +begin + Result := 0; + if TLexCharsets(Item1).SetName < TLexCharsets(Item2).SetName then + Result := -1 + else if TLexCharsets(Item1).SetName > TLexCharsets(Item2).SetName then + Result := 1; +end; + +function AddInt(const aValue: Integer): string; +begin + if (aValue < 0) then + Result := ' - ' + IntToStr(Abs(aValue)) + else if (aValue > 0) then + Result := ' + ' + IntToStr(aValue) + else + Result := ''; +end; + +function StuffString(const Value: UnicodeString): UnicodeString; +var + i: Integer; +begin + Result := ''; + for i := 1 to Length(Value) do + begin + if (Value[i] = '''') then + Result := Result + '''''' + else + Result := Result + Value[i]; + end; +end; + +function FirstLetterCap(S: UnicodeString): UnicodeString; +begin + Result := SynWideLowerCase(S); + if Length(Result) > 0 then + Result[1] := SynWideUpperCase(S[1])[1]; +end; + +{$IFNDEF SYN_COMPILER_6_UP} +function AnsiReplaceStr(const AText, AFromText, AToText: string): string; +begin + Result := StringReplace(AText, AFromText, AToText, [rfReplaceAll]); +end; +{$ENDIF} + +function ToAlphaNum(S: UnicodeString): UnicodeString; +var + c: Char; +begin + for c := #33 to #47 do + S := AnsiReplaceStr(S, c, IntToStr(Ord(c))); + + for c := #58 to #64 do + S := AnsiReplaceStr(S, c, IntToStr(Ord(c))); + + for c := #91 to #96 do + S := AnsiReplaceStr(S, c, IntToStr(Ord(c))); + + for c := #123 to #191 do + S := AnsiReplaceStr(S, c, IntToStr(Ord(c))); + + Result := S; +end; + +function IsASCIIAlphaNum(S: UnicodeString): Boolean; +var + i: Integer; +begin + Result := True; + + S := ToAlphaNum(S); + + for i := 1 to Length(S) do + case S[i] of + 'a'..'z', 'A'..'Z', '0'..'9', '_': ; + else + begin + Result := False; + Exit; + end; + end; +end; + +constructor TLexEnclosedBy.Create; +begin + inherited Create; + TokenName := ''; + ProcName := ''; + StartsWith := ''; + EndsWith := ''; + MultiLine := False; +end; + +constructor TLexDefaultAttri.Create; +begin + inherited Create; + Style := ''; + Foreground := ''; + Background := ''; +end; + +procedure TFormMain.MakeSensitiveHashTable; +var + I: Char; +begin + for I := #0 to #255 do + begin + case CharInSet(I, ['_', 'A'..'Z', 'a'..'z']) of + True: + begin + if (I > #64) and (I < #91) then + mSKeyHashTable[I] := Ord(I) - 64 + else if (I > #96) then + mSKeyHashTable[I] := Ord(I) - 95; + end; + else + mSKeyHashTable[I] := 0; + end; + end; +end; + +procedure TFormMain.MakeHashTable; +var + I, J: Char; +begin + for I := #0 to #255 do + begin + J := UpperCase(I)[1]; + case CharInSet(I, ['_', 'A'..'Z', 'a'..'z']) of + True: mKeyHashTable[I] := Ord(J) - 64; + else + mKeyHashTable[I] := 0; + end; + end; +end; + +procedure TFormMain.WriteSettings; +begin + with TRegIniFile.Create(FIniFile) do + try + WriteString('General', 'OpenDir', OpenDialog.InitialDir); + WriteBool(FFileName, 'GetKeyWords', CheckBoxGetKeyWords.Checked); + WriteBool(FFileName, 'CheckBoxGPLHeader', CheckBoxGPLHeader.Checked); + WriteString(FFileName, 'Author', EditAuthor.Text); + WriteString(FFileName, 'Description', EditDescription.Text); + WriteString(FFileName, 'Version', EditVersion.Text); + WriteString(FFileName, 'Filter', ComboBoxFilter.Text); + WriteString(FFileName, 'Language', ComboBoxLangName.Text); + WriteString(FFileName, 'AttrIdentifier', ComboBoxAttrIdentifier.Text); + WriteString(FFileName, 'AttrReservedWord', ComboBoxAttrReservedWord.Text); + WriteString(FFileName, 'UnknownTokenAttr', ComboBoxUnknownTokenAttr.Text); + WriteString(FFileName, 'Fields', ListBoxFields.Items.CommaText); + finally + Free; + end; +end; + +function TFormMain.PerformFileOpen: Boolean; +var + UserName: PChar; +{$IFDEF SYN_COMPILER_5_UP} + Count: Cardinal; +{$ELSE} + Count: Integer; +{$ENDIF} +begin + if OpenDialog.Execute then + begin + Count := 0; + Result := True; + FFileName := ExtractFileName(OpenDialog.FileName); + Caption := 'SynGen - ' + FFileName; + Application.Title := Caption; + OpenDialog.InitialDir := ExtractFilePath(OpenDialog.FileName); + GetUserName(nil, Count); + // retrieve the required size of the user name buffer + UserName := StrAlloc(Count); // allocate memory for the user name + GetUserName(UserName, Count); // retrieve the user name + with TRegIniFile.Create(FIniFile) do + try + EditAuthor.Text := ReadString(FFileName, 'Author', StrPas(UserName)); + EditDescription.Text := ReadString(FFileName, 'Description', + 'Syntax Parser/Highlighter'); + EditVersion.Text := ReadString(FFileName, 'Version', '0.1'); + ComboBoxFilter.Text := ReadString(FFileName, 'Filter', 'All files (*.*)|*.*'); + ComboBoxLangName.Text := ReadString(FFileName, 'Language', ''); + CheckBoxGetKeyWords.Checked := ReadBool(FFileName, 'GetKeyWords', True); + CheckBoxGPLHeader.Checked := ReadBool(FFileName, 'CheckBoxGPLHeader', True); + ComboBoxAttrIdentifier.ItemIndex := ComboBoxAttrIdentifier.Items.IndexOf + (ReadString(FFileName, 'AttrIdentifier', 'SYNS_AttrIdentifier')); + ComboBoxAttrReservedWord.ItemIndex := ComboBoxAttrReservedWord.Items.IndexOf + (ReadString(FFileName, 'AttrReservedWord', 'SYNS_AttrReservedWord')); + ComboBoxUnknownTokenAttr.ItemIndex := ComboBoxUnknownTokenAttr.Items.IndexOf + (ReadString(FFileName, 'UnknownTokenAttr', 'Identifier')); + ListBoxFields.Items.CommaText := ReadString(FFileName, 'Fields', ''); + finally + Free; + end; + StrDispose(UserName); + ComboBoxLangNameChange(Self); + end + else + Result := False; +end; + +procedure TFormMain.FormCreate(Sender: TObject); +var + i: Integer; + items: TStrings; +begin + for i := FormMain.ComponentCount - 1 downto 0 do + if FormMain.Components[i] is TComboBox then + if TComboBox(FormMain.Components[i]).Parent = GrpAttrNames then + begin + items := TComboBox(FormMain.Components[i]).Items; + items.Clear; + items.Add('SYNS_AttrAsm'); + items.Add('SYNS_AttrAsmComment'); + items.Add('SYNS_AttrAsmKey'); + items.Add('SYNS_AttrASP'); + items.Add('SYNS_AttrAssembler'); + items.Add('SYNS_AttrBlock'); + items.Add('SYNS_AttrBrackets'); + items.Add('SYNS_AttrCharacter'); + items.Add('SYNS_AttrClass'); + items.Add('SYNS_AttrComment'); + items.Add('SYNS_AttrCondition'); + items.Add('SYNS_AttrDir'); + items.Add('SYNS_AttrDirective'); + items.Add('SYNS_AttrDocumentation'); + items.Add('SYNS_AttrEmbedSQL'); + items.Add('SYNS_AttrEmbedText'); + items.Add('SYNS_AttrEscapeAmpersand'); + items.Add('SYNS_AttrForm'); + items.Add('SYNS_AttrFunction'); + items.Add('SYNS_AttrIcon'); + items.Add('SYNS_AttrIdentifier'); + items.Add('SYNS_AttrIllegalChar'); + items.Add('SYNS_AttrIndirect'); + items.Add('SYNS_AttrInvalidSymbol'); + items.Add('SYNS_AttrInternalFunction'); + items.Add('SYNS_AttrKey'); + items.Add('SYNS_AttrLabel'); + items.Add('SYNS_AttrMacro'); + items.Add('SYNS_AttrMarker'); + items.Add('SYNS_AttrMessage'); + items.Add('SYNS_AttrMiscellaneous'); + items.Add('SYNS_AttrNull'); + items.Add('SYNS_AttrNumber'); + items.Add('SYNS_AttrOperator'); + items.Add('SYNS_AttrPragma'); + items.Add('SYNS_AttrPreprocessor'); + items.Add('SYNS_AttrQualifier'); + items.Add('SYNS_AttrRegister'); + items.Add('SYNS_AttrReservedWord'); + items.Add('SYNS_AttrRpl'); + items.Add('SYNS_AttrRplKey'); + items.Add('SYNS_AttrRplComment'); + items.Add('SYNS_AttrSASM'); + items.Add('SYNS_AttrSASMComment'); + items.Add('SYNS_AttrSASMKey'); + items.Add('SYNS_AttrSecondReservedWord'); + items.Add('SYNS_AttrSection'); + items.Add('SYNS_AttrSpace'); + items.Add('SYNS_AttrSpecialVariable'); + items.Add('SYNS_AttrString'); + items.Add('SYNS_AttrSymbol'); + items.Add('SYNS_AttrSyntaxError'); + items.Add('SYNS_AttrSystem'); + items.Add('SYNS_AttrSystemValue'); + items.Add('SYNS_AttrText'); + items.Add('SYNS_AttrUnknownWord'); + items.Add('SYNS_AttrUser'); + items.Add('SYNS_AttrUserFunction'); + items.Add('SYNS_AttrValue'); + items.Add('SYNS_AttrVariable'); + end; + PageControl.ActivePage := PageControl.Pages[0]; + FLex := TGenLex.Create; + FKeyList := TList.Create; + FSetList := TList.Create; + FEnclosedList := TList.Create; + FSampleSourceList := TStringList.Create; + FIdentList := TStringList.Create; + // read ini file + FIniFile := Copy(ExtractFileName(Application.ExeName), 0, + Length(ExtractFileName(Application.ExeName)) - + Length(ExtractFileExt(Application.ExeName))) + '.ini'; + with TRegIniFile.Create(FIniFile) do + try + OpenDialog.InitialDir := ReadString('General', 'OpenDir', + ExtractFilePath(Application.ExeName)); + finally + Free; + end; + + { Move form off the screen, but show already, to activate it correctly when + OpenFileDialog is closed with OK. } + Left := -10000; + Show; + if PerformFileOpen then + begin + MakeHashTable; + MakeSensitiveHashTable; + Position := poScreenCenter; // move form on the screen ("make visible") + end + else + Application.Terminate +end; + +procedure TFormMain.ClearAll; +var + I: Integer; +begin + // Clear the contents of FKeyList + for I := 0 to (FKeyList.Count - 1) do + TObject(FKeyList[I]).Free; + FKeyList.Clear; + // Clear the contents of FSetList + for I := 0 to (FSetList.Count - 1) do + TObject(FSetList[I]).Free; + FSetList.Clear; + // Clear the contents of FEnclosedList + for I := 0 to (FEnclosedList.Count - 1) do + TObject(FEnclosedList[I]).Free; + FEnclosedList.Clear; + // Clear the contents of FIdentList + for I := 0 to (FIdentList.Count - 1) do + begin + if Assigned(FIdentList.Objects[I]) then + TObject(FIdentList.Objects[I]).Free; + end; + FIdentList.Clear; + // Clear the contents of FSampleSourceList + FSampleSourceList.Clear; +end; + +procedure TFormMain.FormDestroy(Sender: TObject); +begin + ClearAll; + FLex.Free; + FIdentList.Free; + FKeyList.Free; + FSetList.Free; + FEnclosedList.Free; +end; + +procedure TFormMain.ButtonStartClick(Sender: TObject); +var + LexFileLines: TUnicodeStringList; +begin + ClearAll; + + Screen.Cursor := crHourGlass; + + LexFileLines := TUnicodeStringList.Create; + try + LexFileLines.LoadFromFile(OpenDialog.FileName); + FLexFileContents := LexFileLines.Text; + finally + LexFileLines.Free; + end; + FLex.Origin := PWideChar(FLexFileContents); + FLex.Tokenize; + + while FLex.RunId <> IDIdentifier do + FLex.Next; + FLexName := FLex.RunToken; + + FLex.Next; + while FLex.RunId <> IDIdentifier do + FLex.Next; + FIdentPre := FLex.RunToken; + + OutFileCreate(OpenDialog.FileName); + try + while not (FLex.RunId in [IdSensitive, IdIdentStart]) do + FLex.Next; + + if FLex.RunId = IdSensitive then + FSensitivity := True + else + FSensitivity := False; + FLex.Next; + + while FLex.RunId <> IDCharSet do + FLex.Next; + FIdentStart := FLex.RunToken; + FLex.Next; + + while FLex.RunId <> IDNull do + begin + case FLex.RunId of + IDCharSet: FIdentContent := FLex.RunToken; + IDKeys: FillKeyList; + IDTokenTypes: FillTokenTypeList; + IDChars: ParseCharSets; + IDEnclosedBy: ParseEnclosedBy; + IDSampleSource: ParseSampleSource; + end; + FLex.Next; + end; + + if (FKeyList.Count = 0) then + raise Exception.Create('You should specify at least 1 keyword!'); + if (FIdentList.Count = 0) then + raise Exception.Create('You should specify at least 1 token type'); + if not KeywordsAreAllAlphaNumAndDifferent then + raise Exception.Create('One or more keywords contain unhandable characters'); + + FrmHashTableGen.AssignKeyWords(FKeyList, FSensitivity); + FrmHashTableGen.ShowModal; + + WriteRest; + while (FLex.RunId <> IdNull) do + begin + FLex.Next; + end; + finally + Screen.Cursor := crDefault; + CloseFile(FOutFile); + end; + MessageDlg(FLexName + ' created on ' + DateTimeToStr(Now), mtInformation, + [mbOk], 0); +end; + +procedure TFormMain.FillKeyList; +var + aLexKey: TLexKeys; + aString: string; + aTokenType: string; +begin + FLex.Next; + + aTokenType := ''; + while FLex.RunId <> IdCRLF do + begin + if not (FLex.RunId in [IdSpace, IdBraceOpen]) then + aTokenType := aTokenType + FLex.RunToken; + FLex.Next; + end; + + if (aTokenType = '') then + aTokenType := 'Key'; + + while FLex.RunId <> IdStop do + begin + while FLex.RunId in [IdSpace, IdBraceOpen, IdCRLF] do + FLex.Next; + if FLex.RunId <> IdStop then + begin + aString := ''; + while not (FLex.RunId in [IdSpace, IdBraceOpen, IdCRLF]) do + begin + aString := aString + FLex.RunToken; + FLex.Next; + end; + aLexKey := TLexKeys.Create; + aLexKey.TokenType := aTokenType; + aLexKey.KeyName := aString; + FKeyList.Add(aLexKey); + end + else + Break; + FLex.Next; + end; + FKeyList.Sort(CompareKeys); +end; + +procedure TFormMain.FillTokenTypeList; +var + i: Integer; + List: TStringList; + sIdent: string; + sLine: string; + DefAttri: TLexDefaultAttri; +begin + FLex.Next; + FIdentList.Add(FIdentPre + 'Unknown'); + FIdentList.Add(FIdentPre + 'Null'); + while (FLex.RunId <> IdStop) do + begin + while FLex.RunId in [IdSpace, IdBraceOpen, IdCRLF, IDUnknown] do + FLex.Next; + if (FLex.RunId <> IdStop) then + begin + sIdent := FIdentPre + FLex.RunToken; + if not IsValidIdent(sIdent) then + raise Exception.Create('Invalid identifier for token type: ' + sIdent); + + if (FIdentList.IndexOf(sIdent) < 0) then + FIdentList.Add(sIdent); + FLex.Next; + + sLine := ''; + while (FLex.RunId = IdSpace) do + FLex.Next; + while not (FLex.RunId in [IdStop, IdCRLF]) do + begin { is there more data on this line? } + sLine := sLine + FLex.RunToken; + FLex.Next; + end; + + if (sLine <> '') then { The Msg file specifies default attributes } + begin + List := TStringList.Create; + try + while (sLine <> '') do + begin + i := Pos('|', sLine); + if (i > 0) then + begin + List.Add(Copy(sLine, 1, i - 1)); + Delete(sLine, 1, i); + end + else + begin + List.Add(sLine); + sLine := ''; + end; + end; + + i := FIdentList.IndexOf(sIdent); + if (i >= 0) then + begin + DefAttri := TLexDefaultAttri.Create; + DefAttri.Style := List.Values['Style']; + DefAttri.Foreground := List.Values['Foreground']; + DefAttri.Background := List.Values['Background']; + FIdentList.Objects[i] := DefAttri; + end; + finally + List.Free; + end; + end; + end + else + Break; + end; +end; + +procedure TFormMain.OutFileCreate(InName: string); +var + OutName, UName: string; + sysTime: TSystemTime; + ISODate: string; +begin + OutName := ChangeFileExt(InName, '.pas'); + Uname := ExtractFileName(ChangeFileExt(InName, '')); + AssignFile(FOutFile, OutName); + rewrite(FOutFile); + GetSystemTime(sysTime); + ISODate := Format('%.4d-%.2d-%.2d', [sysTime.wYear, sysTime.wMonth, + sysTime.wDay]); + if CheckBoxGPLHeader.Checked then + begin + Writeln(FOutFile, + '{-------------------------------------------------------------------------------'); + Writeln(FOutFile, + 'The contents of this file are subject to the Mozilla Public License'); + Writeln(FOutFile, + 'Version 1.1 (the "License"); you may not use this file except in compliance'); + Writeln(FOutFile, + 'with the License. You may obtain a copy of the License at'); + Writeln(FOutFile, 'http://www.mozilla.org/MPL/'); + Writeln(FOutFile); + Writeln(FOutFile, + 'Software distributed under the License is distributed on an "AS IS" basis,'); + Writeln(FOutFile, + 'WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for'); + Writeln(FOutFile, + 'the specific language governing rights and limitations under the License.'); + Writeln(FOutFile); + Writeln(FOutFile, 'Code template generated with SynGen.'); + Writeln(FOutFile, 'The original code is: ' + OutName + ', released ' + ISODate + + '.'); + Writeln(FOutFile, 'Description: ' + EditDescription.Text); + Writeln(FOutFile, 'The initial author of this file is ' + EditAuthor.Text + + '.'); + Writeln(FOutFile, 'Copyright (c) ' + Format('%d', [sysTime.wYear]) + + ', all rights reserved.'); + Writeln(FOutFile); + Writeln(FOutFile, + 'Contributors to the SynEdit and mwEdit projects are listed in the'); + Writeln(FOutFile, 'Contributors.txt file.'); + Writeln(FOutFile); + Writeln(FOutFile, + 'Alternatively, the contents of this file may be used under the terms of the'); + Writeln(FOutFile, + 'GNU General Public License Version 2 or later (the "GPL"), in which case'); + Writeln(FOutFile, + 'the provisions of the GPL are applicable instead of those above.'); + Writeln(FOutFile, + 'If you wish to allow use of your version of this file only under the terms'); + Writeln(FOutFile, + 'of the GPL and not to allow others to use your version of this file'); + Writeln(FOutFile, + 'under the MPL, indicate your decision by deleting the provisions above and'); + Writeln(FOutFile, + 'replace them with the notice and other provisions required by the GPL.'); + Writeln(FOutFile, + 'If you do not delete the provisions above, a recipient may use your version'); + Writeln(FOutFile, 'of this file under either the MPL or the GPL.'); + Writeln(FOutFile); + Writeln(FOutFile, '$' + 'Id: ' + '$'); + Writeln(FOutFile); + Writeln(FOutFile, + 'You may retrieve the latest version of this file at the SynEdit home page,'); + Writeln(FOutFile, 'located at http://SynEdit.SourceForge.net'); + Writeln(FOutFile); + Writeln(FOutFile, + '-------------------------------------------------------------------------------}'); + end + else + begin + Writeln(FOutFile, + '{+-----------------------------------------------------------------------------+'); + Writeln(FOutFile, ' | Class: ' + FLexName); + Writeln(FOutFile, ' | Created: ' + ISODate); + Writeln(FOutFile, ' | Last change: ' + ISODate); + Writeln(FOutFile, ' | Author: ' + EditAuthor.Text); + Writeln(FOutFile, ' | Description: ' + EditDescription.Text); + Writeln(FOutFile, ' | Version: ' + EditVersion.Text); + Writeln(FOutFile, ' |'); + Writeln(FOutFile, ' | Copyright (c) ' + Format('%d', [sysTime.wYear]) + #32 + + EditAuthor.Text + '. All rights reserved.'); + Writeln(FOutFile, ' |'); + Writeln(FOutFile, ' | Generated with SynGen.'); + Writeln(FOutFile, + ' +----------------------------------------------------------------------------+}'); + end; + Writeln(FOutFile); + Writeln(FOutFile, 'unit ' + Uname + ';'); + Writeln(FOutFile); + Writeln(FOutFile, '{$I SynEdit.inc}'); + Writeln(FOutFile); + Writeln(FOutFile, 'interface'); + Writeln(FOutFile); + Writeln(FOutFile, 'uses'); + Writeln(FOutFile, ' Graphics,'); + Writeln(FOutFile, ' SynEditTypes,'); + Writeln(FOutFile, ' SynEditHighlighter,'); + Writeln(FOutFile, ' SynUnicode,'); + Writeln(FOutFile, ' SysUtils,'); + Writeln(FOutFile, ' Classes;'); + Writeln(FOutFile); + Writeln(FOutFile, 'type'); + Writeln(FOutFile, ' T' + FIdentPre + 'TokenKind = ('); +end; + +procedure TFormMain.ParseCharsets; +begin + FLex.Next; + while FLex.RunId <> IdStop do + begin + case FLex.RunId of + IdCharset: RetrieveCharset; + else + FLex.Next; + end; + end; +end; + +procedure TFormMain.ParseEnclosedBy; +begin + FLex.Next; + while not (FLex.RunId in [IdStop, IdNull]) do + RetrieveEnclosedBy; +end; + +procedure TFormMain.ParseSampleSource; +begin + FLex.Next; + if (FLex.RunId = IdCRLF) then + FLex.Next; + + while not (FLex.RunId in [IdStop, IdNull]) do + RetrieveSampleSource; +end; + +procedure TFormMain.RetrieveCharset; +var + aSet: TLexCharsets; +begin + aSet := TLexCharsets.Create; + aSet.Charset := FLex.RunToken; + while FLex.RunId <> IDIdentifier do + FLex.Next; + aSet.SetName := FLex.RunToken; + while FLex.RunId <> IDBeginProc do + FLex.Next; + FLex.Next; + while FLex.RunId in [IdCRLF, IdSpace] do + FLex.Next; + while not (FLex.RunId = IdEndProc) do + begin + aSet.ProcData := aSet.ProcData + FLex.RunToken; + FLex.Next; + end; + FSetList.Add(aSet); + FLex.Next; +end; + +procedure TFormMain.RetrieveSampleSource; +var + sLine: string; +begin + sLine := ''; + while not (FLex.RunId in [IdCRLF, IdNull, IdStop]) do + begin + sLine := sLine + FLex.RunToken; + FLex.Next; + end; + if (FLex.RunId = IdCRLF) then + FLex.Next; + + FSampleSourceList.Add(sLine); +end; + +procedure TFormMain.RetrieveEnclosedBy; +var + aThing: TLexEnclosedBy; + sLine: string; + iPos: Integer; +begin + while FLex.RunId in [IdCRLF, IdSpace] do + FLex.Next; + + sLine := ''; + while not (FLex.RunId in [IdCRLF, IdNull, IdStop]) do + begin + sLine := sLine + FLex.RunToken; + FLex.Next; + end; + + if (sLine <> '') then + begin + aThing := TLexEnclosedBy.Create; + + iPos := Pos(',', sLine); + aThing.TokenName := Copy(sLine, 1, iPos - 1); + Delete(sLine, 1, iPos); + + iPos := Pos(',', sLine); + aThing.ProcName := Copy(sLine, 1, iPos - 1); + Delete(sLine, 1, iPos); + + iPos := Pos(',', sLine); + aThing.StartsWith := Copy(sLine, 1, iPos - 1); + Delete(sLine, 1, iPos); + + iPos := Pos(',', sLine); + if (iPos > 0) then + begin + aThing.EndsWith := Copy(sLine, 1, iPos - 1); + Delete(sLine, 1, iPos); + if (Pos('MULTILINE', UpperCase(sLine)) = 1) then + aThing.MultiLine := True; + end + else + aThing.EndsWith := sLine; + + FEnclosedList.Add(aThing); + end + else if (FLex.RunId <> IdStop) then + FLex.Next; +end; { RetrieveEnclosedBy } + +function TFormMain.FilterInvalidChars(const Value: string): string; +var + i: Integer; +begin + Result := ''; + for i := 1 to Length(Value) do + begin + if IsValidIdent(Result + Value[i]) then + Result := Result + Value[i]; + end; +end; { FilterInvalidChars } + +function TFormMain.GetFilterName: string; +var + FilterName: string; +begin + FilterName := ''; + case ComboBoxFilter.ItemIndex of + -1: FilterName := 'SYNS_Filter' + FilterInvalidChars(ComboBoxLangName.Text); + 0: FilterName := 'SYNS_FilterPascal'; + 1: FilterName := 'SYNS_FilterHP48'; + 2: FilterName := 'SYNS_FilterCAClipper'; + 3: FilterName := 'SYNS_FilterCPP'; + 4: FilterName := 'SYNS_FilterJava'; + 5: FilterName := 'SYNS_FilterPerl'; + 6: FilterName := 'SYNS_FilterAWK'; + 7: FilterName := 'SYNS_FilterHTML'; + 8: FilterName := 'SYNS_FilterVBScript'; + 9: FilterName := 'SYNS_FilterGalaxy'; + 10: FilterName := 'SYNS_FilterPython'; + 11: FilterName := 'SYNS_FilterSQL'; + 12: FilterName := 'SYNS_FilterTclTk'; + 13: FilterName := 'SYNS_FilterRTF'; + 14: FilterName := 'SYNS_FilterBatch'; + 15: FilterName := 'SYNS_FilterDFM'; + 16: FilterName := 'SYNS_FilterX86Asm'; + 17: FilterName := 'SYNS_FilterGembase'; + 18: FilterName := 'SYNS_FilterINI'; + 19: FilterName := 'SYNS_FilterML'; + 20: FilterName := 'SYNS_FilterVisualBASIC'; + 21: FilterName := 'SYNS_FilterADSP21xx'; + 22: FilterName := 'SYNS_FilterPHP'; + 23: FilterName := 'SYNS_FilterCache'; + 24: FilterName := 'SYNS_FilterCSS'; + 25: FilterName := 'SYNS_FilterJScript'; + 26: FilterName := 'SYNS_FilterKIX'; + 27: FilterName := 'SYNS_FilterBaan'; + 28: FilterName := 'SYNS_FilterFoxpro'; + 29: FilterName := 'SYNS_FilterFortran'; + 30: FilterName := 'SYNS_FilterAsm68HC11'; + end; + Result := FilterName; +end; + +function TFormMain.GetFriendlyLangName: string; +var + LangName: string; +begin + case ComboBoxLangName.ItemIndex of + -1: LangName := 'SYNS_FriendlyLang' + FilterInvalidChars(ComboBoxLangName.Text); + 0: LangName := 'SYNS_FriendlyLangHP48'; + 1: LangName := 'SYNS_FriendlyLangCAClipper'; + 2: LangName := 'SYNS_FriendlyLangCPP'; + 3: LangName := 'SYNS_FriendlyLangJava'; + 4: LangName := 'SYNS_FriendlyLangPerl'; + 5: LangName := 'SYNS_FriendlyLangBatch'; + 6: LangName := 'SYNS_FriendlyLangDfm'; + 7: LangName := 'SYNS_FriendlyLangAWK'; + 8: LangName := 'SYNS_FriendlyLangHTML'; + 9: LangName := 'SYNS_FriendlyLangVBSScript'; + 10: LangName := 'SYNS_FriendlyLangGalaxy'; + 11: LangName := 'SYNS_FriendlyLangGeneral'; + 12: LangName := 'SYNS_FriendlyLangPascal'; + 13: LangName := 'SYNS_FriendlyLangX86Asm'; + 14: LangName := 'SYNS_FriendlyLangPython'; + 15: LangName := 'SYNS_FriendlyLangTclTk'; + 16: LangName := 'SYNS_FriendlyLangSQL'; + 17: LangName := 'SYNS_FriendlyLangGembase'; + 18: LangName := 'SYNS_FriendlyLangINI'; + 19: LangName := 'SYNS_FriendlyLangML'; + 20: LangName := 'SYNS_FriendlyLangVisualBASIC'; + 21: LangName := 'SYNS_FriendlyLangADSP21xx'; + 22: LangName := 'SYNS_FriendlyLangPHP'; + 23: LangName := 'SYNS_FriendlyLangSybaseSQL'; + 24: LangName := 'SYNS_FriendlyLangGeneralMulti'; + 25: LangName := 'SYNS_FriendlyLangCache'; + 26: LangName := 'SYNS_FriendlyLangCSS'; + 27: LangName := 'SYNS_FriendlyLangJScript'; + 28: LangName := 'SYNS_FriendlyLangKIX'; + 29: LangName := 'SYNS_FriendlyLangBaan'; + 30: LangName := 'SYNS_FriendlyLangFoxpro'; + 31: LangName := 'SYNS_FriendlyLangFortran'; + 32: LangName := 'SYNS_FriendlyLang68HC11'; + end; + Result := LangName; +end; + +function TFormMain.GetLangName: string; +var + LangName: string; +begin + case ComboBoxLangName.ItemIndex of + -1: LangName := 'SYNS_Lang' + FilterInvalidChars(ComboBoxLangName.Text); + 0: LangName := 'SYNS_LangHP48'; + 1: LangName := 'SYNS_LangCAClipper'; + 2: LangName := 'SYNS_LangCPP'; + 3: LangName := 'SYNS_LangJava'; + 4: LangName := 'SYNS_LangPerl'; + 5: LangName := 'SYNS_LangBatch'; + 6: LangName := 'SYNS_LangDfm'; + 7: LangName := 'SYNS_LangAWK'; + 8: LangName := 'SYNS_LangHTML'; + 9: LangName := 'SYNS_LangVBSScript'; + 10: LangName := 'SYNS_LangGalaxy'; + 11: LangName := 'SYNS_LangGeneral'; + 12: LangName := 'SYNS_LangPascal'; + 13: LangName := 'SYNS_LangX86Asm'; + 14: LangName := 'SYNS_LangPython'; + 15: LangName := 'SYNS_LangTclTk'; + 16: LangName := 'SYNS_LangSQL'; + 17: LangName := 'SYNS_LangGembase'; + 18: LangName := 'SYNS_LangINI'; + 19: LangName := 'SYNS_LangML'; + 20: LangName := 'SYNS_LangVisualBASIC'; + 21: LangName := 'SYNS_LangADSP21xx'; + 22: LangName := 'SYNS_LangPHP'; + 23: LangName := 'SYNS_LangSybaseSQL'; + 24: LangName := 'SYNS_LangGeneralMulti'; + 25: LangName := 'SYNS_LangCache'; + 26: LangName := 'SYNS_LangCSS'; + 27: LangName := 'SYNS_LangJScript'; + 28: LangName := 'SYNS_LangKIX'; + 29: LangName := 'SYNS_LangBaan'; + 30: LangName := 'SYNS_LangFoxpro'; + 31: LangName := 'SYNS_LangFortran'; + 32: LangName := 'SYNS_Lang68HC11'; + end; + Result := LangName; +end; + +procedure TFormMain.WriteRest; +var + I, J: Integer; + LineLength: Integer; + KeyString: string; + AttrName: string; + FriendlyAttrName: string; + AttrTemp: string; + TempStringList: TStringList; + sPrefix: string; + DefAttri: TLexDefaultAttri; +begin + FIdentList.Sort; + FSetList.Sort(CompareSets); + I := 0; + while I < FIdentList.Count - 1 do + begin + Writeln(FOutFile, ' ' + FIdentList[I] + ','); + inc(I); + end; + Writeln(FOutFile, ' ' + FIdentList[I] + ');'); + Writeln(FOutFile); + Write(FOutFile, ' TRangeState = (rsUnknown'); + for I := 0 to (FEnclosedList.Count - 1) do + Write(FOutFile, ', rs' + TLexEnclosedBy(FEnclosedList[I]).ProcName); + Writeln(FOutFile, ');'); + Writeln(FOutFile); + Writeln(FOutFile, ' TProcTableProc = procedure of object;'); + Writeln(FOutFile); + Writeln(FOutFile, ' PIdentFuncTableFunc = ^TIdentFuncTableFunc;'); + Writeln(FOutFile, ' TIdentFuncTableFunc = function (Index: Integer): T' + FIdentPre + + 'TokenKind of object;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'type'); + Writeln(FOutFile, ' ' + FLexName + ' = class(TSynCustomHighlighter)'); + Writeln(FOutFile, ' private'); + Writeln(FOutFile, ' FRange: TRangeState;'); + + if ListBoxFields.Items.Count > 0 then + for i := 0 to ListBoxFields.Items.Count - 1 do + Writeln(FOutFile, ' ' + ListBoxFields.Items[i] + ';'); + + Writeln(FOutFile, ' FTokenId: TtkTokenKind;'); + Writeln(FOutFile, + ' fIdentFuncTable: array[0..' + + IntToStr(FrmHashTableGen.KeyIndicesCount - 1) + ']' + + ' of TIdentFuncTableFunc;'); + + I := 0; + while I < FIdentList.Count do + begin + if (FIdentList[I] <> FIdentPre + 'Null') and (FIdentList[I] <> FIdentPre + + 'Unknown') then + Writeln(FOutFile, ' f' + Copy(FIdentList[I], Length(FIdentPre) + 1, + Length(FIdentList[I])) + 'Attri: TSynHighlighterAttributes;'); + inc(I); + end; + + Writeln(FOutFile, ' function HashKey(Str: PWideChar): Cardinal;'); + + I := 0; + while I < FKeyList.Count do + begin + Writeln(FOutFile, AnsiString(' function Func' + + ToAlphaNum(FirstLetterCap(TLexKeys(FKeyList[I]).KeyName)) + + '(Index: Integer): T' + FIdentPre + 'TokenKind;')); + inc(I); + end; + + I := 0; + while I < FSetList.Count do + begin + Writeln(FOutFile, ' procedure ' + TLexCharsets(FSetList[I]).SetName + + 'Proc;'); + inc(I); + end; + + Writeln(FOutFile, ' procedure UnknownProc;'); + Writeln(FOutFile, ' function AltFunc(Index: Integer): T' + FIdentPre + 'TokenKind;'); + Writeln(FOutFile, ' procedure InitIdent;'); + Writeln(FOutFile, ' function IdentKind(MayBe: PWideChar): T' + FIdentPre + + 'TokenKind;'); + Writeln(FOutFile, ' procedure NullProc;'); + if (FIdentList.IndexOf(FIdentPre + 'Space') >= 0) then + Writeln(FOutFile, ' procedure SpaceProc;'); + Writeln(FOutFile, ' procedure CRProc;'); + Writeln(FOutFile, ' procedure LFProc;'); + for I := 0 to (FEnclosedList.Count - 1) do + begin + Writeln(FOutFile, ' procedure ' + TLexEnclosedBy(FEnclosedList[I]).ProcName + + 'OpenProc;'); + Writeln(FOutFile, ' procedure ' + TLexEnclosedBy(FEnclosedList[I]).ProcName + + 'Proc;'); + end; + Writeln(FOutFile, ' protected'); + Writeln(FOutFile, ' function GetSampleSource: UnicodeString; override;'); + Writeln(FOutFile, ' function IsFilterStored: Boolean; override;'); + Writeln(FOutFile, ' public'); + Writeln(FOutFile, ' constructor Create(AOwner: TComponent); override;'); + Writeln(FOutFile, ' class function GetFriendlyLanguageName: UnicodeString; override;'); + Writeln(FOutFile, ' class function GetLanguageName: string; override;'); + Writeln(FOutFile, ' function GetRange: Pointer; override;'); + Writeln(FOutFile, ' procedure ResetRange; override;'); + Writeln(FOutFile, ' procedure SetRange(Value: Pointer); override;'); + Writeln(FOutFile, + ' function GetDefaultAttribute(Index: Integer): TSynHighlighterAttributes; override;'); + Writeln(FOutFile, ' function GetEol: Boolean; override;'); + if CheckBoxGetKeyWords.Checked then + Writeln(FOutFile, ' function GetKeyWords(TokenKind: Integer): UnicodeString; override;'); + Writeln(FOutFile, ' function GetTokenID: TtkTokenKind;'); + Writeln(FOutFile, + ' function GetTokenAttribute: TSynHighlighterAttributes; override;'); + Writeln(FOutFile, ' function GetTokenKind: Integer; override;'); + Writeln(FOutFile, ' function IsIdentChar(AChar: WideChar): Boolean; override;'); + Writeln(FOutFile, ' procedure Next; override;'); + Writeln(FOutFile, ' published'); + + I := 0; + while I < FIdentList.Count do + begin + if (FIdentList[I] <> FIdentPre + 'Null') and (FIdentList[I] <> FIdentPre + + 'Unknown') then + Writeln(FOutFile, ' property ' + Copy(FIdentList[I], Length(FIdentPre) + + 1, Length(FIdentList[I])) + + 'Attri: TSynHighlighterAttributes read f' + Copy(FIdentList[I], + Length(FIdentPre) + 1, Length(FIdentList[I])) + + 'Attri write f' + Copy(FIdentList[I], Length(FIdentPre) + 1, + Length(FIdentList[I])) + 'Attri;'); + inc(I); + end; + + Writeln(FOutFile, ' end;'); + Writeln(FOutFile); + Writeln(FOutFile, 'implementation'); + Writeln(FOutFile); + Writeln(FOutFile, 'uses'); + Writeln(FOutFile, ' SynEditStrConst;'); + Writeln(FOutFile); + if (ComboBoxFilter.ItemIndex = -1) or (ComboBoxLangName.ItemIndex = -1) then + begin + Writeln(FOutFile, 'resourcestring'); + if (ComboBoxFilter.ItemIndex = -1) then + Writeln(FOutFile, ' SYNS_Filter' + FilterInvalidChars(ComboBoxLangName.Text) + + ' = ''' + ComboBoxFilter.Text + ''';'); + if (ComboBoxLangName.ItemIndex = -1) then + begin + Writeln(FOutFile, ' SYNS_Lang' + FilterInvalidChars(ComboBoxLangName.Text) + + ' = ''' + ComboBoxLangName.Text + ''';'); + + Writeln(FOutFile, ' SYNS_FriendlyLang' + FilterInvalidChars(ComboBoxLangName.Text) + + ' = ''' + ComboBoxLangName.Text + ''';'); + end; + + I := 0; + while I < FIdentList.Count do + begin + AttrTemp := Copy(FIdentList[I], Length(FIdentPre) + 1, + Length(FIdentList[I])); + if (ComboBoxAttrIdentifier.Items.IndexOf('SYNS_Attr' + AttrTemp) < 0) and + (AttrTemp <> 'Unknown') then + begin + Writeln(FOutFile, ' SYNS_Attr' + FilterInvalidChars(AttrTemp) + ' = ''' + + AttrTemp + ''';'); + Writeln(FOutFile, ' SYNS_FriendlyAttr' + FilterInvalidChars(AttrTemp) + ' = ''' + + AttrTemp + ''';'); + end; + Inc(i); + end; + Writeln(FOutFile); + end; + + Writeln(FOutFile, 'const'); + Write(FOutFile, FrmHashTableGen.GetKeyWordConstantsSource(FSensitivity)); + Writeln(FOutFile); + + Writeln(FOutFile, 'procedure ' + FLexName + '.InitIdent;'); + Writeln(FOutFile, 'var'); + Writeln(FOutFile, ' i: Integer;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' for i := Low(fIdentFuncTable) to High(fIdentFuncTable) do'); + Writeln(FOutFile, ' if KeyIndices[i] = -1 then'); + Writeln(FOutFile, ' fIdentFuncTable[i] := AltFunc;'); + Writeln(FOutFile, ''); + + I := 0; + while I < FKeyList.Count do + begin + if I < FKeyList.Count - 1 then + while TLexKeys(FKeyList[I]).Key = TLexKeys(FKeyList[I + 1]).Key do + begin + inc(I); + if I >= FKeyList.Count - 1 then + break; + end; + KeyString := IntToStr(TLexKeys(FKeyList[I]).Key); + Writeln(FOutFile, ' fIdentFuncTable[' + KeyString + '] := Func' + + ToAlphaNum(FirstLetterCap(TLexKeys(FKeyList[I]).KeyName)) + ';'); + inc(I); + end; + + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Write(FOutFile, FrmHashTableGen.GetHashKeyFunctionSource(FLexName)); + Writeln(FOutFile); + + I := 0; + while I < FKeyList.Count do + begin + KeyString := ToAlphaNum(FirstLetterCap(TLexKeys(FKeyList[I]).KeyName)); + Writeln(FOutFile, 'function ' + FLexName + '.Func' + KeyString + '(Index: Integer): T' + + FIdentPre + 'TokenKind;'); + Writeln(FOutFile, 'begin'); + if I < FKeyList.Count - 1 then + while TLexKeys(FKeyList[I]).Key = TLexKeys(FKeyList[I + 1]).Key do + begin + Writeln(FOutFile, ' if IsCurrentToken(KeyWords[Index]) then'); + Writeln(FOutFile, ' Result := ' + FIdentPre + TLexKeys(FKeyList[I]).TokenType); + Writeln(FOutFile, ' else'); + inc(I); + if I >= FKeyList.Count - 1 then + break; + end; + Writeln(FOutFile, ' if IsCurrentToken(KeyWords[Index]) then'); + Writeln(FOutFile, ' Result := ' + FIdentPre + TLexKeys(FKeyList[I]).TokenType); + Writeln(FOutFile, ' else'); + Writeln(FOutFile, ' Result := ' + FIdentPre + 'Identifier;'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + inc(I); + end; + + Writeln(FOutFile, 'function ' + FLexName + '.AltFunc(Index: Integer): T' + FIdentPre + + 'TokenKind;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' Result := ' + FIdentPre + 'Identifier;'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'function ' + FLexName + '.IdentKind(MayBe: PWideChar): T' + + FIdentPre + 'TokenKind;'); + Writeln(FOutFile, 'var'); + Writeln(FOutFile, ' Key: Cardinal;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' fToIdent := MayBe;'); + Writeln(FOutFile, ' Key := HashKey(MayBe);'); + Writeln(FOutFile, ' if Key <= High(fIdentFuncTable) then'); + Writeln(FOutFile, ' Result := FIdentFuncTable[Key](KeyIndices[Key])'); + Writeln(FOutFile, ' else'); + Writeln(FOutFile, ' Result := ' + FIdentPre + 'Identifier;'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + if (FIdentList.IndexOf(FIdentPre + 'Space') >= 0) then + begin + Writeln(FOutFile, 'procedure ' + FLexName + '.SpaceProc;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' inc(Run);'); + Writeln(FOutFile, ' FTokenId := ' + FIdentPre + 'Space;'); + Writeln(FOutFile, ' while (FLine[Run] <= #32) and not IsLineEnd(Run) do inc(Run);'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + end; + + Writeln(FOutFile, 'procedure ' + FLexName + '.NullProc;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' FTokenId := ' + FIdentPre + 'Null;'); + Writeln(FOutFile, ' inc(Run);'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'procedure ' + FLexName + '.CRProc;'); + Writeln(FOutFile, 'begin'); + if (FIdentList.IndexOf(FIdentPre + 'Space') >= 0) then + Writeln(FOutFile, ' FTokenId := ' + FIdentPre + 'Space;') + else + Writeln(FOutFile, ' FTokenId := ' + FIdentPre + 'Unknown;'); + Writeln(FOutFile, ' inc(Run);'); + Writeln(FOutFile, ' if FLine[Run] = #10 then'); + Writeln(FOutFile, ' inc(Run);'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'procedure ' + FLexName + '.LFProc;'); + Writeln(FOutFile, 'begin'); + if (FIdentList.IndexOf(FIdentPre + 'Space') >= 0) then + Writeln(FOutFile, ' FTokenId := ' + FIdentPre + 'Space;') + else + Writeln(FOutFile, ' FTokenId := ' + FIdentPre + 'Unknown;'); + Writeln(FOutFile, ' inc(Run);'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + for I := 0 to (FEnclosedList.Count - 1) do + begin + Writeln(FOutFile, 'procedure ' + FLexName + '.' + + TLexEnclosedBy(FEnclosedList[I]).ProcName + 'OpenProc;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' Inc(Run);'); + if (Length(TLexEnclosedBy(FEnclosedList[I]).StartsWith) > 1) then + begin + Write(FOutFile, ' if '); + for J := 2 to Length(TLexEnclosedBy(FEnclosedList[I]).StartsWith) do + begin + if (J > 2) then + begin + Writeln(FOutFile, ' and'); + Write(FOutFile, ' '); + end; + Write(FOutFile, '(FLine[Run' + AddInt(J - 2) + '] = ''' + + StuffString(TLexEnclosedBy(FEnclosedList[I]).StartsWith[J]) + ''')'); + end; + Writeln(FOutFile, ' then'); + Writeln(FOutFile, ' begin'); + Writeln(FOutFile, ' Inc(Run, ' + + IntToStr(Length(TLexEnclosedBy(FEnclosedList[I]).StartsWith)-1) + ');'); + Writeln(FOutFile, ' FRange := rs' + + TLexEnclosedBy(FEnclosedList[I]).ProcName + ';'); + if not TLexEnclosedBy(FEnclosedList[I]).MultiLine then + begin + Writeln(FOutFile, ' ' + TLexEnclosedBy(FEnclosedList[I]).ProcName + + 'Proc;'); + end; + Writeln(FOutFile, ' FTokenId := ' + FIdentPre + + TLexEnclosedBy(FEnclosedList[I]).TokenName + ';'); + Writeln(FOutFile, ' end'); + Writeln(FOutFile, ' else'); + if (FIdentList.IndexOf(FIdentPre + 'Symbol') >= 0) then + Writeln(FOutFile, ' FTokenId := ' + FIdentPre + 'Symbol;') + else + Writeln(FOutFile, ' FTokenId := ' + FIdentPre + 'Identifier;'); + end + else + begin + Writeln(FOutFile, ' FRange := rs' + + TLexEnclosedBy(FEnclosedList[I]).ProcName + ';'); + if not TLexEnclosedBy(FEnclosedList[I]).MultiLine then + begin + Writeln(FOutFile, ' ' + TLexEnclosedBy(FEnclosedList[I]).ProcName + + 'Proc;'); + end; + Writeln(FOutFile, ' FTokenId := ' + FIdentPre + + TLexEnclosedBy(FEnclosedList[I]).TokenName + ';'); + end; + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + Writeln(FOutFile, 'procedure ' + FLexName + '.' + + TLexEnclosedBy(FEnclosedList[I]).ProcName + 'Proc;'); + Writeln(FOutFile, 'begin'); + if TLexEnclosedBy(FEnclosedList[I]).MultiLine then + begin + Writeln(FOutFile, ' case FLine[Run] of'); + Writeln(FOutFile, ' #0: NullProc;'); + Writeln(FOutFile, ' #10: LFProc;'); + Writeln(FOutFile, ' #13: CRProc;'); + Writeln(FOutFile, ' else'); + Writeln(FOutFile, ' begin'); + sPrefix := ' '; + end + else + sPrefix := ''; + Writeln(FOutFile, sPrefix, ' FTokenId := ' + FIdentPre + + TLexEnclosedBy(FEnclosedList[I]).TokenName + ';'); + Writeln(FOutFile, sPrefix, ' repeat'); + Write(FOutFile, sPrefix, ' if '); + for J := 1 to Length(TLexEnclosedBy(FEnclosedList[I]).EndsWith) do + begin + if (J > 1) then + begin + Writeln(FOutFile, ' and'); + Write(FOutFile, sPrefix, ' '); + end; + Write(FOutFile, '(FLine[Run' + AddInt(J - 1) + '] = ''' + + StuffString(TLexEnclosedBy(FEnclosedList[I]).EndsWith[J]) + ''')'); + end; + Writeln(FOutFile, ' then'); + Writeln(FOutFile, sPrefix, ' begin'); + Writeln(FOutFile, sPrefix, ' Inc(Run, ' + + IntToStr(Length(TLexEnclosedBy(FEnclosedList[I]).EndsWith)) + ');'); + Writeln(FOutFile, sPrefix, ' FRange := rsUnknown;'); + Writeln(FOutFile, sPrefix, ' Break;'); + Writeln(FOutFile, sPrefix, ' end;'); + Writeln(FOutFile, sPrefix, ' if not IsLineEnd(Run) then'); + Writeln(FOutFile, sPrefix, ' Inc(Run);'); + Writeln(FOutFile, sPrefix, ' until IsLineEnd(Run);'); + Writeln(FOutFile, sPrefix, 'end;'); + if TLexEnclosedBy(FEnclosedList[I]).MultiLine then + begin + Writeln(FOutFile, ' end;'); + Writeln(FOutFile, 'end;'); + end; + Writeln(FOutFile); + end; + + Writeln(FOutFile, 'constructor ' + FLexName + '.Create(AOwner: TComponent);'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' inherited Create(AOwner);'); + Writeln(FOutFile, ' fCaseSensitive := ' + BoolStrs[FSensitivity] + ';'); + Writeln(FOutFile); + + I := 0; + while I < FIdentList.Count do + begin + AttrTemp := Copy(FIdentList[I], Length(FIdentPre) + 1, Length(FIdentList[I])); + if AttrTemp = 'Key' then + AttrName := ComboBoxAttrReservedWord.Text + else if AttrTemp = 'Identifier' then + AttrName := ComboBoxAttrIdentifier.Text + else + AttrName := 'SYNS_Attr' + FilterInvalidChars(AttrTemp); + + if Pos('SYNS_', AttrName) = 1 then + begin + FriendlyAttrName := AttrName; + Insert('Friendly', FriendlyAttrName, Length('SYNS_') + 1) + end + else + FriendlyAttrName := 'Friendly' + AttrName; + + if (FIdentList[I] <> FIdentPre + 'Null') and (FIdentList[I] <> FIdentPre + + 'Unknown') then + begin + AttrTemp := 'f' + AttrTemp + 'Attri'; + Writeln(FOutFile, ' ' + AttrTemp + ' := TSynHighLighterAttributes.Create(' + + AttrName + ', ' + FriendlyAttrName + ');'); + if Assigned(FIdentList.Objects[i]) then + begin + DefAttri := TLexDefaultAttri(FIdentList.Objects[i]); + if (DefAttri.Style <> '') then + Writeln(FOutFile, ' ' + AttrTemp + '.Style := ' + DefAttri.Style + + ';'); + if (DefAttri.Foreground <> '') then + Writeln(FOutFile, ' ' + AttrTemp + '.Foreground := ' + + DefAttri.Foreground + ';'); + if (DefAttri.Background <> '') then + Writeln(FOutFile, ' ' + AttrTemp + '.Background := ' + + DefAttri.Background + ';'); + end + else if (FIdentList[I] = FIdentPre + 'Key') then + Writeln(FOutFile, ' ' + AttrTemp + '.Style := [fsBold];') + else if (FIdentList[I] = FIdentPre + 'Comment') then + begin + Writeln(FOutFile, ' ' + AttrTemp + '.Style := [fsItalic];'); + Writeln(FOutFile, ' ' + AttrTemp + '.Foreground := clNavy;'); + end; + Writeln(FOutFile, ' AddAttribute(' + AttrTemp + ');'); + Writeln(FOutFile); + end; + Inc(I); + end; + + Writeln(FOutFile, ' SetAttributesOnChange(DefHighlightChange);'); + Writeln(FOutFile, ' InitIdent;'); + + Writeln(FOutFile, ' fDefaultFilter := ' + GetFilterName + ';'); + Writeln(FOutFile, ' FRange := rsUnknown;'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + I := 0; + while I < FSetList.Count do + begin + Writeln(FOutFile, 'procedure ' + FLexName + '.' + + TLexCharsets(FSetList[I]).SetName + 'Proc;'); + Writeln(FOutFile, 'begin'); + Write(FOutFile, ' ' + TLexCharsets(FSetList[I]).ProcData); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + inc(I); + end; + + Writeln(FOutFile, 'procedure ' + FLexName + '.UnknownProc;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' inc(Run);'); + Writeln(FOutFile, ' FTokenId := ' + FIdentPre + 'Unknown;'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'procedure ' + FLexName + '.Next;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' fTokenPos := Run;'); + if (FEnclosedList.Count > 0) then + begin + Writeln(FOutFile, ' case FRange of'); + for I := 0 to (FEnclosedList.Count - 1) do + begin + if TLexEnclosedBy(FEnclosedList[I]).MultiLine then + begin + Writeln(FOutFile, ' rs' + TLexEnclosedBy(FEnclosedList[I]).ProcName + + ': ' + TLexEnclosedBy(FEnclosedList[I]).ProcName + 'Proc;'); + end; + end; + Writeln(FOutFile, ' else'); + Writeln(FOutFile, ' case FLine[Run] of'); + Writeln(FOutFile, ' #0: NullProc;'); + Writeln(FOutFile, ' #10: LFProc;'); + Writeln(FOutFile, ' #13: CRProc;'); + + for I := 0 to (FEnclosedList.Count - 1) do + begin + if (TLexEnclosedBy(FEnclosedList[I]).StartsWith <> '') then + begin + Writeln(FOutFile, ' ''' + + StuffString(TLexEnclosedBy(FEnclosedList[I]).StartsWith[1]) + + ''': ' + TLexEnclosedBy(FEnclosedList[I]).ProcName + 'OpenProc;'); + end; + end; + if (FIdentList.IndexOf(FIdentPre + 'Space') >= 0) then + Writeln(FOutFile, ' #1..#9, #11, #12, #14..#32: SpaceProc;'); + I := 0; + while I < FSetList.Count do + begin + Writeln(FOutFile, ' ' + TLexCharsets(FSetList[I]).Charset + + ': ' + TLexCharsets(FSetList[I]).SetName + 'Proc;'); + Inc(I); + end; + + Writeln(FOutFile, ' else'); + Writeln(FOutFile, ' UnknownProc;'); + Writeln(FOutFile, ' end;'); + Writeln(FOutFile, ' end;'); + end + else + begin + Writeln(FOutFile, ' case FLine[Run] of'); + Writeln(FOutFile, ' #0: NullProc;'); + Writeln(FOutFile, ' #10: LFProc;'); + Writeln(FOutFile, ' #13: CRProc;'); + + if (FIdentList.IndexOf(FIdentPre + 'Space') >= 0) then + Writeln(FOutFile, ' #1..#9, #11, #12, #14..#32: SpaceProc;'); + I := 0; + while I < FSetList.Count do + begin + Writeln(FOutFile, ' ' + TLexCharsets(FSetList[I]).Charset + + ': ' + TLexCharsets(FSetList[I]).SetName + 'Proc;'); + Inc(I); + end; + + Writeln(FOutFile, ' else'); + Writeln(FOutFile, ' UnknownProc;'); + Writeln(FOutFile, ' end;'); + end; + Writeln(FOutFile, ' inherited;'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'function ' + FLexName + + '.GetDefaultAttribute(Index: Integer): TSynHighLighterAttributes;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' case Index of'); + if (FIdentList.IndexOf(FIdentPre + 'Comment') >= 0) then + Writeln(FOutFile, ' SYN_ATTR_COMMENT: Result := FCommentAttri;'); + if (FIdentList.IndexOf(FIdentPre + 'Identifier') >= 0) then + Writeln(FOutFile, ' SYN_ATTR_IDENTIFIER: Result := FIdentifierAttri;'); + if (FIdentList.IndexOf(FIdentPre + 'Key') >= 0) then + Writeln(FOutFile, ' SYN_ATTR_KEYWORD: Result := FKeyAttri;'); + if (FIdentList.IndexOf(FIdentPre + 'String') >= 0) then + Writeln(FOutFile, ' SYN_ATTR_STRING: Result := FStringAttri;'); + if (FIdentList.IndexOf(FIdentPre + 'Space') >= 0) then + Writeln(FOutFile, ' SYN_ATTR_WHITESPACE: Result := FSpaceAttri;'); + if (FIdentList.IndexOf(FIdentPre + 'Symbol') >= 0) then + Writeln(FOutFile, ' SYN_ATTR_SYMBOL: Result := FSymbolAttri;'); + Writeln(FOutFile, ' else'); + Writeln(FOutFile, ' Result := nil;'); + Writeln(FOutFile, ' end;'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'function ' + FLexName + '.GetEol: Boolean;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' Result := Run = FLineLen + 1;'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + if CheckBoxGetKeyWords.Checked then + begin + Writeln(FOutFile, 'function ' + FLexName + '.GetKeyWords(TokenKind: Integer): UnicodeString;'); + Writeln(FOutFile, 'begin'); + TempStringList := TStringList.Create; + try + TempStringList.Sorted := True; + for I := 0 to FKeyList.Count - 1 do + TempStringList.Add(TLexKeys(FKeyList[I]).KeyName); + if TempStringList.Count > 0 then + begin + Writeln(FOutFile, ' Result := '); + for I := 0 to Trunc(Int(Length(TempStringList.CommaText) div 70)) - 1 do + begin + if I = 0 then + LineLength := 69 + else + LineLength := 70; + Writeln(FOutFile, ' ' + #39 + Copy(TempStringList.CommaText, + I * 70, LineLength) + #39 + #32 + #43); + end; + I := Trunc(Int(Length(TempStringList.CommaText) div 70)); + Writeln(FOutFile, ' ' + #39 + Copy(TempStringList.CommaText, + I * 70, Length(TempStringList.CommaText)) + #39 + ';') + end + else + Writeln(FOutFile, ' Result := ' + #39 + #39 + ';'); + finally + TempStringList.Free; + end; + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + end; + + Writeln(FOutFile, 'function ' + FLexName + '.GetTokenID: TtkTokenKind;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' Result := FTokenId;'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'function ' + FLexName + + '.GetTokenAttribute: TSynHighLighterAttributes;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' case GetTokenID of'); + + I := 0; + while I < FIdentList.Count do + begin + if (FIdentList[I] <> FIdentPre + 'Null') and (FIdentList[I] <> FIdentPre + + 'Unknown') then + Writeln(FOutFile, ' ' + FIdentList[I] + ': Result := F' + + Copy(FIdentList[I], Length(FIdentPre) + 1, Length(FIdentList[I])) + + 'Attri;'); + inc(I); + end; + Writeln(FOutFile, ' ' + FIdentPre + 'Unknown: Result := F' + + ComboBoxUnknownTokenAttr.Text + 'Attri;'); + + Writeln(FOutFile, ' else'); + Writeln(FOutFile, ' Result := nil;'); + Writeln(FOutFile, ' end;'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'function ' + FLexName + '.GetTokenKind: Integer;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' Result := Ord(FTokenId);'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'function ' + FLexName + '.IsIdentChar(AChar: WideChar): Boolean;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' case AChar of'); + Writeln(FOutFile, ' ' + FIdentContent + ':'); + Writeln(FOutFile, ' Result := True;'); + Writeln(FOutFile, ' else'); + Writeln(FOutFile, ' Result := False;'); + Writeln(FOutFile, ' end;'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'function ' + FLexName + '.GetSampleSource: UnicodeString;'); + Writeln(FOutFile, 'begin'); + if (FSampleSourceList.Count = 0) then + begin + Writeln(FOutFile, ' Result := '); + Writeln(FOutFile, ' ''Sample source for: ''#13#10 +'); + Writeln(FOutFile, ' ''' + EditDescription.Text + ''';'); + end + else + begin + Writeln(FOutFile, ' Result := '); + for i := 0 to FSampleSourceList.Count - 1 do + begin + if (i > 0) and (i < FSampleSourceList.Count - 1) then + Writeln(FOutFile, '#13#10 +'); + if (i < FSampleSourceList.Count - 1) then + Write(FOutFile, ' '); + if FSampleSourceList[i] <> '' then + Write(FOutFile, '''', StuffString(FSampleSourceList[i]), ''''); + end; + Writeln(FOutFile, ';'); + end; + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'function ' + FLexName + '.IsFilterStored: Boolean;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' Result := FDefaultFilter <> ' + GetFilterName + ';'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'class function ' + FLexName + '.GetFriendlyLanguageName: UnicodeString;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' Result := ' + GetFriendlyLangName + ';'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'class function ' + FLexName + '.GetLanguageName: string;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' Result := ' + GetLangName + ';'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'procedure ' + FLexName + '.ResetRange;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' FRange := rsUnknown;'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'procedure ' + FLexName + '.SetRange(Value: Pointer);'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' FRange := TRangeState(Value);'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'function ' + FLexName + '.GetRange: Pointer;'); + Writeln(FOutFile, 'begin'); + Writeln(FOutFile, ' Result := Pointer(FRange);'); + Writeln(FOutFile, 'end;'); + Writeln(FOutFile); + + Writeln(FOutFile, 'initialization'); + Writeln(FOutFile, '{$IFNDEF SYN_CPPB_1}'); + Writeln(FOutFile, ' RegisterPlaceableHighlighter(' + FLexName + ');'); + Writeln(FOutFile, '{$ENDIF}'); + Writeln(FOutFile, 'end.'); +end; + +procedure TFormMain.ComboBoxLangNameChange(Sender: TObject); +begin + if (ComboBoxLangName.Text <> '') and (ComboBoxFilter.Text <> '') then + ButtonStart.Enabled := True + else + ButtonStart.Enabled := False; +end; + +procedure TFormMain.ListBoxFieldsClick(Sender: TObject); +begin + ButtonDelete.Enabled := True; +end; + +procedure TFormMain.ButtonAddClick(Sender: TObject); +begin + ListBoxFields.Items.Add(EditAddField.Text); + EditAddField.Clear; +end; + +procedure TFormMain.ButtonDeleteClick(Sender: TObject); +begin + ButtonDelete.Enabled := False; + ListBoxFields.Items.Delete(ListBoxFields.ItemIndex); +end; + +procedure TFormMain.EditAddFieldChange(Sender: TObject); +begin + ButtonAdd.Enabled := EditAddField.Text <> ''; +end; + +procedure TFormMain.EditAddFieldKeyPress(Sender: TObject; var Key: Char); +begin + if (Key = ';') or (Key = #32) then + Key := #0; +end; + +procedure TFormMain.MenuItemExitClick(Sender: TObject); +begin + Close; +end; + +procedure TFormMain.MenuItemOpenClick(Sender: TObject); +begin + WriteSettings; + PerformFileOpen; +end; + +procedure TFormMain.FormClose(Sender: TObject; var Action: TCloseAction); +begin + WriteSettings; +end; + +function TFormMain.KeywordsAreAllAlphaNumAndDifferent: Boolean; +var + i: Integer; + KeyWordList: TStringList; +begin + Result := True; + + KeyWordList := TStringList.Create; + try + KeyWordList.Sorted := True; + KeyWordList.Duplicates := dupError; + + try + for i := 0 to FKeyList.Count - 1 do + KeyWordList.Add(TLexKeys(FKeyList[i]).KeyName); + except + Result := False; + Exit; + end; + finally + KeyWordList.Free; + end; + + for i := 0 to FKeyList.Count - 1 do + if not IsASCIIAlphaNum(TLexKeys(FKeyList[i]).KeyName) then + begin + Result := False; + Exit; + end; +end; + +end.