#ifndef YarrParser_h
#define YarrParser_h
-#include <runtime/UString.h>
#include "Yarr.h"
#include <wtf/ASCIICType.h>
+#include <wtf/text/WTFString.h>
#include <wtf/unicode/Unicode.h>
namespace JSC { namespace Yarr {
};
// The Parser class should not be used directly - only via the Yarr::parse() method.
-template<class Delegate>
+template<class Delegate, typename CharType>
class Parser {
private:
template<class FriendDelegate>
- friend const char* parse(FriendDelegate& delegate, const UString& pattern, unsigned backReferenceLimit);
+ friend const char* parse(FriendDelegate&, const String& pattern, unsigned backReferenceLimit);
enum ErrorCode {
NoError,
PatternTooLarge,
QuantifierOutOfOrder,
QuantifierWithoutAtom,
+ QuantifierTooLarge,
MissingParentheses,
ParenthesesUnmatched,
ParenthesesTypeInvalid,
// parseEscape() should never call these delegate methods when
// invoked with inCharacterClass set.
- void assertionWordBoundary(bool) { ASSERT_NOT_REACHED(); }
- void atomBackReference(unsigned) { ASSERT_NOT_REACHED(); }
+ NO_RETURN_DUE_TO_ASSERT void assertionWordBoundary(bool) { RELEASE_ASSERT_NOT_REACHED(); }
+ NO_RETURN_DUE_TO_ASSERT void atomBackReference(unsigned) { RELEASE_ASSERT_NOT_REACHED(); }
private:
Delegate& m_delegate;
UChar m_character;
};
- Parser(Delegate& delegate, const UString& pattern, unsigned backReferenceLimit)
+ Parser(Delegate& delegate, const String& pattern, unsigned backReferenceLimit)
: m_delegate(delegate)
, m_backReferenceLimit(backReferenceLimit)
, m_err(NoError)
- , m_data(pattern.characters())
+ , m_data(pattern.getCharacters<CharType>())
, m_size(pattern.length())
, m_index(0)
, m_parenthesesNestingDepth(0)
{
}
-
+
/*
* parseEscape():
*
ASSERT(!m_err);
ASSERT(min <= max);
+ if (min == UINT_MAX) {
+ m_err = QuantifierTooLarge;
+ return;
+ }
+
if (lastTokenWasAnAtom)
m_delegate.quantifyAtom(min, max, !tryConsume('?'));
else
REGEXP_ERROR_PREFIX "regular expression too large",
REGEXP_ERROR_PREFIX "numbers out of order in {} quantifier",
REGEXP_ERROR_PREFIX "nothing to repeat",
+ REGEXP_ERROR_PREFIX "number too large in {} quantifier",
REGEXP_ERROR_PREFIX "missing )",
REGEXP_ERROR_PREFIX "unmatched parentheses",
REGEXP_ERROR_PREFIX "unrecognized character after (?",
return errorMessages[m_err];
}
-
// Misc helper functions:
typedef unsigned ParseState;
Delegate& m_delegate;
unsigned m_backReferenceLimit;
ErrorCode m_err;
- const UChar* m_data;
+ const CharType* m_data;
unsigned m_size;
unsigned m_index;
unsigned m_parenthesesNestingDepth;
*/
template<class Delegate>
-const char* parse(Delegate& delegate, const UString& pattern, unsigned backReferenceLimit = quantifyInfinite)
+const char* parse(Delegate& delegate, const String& pattern, unsigned backReferenceLimit = quantifyInfinite)
{
- return Parser<Delegate>(delegate, pattern, backReferenceLimit).parse();
+ if (pattern.is8Bit())
+ return Parser<Delegate, LChar>(delegate, pattern, backReferenceLimit).parse();
+ return Parser<Delegate, UChar>(delegate, pattern, backReferenceLimit).parse();
}
} } // namespace JSC::Yarr