2011-05-03 08:23:58 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#ifndef V8_CHAR_PREDICATES_H_
|
|
|
|
#define V8_CHAR_PREDICATES_H_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/unicode.h"
|
2011-05-03 08:23:58 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Unicode character predicates as defined by ECMA-262, 3rd,
|
|
|
|
// used for lexical analysis.
|
|
|
|
|
2015-08-12 07:32:36 +00:00
|
|
|
inline int AsciiAlphaToLower(uc32 c);
|
2008-07-03 15:10:15 +00:00
|
|
|
inline bool IsCarriageReturn(uc32 c);
|
|
|
|
inline bool IsLineFeed(uc32 c);
|
2015-03-03 15:27:46 +00:00
|
|
|
inline bool IsAsciiIdentifier(uc32 c);
|
|
|
|
inline bool IsAlphaNumeric(uc32 c);
|
2008-07-03 15:10:15 +00:00
|
|
|
inline bool IsDecimalDigit(uc32 c);
|
|
|
|
inline bool IsHexDigit(uc32 c);
|
2013-07-19 09:57:35 +00:00
|
|
|
inline bool IsOctalDigit(uc32 c);
|
|
|
|
inline bool IsBinaryDigit(uc32 c);
|
2008-12-01 15:42:35 +00:00
|
|
|
inline bool IsRegExpWord(uc32 c);
|
|
|
|
inline bool IsRegExpNewline(uc32 c);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-10-10 07:13:46 +00:00
|
|
|
|
|
|
|
struct SupplementaryPlanes {
|
|
|
|
static bool IsIDStart(uc32 c);
|
|
|
|
static bool IsIDPart(uc32 c);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-08 14:55:03 +00:00
|
|
|
// ES6 draft section 11.6
|
|
|
|
// This includes '_', '$' and '\', and ID_Start according to
|
|
|
|
// http://www.unicode.org/reports/tr31/, which consists of categories
|
|
|
|
// 'Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', but excluding properties
|
|
|
|
// 'Pattern_Syntax' or 'Pattern_White_Space'.
|
2014-10-10 07:13:46 +00:00
|
|
|
// For code points in the SMPs, we can resort to ICU (if available).
|
2008-07-03 15:10:15 +00:00
|
|
|
struct IdentifierStart {
|
2014-10-10 07:13:46 +00:00
|
|
|
static inline bool Is(uc32 c) {
|
|
|
|
if (c > 0xFFFF) return SupplementaryPlanes::IsIDStart(c);
|
|
|
|
return unibrow::ID_Start::Is(c);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-08 14:55:03 +00:00
|
|
|
// ES6 draft section 11.6
|
|
|
|
// This includes \u200c and \u200d, and ID_Continue according to
|
|
|
|
// http://www.unicode.org/reports/tr31/, which consists of ID_Start,
|
|
|
|
// the categories 'Mn', 'Mc', 'Nd', 'Pc', but excluding properties
|
|
|
|
// 'Pattern_Syntax' or 'Pattern_White_Space'.
|
2014-10-10 07:13:46 +00:00
|
|
|
// For code points in the SMPs, we can resort to ICU (if available).
|
2008-07-03 15:10:15 +00:00
|
|
|
struct IdentifierPart {
|
|
|
|
static inline bool Is(uc32 c) {
|
2014-10-10 07:13:46 +00:00
|
|
|
if (c > 0xFFFF) return SupplementaryPlanes::IsIDPart(c);
|
2014-10-08 14:55:03 +00:00
|
|
|
return unibrow::ID_Start::Is(c) || unibrow::ID_Continue::Is(c);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-10 12:43:10 +00:00
|
|
|
|
2014-10-08 14:55:03 +00:00
|
|
|
// ES6 draft section 11.2
|
|
|
|
// This includes all code points of Unicode category 'Zs'.
|
|
|
|
// \u180e stops being one as of Unicode 6.3.0, but ES6 adheres to Unicode 5.1,
|
|
|
|
// so it is also included.
|
|
|
|
// Further included are \u0009, \u000b, \u0020, \u00a0, \u000c, and \ufeff.
|
2014-10-10 07:13:46 +00:00
|
|
|
// There are no category 'Zs' code points in the SMPs.
|
2014-02-10 12:43:10 +00:00
|
|
|
struct WhiteSpace {
|
2014-10-08 14:55:03 +00:00
|
|
|
static inline bool Is(uc32 c) { return unibrow::WhiteSpace::Is(c); }
|
2014-02-10 12:43:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-08 14:55:03 +00:00
|
|
|
// WhiteSpace and LineTerminator according to ES6 draft section 11.2 and 11.3
|
|
|
|
// This consists of \000a, \000d, \u2028, and \u2029.
|
2014-02-10 12:43:10 +00:00
|
|
|
struct WhiteSpaceOrLineTerminator {
|
|
|
|
static inline bool Is(uc32 c) {
|
|
|
|
return WhiteSpace::Is(c) || unibrow::LineTerminator::Is(c);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#endif // V8_CHAR_PREDICATES_H_
|