michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * ExprParser michael@0: * This class is used to parse XSL Expressions michael@0: * @see ExprLexer michael@0: **/ michael@0: michael@0: #ifndef MITREXSL_EXPRPARSER_H michael@0: #define MITREXSL_EXPRPARSER_H michael@0: michael@0: #include "txCore.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsString.h" michael@0: michael@0: class AttributeValueTemplate; michael@0: class Expr; michael@0: class txExprLexer; michael@0: class FunctionCall; michael@0: class LocationStep; michael@0: class nsIAtom; michael@0: class PredicateList; michael@0: class Token; michael@0: class txIParseContext; michael@0: class txNodeTest; michael@0: class txNodeTypeTest; michael@0: michael@0: class txExprParser michael@0: { michael@0: public: michael@0: michael@0: static nsresult createExpr(const nsSubstring& aExpression, michael@0: txIParseContext* aContext, Expr** aExpr) michael@0: { michael@0: return createExprInternal(aExpression, 0, aContext, aExpr); michael@0: } michael@0: michael@0: /** michael@0: * Creates an Attribute Value Template using the given value michael@0: */ michael@0: static nsresult createAVT(const nsSubstring& aAttrValue, michael@0: txIParseContext* aContext, michael@0: Expr** aResult); michael@0: michael@0: michael@0: protected: michael@0: static nsresult createExprInternal(const nsSubstring& aExpression, michael@0: uint32_t aSubStringPos, michael@0: txIParseContext* aContext, michael@0: Expr** aExpr); michael@0: /** michael@0: * Using nsAutoPtr& to optimize passing the ownership to the michael@0: * created binary expression objects. michael@0: */ michael@0: static nsresult createBinaryExpr(nsAutoPtr& left, michael@0: nsAutoPtr& right, Token* op, michael@0: Expr** aResult); michael@0: static nsresult createExpr(txExprLexer& lexer, txIParseContext* aContext, michael@0: Expr** aResult); michael@0: static nsresult createFilterOrStep(txExprLexer& lexer, michael@0: txIParseContext* aContext, michael@0: Expr** aResult); michael@0: static nsresult createFunctionCall(txExprLexer& lexer, michael@0: txIParseContext* aContext, michael@0: Expr** aResult); michael@0: static nsresult createLocationStep(txExprLexer& lexer, michael@0: txIParseContext* aContext, michael@0: Expr** aResult); michael@0: static nsresult createNodeTypeTest(txExprLexer& lexer, michael@0: txNodeTest** aResult); michael@0: static nsresult createPathExpr(txExprLexer& lexer, michael@0: txIParseContext* aContext, michael@0: Expr** aResult); michael@0: static nsresult createUnionExpr(txExprLexer& lexer, michael@0: txIParseContext* aContext, michael@0: Expr** aResult); michael@0: michael@0: static bool isLocationStepToken(Token* aToken); michael@0: michael@0: static short precedence(Token* aToken); michael@0: michael@0: /** michael@0: * Resolve a QName, given the mContext parse context. michael@0: * Returns prefix and localName as well as namespace ID michael@0: */ michael@0: static nsresult resolveQName(const nsAString& aQName, nsIAtom** aPrefix, michael@0: txIParseContext* aContext, michael@0: nsIAtom** aLocalName, int32_t& aNamespace, michael@0: bool aIsNameTest = false); michael@0: michael@0: /** michael@0: * Using the given lexer, parses the tokens if they represent a michael@0: * predicate list michael@0: * If an error occurs a non-zero String pointer will be returned michael@0: * containing the error message. michael@0: * @param predicateList, the PredicateList to add predicate expressions to michael@0: * @param lexer the ExprLexer to use for parsing tokens michael@0: * @return 0 if successful, or a String pointer to the error message michael@0: */ michael@0: static nsresult parsePredicates(PredicateList* aPredicateList, michael@0: txExprLexer& lexer, michael@0: txIParseContext* aContext); michael@0: static nsresult parseParameters(FunctionCall* aFnCall, txExprLexer& lexer, michael@0: txIParseContext* aContext); michael@0: michael@0: }; michael@0: michael@0: #endif