Beispiel #1
0
        /// <summary>
        /// Parse a formula, return the the tree
        /// </summary>
        /// <param name="input">The formula to be parsed.</param>
        /// <exception cref="ArgumentException">
        /// If formula could not be parsed
        /// </exception>
        /// <returns>Parse tree</returns>
        public static ParseTree ParseToTree(string input)
        {
            var tree = P.Parse(input);

            if (tree.HasErrors())
            {
                throw new ArgumentException("Failed parsing input <<" + input + ">>");
            }

            var intersects = tree.Root.AllNodes().Where(node => node.Is(GrammarNames.TokenIntersect));

            foreach (ParseTreeNode intersect in intersects)
            {
                var newLocation = new SourceLocation(intersect.Span.Location.Position - 1, intersect.Span.Location.Line, intersect.Span.Location.Column - 1);
                intersect.Span = new SourceSpan(newLocation, 1);
            }

            var quotedSheetNodes = tree.Root.AllNodes().Where(node => node.Is(GrammarNames.TokenSheetQuoted));

            foreach (ParseTreeNode quotedSheetNode in quotedSheetNodes)
            {
                PrefixInfo.FixQuotedSheetNodeForWhitespace(quotedSheetNode, input);
            }

            return(tree);
        }