Generates C# code for an IronMeta parser from an abstract syntax tree.
Inheritance: IGenerator
Esempio n. 1
0
        /// <summary>
        /// Generate a parser from an IronMeta grammar.
        /// </summary>
        /// <param name="src_fname">The name of the source file (to use for error messages).</param>
        /// <param name="input">Input stream.</param>
        /// <param name="output">Output writer.</param>
        /// <param name="name_space">Namespace to use in the generated parser.</param>
        public static MatchResult<char, AST.AstNode> Process(string src_fname, IEnumerable<char> input, TextWriter output, string name_space)
        {
            var parser = new Parser();
            var match = parser.GetMatch(input, parser.IronMetaFile);

            if (match.Success)
            {
                var csgen = new CSharpGen(match.Result, name_space);
                csgen.Generate(src_fname, output);
            }

            return match;
        }
Esempio n. 2
0
        public void TestNoBaseClass()
        {
            var grammar = @"ironmeta TestGrammar<char, int> { One = ""1""; }";

            var parser = new Parser();
            var result = parser.GetMatch(grammar, parser.IronMetaFile);
            Assert.IsTrue(result.Success);

            var gen = new CSharpGen(result.Result, "TestNoBaseClass");
            string src = null;
            using (var ms = new MemoryStream())
            using (var sw = new StreamWriter(ms))
            {
                gen.Generate("testNoBaseClass.ironmeta", sw);
                src = Encoding.UTF8.GetString(ms.ToArray());
            }
            Assert.IsTrue(src.Contains("class TestGrammar : IronMeta.Matcher.Matcher<char, int>"));
        }