Пример #1
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("The syntax for the command is:");
                Console.WriteLine("IFC-gen <express schema path> <output directory>");
                return;
            }

            var expressPath = args[0];

            if (!File.Exists(expressPath))
            {
                Console.WriteLine($"The specified express file path, {expressPath}, does not exist.");
                return;
            }

            var outputDir = args[1];

            if (!Directory.Exists(outputDir))
            {
                Console.WriteLine($"The specified output directory, {outputDir}, does not exist.");
                return;
            }

            using (FileStream fs = new FileStream(expressPath, FileMode.Open))
            {
                var input  = new AntlrInputStream(fs);
                var lexer  = new Express.ExpressLexer(input);
                var tokens = new CommonTokenStream(lexer);

                var parser = new Express.ExpressParser(tokens);
                parser.BuildParseTree = true;

                var tree     = parser.schemaDecl();
                var walker   = new ParseTreeWalker();
                var sb       = new StringBuilder();
                var listener = new Express.ExpressListener(sb);
                walker.Walk(listener, tree);

                var outPath = Path.Combine(outputDir, "IFC.cs");
                File.WriteAllText(outPath, sb.ToString());

                // Write tokens to a file for debugging.

                /*var tokenStr = new StringBuilder();
                 * foreach(var t in tokens.GetTokens())
                 * {
                 *      tokenStr.AppendLine(t.ToString());
                 * }
                 * File.WriteAllText("tokens.txt",tokenStr.ToString());*/
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            ParseOptions(args);
            if (showHelp)
            {
                return;
            }

            var generators = new List <Tuple <ILanguageGenerator, ITestGenerator> >();

            if (language == "csharp")
            {
                generators.Add(new Tuple <ILanguageGenerator, ITestGenerator>(new CsharpLanguageGenerator(), new CsharpTestGenerator()));
            }
            else if (language == "proto")
            {
                generators.Add(new Tuple <ILanguageGenerator, ITestGenerator>(new ProtobufGenerator(), new ProtobufTestGenerator()));
            }

            using (FileStream fs = new FileStream(expressPath, FileMode.Open))
            {
                var input  = new AntlrInputStream(fs);
                var lexer  = new Express.ExpressLexer(input);
                var tokens = new CommonTokenStream(lexer);

                var parser = new Express.ExpressParser(tokens);
                parser.BuildParseTree = true;

                var tree   = parser.schemaDecl();
                var walker = new ParseTreeWalker();

                var testSb = new StringBuilder();

                foreach (var generator in generators)
                {
                    var listener = new Express.ExpressListener(generator.Item1, generator.Item2);
                    walker.Walk(listener, tree);
                    Generate(listener, outDir, outDirTests, generator.Item1, generator.Item2);
                }

                // Write tokens to a file for debugging.

                /*var tokenStr = new StringBuilder();
                 * foreach(var t in tokens.GetTokens())
                 * {
                 *      tokenStr.AppendLine(t.ToString());
                 * }
                 * File.WriteAllText("tokens.txt",tokenStr.ToString());*/
            }
        }