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 3, 2024
1 parent ca294a9 commit 892161a
Show file tree
Hide file tree
Showing 59 changed files with 8,911 additions and 9,019 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/// Вывод типа и значения объекта
procedure OtpObject(o: object) :=
Writeln( $'{o?.GetType}[{_ObjectToString(o)}]' );
Writeln( $'{o?.GetType}[{_ObjectToString(o)}]' );
// "o?.GetType" это короткая форма "o=nil ? nil : o.GetType",
// то есть, берём или тип объекта, или nil если сам объект nil
// _ObjectToString это функция, которую использует Writeln для форматирования значений
Expand Down
10 changes: 5 additions & 5 deletions DataScraping/XML/XMLItems.pas
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
private val_combo: ParValCombo;

public static function ParsePtrLvls(text: string): ValueTuple<string, integer, array of integer>;
const const_s = 'const';
const const_s = 'const';
begin
var flat_t := default(string);
var ptr := text.CountOf('*');
Expand Down Expand Up @@ -432,10 +432,10 @@
(self.arr_size = other.arr_size) and
(self.val_combo = other.val_combo);
public static function operator=(p1,p2: ParData) :=
ReferenceEquals(p1,p2) or (
not ReferenceEquals(p1, nil)
and p1.Equals(p2)
);
ReferenceEquals(p1,p2) or (
not ReferenceEquals(p1, nil)
and p1.Equals(p2)
);
public static function operator<>(p1,p2: ParData) := not(p1=p2);
public function Equals(obj: object): boolean; override :=
(obj is ParData(var other)) and (self=other);
Expand Down
87 changes: 2 additions & 85 deletions LastPack.log
Original file line number Diff line number Diff line change
@@ -1,89 +1,6 @@
Executing selected stages:
PullUpstream + Reference + Dummy + OpenCL + OpenCLABC + OpenGL + OpenGLABC + Compile + Test + Release
Executing default stages:
Reference + Dummy + OpenCL + OpenCLABC + OpenGL + OpenGLABC + Compile + Test + Release
Start packing
=================================== First Pack ===================================
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Update Reps ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiling "DataScraping/Reps/PullReps.pas"
Compiling: OK
Runing SubReps Update
SubReps Update: Pulling OpenCL
SubReps Update: cmd /c "(echo [checkout] && git checkout custom 2>&1) && (echo [pull-own]: && git pull SunSerega custom) && (echo [fetch-main] && git fetch 0_official main:main) && (echo [merge-main] && git merge main)"
SubReps Update: OpenCL[OUT] : [checkout]
SubReps Update: OpenCL[OUT] : Your branch is up to date with 'SunSerega/custom'.
SubReps Update: OpenCL[OUT] : Already on 'custom'
SubReps Update: OpenCL[OUT] : [pull-own]:
SubReps Update: OpenCL[ERR] : From SunSerega/OpenCL-Docs
SubReps Update: OpenCL[ERR] : * branch custom -> FETCH_HEAD
SubReps Update: OpenCL[OUT] : Already up to date.
SubReps Update: OpenCL[OUT] : [fetch-main]
SubReps Update: OpenCL[OUT] : [merge-main]
SubReps Update: OpenCL[OUT] : Already up to date.
SubReps Update: Done pulling OpenCL
SubReps Update: Pulling OpenGL
SubReps Update: cmd /c "(echo [checkout] && git checkout custom 2>&1) && (echo [pull-own]: && git pull SunSerega custom) && (echo [fetch-main] && git fetch 0_official main:main) && (echo [merge-main] && git merge main)"
SubReps Update: OpenGL[OUT] : [checkout]
SubReps Update: OpenGL[OUT] : Your branch is up to date with 'SunSerega/custom'.
SubReps Update: OpenGL[OUT] : Already on 'custom'
SubReps Update: OpenGL[OUT] : [pull-own]:
SubReps Update: OpenGL[ERR] : From SunSerega/OpenGL-Registry
SubReps Update: OpenGL[ERR] : * branch custom -> FETCH_HEAD
SubReps Update: OpenGL[OUT] : Already up to date.
SubReps Update: OpenGL[OUT] : [fetch-main]
SubReps Update: OpenGL[OUT] : [merge-main]
SubReps Update: OpenGL[OUT] : Already up to date.
SubReps Update: Done pulling OpenGL
Finished runing SubReps Update
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Scrap XML ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiling "DataScraping/XML/Dummy/ScrapXML.pas"
Compiling: OK
Runing ScrapXML[Dummy]
ScrapXML[Dummy]: Parsing XML
ScrapXML[Dummy]: Constructing named items
ScrapXML[Dummy]: Saving as binary
ScrapXML[Dummy]: Enum: Saved 8 items
ScrapXML[Dummy]: BasicType: Saved 6 items
ScrapXML[Dummy]: Group: Saved 2 items
ScrapXML[Dummy]: Func: Saved 16 items
ScrapXML[Dummy]: Feature: Saved 2 items
ScrapXML[Dummy]: Done
Finished runing ScrapXML[Dummy]
Compiling "DataScraping/XML/OpenCL/ScrapXML.pas"
Compiling: OK
Runing ScrapXML[OpenCL]
ScrapXML[OpenCL]: Parsing "cl"
ScrapXML[OpenCL]: Constructing named items
ScrapXML[OpenCL]: Saving as binary
ScrapXML[OpenCL]: VendorSuffix: Saved 11 items
ScrapXML[OpenCL]: Enum: Saved 1133 items
ScrapXML[OpenCL]: BasicType: Saved 30 items
ScrapXML[OpenCL]: Group: Saved 121 items
ScrapXML[OpenCL]: IdClass: Saved 18 items
ScrapXML[OpenCL]: Struct: Saved 16 items
ScrapXML[OpenCL]: Delegate: Saved 8 items
ScrapXML[OpenCL]: Func: Saved 241 items
ScrapXML[OpenCL]: Feature: Saved 7 items
ScrapXML[OpenCL]: Extension: Saved 134 items
ScrapXML[OpenCL]: Done
Finished runing ScrapXML[OpenCL]
Compiling "DataScraping/XML/OpenGL/ScrapXML.pas"
Compiling: OK
Runing ScrapXML[OpenGL]
ScrapXML[OpenGL]: Parsing "gl"
ScrapXML[OpenGL]: Parsing "wgl"
ScrapXML[OpenGL]: Parsing "glx"
ScrapXML[OpenGL]: Constructing named items
ScrapXML[OpenGL]: Saving as binary
ScrapXML[OpenGL]: VendorSuffix: Saved 35 items
ScrapXML[OpenGL]: Enum: Saved 4770 items
ScrapXML[OpenGL]: BasicType: Saved 116 items
ScrapXML[OpenGL]: Group: Saved 323 items
ScrapXML[OpenGL]: IdClass: Saved 15 items
ScrapXML[OpenGL]: Delegate: Saved 5 items
ScrapXML[OpenGL]: Func: Saved 3575 items
ScrapXML[OpenGL]: Feature: Saved 32 items
ScrapXML[OpenGL]: Extension: Saved 1144 items
ScrapXML[OpenGL]: Done
Finished runing ScrapXML[OpenGL]
=================================== References ===================================
Compiling "Packing/Reference/ReferencePacker.pas"
Compiling: OK
Expand Down
Loading

0 comments on commit 892161a

Please sign in to comment.