1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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/. */
6 #ifndef MITREXSL_EXPRLEXER_H
7 #define MITREXSL_EXPRLEXER_H
13 * A Token class for the ExprLexer.
15 * This class was ported from XSL:P, an open source Java based
16 * XSLT processor, written by yours truly.
35 * start of tokens for 3.7, bullet 1
36 * ExprLexer::nextIsOperatorToken bails if the tokens aren't
45 // These tokens include their following left parenthesis
46 FUNCTION_NAME_AND_PAREN
, // 15
66 //-- additive operators
78 * end of tokens for 3.7, bullet 1 -/
87 using iterator
= nsAString::const_char_iterator
;
89 Token(iterator aStart
, iterator aEnd
, Type aType
)
90 : mStart(aStart
), mEnd(aEnd
), mType(aType
), mNext(nullptr) {}
91 Token(iterator aChar
, Type aType
)
92 : mStart(aChar
), mEnd(aChar
+ 1), mType(aType
), mNext(nullptr) {}
94 const nsDependentSubstring
Value() { return Substring(mStart
, mEnd
); }
96 iterator mStart
, mEnd
;
102 * A class for splitting an "Expr" String into tokens and
103 * performing basic Lexical Analysis.
105 * This class was ported from XSL:P, an open source Java based XSL processor
114 * Parse the given string.
115 * returns an error result if lexing failed.
116 * The given string must outlive the use of the lexer, as the
117 * generated Tokens point to Substrings of it.
118 * mPosition points to the offending location in case of an error.
120 nsresult
parse(const nsAString
& aPattern
);
122 using iterator
= nsAString::const_char_iterator
;
126 * Functions for iterating over the TokenList
131 NS_ASSERTION(mCurrentItem
, "peek called uninitialized lexer");
135 NS_ASSERTION(mCurrentItem
, "peekAhead called on uninitialized lexer");
136 // Don't peek past the end node
137 return (mCurrentItem
&& mCurrentItem
->mNext
) ? mCurrentItem
->mNext
140 bool hasMoreTokens() {
141 NS_ASSERTION(mCurrentItem
, "HasMoreTokens called on uninitialized lexer");
142 return (mCurrentItem
&& mCurrentItem
->mType
!= Token::END
);
148 //-- LF, changed to enum
149 enum _TrivialTokens
{
170 //-- whitespace tokens
184 void addToken(Token
* aToken
);
187 * Returns true if the following Token should be an operator.
188 * This is a helper for the first bullet of [XPath 3.7]
191 bool nextIsOperatorToken(Token
* aToken
);
194 * Returns true if the given character represents a numeric letter (digit)
195 * Implemented in ExprLexerChars.cpp
197 static bool isXPathDigit(char16_t ch
) { return (ch
>= '0' && ch
<= '9'); }