reflaxe icon indicating copy to clipboard operation
reflaxe copied to clipboard

Manipulate file name/path from Generator

Open neimanpinchas opened this issue 1 year ago • 3 comments

Issue: Handling Strict Syntax Errors in Go for Haxe->Go Compiler

Description: I am experiencing an issue with my Haxe->Go compiler where Go is extremely strict about syntax errors in any .go file, regardless of whether the file is actually used by the main function or not. This results in compilation failures due to unused or irrelevant files.

Proposed Solutions:

  1. Export to Class.go.not if syntax check fails:

    • This would involve changing the default filename to indicate that the file has syntax errors, preventing it from being included in the compilation process.
  2. Export to Directory Structure Instead of Flattening the Project:

    • This approach would maintain the original directory structure of the project, rather than flattening it, in this case the go compiler will ignore folders that it doesn't have to look into, This would help prevent conflicts when two classes from different namespaces have the same name, as each class would reside in its respective directory.

Both of them will require me to programmatically change the name of the currently compiled class from Generator, how can I do that with reflaxe?

neimanpinchas avatar Dec 10 '24 18:12 neimanpinchas

Sorry for the delay, you can disable the default file generation by returning null from the Generator functions. Before returning null, use the "extra file" functions from BaseCompiler to manually generate the files: https://github.com/SomeRanDev/reflaxe/blob/7dce4a1afc6bd86e64a46085cfcf7250564585ed/src/reflaxe/BaseCompiler.hx#L409

For example:

var code = "";

// compile AST to code...

// This creates the file if it doesn't exist.
this.appendToExtraFile("my/custom/path.go", code);

return null;

SomeRanDev avatar Dec 12 '24 13:12 SomeRanDev

In my case I only know in the generator that my generated text is not valid.

It seems that appendToExtraFile isn't avilible in the generator static functions.

neimanpinchas avatar Dec 12 '24 14:12 neimanpinchas

After checking generateOutputIterator I think that I will slightly modify the generator functions to return some metadata about compilation success.

neimanpinchas avatar Dec 12 '24 14:12 neimanpinchas