HaxeCheckstyle / haxeparser

A Haxe parser for Haxe
61 stars 23 forks source link

parsing Haxe code at compile time #62

Closed lublak closed 2 years ago

lublak commented 2 years ago

We have first this issue: https://github.com/Simn/hxparse/issues/59 Additionally i get this: C:\HaxeToolkit\haxe\lib\haxeparser/git/src/haxeparser/HaxeParser.hx:369: character 1 : You cannot use @:build inside a macro : make sure that your type is not used in macro If i remove just the static function it works.

Another error: C:\HaxeToolkit\haxe\lib\haxeparser/git/src/haxeparser/HaxeParser.hx:369: character 1 : You cannot use @:build inside a macro : make sure that your type is not used in macro used macro

Can i use it at macro level? If not Is there anlternative for it? Full parsing not just an expression.

Some background Infos: Technically I need to test a haxe file before using it (Syntax and also to test if the class using some packages that are not allowed in is target. And with the current project. I need to test allot in a big environment (with allot of libraries) so compiling each takes to long.

/*
 Current target is --js
*/
macro function test () {
 if(isValidFile('HelloWorld.hx')) {
    Context.getType('HelloWorld');
  }

 return macro null;
}

My plan was to define this type dynamically and cache any errors. Context.getType can not be cached for this type of errors. (https://github.com/HaxeCheckstyle/haxeparser/blob/master/src/haxeparser/DefinitionConverter.hx)

AlexHaxe commented 2 years ago

I would suggest you write a command line tool that does all of the checking and use it as a pre-build step. that way you can speed up compilation during development and testing because all that extra parsing and checking only needs to happens when those files change and not with every build. it also eliminates issues with cached types.

you could even use checkstyle for your testing needs by writing a new check that blacklists certain full qualified types or packages (in that case: please send your PR to checkstyle).

lublak commented 2 years ago

@AlexHaxe thank you for the answer. I will now use it in a command line tool. will there actually be a haxelib release? 3.3.0 is already a bit old.