001/*
002// Licensed to Julian Hyde under one or more contributor license
003// agreements. See the NOTICE file distributed with this work for
004// additional information regarding copyright ownership.
005//
006// Julian Hyde licenses this file to you under the Apache License,
007// Version 2.0 (the "License"); you may not use this file except in
008// compliance with the License. You may obtain a copy of the License at:
009//
010// http://www.apache.org/licenses/LICENSE-2.0
011//
012// Unless required by applicable law or agreed to in writing, software
013// distributed under the License is distributed on an "AS IS" BASIS,
014// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015// See the License for the specific language governing permissions and
016// limitations under the License.
017*/
018package org.olap4j.mdx.parser;
019
020import org.olap4j.mdx.ParseTreeNode;
021import org.olap4j.mdx.SelectNode;
022
023/**
024 * Parser for the MDX query language.
025 *
026 * <p>A parser is reusable but not reentrant: you can call {@link #parseSelect}
027 * and {@link #parseExpression} several times, but not at the same time
028 * from different threads.
029 *
030 * @see MdxParserFactory
031 *
032 * @author jhyde
033 * @since Aug 22, 2006
034 */
035public interface MdxParser {
036    /**
037     * Parses an MDX Select statement and returns the {@link SelectNode} at the
038     * root of the parse tree.
039     *
040     * <p>In order to be parsed successfully, the expression must be
041     * syntactically correct but does not need to be valid. (Syntactic
042     * correctness and validity are described further in the description of
043     * {@link #parseExpression(String)}.)
044     *
045     * @param mdx MDX query string
046     * @return Parse tree
047     */
048    SelectNode parseSelect(String mdx);
049
050    /**
051     * Parses an MDX expression and returns a parse tree.
052     *
053     * <p>An expression is a combination of operators and operands, which can
054     * occur in many places inside an MDX query, such as the definition of a
055     * calculated member or an axis.
056     *
057     * <p>In order to be parsed successfully, the expression must be
058     * syntactically correct but does not need to be valid.
059     * For example,
060     *
061     * <blockquote><code>(1 + (2 + 3)</code></blockquote>
062     *
063     * is syntactically incorrect,
064     * because there are more open parentheses "(" than close parentheses ")",
065     * and the parser will give an error. Conversely,
066     *
067     * <blockquote><code>(1 + [Measures].[Bad Measure])</code></blockquote>
068     *
069     * is syntactically correct, and the parser
070     * will successfully create a parse tree, even if
071     * <code>[Measures].[Bad Measure]</code> does not exist.
072     *
073     * @param mdx MDX expression
074     * @return Parse tree
075     */
076    ParseTreeNode parseExpression(String mdx);
077}
078
079// End MdxParser.java