コード例 #1
0
        public static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("  actorcompiler <input> <output> [--disable-actor-without-wait-warning]");
                return(100);
            }
            Console.WriteLine("actorcompiler {0}", string.Join(" ", args));
            string             input = args[0], output = args[1], outputtmp = args[1] + ".tmp";
            ErrorMessagePolicy errorMessagePolicy = new ErrorMessagePolicy();

            if (args.Contains("--disable-actor-without-wait-warning"))
            {
                errorMessagePolicy.DisableActorWithoutWaitWarning = true;
            }
            try
            {
                var inputData = File.ReadAllText(input);
                using (var outputStream = new StreamWriter(outputtmp))
                    new ActorParser(inputData, input.Replace('\\', '/'), errorMessagePolicy).Write(outputStream, output.Replace('\\', '/'));
                if (File.Exists(output))
                {
                    File.SetAttributes(output, FileAttributes.Normal);
                    File.Delete(output);
                }
                File.Move(outputtmp, output);
                File.SetAttributes(output, FileAttributes.ReadOnly);
                return(0);
            }
            catch (actorcompiler.Error e)
            {
                Console.Error.WriteLine("{0}({1}): error FAC1000: {2}", input, e.SourceLine, e.Message);
                if (File.Exists(outputtmp))
                {
                    File.Delete(outputtmp);
                }
                if (File.Exists(output))
                {
                    File.SetAttributes(output, FileAttributes.Normal);
                    File.Delete(output);
                }
                return(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("{0}({1}): error FAC2000: Internal {2}", input, 1, e.ToString());
                if (File.Exists(outputtmp))
                {
                    File.Delete(outputtmp);
                }
                if (File.Exists(output))
                {
                    File.SetAttributes(output, FileAttributes.Normal);
                    File.Delete(output);
                }
                return(3);
            }
        }
コード例 #2
0
ファイル: ActorParser.cs プロジェクト: zys0807/foundationdb
 public ActorParser(string text, string sourceFile, ErrorMessagePolicy errorMessagePolicy)
 {
     this.sourceFile         = sourceFile;
     this.errorMessagePolicy = errorMessagePolicy;
     tokens = Tokenize(text).Select(t => new Token {
         Value = t
     }).ToArray();
     CountParens();
     //if (sourceFile.EndsWith(".h")) LineNumbersEnabled = false;
     //Console.WriteLine("{0} chars -> {1} tokens", text.Length, tokens.Length);
     //showTokens();
 }
コード例 #3
0
        public static int Main(string[] args)
        {
            bool generateProbes = false;

            if (args.Length < 2)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("  actorcompiler <input> <output> [--disable-diagnostics] [--generate-probes]");
                return(100);
            }
            Console.WriteLine("actorcompiler {0}", string.Join(" ", args));
            string             input = args[0], output = args[1], outputtmp = args[1] + ".tmp";
            ErrorMessagePolicy errorMessagePolicy = new ErrorMessagePolicy();

            foreach (var arg in args)
            {
                if (arg.StartsWith("--"))
                {
                    if (arg.Equals("--disable-diagnostics"))
                    {
                        errorMessagePolicy.DisableDiagnostics = true;
                    }
                    else if (arg.Equals("--generate-probes"))
                    {
                        generateProbes = true;
                    }
                }
            }
            try
            {
                var inputData = File.ReadAllText(input);
                using (var outputStream = new StreamWriter(outputtmp))
                    new ActorParser(inputData, input.Replace('\\', '/'), errorMessagePolicy, generateProbes).Write(outputStream, output.Replace('\\', '/'));
                if (File.Exists(output))
                {
                    File.SetAttributes(output, FileAttributes.Normal);
                    File.Delete(output);
                }
                File.Move(outputtmp, output);
                File.SetAttributes(output, FileAttributes.ReadOnly);
                return(0);
            }
            catch (actorcompiler.Error e)
            {
                Console.Error.WriteLine("{0}({1}): error FAC1000: {2}", input, e.SourceLine, e.Message);
                if (File.Exists(outputtmp))
                {
                    File.Delete(outputtmp);
                }
                if (File.Exists(output))
                {
                    File.SetAttributes(output, FileAttributes.Normal);
                    File.Delete(output);
                }
                return(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("{0}({1}): error FAC2000: Internal {2}", input, 1, e.ToString());
                if (File.Exists(outputtmp))
                {
                    File.Delete(outputtmp);
                }
                if (File.Exists(output))
                {
                    File.SetAttributes(output, FileAttributes.Normal);
                    File.Delete(output);
                }
                return(3);
            }
        }