RomanYankovsky / DelphiAST

Abstract syntax tree builder for Delphi
Mozilla Public License 2.0
271 stars 116 forks source link

How to compile in Lazarus v2.0.6 #289

Closed abulka closed 4 years ago

abulka commented 4 years ago

This project claims to be Lazarus compatible and offers a Lazarus project file DelphiAST\Demo\Parser\ParserDemo.lpi yet I cannot get it to compile. Here are the numerous obstacles I've encountered:

Had to move the DelphiAST\Source dir into the DelphiAST\Demo dir.

Had to abandon the Mac version, because Windows is not defined.

Had to copy https://github.com/maciej-izak/generics.collections into the DelphiAST\Demo\Source\FreePascalSupport directory

Similarly, had to copy https://github.com/Wosi/FPC_StringBuilder into the DelphiAST\Demo\Source\FreePascalSupport directory and had to use the https://github.com/Wosi/FPC_StringBuilder fork not the original https://github.com/hinst/FPC_StringBuiler

Had to add

{$IFDEF FPC}
{$MACRO ON}
{$define RTLVersion := 25}
{$define CompilerVersion := 18}
{$ENDIF} 

to the top of SimplParser.Lexer though I don't think the values are correct for my version of Lazarus v2.0.6 but I had to define those constants in order to compile. Any suggestions for correct values welcome.

Got a compilation error str := UTF8ToUnicodeString(u8); in DelphiAST.Serialize.Binary.pas - isn't UTF8ToUnicodeString a Delphi only concept? In frustration I simply wrapped it in

{$IFDEF UNICODE}
  str := UTF8ToUnicodeString(u8);
{$ELSE}
   str := String(u8);
{$ENDIF}  

and the compilation moved on, presumably because UNICODE is not defined? Anyway...

Currently I cannot get past the "error: Illegal qualifier" in DelphiAST.Writer.pas 79

   Builder.Append('<' + UpperCase(SyntaxNodeNames[Node.Typ]));  

and am stuck.

Wosi commented 4 years ago

Relative search paths are wrong since ParserDemo has been moved to a subfolder. There are also a few other things that didn't work with FPC for quite a while. I made it work again (see #290).

It's important to checkout submodules when you want to compile it with FPC. Otherwise the compiler can't find generics.collections and stringbuilder. Use this command in order to get the submodules:

git submodule update --init --recursive

abulka commented 4 years ago

Thanks so much - the new version plus the fancy git command resulted in a successful compile on Windows 10.

I then pushed my luck and tried to compile it on Mac.

Then the demo ran OK on Mac too!