Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
 public void SetSource(SourceProjectFile src)
 {
     if (this.Source is null)
     {
         this.Source = src;
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Exemplo n.º 3
0
 public static SourceProject FromText(IEnumerable <string> content, string name, string output, SourceProjectType projectType)
 => new SourceProject(name, output, projectType, SourceProjectFile.FromText(ToSingleText(content)));