1
- let eof = - 1
1
+ let eof = Char. unsafe_chr ( - 1 )
2
2
3
- let space = 0x0020
4
- let newline = 0x0A (* \n *) [@@ live]
5
- let lineFeed = 0x0A (* \n *)
6
- let carriageReturn = 0x0D (* \r *)
7
- let lineSeparator = 0x2028
8
- let paragraphSeparator = 0x2029
3
+ let lineSeparator = Char. unsafe_chr 0x2028
4
+ let paragraphSeparator = Char. unsafe_chr 0x2029
9
5
10
- let tab = 0x09
6
+ let isUpperCase ch = 'A' < = ch && ch < = 'Z' [@@ inline]
7
+ let isLowerCase ch = 'a' < = ch && ch < = 'z' [@@ inline]
11
8
12
- let bang = 0x21
13
- let dot = 0x2E
14
- let colon = 0x3A
15
- let comma = 0x2C
16
- let backtick = 0x60
17
- (* let question = 0x3F *)
18
- let semicolon = 0x3B
19
- let underscore = 0x5F
20
- let singleQuote = 0x27
21
- let doubleQuote = 0x22
22
- let equal = 0x3D
23
- let bar = 0x7C
24
- let tilde = 0x7E
25
- let question = 0x3F
26
- let ampersand = 0x26
27
- let at = 0x40
28
- let dollar = 0x24
29
- let percent = 0x25
9
+ let isDigit ch = '0' < = ch && ch < = '9' [@@ inline]
30
10
31
- let lparen = 0x28
32
- let rparen = 0x29
33
- let lbracket = 0x5B
34
- let rbracket = 0x5D
35
- let lbrace = 0x7B
36
- let rbrace = 0x7D
11
+ let isLetter ch = isUpperCase ch || isLowerCase ch
37
12
38
- let forwardslash = 0x2F (* / *)
39
- let backslash = 0x5C (* \ *)
40
-
41
- let greaterThan = 0x3E
42
- let hash = 0x23
43
- let lessThan = 0x3C
44
-
45
- let minus = 0x2D
46
- let plus = 0x2B
47
- let asterisk = 0x2A
48
-
49
- let _0 = 0x30
50
- let _1 = 0x31 [@@ live]
51
- let _2 = 0x32 [@@ live]
52
- let _3 = 0x33 [@@ live]
53
- let _4 = 0x34 [@@ live]
54
- let _5 = 0x35 [@@ live]
55
- let _6 = 0x36 [@@ live]
56
- let _7 = 0x37 [@@ live]
57
- let _8 = 0x38 [@@ live]
58
- let _9 = 0x39
59
-
60
- module Lower = struct
61
- let a = 0x61
62
- let b = 0x62
63
- let c = 0x63 [@@ live]
64
- let d = 0x64 [@@ live]
65
- let e = 0x65
66
- let f = 0x66
67
- let g = 0x67
68
- let h = 0x68 [@@ live]
69
- let i = 0x69 [@@ live]
70
- let j = 0x6A [@@ live]
71
- let k = 0x6B [@@ live]
72
- let l = 0x6C [@@ live]
73
- let m = 0x6D [@@ live]
74
- let n = 0x6E
75
- let o = 0x6F
76
- let p = 0x70
77
- let q = 0x71 [@@ live]
78
- let r = 0x72
79
- let s = 0x73 [@@ live]
80
- let t = 0x74
81
- let u = 0x75 [@@ live]
82
- let v = 0x76 [@@ live]
83
- let w = 0x77 [@@ live]
84
- let x = 0x78
85
- let y = 0x79 [@@ live]
86
- let z = 0x7A
87
- end
88
-
89
- module Upper = struct
90
- let a = 0x41
91
- (* let b = 0x42 *)
92
- let c = 0x43 [@@ live]
93
- let d = 0x44 [@@ live]
94
- let e = 0x45 [@@ live]
95
- let f = 0x46 [@@ live]
96
- let g = 0x47
97
- let h = 0x48 [@@ live]
98
- let i = 0x49 [@@ live]
99
- let j = 0x4A [@@ live]
100
- let k = 0x4B [@@ live]
101
- let l = 0x4C [@@ live]
102
- let m = 0x4D [@@ live]
103
- let b = 0x4E [@@ live]
104
- let o = 0x4F [@@ live]
105
- let p = 0x50 [@@ live]
106
- let q = 0x51 [@@ live]
107
- let r = 0x52 [@@ live]
108
- let s = 0x53 [@@ live]
109
- let t = 0x54 [@@ live]
110
- let u = 0x55 [@@ live]
111
- let v = 0x56 [@@ live]
112
- let w = 0x57 [@@ live]
113
- let x = 0x58 [@@ live]
114
- let y = 0x59 [@@ live]
115
- let z = 0x5a
116
- end
117
-
118
- (* returns lower-case ch, ch should be ascii *)
119
- let lower ch =
120
- (* if ch >= Lower.a && ch <= Lower.z then ch else ch + 32 *)
121
- 32 lor ch
122
-
123
- let isLetter ch =
124
- Lower. a < = ch && ch < = Lower. z ||
125
- Upper. a < = ch && ch < = Upper. z
126
-
127
- let isUpperCase ch =
128
- Upper. a < = ch && ch < = Upper. z
129
-
130
- let isDigit ch = _0 < = ch && ch < = _9
131
-
132
- let isHex ch =
133
- (_0 < = ch && ch < = _9) ||
134
- (Lower. a < = (lower ch) && (lower ch) < = Lower. f)
13
+ let isHex = function
14
+ | '0' ..'9' | 'a' ..'f' | 'A' ..'F' -> true
15
+ | _ -> false
135
16
136
17
(*
137
18
// ES5 7.3:
@@ -146,15 +27,16 @@ let isHex ch =
146
27
// breaking characters are treated as white space but not as line terminators.
147
28
*)
148
29
let isLineBreak ch =
149
- ch == lineFeed
150
- || ch == carriageReturn
30
+ ch == '\n'
31
+ || ch == '\r'
151
32
|| ch == lineSeparator
152
33
|| ch == paragraphSeparator
153
34
154
35
let digitValue ch =
155
- if _0 < = ch && ch < = _9 then
156
- ch - 48
157
- else if Lower. a < = (lower ch) && (lower ch) < = Lower. f then
158
- (lower ch) - Lower. a + 10
159
- else
160
- 16 (* larger than any legal value *)
36
+ match ch with
37
+ | '0' ..'9' -> (Char. code ch) - 48
38
+ | 'a' ..'f' ->
39
+ (Char. code ch) - (Char. code 'a' ) + 10
40
+ | 'A' ..'F' ->
41
+ (Char. code ch) + 32 - (Char. code 'a' ) + 10
42
+ | _ -> 16 (* larger than any legal value *)
0 commit comments