Skip to content

Commit

Permalink
Change code style: Tabs after short sub-program
Browse files Browse the repository at this point in the history
bad tabs searcher:
```
##
procedure WriteInColor(s: string; c: System.ConsoleColor);
begin
  var oc := Console.ForegroundColor;
  Console.ForegroundColor := c;
  Write(s);
  Console.ForegroundColor := oc;
end;

var r := new Regex(
  '(?<=\r|\n)'+ // expect line start
  '((?:  )*)(?! )'+ // initial tabs
  '(?!where)'+ // ignore class where section
  '(?:(?!//)[^\r\n]*)'+ // ignore commented out stuff
  '(?<!\Wrecord)'+ // ignore one line record
  '\W(?:function|procedure|constructor)(?=\W)'+ // method keyword
  '(?<!''[^\r\n]*)'+ // ignore string literals
  '(?:\s+\w+|(?<=constructor))'+ // check that sub-program has name (or is constructor)
  '(?![^\r\n]*\W(?:abstract)\W)'+ // ignore abstract and external
  '(?![^\r\n]*\)[^\r\n]*:=[^\r\n]*;)'+ // ignore short methods
  '(?![^\r\n(]*:=[^\r\n]*;)'+ // ignore short methods with no ()
  '[^\r\n]*(?:\r?\n)'+ // up to line break
  '(?![^\r\n]*(?<!\w)(?:public|private|protected|function|procedure)\W)'+ // ignore if next line is another class member
  '(?![^\r\n]*{\$endif)'+ // ignore if next line is $endif
  '(?! *(?://[^\r\n]*)?(?:\r?\n))'+ // ignore if next line is empty
  '\1(?!(?:begin|try)\W|  )', // check wrong tabs
RegexOptions.Singleline);
var c := 0;
var files := EnumerateAllFiles('G:\0Prog\POCGL', '*.pas').ToArray;
foreach var fname in files index i do
begin
  $'>>> {fname}'.Println;
  Console.Title := $'{i}/{files.Length} ({i/files.Length:P})';
  var text := ReadAllText(fname);
  foreach var m: &Match in r.Matches(text) do
  begin
    var lc := text.Take(m.Index).CountOf(#10)+1; // count line and char both from 1
    var cc := m.Index-text.LastIndexOf(#10,m.Index);
    $'[{fname}] at line {lc} char {cc}:'.Println;

    Write( text.Remove(m.Index)?[^100:] );
    WriteInColor(m.Value, System.ConsoleColor.Yellow);
    Write( text.Remove(0,m.Index+m.Length)?[:100] );

    Println;
    Println('='*50);
    c += 1;

    while true do
    begin
      var s := ReadlnString;
      case s of
        'o': Exec(fname);
        '': break;
        else $'Unknown command [{s}]'.Println;
      end;
    end;
  end;

end;
Console.Title := $'Done';
$'Total {c} found'.Println;
Readln;
```
  • Loading branch information
SunSerega committed Apr 4, 2024
1 parent efe51f1 commit 5109583
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 190 deletions.
13 changes: 6 additions & 7 deletions AOtp.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ interface
{$region Exception's}

MessageException = class(Exception)
public constructor(text: string) :=
inherited Create(text);
public constructor(text: string) := inherited Create(text);
private constructor := raise new System.InvalidOperationException;
end;
ParentHaltException = class(Exception)
Expand Down Expand Up @@ -406,11 +405,11 @@ procedure StartBgThread(p: ()->());
end;

procedure Otp(line: OtpLine) :=
if AsyncProcOtp.curr<>nil then
AsyncProcOtp.curr.Enq(line) else
if Logger.main=nil then
line.Println else
Logger.main.Otp(line);
if AsyncProcOtp.curr<>nil then
AsyncProcOtp.curr.Enq(line) else
if Logger.main=nil then
line.Println else
Logger.main.Otp(line);
procedure Otp(line: string; kind: OtpKind) :=
Otp(new OtpLine(line, kind));
procedure Otp(line: string; kinds: array of string) :=
Expand Down
34 changes: 15 additions & 19 deletions AQueue.pas
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,33 @@ AsyncQueue<T> = class(IEnumerable<T>, IEnumerator<T>)
{$endif DEBUG}

public constructor :=
q := new Queue<T>;
q := new Queue<T>;
public constructor(capacity: integer) :=
q := new Queue<T>(capacity);
q := new Queue<T>(capacity);

public procedure Enq(o: T) :=
lock q do
public procedure Enq(o: T) := lock q do
begin
if done then raise new System.InvalidOperationException($'ERROR: Попытка писать {TypeName(o)}[{_ObjectToString(o)}] в завершенную {TypeName(self)}');
q.Enqueue(o);
ev.Set;
end;
public procedure EnqRange(sq: sequence of T) :=
foreach var o in sq do Enq(o);
foreach var o in sq do Enq(o);

public procedure Finish;
public procedure Finish := lock q do
begin
lock q do
begin
if done then raise new InvalidOperationException($'ERROR: Двойная попытка завершить {self.GetType}'
{$ifdef DEBUG}
+':'#10#10+
done_trace + #10#10 +
System.Environment.StackTrace
{$endif DEBUG}
);
done := true;
if done then raise new InvalidOperationException($'ERROR: Двойная попытка завершить {self.GetType}'
{$ifdef DEBUG}
done_trace := System.Environment.StackTrace;
+':'#10#10+
done_trace + #10#10 +
System.Environment.StackTrace
{$endif DEBUG}
ev.Set;
end;
);
done := true;
{$ifdef DEBUG}
done_trace := System.Environment.StackTrace;
{$endif DEBUG}
ev.Set;
end;

public function GetEnumerator: IEnumerator<T> := self;
Expand Down
12 changes: 6 additions & 6 deletions ColoredStrings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ ColoredStringPart<TKey> = class
{$region Append}

public procedure Append(ch: char) :=
if range.i2.IsInvalid then sb += ch else
raise new System.InvalidOperationException($'{TypeName(self)} is sealed');
if range.i2.IsInvalid then sb += ch else
raise new System.InvalidOperationException($'{TypeName(self)} is sealed');

public procedure Append(ch: char; c: integer) :=
loop c do Append(ch);
loop c do Append(ch);

public procedure Append(s: string) :=
for var i := 0 to s.Length-1 do Append(s[i]);
for var i := 0 to s.Length-1 do Append(s[i]);

public procedure Append(s: StringSection) :=
for var i := 0 to s.Length-1 do Append(s[i]);
for var i := 0 to s.Length-1 do Append(s[i]);

public static procedure operator+=(b: ColoredStringBuilderBase<TKey>; ch: char) := b.Append(ch);
public static procedure operator+=(b: ColoredStringBuilderBase<TKey>; s: string) := b.Append(s);
Expand Down Expand Up @@ -179,7 +179,7 @@ ColoredStringPart<TKey> = class
Result[i] := parts[i].FinishAsPart;
end;
private function FinishAsPart :=
new ColoredStringPart<TKey>(self.key, self.GetFixedRange, FinishAllParts);
new ColoredStringPart<TKey>(self.key, self.GetFixedRange, FinishAllParts);

public function Finish: ColoredString<TKey>;
begin
Expand Down
42 changes: 21 additions & 21 deletions Parsing.pas
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ StringIndex = record(IComparable<StringIndex>)

public static function operator=(ind1, ind2: StringIndex) := ind1.val=ind2.val;
public static function operator=(ind1: StringIndex; ind2: integer) :=
(ind1.val=ind2) and not ind1.IsInvalid;
(ind1.val=ind2) and not ind1.IsInvalid;
public static function operator=(ind1: integer; ind2: StringIndex) :=
(ind1=ind2.val) and not ind2.IsInvalid;
(ind1=ind2.val) and not ind2.IsInvalid;

public static function operator<(ind1: StringIndex; ind2: integer) := integer(ind1)<ind2;
public static function operator>(ind1: StringIndex; ind2: integer) := integer(ind1)>ind2;
Expand All @@ -53,20 +53,20 @@ StringIndex = record(IComparable<StringIndex>)
public static function operator>=(ind1, ind2: StringIndex) := not (ind1<ind2);

public static function MinOrInvalid(ind1, ind2: StringIndex) :=
if ind1.IsInvalid or ind2.IsInvalid then Invalid else
Min(ind1.val, ind2.val);
if ind1.IsInvalid or ind2.IsInvalid then Invalid else
Min(ind1.val, ind2.val);
public static function MaxOrInvalid(ind1, ind2: StringIndex) :=
if ind1.IsInvalid or ind2.IsInvalid then Invalid else
Max(ind1.val, ind2.val);
if ind1.IsInvalid or ind2.IsInvalid then Invalid else
Max(ind1.val, ind2.val);

public static function MinValid(ind1, ind2: StringIndex) :=
if ind2.IsInvalid then ind1 else
if ind1.IsInvalid then ind2 else
Min(ind1.val, ind2.val);
if ind2.IsInvalid then ind1 else
if ind1.IsInvalid then ind2 else
Min(ind1.val, ind2.val);
public static function MaxValid(ind1, ind2: StringIndex) :=
if ind2.IsInvalid then ind1 else
if ind1.IsInvalid then ind2 else
Max(ind1.val, ind2.val);
if ind2.IsInvalid then ind1 else
if ind1.IsInvalid then ind2 else
Max(ind1.val, ind2.val);

public static function Compare(ind1, ind2: StringIndex; invalid_ord: integer := 0): integer;
begin
Expand Down Expand Up @@ -109,7 +109,7 @@ StringIndex = record(IComparable<StringIndex>)
end;

public function ToString: string; override :=
if self.IsInvalid then 'StringIndex.Invalid' else self.val.ToString;
if self.IsInvalid then 'StringIndex.Invalid' else self.val.ToString;
public function Print: StringIndex;
begin
self.ToString.Print;
Expand Down Expand Up @@ -171,9 +171,9 @@ StringSection = record
public constructor := exit;

public procedure ValidateInd(ind: StringIndex) :=
if (ind >= StringIndex(Length)) then raise new System.IndexOutOfRangeException($'Index {ind} was >= {Length}');
if (ind >= StringIndex(Length)) then raise new System.IndexOutOfRangeException($'Index {ind} was >= {Length}');
public procedure ValidateLen(len: StringIndex) :=
if (len > StringIndex(Length)) then raise new System.IndexOutOfRangeException($'Length {len} was > {Length}');
if (len > StringIndex(Length)) then raise new System.IndexOutOfRangeException($'Length {len} was > {Length}');

public static function operator in(ind: StringIndex; s: StringSection) := ind in s.range;

Expand Down Expand Up @@ -267,13 +267,13 @@ StringSection = record
end;
end;
public function TrimWhile(ch_validator: char->boolean) := self
.TrimFirstWhile(ch_validator)
.TrimLastWhile(ch_validator);
.TrimFirstWhile(ch_validator)
.TrimLastWhile(ch_validator);

public function TakeFirstWhile(ch_validator: char->boolean) :=
self.TakeFirst(0).NextWhile(self.I2, ch_validator);
self.TakeFirst(0).NextWhile(self.I2, ch_validator);
public function TakeLastWhile(ch_validator: char->boolean) :=
self.TakeLast(0).PrevWhile(self.I1, ch_validator);
self.TakeLast(0).PrevWhile(self.I1, ch_validator);

public function TrimAfterFirst(ch: char): StringSection;
begin
Expand Down Expand Up @@ -514,7 +514,7 @@ StringSection = record
end;

public function IsEscaped(min_ind: StringIndex; escape_sym: char) :=
self.TakeFirst(0).PrevWhile(min_ind, ch->ch=escape_sym).Length.IsOdd;
self.TakeFirst(0).PrevWhile(min_ind, ch->ch=escape_sym).Length.IsOdd;

public procedure UnescapeTo(res: StringBuilder; escape_sym: char);
begin
Expand Down Expand Up @@ -578,7 +578,7 @@ StringSection = record
end;

public function ToString: string; override :=
if self.IsInvalid then 'StringSection.Invalid' else range.ToString(text);
if self.IsInvalid then 'StringSection.Invalid' else range.ToString(text);
public property AsString: string read ToString;

end;
Expand Down
32 changes: 16 additions & 16 deletions Patterns.pas
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ PatternPath<TJumpNode> = record
public n: TJumpNode;
public constructor(n: TJumpNode) := self.n := n;
public static function operator implicit(n: TJumpNode): PatternPath<TJumpNode> :=
new PatternPath<TJumpNode>(n);
new PatternPath<TJumpNode>(n);

public function Count: integer;
begin
Expand All @@ -65,7 +65,7 @@ PatternPath<TJumpNode> = record
end;

public function ToString: string; override :=
self.ToArray(n->n).JoinToString(', ');
self.ToArray(n->n).JoinToString(', ');

end;

Expand Down Expand Up @@ -136,12 +136,12 @@ BasicPatternPointDummy<TPointer> = record(IPatternPoint<BasicPatternPointDummy
function Equals(p: BasicPatternPointDummy<TPointer>) := self.ep = p.ep;

public static function operator implicit(ep: TPointer): BasicPatternPointDummy<TPointer> :=
new BasicPatternPointDummy<TPointer>(ep);
new BasicPatternPointDummy<TPointer>(ep);

public property Edge: TPointer read ep;

public function ToString: string; override :=
$'{self.GetType.Name}(Edge={Edge})';
$'{self.GetType.Name}(Edge={Edge})';

end;

Expand Down Expand Up @@ -173,7 +173,7 @@ BasicPatternPointRec<TPointer, TOther> = record(IPatternPoint<BasicPatternPoin
public property OtherEdges: TOther read other;

public function ToString: string; override :=
$'{self.GetType.Name}(FirstEdge={FirstEdge}; OtherEdges={OtherEdges})';
$'{self.GetType.Name}(FirstEdge={FirstEdge}; OtherEdges={OtherEdges})';

end;

Expand All @@ -183,7 +183,7 @@ BasicPatternPoint2<TPointer1, TPointer2> = record(IPatternPoint<BasicPatternPo
private impl: BasicPatternPointRec<TPointer1, BasicPatternPointDummy<TPointer2>>;

public constructor(ep1: TPointer1; ep2: TPointer2) := impl :=
new BasicPatternPointRec<TPointer1, BasicPatternPointDummy<TPointer2>>(ep1, ep2);
new BasicPatternPointRec<TPointer1, BasicPatternPointDummy<TPointer2>>(ep1, ep2);

public [MethodImpl(MethodImplOptions.AggressiveInlining)]
function AnyEdgesDone := impl.AnyEdgesDone;
Expand All @@ -200,8 +200,8 @@ BasicPatternPoint2<TPointer1, TPointer2> = record(IPatternPoint<BasicPatternPo
public property Edge2: TPointer2 read impl.OtherEdges.Edge;

public function ToString: string; override :=
$'({Edge1}; {Edge2})';
// $'{self.GetType.Name}(Edge1={Edge1}; Edge2={Edge2})';
$'({Edge1}; {Edge2})';
// $'{self.GetType.Name}(Edge1={Edge1}; Edge2={Edge2})';

end;

Expand Down Expand Up @@ -235,7 +235,7 @@ BasicJumpCost = record(IJumpCost<BasicJumpCost>)
public function Plus(cost: BasicJumpCost): BasicJumpCost := self.val+cost.val;

public function ToString: string; override :=
$'{TypeName(self)}({val})';
$'{TypeName(self)}({val})';

end;

Expand Down Expand Up @@ -276,7 +276,7 @@ BasicCharIterator = record(IPatternEdgePointer<BasicCharIterator>, IPatternEdg
public static function operator<>(i1, i2: BasicCharIterator) := not (i1=i2);
public function Equals(i: BasicCharIterator) := self=i;
public function Equals(o: object): boolean; override :=
(o is BasicCharIterator(var i)) and self.Equals(i);
(o is BasicCharIterator(var i)) and self.Equals(i);

public property Current: char read s.First;

Expand Down Expand Up @@ -326,8 +326,8 @@ BasicCharIterator = record(IPatternEdgePointer<BasicCharIterator>, IPatternEdg
public function MakeCostJumps(i: BasicCharIterator) := BasicCharIterator.MakeCostJumps(self, i);

public function ToString: string; override :=
s.I1.ToString;
// $'{TypeName(self)}(ind={s.I1}; left={s})';
s.I1.ToString;
// $'{TypeName(self)}(ind={s.I1}; left={s})';

end;

Expand Down Expand Up @@ -363,11 +363,11 @@ BasicCharIterator = record(IPatternEdgePointer<BasicCharIterator>, IPatternEdg
BasicPattern = static class

public static function MinPaths<TPointer1,TPointer2>(ep1: TPointer1; ep2: TPointer2): sequence of array of BasicPatternDiffBase;
where TPointer1: record, IPatternEdgePointer<TPointer1>;
where TPointer2: record, IPatternEdgePointer<TPointer2>;
where TPointer1: record, IPatternEdgePointer<TPointer1>;
where TPointer2: record, IPatternEdgePointer<TPointer2>;

public static function MinPaths<TPointer>(ep1, ep2: TPointer): sequence of array of BasicPatternDiff<TPointer>;
where TPointer: record, IPatternEdgePointer<TPointer>;
where TPointer: record, IPatternEdgePointer<TPointer>;

end;

Expand Down Expand Up @@ -408,7 +408,7 @@ implementation
end;

procedure RemoveWorseThan(p: TPoint) :=
pts.RemoveAll(j_res->j_res.Item1.IncLessThan(p));
pts.RemoveAll(j_res->j_res.Item1.IncLessThan(p));

end;

Expand Down
Loading

0 comments on commit 5109583

Please sign in to comment.