blob: b7c5d42320fc953c1744016f39a846e4eb1bb978 [file] [log] [blame]
Ben Murdoch257744e2011-11-30 15:57:28 +00001// Copyright 2011 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_CHAR_PREDICATES_H_
6#define V8_CHAR_PREDICATES_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/unicode.h"
Ben Murdoch257744e2011-11-30 15:57:28 +00009
Steve Blocka7e24c12009-10-30 11:49:00 +000010namespace v8 {
11namespace internal {
12
13// Unicode character predicates as defined by ECMA-262, 3rd,
14// used for lexical analysis.
15
16inline bool IsCarriageReturn(uc32 c);
17inline bool IsLineFeed(uc32 c);
18inline bool IsDecimalDigit(uc32 c);
19inline bool IsHexDigit(uc32 c);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020inline bool IsOctalDigit(uc32 c);
21inline bool IsBinaryDigit(uc32 c);
Steve Blocka7e24c12009-10-30 11:49:00 +000022inline bool IsRegExpWord(uc32 c);
23inline bool IsRegExpNewline(uc32 c);
24
25struct 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
35struct IdentifierPart {
36 static inline bool Is(uc32 c) {
37 return IdentifierStart::Is(c)
38 || unibrow::Number::Is(c)
Ben Murdoch3ef787d2012-04-12 10:51:47 +010039 || c == 0x200C // U+200C is Zero-Width Non-Joiner.
40 || c == 0x200D // U+200D is Zero-Width Joiner.
Steve Blocka7e24c12009-10-30 11:49:00 +000041 || unibrow::CombiningMark::Is(c)
42 || unibrow::ConnectorPunctuation::Is(c);
43 }
44};
45
Ben Murdochb8a8cc12014-11-26 15:28:44 +000046
47// WhiteSpace according to ECMA-262 5.1, 7.2.
48struct 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.
61struct WhiteSpaceOrLineTerminator {
62 static inline bool Is(uc32 c) {
63 return WhiteSpace::Is(c) || unibrow::LineTerminator::Is(c);
64 }
65};
66
Steve Blocka7e24c12009-10-30 11:49:00 +000067} } // namespace v8::internal
68
69#endif // V8_CHAR_PREDICATES_H_