codetools: BeautifyStatement: skip comments

git-svn-id: trunk@30436 -
This commit is contained in:
mattias 2011-04-23 14:52:54 +00:00
parent d8d7ef7d44
commit 9b3b219b30

View File

@ -106,7 +106,7 @@ type
Src: string; Src: string;
procedure AddAtom(var CurCode: string; NewAtom: string); procedure AddAtom(var CurCode: string; NewAtom: string);
procedure ReadNextAtom; procedure ReadNextAtom;
procedure ReadTilDirectiveEnd; procedure ReadTilCommentEnd;
procedure StartComment(p: integer); procedure StartComment(p: integer);
procedure EndComment(CommentStart: char; p: integer); procedure EndComment(CommentStart: char; p: integer);
public public
@ -1363,21 +1363,14 @@ begin
AtomEnd:=CurPos; AtomEnd:=CurPos;
end; end;
procedure TBeautifyCodeOptions.ReadTilDirectiveEnd; procedure TBeautifyCodeOptions.ReadTilCommentEnd;
var var
Lvl: Integer; Lvl: Integer;
begin begin
Lvl:=1; Lvl:=CommentLvl;
repeat repeat
ReadNextAtom; ReadNextAtom;
if (CurAtomType in [atCommentStart,atDirectiveStart]) until (CurAtomType=atNone) or (CommentLvl<Lvl);
and NestedComments then
inc(Lvl)
else if CurAtomType=atCommentEnd then begin
dec(Lvl);
if Lvl=0 then break;
end;
until CurAtomType=atNone;
end; end;
procedure TBeautifyCodeOptions.StartComment(p: integer); procedure TBeautifyCodeOptions.StartComment(p: integer);
@ -1457,10 +1450,11 @@ begin
while (CurPos<=SrcLen) do begin while (CurPos<=SrcLen) do begin
repeat repeat
ReadNextAtom; ReadNextAtom;
if CurAtomType=atDirectiveStart then begin if CurAtomType in [atDirectiveStart,atCommentStart] then begin
// don't touch directives: they can contain macros and filenames // don't touch directives: they can contain macros and filenames
// don't touch comments
OldAtomStart:=AtomStart; OldAtomStart:=AtomStart;
ReadTilDirectiveEnd; ReadTilCommentEnd;
AtomStart:=OldAtomStart; AtomStart:=OldAtomStart;
end; end;
CurAtom:=copy(Src,AtomStart,AtomEnd-AtomStart); CurAtom:=copy(Src,AtomStart,AtomEnd-AtomStart);