Ejemplo n.º 1
0
        protected static ParseTree <Program> ParseTextAndCheck(string sourceText, string parseFileName = null)
        {
            ParseTree <Program> parseTree = parseFileName != null
                ? parser.Parse(sourceText, parseFileName)
                : parser.Parse(sourceText);

            CheckParseTree(parseTree);

            return(parseTree);
        }
Ejemplo n.º 2
0
        protected static ParseTree <TRoot> ParseTextAndCheckTS <TRoot>(INonTerminal <TRoot> root, string sourceText, string parseFileName = null)
        {
            ParseTree <TRoot> parseTree = parseFileName != null
                ? parser.Parse(sourceText, parseFileName, root)
                : parser.Parse(sourceText, root);

            CheckParseTree(parseTree);

            return(parseTree);
        }
Ejemplo n.º 3
0
        private static void CheckParseTree(ParseTree parseTree)
        {
            Assert.IsNotNull(parseTree, "Parser error: parse tree is null");

            string errorMessages = string.Join("\n",
                                               parseTree.ParserMessages.Select(parserMessage => string.Format("{0} {1}: {2}", parseTree.FileName, parserMessage.Location.ToString(), parserMessage.Message))
                                               );

            Assert.IsFalse(parseTree.HasErrors(), "Parser errors:\n{0}", errorMessages);
            Assert.AreEqual(ParseTreeStatus.Parsed, parseTree.Status, "Parser errors:\n{0}", errorMessages);
        }