Exemple #1
0
        /// <summary>
        /// Emits the artifacts for multiple compilation units with the same compilation mode and target runtime
        /// </summary>
        /// <param name="units">The compilation units</param>
        protected void ExecuteDoEmitSameModeSameTarget(List <Unit> units)
        {
            EmitterBase emitter = null;

            switch (GetTargetRuntimeFor(units[0].Grammar))
            {
            case Runtime.Net:
                emitter = new EmitterForNet(reporter, units);
                break;

            case Runtime.Java:
                emitter = new EmitterForJava(reporter, units);
                break;

            case Runtime.Rust:
                emitter = new EmitterForRust(reporter, units, outputTargetRust);
                break;
            }
            bool success = emitter.Emit();

            if (!success)
            {
                reporter.Error("Failed to emit some output");
            }
        }
Exemple #2
0
        /// <summary>
        /// Builds the test parsers
        /// </summary>
        private void BuildTestParsers(string fixtureName, string testName)
        {
            // get all units from the tests
            List <Unit> units = new List <Unit>();

            // add the unit for the expected tree parser
            Stream stream1 = typeof(Program).Assembly.GetManifestResourceStream("Hime.Tests.Driver.Resources.Fixture.gram");
            Stream stream2 = typeof(CompilationTask).Assembly.GetManifestResourceStream("Hime.SDK.Sources.Input.HimeGrammar.gram");

            Hime.SDK.Input.Loader loader = new Hime.SDK.Input.Loader();
            loader.AddInputRaw(stream1);
            loader.AddInputRaw(stream2);
            List <Grammar> grammars = loader.Load();

            foreach (Grammar grammar in grammars)
            {
                if (grammar.Name == "ExpectedTree")
                {
                    units.Add(new Unit(grammar, "", Mode.Assembly, ParsingMethod.LALR1, "Hime.Tests.Generated", Modifier.Public));
                    break;
                }
            }

            // add the unit for the parsers
            foreach (Fixture fixture in fixtures)
            {
                if (fixtureName != null && fixture.Name != fixtureName)
                {
                    continue;
                }
                foreach (Test test in fixture.Tests)
                {
                    if (testName != null && test.Name != testName)
                    {
                        continue;
                    }
                    units.Add(test.GetUnit(fixture.Name));
                }
            }

            // emit the artifacts
            (new EmitterForNet(reporter, units)).Emit();
            File.Move("Parsers.dll", "parsers-net.dll");
            (new EmitterForJava(reporter, units)).Emit();
            File.Move("Parsers.jar", "parsers-java.jar");
            EmitterForRust emitterForRust = new EmitterForRust(reporter, units, Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)), "runtime-rust"));

            emitterForRust.Emit();
            File.Move("Parsers.crate", "parsers-rust.crate");
            File.Move("Parsers" + emitterForRust.SuffixSystemAssembly, "parsers-rust" + emitterForRust.SuffixSystemAssembly);
        }