Esempio n. 1
0
        public void CanRoundtripTestcase()
        {
            string testcase = GetTestcase();
            var    ast      = WebIDLParser.Parse(new StringReader(testcase));
            string actual   = WebIDLFormatter.Format(ast);

            //File.WriteAllText("Result.webidl", actual);

            var expectedLines = testcase.Replace("\r\n", "\n").Split('\n');
            var actualLines   = actual.Replace("\r\n", "\n").Split('\n').Select(Normalize).Where(s => s != "").ToArray();
            int actualIndex   = 0;

            for (int expectedIndex = 0; expectedIndex < expectedLines.Length; expectedIndex++)
            {
                string expectedLine = Normalize(expectedLines[expectedIndex].Trim());
                if (expectedLine == "")
                {
                    continue;
                }
                if (actualIndex == actualLines.Length)
                {
                    Assert.Fail("Testcase line #{0}:\nWas \"{1}\".\nNo more expected lines.", expectedIndex + 1, expectedLines[expectedIndex]);
                }
                if (expectedLine != actualLines[actualIndex])
                {
                    Assert.Fail("Testcase line #{0}:\nWas \"{1}\".\nexpected \"{2}\".", expectedIndex + 1, actualLines[actualIndex], expectedLines[expectedIndex]);
                }
                actualIndex++;
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var input = File.ReadAllText(WebGL1SpecFile);

            input += File.ReadAllText(WebGL2SpecFile);
            var inputStream       = CharStreams.fromstring(input);
            var lexer             = new WebIDLLexer(inputStream);
            var tokenStream       = new CommonTokenStream(lexer);
            var parser            = new WebIDLParser(tokenStream);
            var contextSyntaxTree = parser.webIDL();

            using (var outputStream = File.CreateText(OutputFile))
            {
                outputStream.WriteLine("using WebAssembly.Core;");
                outputStream.WriteLine();
                outputStream.WriteLine("namespace WebGLDotNET");
                outputStream.WriteLine("{");
                outputStream.WriteLine("#pragma warning disable MEN002");

                var listener = new WebIDLListener(outputStream);
                ParseTreeWalker.Default.Walk(listener, contextSyntaxTree);

                outputStream.WriteLine("#pragma warning restore MEN002");
                outputStream.WriteLine("}");
            }
        }
Esempio n. 3
0
        public void CanResolveTestcase()
        {
            string testcase = GetTestcase();
            var    ast      = WebIDLParser.Parse(new StringReader(testcase));
            var    resolved = WebIDLResolver.Resolve(new[] { ast });

            Assert.AreEqual(resolved.Item2.Count, 0, "Errors:" + Environment.NewLine + string.Join(Environment.NewLine, resolved.Item2));
        }
        private void AssertCorrect(string webidl, string expected)
        {
            var    ast      = WebIDLParser.Parse(new StringReader(webidl));
            var    resolved = WebIDLResolver.Resolve(new[] { ast });
            string actual   = (resolved.Item2.Count > 0 ? string.Join("\n", resolved.Item2.Select(s => "error: " + s)) + "\n\n": "") + Format(resolved.Item1);

            Assert.That(actual.Trim().Replace("\r\n", "\n"), Is.EqualTo(expected.Trim().Replace("\r\n", "\n")), "Expected:\n" + expected + "\n\nActual:\n" + actual);
        }
Esempio n. 5
0
        public Document(string sourcetext)
        {
            var stringstream = new ANTLRStringStream(sourcetext);

            var lexer = new WebIDLLexer(stringstream);

            var tokens = new CommonTokenStream(lexer);

            var grammar = new WebIDLParser(tokens);



            this.members = new Package(this);
            this.members.append((CommonTree)grammar.documentDef().Tree);
        }