private static CompileResult ParseFile(SourceProjectFile sourceFile, out AST ast) { // If not virtual, make sure the file exists if (!sourceFile.IsVirtual) { if (!File.Exists(sourceFile.Value)) { ast = null; return(new CompileResult(false, $"Source file \"{sourceFile.Value}\" not found.")); } } // Lex program Lexer lexer = new Lexer(); LexToken[] tokens = sourceFile.IsVirtual ? lexer.Lex(sourceFile.Value) : lexer.LexFile(sourceFile.Value); // Build AST and return it ASTBuilder builder = new ASTBuilder(tokens); ParsingResult result = builder.Parse(); if (result.Success) { ast = builder.Build(); ast.SetSource(sourceFile); return(new CompileResult(true)); } else { ast = null; return(new CompileResult(false)); } }
public void SetSource(SourceProjectFile src) { if (this.Source is null) { this.Source = src; } else { throw new InvalidOperationException(); } }
public static SourceProject FromText(IEnumerable <string> content, string name, string output, SourceProjectType projectType) => new SourceProject(name, output, projectType, SourceProjectFile.FromText(ToSingleText(content)));