From 001f8d52172dd964c5d59ce0f29a2ce75385239e Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sat, 30 Jul 2016 20:11:19 +0200 Subject: [PATCH] fix lexing issue with option lxoNoComments --- src/ce_dlang.pas | 27 ++++++++++++++++++--------- src/ce_editor.pas | 2 +- src/ce_libmaneditor.pas | 34 ++++++++++++++++++++++++++-------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/ce_dlang.pas b/src/ce_dlang.pas index e0ce310c..9eb28030 100644 --- a/src/ce_dlang.pas +++ b/src/ce_dlang.pas @@ -363,10 +363,13 @@ begin if isOutOfBound then exit; end; - addToken(ltkComment); + if not noComment then + begin + addToken(ltkComment); + if callBackDoStop then + exit; + end; reader.Next; - if callBackDoStop then - exit; continue; end else @@ -390,10 +393,13 @@ begin if isOutOfBound then exit; end; - addToken(ltkComment); + if not noComment then + begin + addToken(ltkComment); + if callBackDoStop then + exit; + end; reader.Next; - if callBackDoStop then - exit; continue; end else @@ -431,10 +437,13 @@ begin exit; end; until nestedCom = 0; - addToken(ltkComment); + if not noComment then + begin + addToken(ltkComment); + if callBackDoStop then + exit; + end; reader.Next; - if callBackDoStop then - exit; continue; end else diff --git a/src/ce_editor.pas b/src/ce_editor.pas index 2f5d4e4b..b98427de 100644 --- a/src/ce_editor.pas +++ b/src/ce_editor.pas @@ -722,7 +722,7 @@ begin begin if fDoc.isDSource then begin - lex(fDoc.Lines.Text, fTokList, @lexFindToken); + lex(fDoc.Lines.Text, fTokList, @lexFindToken, [lxoNoComments]); md := getModuleName(fTokList); fTokList.Clear; if md.isEmpty then diff --git a/src/ce_libmaneditor.pas b/src/ce_libmaneditor.pas index 21137dec..7bbb77ee 100644 --- a/src/ce_libmaneditor.pas +++ b/src/ce_libmaneditor.pas @@ -66,6 +66,7 @@ type private fProj: ICECommonProject; fFreeProj: ICECommonProject; + fModStart: boolean; procedure updateButtonsState; procedure projNew(project: ICECommonProject); procedure projChanged(project: ICECommonProject); @@ -75,6 +76,8 @@ type procedure projCompiled(project: ICECommonProject; success: boolean); function itemForRow(row: TListItem): TLibraryItem; procedure RowToLibrary(row: TListItem); + function sourceRoot(project: ICECommonProject): string; + procedure lexFindToken(const token: PLexToken; out stop: boolean); // procedure dataToGrid; protected @@ -84,7 +87,7 @@ type end; // determine the root of a library, according to the module names - function sourceRoot(project: ICECommonProject): string; + //function sourceRoot(project: ICECommonProject): string; implementation {$R *.lfm} @@ -799,10 +802,10 @@ begin LibMan.updateCrossDependencies; end; -function sourceRoot(project: ICECommonProject): string; +function TCELibManEditorWidget.sourceRoot(project: ICECommonProject): string; var i, j: integer; - name: string; + mnme: string; fold: string; modn: TStringList; modf: TStringList; @@ -814,8 +817,8 @@ begin // 1 source, same folder if project.sourcesCount = 1 then begin - name := project.sourceAbsolute(0); - if name.extractFilePath = base then + mnme := project.sourceAbsolute(0); + if mnme.extractFilePath = base then exit(base); end; @@ -826,11 +829,12 @@ begin // get module name and store the parent.parent.parent... dir for i := 0 to project.sourcesCount-1 do begin + fModStart := false; fold := project.sourceAbsolute(i); modf.LoadFromFile(fold); - lex(modf.Text, toks); - name := getModuleName(toks); - for j := 0 to WordCount(name, ['.'])-1 do + lex(modf.Text, toks, @lexFindToken, [lxoNoComments]); + mnme := getModuleName(toks); + for j := 0 to WordCount(mnme, ['.'])-1 do fold := extractFileDir(fold); modn.Add(fold); toks.Clear; @@ -860,4 +864,18 @@ begin end; end; +procedure TCELibManEditorWidget.lexFindToken(const token: PLexToken; out stop: boolean); +begin + if (token^.kind = ltkKeyword) and (token^.data = 'module') then + begin + fModStart := true; + exit; + end; + if fModStart and (token^.kind = ltkSymbol) and (token^.data = ';') then + begin + stop := true; + fModStart := false; + end; +end; + end.