예제 #1
0
        /// <summary>
        /// Generate a parser from an IronMeta grammar.
        /// </summary>
        /// <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.Node> Process(IEnumerable <char> input, TextWriter output, string name_space)
        {
            var parser = new BootstrapParser();
            var match  = parser.GetMatch(input, parser.IronMetaFile);

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

            return(match);
        }
예제 #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>"));
        }