package dyvilx.tools.gensrc;

import dyvil.collection.List;
import dyvil.collection.mutable.ArrayList;
import dyvilx.tools.compiler.DyvilCompiler;
import dyvilx.tools.compiler.config.CompilerConfig;
import dyvilx.tools.gensrc.ast.Template;
import dyvilx.tools.gensrc.sources.GenSrcFileType;

import java.io.File;

public class GenSrc extends DyvilCompiler
{
	private List<File>     specs     = new ArrayList<>();
	private List<Template> templates = new ArrayList<>();

	@Override
	protected CompilerConfig createConfig()
	{
		return new GenSrcConfig(this);
	}

	@Override
	protected void setupFileFinder()
	{
		this.fileFinder.registerFileType(GenSrcFileType.TEMPLATE_EXTENSION, GenSrcFileType.TEMPLATE);
		this.fileFinder.registerFileType(GenSrcFileType.SPEC_EXTENSION, GenSrcFileType.SPEC);
	}

	public void addSpec(File file)
	{
		this.specs.add(file);
	}

	public void addTemplate(Template template)
	{
		this.templates.add(template);
	}

	@Override
	public void test()
	{
		if (this.config.getMainType() == null)
		{
			this.config.setMainType("GenerateSources");

			final List<String> mainArgs = this.config.getMainArgs();
			mainArgs.clear();
			for (File spec : this.specs)
			{
				// the paths of the specs become the main arguments
				mainArgs.add(spec.getPath());
			}
		}
		super.test();
	}
}

@@ -1047,23 +1047,34 @@
 pe(%22
-GenerateSources
+dyvilx.tools.gensrc.Runner
 %22);%0A
@@ -1162,131 +1162,423 @@
 %0A%09%09%09
-for (File spec : this.specs)%0A%09%09%09%7B%0A%09%09%09%09// the paths of the specs become the main arguments%0A%09%09%09%09mainArgs.add(spec.getPath());
+mainArgs.add(%22output_dir=%22 + ((GenSrcConfig) this.config).getGenSrcDir());%0A%09%09%09for (Template template : this.templates)%0A%09%09%09%7B%0A%09%09%09%09final String internalName = template.getInternalName();%0A%0A%09%09%09%09mainArgs.add(%22-t%22);%0A%09%09%09%09mainArgs.add(template.getFullName());%0A%0A%09%09%09%09for (File spec : this.specs)%0A%09%09%09%09%7B%0A%09%09%09%09%09final String path = spec.getPath();%0A%09%09%09%09%09if (path.contains(internalName))%0A%09%09%09%09%09%7B%0A%09%09%09%09%09%09mainArgs.add(path);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D
 %0A%09%09%09

Use GenSrc Runner