Line data Source code
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 Expr;
20 : class txExprLexer;
21 : class FunctionCall;
22 : class LocationStep;
23 : class nsIAtom;
24 : class PredicateList;
25 : class Token;
26 : class txIParseContext;
27 : class txNodeTest;
28 :
29 : class txExprParser
30 : {
31 : public:
32 :
33 0 : static nsresult createExpr(const nsAString& aExpression,
34 : txIParseContext* aContext, Expr** aExpr)
35 : {
36 0 : return createExprInternal(aExpression, 0, aContext, aExpr);
37 : }
38 :
39 : /**
40 : * Creates an Attribute Value Template using the given value
41 : */
42 : static nsresult createAVT(const nsAString& aAttrValue,
43 : txIParseContext* aContext,
44 : Expr** aResult);
45 :
46 :
47 : protected:
48 : static nsresult createExprInternal(const nsAString& aExpression,
49 : uint32_t aSubStringPos,
50 : txIParseContext* aContext,
51 : Expr** aExpr);
52 : /**
53 : * Using nsAutoPtr& to optimize passing the ownership to the
54 : * created binary expression objects.
55 : */
56 : static nsresult createBinaryExpr(nsAutoPtr<Expr>& left,
57 : nsAutoPtr<Expr>& right, Token* op,
58 : Expr** aResult);
59 : static nsresult createExpr(txExprLexer& lexer, txIParseContext* aContext,
60 : Expr** aResult);
61 : static nsresult createFilterOrStep(txExprLexer& lexer,
62 : txIParseContext* aContext,
63 : Expr** aResult);
64 : static nsresult createFunctionCall(txExprLexer& lexer,
65 : txIParseContext* aContext,
66 : Expr** aResult);
67 : static nsresult createLocationStep(txExprLexer& lexer,
68 : txIParseContext* aContext,
69 : Expr** aResult);
70 : static nsresult createNodeTypeTest(txExprLexer& lexer,
71 : txNodeTest** aResult);
72 : static nsresult createPathExpr(txExprLexer& lexer,
73 : txIParseContext* aContext,
74 : Expr** aResult);
75 : static nsresult createUnionExpr(txExprLexer& lexer,
76 : txIParseContext* aContext,
77 : Expr** aResult);
78 :
79 : static bool isLocationStepToken(Token* aToken);
80 :
81 : static short precedence(Token* aToken);
82 :
83 : /**
84 : * Resolve a QName, given the mContext parse context.
85 : * Returns prefix and localName as well as namespace ID
86 : */
87 : static nsresult resolveQName(const nsAString& aQName, nsIAtom** aPrefix,
88 : txIParseContext* aContext,
89 : nsIAtom** aLocalName, int32_t& aNamespace,
90 : bool aIsNameTest = false);
91 :
92 : /**
93 : * Using the given lexer, parses the tokens if they represent a
94 : * predicate list
95 : * If an error occurs a non-zero String pointer will be returned
96 : * containing the error message.
97 : * @param predicateList, the PredicateList to add predicate expressions to
98 : * @param lexer the ExprLexer to use for parsing tokens
99 : * @return 0 if successful, or a String pointer to the error message
100 : */
101 : static nsresult parsePredicates(PredicateList* aPredicateList,
102 : txExprLexer& lexer,
103 : txIParseContext* aContext);
104 : static nsresult parseParameters(FunctionCall* aFnCall, txExprLexer& lexer,
105 : txIParseContext* aContext);
106 :
107 : };
108 :
109 : #endif
|