dom/xslt/xpath/txExprParser.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:1a2ba371ce9f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /**
7 * ExprParser
8 * This class is used to parse XSL Expressions
9 * @see ExprLexer
10 **/
11
12 #ifndef MITREXSL_EXPRPARSER_H
13 #define MITREXSL_EXPRPARSER_H
14
15 #include "txCore.h"
16 #include "nsAutoPtr.h"
17 #include "nsString.h"
18
19 class AttributeValueTemplate;
20 class Expr;
21 class txExprLexer;
22 class FunctionCall;
23 class LocationStep;
24 class nsIAtom;
25 class PredicateList;
26 class Token;
27 class txIParseContext;
28 class txNodeTest;
29 class txNodeTypeTest;
30
31 class txExprParser
32 {
33 public:
34
35 static nsresult createExpr(const nsSubstring& aExpression,
36 txIParseContext* aContext, Expr** aExpr)
37 {
38 return createExprInternal(aExpression, 0, aContext, aExpr);
39 }
40
41 /**
42 * Creates an Attribute Value Template using the given value
43 */
44 static nsresult createAVT(const nsSubstring& aAttrValue,
45 txIParseContext* aContext,
46 Expr** aResult);
47
48
49 protected:
50 static nsresult createExprInternal(const nsSubstring& aExpression,
51 uint32_t aSubStringPos,
52 txIParseContext* aContext,
53 Expr** aExpr);
54 /**
55 * Using nsAutoPtr& to optimize passing the ownership to the
56 * created binary expression objects.
57 */
58 static nsresult createBinaryExpr(nsAutoPtr<Expr>& left,
59 nsAutoPtr<Expr>& right, Token* op,
60 Expr** aResult);
61 static nsresult createExpr(txExprLexer& lexer, txIParseContext* aContext,
62 Expr** aResult);
63 static nsresult createFilterOrStep(txExprLexer& lexer,
64 txIParseContext* aContext,
65 Expr** aResult);
66 static nsresult createFunctionCall(txExprLexer& lexer,
67 txIParseContext* aContext,
68 Expr** aResult);
69 static nsresult createLocationStep(txExprLexer& lexer,
70 txIParseContext* aContext,
71 Expr** aResult);
72 static nsresult createNodeTypeTest(txExprLexer& lexer,
73 txNodeTest** aResult);
74 static nsresult createPathExpr(txExprLexer& lexer,
75 txIParseContext* aContext,
76 Expr** aResult);
77 static nsresult createUnionExpr(txExprLexer& lexer,
78 txIParseContext* aContext,
79 Expr** aResult);
80
81 static bool isLocationStepToken(Token* aToken);
82
83 static short precedence(Token* aToken);
84
85 /**
86 * Resolve a QName, given the mContext parse context.
87 * Returns prefix and localName as well as namespace ID
88 */
89 static nsresult resolveQName(const nsAString& aQName, nsIAtom** aPrefix,
90 txIParseContext* aContext,
91 nsIAtom** aLocalName, int32_t& aNamespace,
92 bool aIsNameTest = false);
93
94 /**
95 * Using the given lexer, parses the tokens if they represent a
96 * predicate list
97 * If an error occurs a non-zero String pointer will be returned
98 * containing the error message.
99 * @param predicateList, the PredicateList to add predicate expressions to
100 * @param lexer the ExprLexer to use for parsing tokens
101 * @return 0 if successful, or a String pointer to the error message
102 */
103 static nsresult parsePredicates(PredicateList* aPredicateList,
104 txExprLexer& lexer,
105 txIParseContext* aContext);
106 static nsresult parseParameters(FunctionCall* aFnCall, txExprLexer& lexer,
107 txIParseContext* aContext);
108
109 };
110
111 #endif

mercurial