Example #1
0
        static void Main(string[] args)
        {
            try
            {
                ParseArgs(args);
            }
            catch (FileNotFoundException ex)
            {
                Fatal("No such file: {0}", ex.FileName);
            }

            if (input == null)
                Usage();

            using (var sr = new StreamReader(input))
            {
                var source = sr.ReadToEnd();

                if (!forceCompile && outputPath != null && File.Exists(outputPath))
                {
                    using (var sr2 = new StreamReader(File.Open(outputPath, FileMode.Open)))
                    {
                        sr2.ReadLine();
                        if (source.MD5() == sr2.ReadLine().Replace("// ", ""))
                            Fatal("Skipping compile as MD5 matches");
                    }
                }

                Parser translator = null;
                switch (filetype)
                {
                    case ".erb": translator = new ErbParser(source); break;
                    default: translator = new Parser(source); break;
                }
                translator.Parse();

                output = File.Open(outputPath, FileMode.Create);
                using (var sw = new StreamWriter(output))
                {
                    sw.Write(translator.CompileToPHP(source));
                    sw.Flush();
                }
            }
        }