OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_CHAR_PREDICATES_H_ | 5 #ifndef V8_CHAR_PREDICATES_H_ |
6 #define V8_CHAR_PREDICATES_H_ | 6 #define V8_CHAR_PREDICATES_H_ |
7 | 7 |
8 #include "src/unicode.h" | 8 #include "src/unicode.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 // Unicode character predicates as defined by ECMA-262, 3rd, | 13 // Unicode character predicates as defined by ECMA-262, 3rd, |
14 // used for lexical analysis. | 14 // used for lexical analysis. |
15 | 15 |
16 inline bool IsCarriageReturn(uc32 c); | 16 inline bool IsCarriageReturn(uc32 c); |
17 inline bool IsLineFeed(uc32 c); | 17 inline bool IsLineFeed(uc32 c); |
18 inline bool IsDecimalDigit(uc32 c); | 18 inline bool IsDecimalDigit(uc32 c); |
19 inline bool IsHexDigit(uc32 c); | 19 inline bool IsHexDigit(uc32 c); |
20 inline bool IsOctalDigit(uc32 c); | 20 inline bool IsOctalDigit(uc32 c); |
21 inline bool IsBinaryDigit(uc32 c); | 21 inline bool IsBinaryDigit(uc32 c); |
22 inline bool IsRegExpWord(uc32 c); | 22 inline bool IsRegExpWord(uc32 c); |
23 inline bool IsRegExpNewline(uc32 c); | 23 inline bool IsRegExpNewline(uc32 c); |
24 | 24 |
| 25 // ES6 draft section 11.6 |
| 26 // This includes '_', '$' and '\', and ID_Start according to |
| 27 // http://www.unicode.org/reports/tr31/, which consists of categories |
| 28 // 'Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', but excluding properties |
| 29 // 'Pattern_Syntax' or 'Pattern_White_Space'. |
25 struct IdentifierStart { | 30 struct IdentifierStart { |
| 31 static inline bool Is(uc32 c) { return unibrow::ID_Start::Is(c); } |
| 32 }; |
| 33 |
| 34 |
| 35 // ES6 draft section 11.6 |
| 36 // This includes \u200c and \u200d, and ID_Continue according to |
| 37 // http://www.unicode.org/reports/tr31/, which consists of ID_Start, |
| 38 // the categories 'Mn', 'Mc', 'Nd', 'Pc', but excluding properties |
| 39 // 'Pattern_Syntax' or 'Pattern_White_Space'. |
| 40 struct IdentifierPart { |
26 static inline bool Is(uc32 c) { | 41 static inline bool Is(uc32 c) { |
27 switch (c) { | 42 return unibrow::ID_Start::Is(c) || unibrow::ID_Continue::Is(c); |
28 case '$': case '_': case '\\': return true; | |
29 default: return unibrow::Letter::Is(c); | |
30 } | |
31 } | 43 } |
32 }; | 44 }; |
33 | 45 |
34 | 46 |
35 struct IdentifierPart { | 47 // ES6 draft section 11.2 |
36 static inline bool Is(uc32 c) { | 48 // This includes all code points of Unicode category 'Zs'. |
37 return IdentifierStart::Is(c) | 49 // \u180e stops being one as of Unicode 6.3.0, but ES6 adheres to Unicode 5.1, |
38 || unibrow::Number::Is(c) | 50 // so it is also included. |
39 || c == 0x200C // U+200C is Zero-Width Non-Joiner. | 51 // Further included are \u0009, \u000b, \u0020, \u00a0, \u000c, and \ufeff. |
40 || c == 0x200D // U+200D is Zero-Width Joiner. | 52 struct WhiteSpace { |
41 || unibrow::CombiningMark::Is(c) | 53 static inline bool Is(uc32 c) { return unibrow::WhiteSpace::Is(c); } |
42 || unibrow::ConnectorPunctuation::Is(c); | |
43 } | |
44 }; | 54 }; |
45 | 55 |
46 | 56 |
47 // WhiteSpace according to ECMA-262 5.1, 7.2. | 57 // WhiteSpace and LineTerminator according to ES6 draft section 11.2 and 11.3 |
48 struct WhiteSpace { | 58 // This consists of \000a, \000d, \u2028, and \u2029. |
49 static inline bool Is(uc32 c) { | |
50 return c == 0x0009 || // <TAB> | |
51 c == 0x000B || // <VT> | |
52 c == 0x000C || // <FF> | |
53 c == 0xFEFF || // <BOM> | |
54 // \u0020 and \u00A0 are included in unibrow::WhiteSpace. | |
55 unibrow::WhiteSpace::Is(c); | |
56 } | |
57 }; | |
58 | |
59 | |
60 // WhiteSpace and LineTerminator according to ECMA-262 5.1, 7.2 and 7.3. | |
61 struct WhiteSpaceOrLineTerminator { | 59 struct WhiteSpaceOrLineTerminator { |
62 static inline bool Is(uc32 c) { | 60 static inline bool Is(uc32 c) { |
63 return WhiteSpace::Is(c) || unibrow::LineTerminator::Is(c); | 61 return WhiteSpace::Is(c) || unibrow::LineTerminator::Is(c); |
64 } | 62 } |
65 }; | 63 }; |
66 | 64 |
67 } } // namespace v8::internal | 65 } } // namespace v8::internal |
68 | 66 |
69 #endif // V8_CHAR_PREDICATES_H_ | 67 #endif // V8_CHAR_PREDICATES_H_ |
OLD | NEW |