public void Execute(ToffeeWriter writer) { if (Command == "begin") { string filename = writer.GetLineToWrite(Argument); string filepath; if (writer.OutputDirectory != "") { filepath = Path.Combine(writer.OutputDirectory, filename); } else { filepath = Path.GetFullPath(filename); } string path = Path.GetDirectoryName(filepath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } writer.Log("Begin file: {0}", filepath); writer.Stream = new FileStream(filepath, FileMode.Create); } else if (Command == "end") { writer.Writer.Flush(); writer.Stream.Dispose(); } else { writer.Log("Unknown file command '{0}'", Command); } }
public void Execute(ToffeeWriter writer) { foreach (IGeneratorCommand command in Commands) { command.Execute(writer); } }
public void Execute(ToffeeWriter writer) { writer.Log("Writing {0}", Value); string value = writer.GetLineToWrite(Value); if (writer.AppendNewline) { writer.Writer.WriteLine(value); } else { writer.Writer.Write(value); } }
public void Execute(ToffeeWriter writer) { if (Not) { writer.Log("Checking if '{0}' is not defined", Define); if (!writer.Defines.Contains(Define)) { writer.Log("'{0}' was not defined, entering TrueCode", Define); foreach (IGeneratorCommand command in TrueCode) { command.Execute(writer); } } else { writer.Log("'{0}' was defined, entering FalseCode", Define); foreach (IGeneratorCommand command in FalseCode) { command.Execute(writer); } } } else { writer.Log("Checking if '{0}' is defined", Define); if (writer.Defines.Contains(Define)) { writer.Log("'{0}' was defined, entering TrueCode", Define); foreach (IGeneratorCommand command in TrueCode) { command.Execute(writer); } } else { writer.Log("'{0}' was not defined, entering FalseCode", Define); foreach (IGeneratorCommand command in FalseCode) { command.Execute(writer); } } } writer.Log("Left Code for '{0}'", Define); }
public void Execute(ToffeeWriter writer) { switch (Command.ToLower()) { case "indent": string argument = Argument.ToLower(); if (argument == "forwards") { writer.IndentLevel++; } else if (argument == "backwards") { writer.IndentLevel--; } else if (argument == "on") { writer.Indent = true; } else if (argument == "off") { writer.Indent = false; } break; case "newline": if (Argument == "0") { writer.AppendNewline = false; } else { writer.AppendNewline = true; } break; case "crash": throw new ToffeeWriterException("Writer was told to crash."); default: writer.Log("Unknown writer command '{0}'", Command); break; } }
public CSharpDataGatherer(ToffeeWriter writer, TdlFile file) : base(writer, file) { AllObjects = file.AllObjects; CurrentObjectIndex = 0; CurrentPropertyIndex = 0; }
public void Execute(ToffeeWriter writer) { writer.Repeat(); }
private static bool BeginApplication() { // Let's try to load the script file specified Console.WriteLine("Loading generator..."); string scriptFilepath = string.Format("{0}/Scripts/{1}.tofc", AppDomain.CurrentDomain.BaseDirectory, Arguments.GeneratorScript); try { Generator = new ToffeeGenerator(scriptFilepath, Arguments.Verbose || Arguments.VerboseGenerator); } catch (ToffeeGeneratorException e) { Console.WriteLine("An error occurred while creating the generator:"); Console.WriteLine("ToffeeGeneratorException: {0}", e.Message); } // We've successfully loaded the script file, let's make the writer! Writer = new ToffeeWriter(Generator, Arguments.Verbose || Arguments.VerboseWriter); // Now, let's load the toffee file Console.WriteLine("Loading input file..."); if (Path.GetExtension(Arguments.InputFile) != ".tdl") { Console.WriteLine("Input file must have '.tdl' extension."); return(false); } TdlFile file = new TdlFile(Arguments.BaseNamespace, Arguments.Verbose || Arguments.VerboseParser); try { if (!file.ParseFile(Path.GetFullPath(Arguments.InputFile))) { Console.WriteLine("Could not find the input file."); return(false); } } catch (TdlParserException e) { Console.WriteLine("An error occurred while parsing."); Console.WriteLine(e.Message); return(false); } Console.WriteLine("Hash: {0}", file.Hash); // Finally, let's output! Console.WriteLine("Generating..."); try { object gatherer = ToffeeDataGatherers.Instance.GetGatherer( Path.GetFileNameWithoutExtension(Arguments.GeneratorScript), Writer, file); if (gatherer == null) { Console.WriteLine("An error occurred while generating."); Console.WriteLine("Couldn't find gatherer for specified script."); return(false); } Writer.Gatherer = gatherer; if (Arguments.OutputDirectory != "") { Writer.Generate(Path.GetFullPath(Arguments.OutputDirectory)); } else { Writer.Generate(Arguments.OutputDirectory); } } catch (ToffeeWriterException e) { Console.WriteLine("An error occurred while generating."); Console.WriteLine(e.Message); return(false); } return(true); }
public void Execute(ToffeeWriter writer) { writer.GetData(WantedData); }
public void Execute(ToffeeWriter writer) { writer.ExecutePattern(Pattern); }