forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacters.ts
More file actions
99 lines (87 loc) · 2.71 KB
/
characters.ts
File metadata and controls
99 lines (87 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import Char from 'typescript-char';
import { getUnicodeCategory, UnicodeCategory } from './unicode';
export function isIdentifierStartChar(ch: number) {
switch (ch) {
// Underscore is explicitly allowed to start an identifier
case Char.Underscore:
return true;
// Characters with the Other_ID_Start property
case 0x1885:
case 0x1886:
case 0x2118:
case 0x212e:
case 0x309b:
case 0x309c:
return true;
default:
break;
}
const cat = getUnicodeCategory(ch);
switch (cat) {
// Supported categories for starting an identifier
case UnicodeCategory.UppercaseLetter:
case UnicodeCategory.LowercaseLetter:
case UnicodeCategory.TitlecaseLetter:
case UnicodeCategory.ModifierLetter:
case UnicodeCategory.OtherLetter:
case UnicodeCategory.LetterNumber:
return true;
default:
break;
}
return false;
}
export function isIdentifierChar(ch: number) {
if (isIdentifierStartChar(ch)) {
return true;
}
switch (ch) {
// Characters with the Other_ID_Continue property
case 0x00b7:
case 0x0387:
case 0x1369:
case 0x136a:
case 0x136b:
case 0x136c:
case 0x136d:
case 0x136e:
case 0x136f:
case 0x1370:
case 0x1371:
case 0x19da:
return true;
default:
break;
}
switch (getUnicodeCategory(ch)) {
// Supported categories for continuing an identifier
case UnicodeCategory.NonSpacingMark:
case UnicodeCategory.SpacingCombiningMark:
case UnicodeCategory.DecimalDigitNumber:
case UnicodeCategory.ConnectorPunctuation:
return true;
default:
break;
}
return false;
}
export function isWhiteSpace(ch: number): boolean {
return ch <= Char.Space || ch === 0x200b; // Unicode whitespace
}
export function isLineBreak(ch: number): boolean {
return ch === Char.CarriageReturn || ch === Char.LineFeed;
}
export function isDecimal(ch: number): boolean {
return (ch >= Char._0 && ch <= Char._9) || ch === Char.Underscore;
}
export function isHex(ch: number): boolean {
return isDecimal(ch) || (ch >= Char.a && ch <= Char.f) || (ch >= Char.A && ch <= Char.F) || ch === Char.Underscore;
}
export function isOctal(ch: number): boolean {
return (ch >= Char._0 && ch <= Char._7) || ch === Char.Underscore;
}
export function isBinary(ch: number): boolean {
return ch === Char._0 || ch === Char._1 || ch === Char.Underscore;
}