Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_CHAR_PREDICATES_H_ |
| 6 | #define V8_CHAR_PREDICATES_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 8 | #include "src/unicode.h" |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10 | namespace v8 { |
| 11 | namespace internal { |
| 12 | |
| 13 | // Unicode character predicates as defined by ECMA-262, 3rd, |
| 14 | // used for lexical analysis. |
| 15 | |
| 16 | inline bool IsCarriageReturn(uc32 c); |
| 17 | inline bool IsLineFeed(uc32 c); |
| 18 | inline bool IsDecimalDigit(uc32 c); |
| 19 | inline bool IsHexDigit(uc32 c); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 20 | inline bool IsOctalDigit(uc32 c); |
| 21 | inline bool IsBinaryDigit(uc32 c); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 22 | inline bool IsRegExpWord(uc32 c); |
| 23 | inline bool IsRegExpNewline(uc32 c); |
| 24 | |
| 25 | struct IdentifierStart { |
| 26 | static inline bool Is(uc32 c) { |
| 27 | switch (c) { |
| 28 | case '$': case '_': case '\\': return true; |
| 29 | default: return unibrow::Letter::Is(c); |
| 30 | } |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | |
| 35 | struct IdentifierPart { |
| 36 | static inline bool Is(uc32 c) { |
| 37 | return IdentifierStart::Is(c) |
| 38 | || unibrow::Number::Is(c) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 39 | || c == 0x200C // U+200C is Zero-Width Non-Joiner. |
| 40 | || c == 0x200D // U+200D is Zero-Width Joiner. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 41 | || unibrow::CombiningMark::Is(c) |
| 42 | || unibrow::ConnectorPunctuation::Is(c); |
| 43 | } |
| 44 | }; |
| 45 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 46 | |
| 47 | // WhiteSpace according to ECMA-262 5.1, 7.2. |
| 48 | struct WhiteSpace { |
| 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 { |
| 62 | static inline bool Is(uc32 c) { |
| 63 | return WhiteSpace::Is(c) || unibrow::LineTerminator::Is(c); |
| 64 | } |
| 65 | }; |
| 66 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 67 | } } // namespace v8::internal |
| 68 | |
| 69 | #endif // V8_CHAR_PREDICATES_H_ |