AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Parsen von Source Code Files

Ein Thema von bernhard_LA · begonnen am 14. Mär 2022 · letzter Beitrag vom 15. Mär 2022
 
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#9

AW: Parsen von Source Code Files

  Alt 15. Mär 2022, 10:20
Habe mal auf die schnelle was getippst wie ich es machen würde. Vielleicht hilft es?!
Delphi-Quellcode:
program FileWriter;

{$APPTYPE CONSOLE}

{.$R *.res}

uses
  System.SysUtils, System.Classes, System.IOUtils;


function MyParse(const AInFile, AOutFile: string): Boolean;
var
  LData: TBytes;
  LOutput: TStringList;
  i: Int64;
  s: string;
begin
  Result := False;
  s := '';
  if FileExists(AInFile) then
    begin
      LOutput := TStringList.Create;
      try
        LData := TFile.ReadAllBytes(AInFile); // Lade Datei in den Speicher
        for i := Low(LData) to High(LData) do
          begin
            if ((LData[i] <> $0D) and (LData[i] <> $0A) and (LData[i] <> $3B) and (LData[i] <> $20)) then // Zeilenumbrüche, Leerzeichen und Semikolon rausfiltern
              s := s + Chr(LData[i]);
            if (LData[i] = $3B) then // Semikolon entdeckt, erstelle fertige Zeile
              begin
                s := s + Chr(LData[i]);
                LOutput.Add(s);
                s := '';
              end;
          end;
        if LOutput.Count > 0 then
          begin
            LOutput.SaveToFile(AOutFile);
            Result := True;
          end;
      finally
        LOutput.Free;
      end;
    end;
end;

var
  LPath: string;
begin
  try
    Writeln('Parser starting...');
    LPath := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
    MyParse(LPath + 'TestFile.txt', LPath + 'TestOut.txt');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

//edit

als beispiel InFile:
Delphi-Quellcode:
sky130_fd_sc_hd__a21oi_1 _25041_ ( .A1(_15472_)
.A2(_16059_)
.B1(_15410_)
.Y(_16230_)
);

 sky130_fd_sc_hd__a21o_1 _25042_ ( .A1(_15433_)
.A2(_15309_)
.B1(_15394_)
.X(_16231_)
);sky130_fd_sc_hd__nor3_1 _29993_ ( .A(_05384_), .B(_05386_), .C(_05388_), .Y(_05389_) );
  
sky130_fd_sc_hd__a211oi_1 _29994_ ( .A1(_05371_), .A2(_05377_), .B1(_05382_), .C1(_05389_), .Y(_05390_) );sky130_fd_sc_hd__nor3_1 _29993_ (.A(_05384_), .B(_05386_),.C(_05388_),.Y(_05389_) );
sky130_fd_sc_hd__a211oi_1 _29994_ (.A1(_05371_),.A2(_05377_),.B1(_05382_),.C1(_05389_),.Y(_05390_));

sky130_fd_sc_hd__a211oi_1 _29994_ ( _05371 , _05377_, _05382_, _05389_ , _05390_ );
kommt folgendes raus:
Delphi-Quellcode:
sky130_fd_sc_hd__a21oi_1_25041_(.A1(_15472_).A2(_16059_).B1(_15410_).Y(_16230_));
sky130_fd_sc_hd__a21o_1_25042_(.A1(_15433_).A2(_15309_).B1(_15394_).X(_16231_));
sky130_fd_sc_hd__nor3_1_29993_(.A(_05384_),.B(_05386_),.C(_05388_),.Y(_05389_));
sky130_fd_sc_hd__a211oi_1_29994_(.A1(_05371_),.A2(_05377_),.B1(_05382_),.C1(_05389_),.Y(_05390_));
sky130_fd_sc_hd__nor3_1_29993_(.A(_05384_),.B(_05386_),.C(_05388_),.Y(_05389_));
sky130_fd_sc_hd__a211oi_1_29994_(.A1(_05371_),.A2(_05377_),.B1(_05382_),.C1(_05389_),.Y(_05390_));
sky130_fd_sc_hd__a211oi_1_29994_(_05371,_05377_,_05382_,_05389_,_05390_);
Gruß vom KodeZwerg

Geändert von KodeZwerg (15. Mär 2022 um 11:45 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:28 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz