1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xslt/xpath/txExprParser.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/** 1.10 + * ExprParser 1.11 + * This class is used to parse XSL Expressions 1.12 + * @see ExprLexer 1.13 +**/ 1.14 + 1.15 +#ifndef MITREXSL_EXPRPARSER_H 1.16 +#define MITREXSL_EXPRPARSER_H 1.17 + 1.18 +#include "txCore.h" 1.19 +#include "nsAutoPtr.h" 1.20 +#include "nsString.h" 1.21 + 1.22 +class AttributeValueTemplate; 1.23 +class Expr; 1.24 +class txExprLexer; 1.25 +class FunctionCall; 1.26 +class LocationStep; 1.27 +class nsIAtom; 1.28 +class PredicateList; 1.29 +class Token; 1.30 +class txIParseContext; 1.31 +class txNodeTest; 1.32 +class txNodeTypeTest; 1.33 + 1.34 +class txExprParser 1.35 +{ 1.36 +public: 1.37 + 1.38 + static nsresult createExpr(const nsSubstring& aExpression, 1.39 + txIParseContext* aContext, Expr** aExpr) 1.40 + { 1.41 + return createExprInternal(aExpression, 0, aContext, aExpr); 1.42 + } 1.43 + 1.44 + /** 1.45 + * Creates an Attribute Value Template using the given value 1.46 + */ 1.47 + static nsresult createAVT(const nsSubstring& aAttrValue, 1.48 + txIParseContext* aContext, 1.49 + Expr** aResult); 1.50 + 1.51 + 1.52 +protected: 1.53 + static nsresult createExprInternal(const nsSubstring& aExpression, 1.54 + uint32_t aSubStringPos, 1.55 + txIParseContext* aContext, 1.56 + Expr** aExpr); 1.57 + /** 1.58 + * Using nsAutoPtr& to optimize passing the ownership to the 1.59 + * created binary expression objects. 1.60 + */ 1.61 + static nsresult createBinaryExpr(nsAutoPtr<Expr>& left, 1.62 + nsAutoPtr<Expr>& right, Token* op, 1.63 + Expr** aResult); 1.64 + static nsresult createExpr(txExprLexer& lexer, txIParseContext* aContext, 1.65 + Expr** aResult); 1.66 + static nsresult createFilterOrStep(txExprLexer& lexer, 1.67 + txIParseContext* aContext, 1.68 + Expr** aResult); 1.69 + static nsresult createFunctionCall(txExprLexer& lexer, 1.70 + txIParseContext* aContext, 1.71 + Expr** aResult); 1.72 + static nsresult createLocationStep(txExprLexer& lexer, 1.73 + txIParseContext* aContext, 1.74 + Expr** aResult); 1.75 + static nsresult createNodeTypeTest(txExprLexer& lexer, 1.76 + txNodeTest** aResult); 1.77 + static nsresult createPathExpr(txExprLexer& lexer, 1.78 + txIParseContext* aContext, 1.79 + Expr** aResult); 1.80 + static nsresult createUnionExpr(txExprLexer& lexer, 1.81 + txIParseContext* aContext, 1.82 + Expr** aResult); 1.83 + 1.84 + static bool isLocationStepToken(Token* aToken); 1.85 + 1.86 + static short precedence(Token* aToken); 1.87 + 1.88 + /** 1.89 + * Resolve a QName, given the mContext parse context. 1.90 + * Returns prefix and localName as well as namespace ID 1.91 + */ 1.92 + static nsresult resolveQName(const nsAString& aQName, nsIAtom** aPrefix, 1.93 + txIParseContext* aContext, 1.94 + nsIAtom** aLocalName, int32_t& aNamespace, 1.95 + bool aIsNameTest = false); 1.96 + 1.97 + /** 1.98 + * Using the given lexer, parses the tokens if they represent a 1.99 + * predicate list 1.100 + * If an error occurs a non-zero String pointer will be returned 1.101 + * containing the error message. 1.102 + * @param predicateList, the PredicateList to add predicate expressions to 1.103 + * @param lexer the ExprLexer to use for parsing tokens 1.104 + * @return 0 if successful, or a String pointer to the error message 1.105 + */ 1.106 + static nsresult parsePredicates(PredicateList* aPredicateList, 1.107 + txExprLexer& lexer, 1.108 + txIParseContext* aContext); 1.109 + static nsresult parseParameters(FunctionCall* aFnCall, txExprLexer& lexer, 1.110 + txIParseContext* aContext); 1.111 + 1.112 +}; 1.113 + 1.114 +#endif