/// <summary> /// Incluye los archivos origen /// </summary> private Program IncludeFiles(string fileName, Program sourceProgram) { Program program = new Program("Main", null); // Añade las instrucciones al programa foreach (InstructionBase instruction in sourceProgram.Sentences) { if (instruction is InstructionIncludeFile) { InstructionIncludeFile include = instruction as InstructionIncludeFile; if (include != null) { string newFileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(fileName), include.FileName); if (System.IO.File.Exists(newFileName)) { Program programIncluded = CompileSource(LoadFile(newFileName)); // Añade las sentencias program.Sentences.AddRange(programIncluded.Sentences); // Añade las funciones program.Functions.AddRange(programIncluded.Functions); } } } else { program.Sentences.Add(instruction); } } // Devuelve el programa return(program); }
/// <summary> /// Crea la instrucción de crear archivo /// </summary> private InstructionIncludeFile CreateInstructionIncludeFile() { InstructionIncludeFile instruction = new InstructionIncludeFile(GetToken()); TokenSmallCss token = GetToken(); // Captura el nombre de archivo if (token.Row == instruction.Token.Row && token.TypeCss == TokenSmallCss.TokenCssType.Literal) { instruction.FileName = token.Value; } else if (token.Row == instruction.Token.Row && token.TypeCss == TokenSmallCss.TokenCssType.Comment) { instruction.FileName = "_" + token.Value; } else { instruction.Error = ParseError("No se reconoce el nombre de archivo a incluir"); } // Devuelve la instrucción return(instruction); }