/// <summary> /// sourcePath: Directory, targetPath: File /// </summary> /// <param name="sourcePath"></param> /// <param name="targetPath"></param> public static void CompileTo(string sourcePath, string targetPath) { var compiler = new XYCompiler(sourcePath); var output = compiler.Output(); if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); } File.WriteAllText(targetPath, output, Encoding.UTF8); }
void InheritParent(XYCompiler parent) { if (parent == null) { return; } if (parent._targetRootPath != null) { _targetRootPath = parent._targetRootPath; } if (parent._modeTrimTab != null) { _modeTrimTab = parent._modeTrimTab; } if (parent._clearList != null) { _clearList = new List <string>(parent._clearList); } }
void CompileToPath(string sourcePath, string targetPath) { var compiler = new XYCompiler(sourcePath, parent: this); compiler.OutputToPath(targetPath); }
public XYCompiler(string sourcePath, Dictionary <string, string> variables = null, XYCompiler parent = null) { if (Directory.Exists(sourcePath)) { // sourcePath是目录 this.mainPath = sourcePath + "\\__main__." + Extension; if (File.Exists(this.mainPath)) { // 找到main,执行编译 this.sourcePath = sourcePath; } else { // 没找到main,报错 // TODO 没找到main,尝试遍历子目录? throw new FileNotFoundException("Can't find __main__.txt at: " + sourcePath); } } else { // sourcePath是文件 this.mainPath = sourcePath + "." + Extension; // 先假设COMPILE/IMPORT的文件没有填写后缀名 if (!File.Exists(this.mainPath)) { // sourcePath填写了后缀名,将sourcePath不作处理直接赋值给mainPath this.mainPath = sourcePath; } this.sourcePath = Path.GetDirectoryName(this.mainPath); } this.variables = variables; InheritParent(parent); }
public static string Compile(string sourcePath) { var compiler = new XYCompiler(sourcePath); return(compiler.Output(true)); }