codetools: indentation for comments

git-svn-id: trunk@20485 -
This commit is contained in:
mattias 2009-06-06 17:30:16 +00:00
parent 6438eaf854
commit 56629b80c6
2 changed files with 34 additions and 6 deletions

View File

@ -189,6 +189,10 @@ type
FOnGetExamples: TOnGetFABExamples;
FCodePolicies: TAVLTree;// tree of TFABPolicies sorted for Code
FOnGetNestedComments: TOnGetFABNestedComments;
procedure ParseSource(const Src: string; StartPos, EndPos: integer;
NestedComments: boolean;
Stack: TFABBlockStack; Policies: TFABPolicies;
out LastAtomStart, LastAtomEnd: integer);
procedure ParseSource(const Src: string; StartPos, EndPos: integer;
NestedComments: boolean;
Stack: TFABBlockStack; Policies: TFABPolicies);
@ -360,7 +364,7 @@ end;
procedure TFullyAutomaticBeautifier.ParseSource(const Src: string;
StartPos, EndPos: integer; NestedComments: boolean; Stack: TFABBlockStack;
Policies: TFABPolicies);
Policies: TFABPolicies; out LastAtomStart, LastAtomEnd: integer);
var
p: Integer;
AtomStart: integer;
@ -490,12 +494,19 @@ var
r: PChar;
Block: PBlock;
begin
LastAtomStart:=0;
LastAtomEnd:=0;
p:=StartPos;
repeat
ReadRawNextPascalAtom(Src,p,AtomStart,NestedComments);
DebugLn(['TFullyAutomaticBeautifier.ParseSource Atom=',copy(Src,AtomStart,p-AtomStart)]);
if p>=EndPos then break;
if p>=EndPos then begin
if (AtomStart<=p) and (p>EndPos) then begin
LastAtomStart:=p;
LastAtomEnd:=p;
end;
break;
end;
// check if first block inner found
FirstAtomOnNewLine:=false;
if (Stack.Top>=0) then begin
@ -787,6 +798,16 @@ begin
until false;
end;
procedure TFullyAutomaticBeautifier.ParseSource(const Src: string; StartPos,
EndPos: integer; NestedComments: boolean; Stack: TFABBlockStack;
Policies: TFABPolicies);
var
LastAtomStart, LastAtomEnd: integer;
begin
ParseSource(Src,StartPos,EndPos,NestedComments,Stack,Policies,
LastAtomStart,LastAtomEnd);
end;
function TFullyAutomaticBeautifier.FindPolicyInExamples(StartCode: TCodeBuffer;
Typ: TFABBlockType): TFABPolicies;
var
@ -900,6 +921,7 @@ var
var
Stack: TFABBlockStack;
Policies: TFABPolicies;
LastAtomStart, LastAtomEnd: integer;
begin
Result:=false;
FillByte(Indent,SizeOf(Indent),0);
@ -911,13 +933,20 @@ begin
Stack:=TFABBlockStack.Create;
try
// parse source in front
ParseSource(Source,1,CleanPos,NewNestedComments,Stack,Policies);
if Stack.Top<0 then begin
ParseSource(Source,1,CleanPos,NewNestedComments,Stack,Policies,
LastAtomStart,LastAtomEnd);
if (Stack.Top<0) then begin
// no context
DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed code in front: no context']);
GetDefaultIndent(Source,CleanPos,NewNestedComments,Indent);
exit;
end;
if (LastAtomStart>0) and (CleanPos>LastAtomStart) then begin
// in comment or atom
DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed code in front: position in middle of atom, e.g. comment']);
GetDefaultIndent(Source,CleanPos,NewNestedComments,Indent);
exit;
end;
Block:=Stack.Stack[Stack.Top];
DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed code in front: context=',FABBlockTypeNames[Block.Typ],' blockindent=',GetLineIndentWithTabs(Source,Block.StartPos,DefaultTabWidth)]);

View File

@ -5179,7 +5179,6 @@ type
var
CleanCursorPos: integer;
StartNode: TCodeTreeNode;
NewIndent: TFABIndentationPolicy;
procedure InitStack(out Stack: TBlockStack);
begin