mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-16 01:00:34 +01:00
codetools: indentations: parsing source behind
git-svn-id: trunk@20314 -
This commit is contained in:
parent
56029b3100
commit
520cd91793
@ -733,8 +733,26 @@ function TFullyAutomaticBeautifier.GetIndent(const Source: string;
|
||||
out Indent: TFABIndentationPolicy): boolean;
|
||||
var
|
||||
Policies: TFABPolicies;
|
||||
Stack: TFABBlockStack;
|
||||
Block: TBlock;
|
||||
|
||||
function CheckPolicies(var Found: boolean): boolean;
|
||||
begin
|
||||
if Policies.Indentations[Block.Typ].IndentValid then begin
|
||||
// policy found
|
||||
DebugLn(['TFullyAutomaticBeautifier.GetIndent policy found: InnerIndent=',Policies.Indentations[Block.Typ].Indent]);
|
||||
Indent.Indent:=GetLineIndentWithTabs(Source,Block.StartPos,DefaultTabWidth)
|
||||
+Policies.Indentations[Block.Typ].Indent;
|
||||
Indent.IndentValid:=true;
|
||||
Result:=true;
|
||||
Found:=true;
|
||||
end else begin
|
||||
Result:=false;
|
||||
Found:=false;
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
Stack: TFABBlockStack;
|
||||
begin
|
||||
Result:=false;
|
||||
FillByte(Indent,SizeOf(Indent),0);
|
||||
@ -756,14 +774,11 @@ begin
|
||||
Block:=Stack.Stack[Stack.Top];
|
||||
DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed code in front: context=',FABBlockTypeNames[Block.Typ],' blockindent=',GetLineIndentWithTabs(Source,Block.StartPos,DefaultTabWidth)]);
|
||||
|
||||
if Policies.Indentations[Block.Typ].IndentValid then begin
|
||||
// policy already found
|
||||
DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed code in front: policy found: InnerIndent=',Policies.Indentations[Block.Typ].Indent]);
|
||||
Indent.Indent:=GetLineIndentWithTabs(Source,Block.StartPos,DefaultTabWidth)
|
||||
+Policies.Indentations[Block.Typ].Indent;
|
||||
Indent.IndentValid:=true;
|
||||
exit(true);
|
||||
end;
|
||||
if CheckPolicies(Result) then exit;
|
||||
|
||||
// parse source behind
|
||||
ParseSource(Source,CleanPos,length(Source)+1,NewNestedComments,Stack,Policies);
|
||||
if CheckPolicies(Result) then exit;
|
||||
|
||||
finally
|
||||
Stack.Free;
|
||||
|
||||
@ -45,7 +45,7 @@ begin
|
||||
writeln('Usage: '+ParamStrUTF8(0)+' filename line column');
|
||||
exit;
|
||||
end;
|
||||
Filename:=ParamStrUTF8(1);
|
||||
Filename:=ExpandFileNameUTF8(ParamStrUTF8(1));
|
||||
Y:=StrToInt(ParamStrUTF8(2));
|
||||
X:=StrToInt(ParamStrUTF8(3));
|
||||
end else begin
|
||||
@ -63,7 +63,7 @@ begin
|
||||
try
|
||||
Code.LineColToPosition(Y,X,p);
|
||||
if p<1 then begin
|
||||
writeln('ERROR: invalid position: X=',X,' Y=',Y);
|
||||
writeln('ERROR: invalid position: X=',X,' Y=',Y,' in ',Code.Filename);
|
||||
exit;
|
||||
end;
|
||||
if FAB.GetIndent(Code.Source,p,true,Indentation) then begin
|
||||
|
||||
Loading…
Reference in New Issue
Block a user