Home > database >  What's the proper way to implement a parser in Delphi?
What's the proper way to implement a parser in Delphi?

Time:11-21

There are a lot of frameworks, libraries to help you writing parsers in languages like JavaScript or Rust. Now I need to write a parser in Delphi. After some Googling, it seems there is no prominent Delphi project for this. I want to know how you Delphi guys writing parsers? Is there any libraries to help me (paid commercial product is fine)? Btw, I'm new to Delphi.

CodePudding user response:

Things you might have neglected are,

  • Many of the parser frameworks (like ANTLR/PEG) are extensible, so even if by default they don't ship with a language support for Delphi/Pascal, you can find somebody else's work or write your own.
  • ANTLR 3 has Delphi support, such as language target(used to compile grammars to Delphi/Pascal) as well as runtime(the runtime to include in your application to enable the compiled parser code). But ANTLR 4 drops such, probably due to the fact that not many people use Delphi compared to other languages.
  • For commercial parser frameworks, you should talk directly to their presale guys and see if they already have Delphi/Pascal support. They usually have an out-of-date website, so not easy to know what target languages they really support.

CodePudding user response:

Parser for what? If its for something like a string you can use this parser:

function Parse(Source, L, R: string): string;
begin
  Delete(Source, 1, Pos(L, Source)   Length(L) - 1);
  Result := Copy(Source, 1, Pos(R, Source) - 1);
end;

L - From first time "" found in the text L - To the next "" found in the text

It works pretty great with parsing sources from a website for data.

  • Related