Skip to content

Commit 9ffb98f

Browse files
author
John Holdsworth
committed
Trim down operators.
1 parent 0f58650 commit 9ffb98f

File tree

2 files changed

+21
-83
lines changed

2 files changed

+21
-83
lines changed

Sources/SwiftParser/Lexer/Cursor.swift

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -942,34 +942,18 @@ extension Lexer.Cursor {
942942
preferRegexOverBinaryOperator: preferRegexOverBinaryOperator
943943
)
944944

945-
case "A", "B", "C",
946-
"D", "E", "F",
947-
"G", "H", "I",
948-
"J", "K", "L",
949-
"M", "N", "O",
950-
"P", "Q", "R",
951-
"S", "T", "U",
952-
"V", "W", "X",
953-
"Y", "Z",
954-
"a", "b", "c",
955-
"d", "e", "f",
956-
"g", "h", "i",
957-
"j", "k", "l",
958-
"m", "n", "o",
959-
"p", "q", "r",
960-
"s", "t", "u",
961-
"v", "w", "x",
962-
"y", "z",
963-
"_":
945+
case "A", "B", "C", "D", "E", "F", "G", "H", "I",
946+
"J", "K", "L", "M", "N", "O", "P", "Q", "R",
947+
"S", "T", "U", "V", "W", "X", "Y", "Z",
948+
"a", "b", "c", "d", "e", "f", "g", "h", "i",
949+
"j", "k", "l", "m", "n", "o", "p", "q", "r",
950+
"s", "t", "u", "v", "w", "x", "y", "z", "_":
964951
return self.lexIdentifier()
965952

966953
case "$":
967954
return self.lexDollarIdentifier()
968955

969-
case "0", "1", "2",
970-
"3", "4", "5",
971-
"6", "7", "8",
972-
"9":
956+
case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9":
973957
return self.lexNumber()
974958
case #"'"#, #"""#:
975959
return self.lexStringQuote(isOpening: true, leadingDelimiterLength: 0)
@@ -1184,47 +1168,25 @@ extension Lexer.Cursor {
11841168
// Start character of tokens.
11851169
// case (char)-1: case (char)-2:
11861170
case // Punctuation.
1187-
"{", "[", "(",
1188-
"}", "]", ")",
1189-
"@", ",", ";",
1190-
":", "\\", "$",
1191-
"#",
1171+
"{", "[", "(", "}", "]", ")", "@",
1172+
",", ";", ":", "\\", "$", "#",
11921173

11931174
// Start of integer/hex/float literals.
1194-
"0", "1", "2",
1195-
"3", "4", "5",
1196-
"6", "7", "8",
1197-
"9",
1175+
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
11981176

11991177
// Start of literals.
12001178
#"""#, #"'"#, "`",
12011179

12021180
// Start of identifiers.
1203-
"A", "B", "C",
1204-
"D", "E", "F",
1205-
"G", "H", "I",
1206-
"J", "K", "L",
1207-
"M", "N", "O",
1208-
"P", "Q", "R",
1209-
"S", "T", "U",
1210-
"V", "W", "X",
1211-
"Y", "Z",
1212-
"a", "b", "c",
1213-
"d", "e", "f",
1214-
"g", "h", "i",
1215-
"j", "k", "l",
1216-
"m", "n", "o",
1217-
"p", "q", "r",
1218-
"s", "t", "u",
1219-
"v", "w", "x",
1220-
"y", "z",
1221-
"_",
1181+
"A", "B", "C", "D", "E", "F", "G", "H", "I",
1182+
"J", "K", "L", "M", "N", "O", "P", "Q", "R",
1183+
"S", "T", "U", "V", "W", "X", "Y", "Z",
1184+
"a", "b", "c", "d", "e", "f", "g", "h", "i",
1185+
"j", "k", "l", "m", "n", "o", "p", "q", "r",
1186+
"s", "t", "u", "v", "w", "x", "y", "z", "_",
12221187

12231188
// Start of operators.
1224-
"%", "!", "?",
1225-
"=", "-", "+",
1226-
"*", "&", "|",
1227-
"^", "~", ".":
1189+
"%", "!", "?", "=", "-", "+", "*", "&", "|", "^", "~", ".":
12281190
break
12291191
case 0xEF:
12301192
if self.is(at: 0xBB), self.is(offset: 1, at: 0xBF) {
@@ -1287,7 +1249,7 @@ extension Lexer.Cursor {
12871249
let zeroConsumed = self.advance(matching: "0") // Consume '0'
12881250
let oConsumed = self.advance(matching: "o") // Consume 'o'
12891251
precondition(zeroConsumed && oConsumed)
1290-
if let peeked = self.peek(), peeked < "0" || peeked > "7" {
1252+
if let peeked = self.peek(), peeked < UInt8(ascii: "0") || peeked > UInt8(ascii: "7") {
12911253
let errorPos = self
12921254
self.advance(while: { $0.isValidIdentifierContinuationCodePoint })
12931255
return Lexer.Result(

Sources/SwiftParser/Lexer/UnicodeScalarExtensions.swift

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,9 @@ extension Unicode.Scalar {
9696
var isOperatorStartCodePoint: Bool {
9797
// ASCII operator chars.
9898
if self.value < 0x80 {
99-
switch UInt8(self.value) {
100-
case "/", "=", "-",
101-
"+", "*", "%",
102-
"<", ">", "!",
103-
"&", "|", "^",
104-
"~", ".", "?":
99+
switch self {
100+
case "/", "=", "-", "+", "*", "%", "<",
101+
">", "!", "&", "|", "^", "~", ".", "?":
105102
return true
106103
default:
107104
return false
@@ -261,32 +258,11 @@ extension UInt8 {
261258
public static func != (i: Self, s: Unicode.Scalar) -> Bool {
262259
return i != UInt8(ascii: s)
263260
}
264-
@inline(__always)
265-
public static func <= (i: Self, s: Unicode.Scalar) -> Bool {
266-
return i <= UInt8(ascii: s)
267-
}
268-
@inline(__always)
269-
public static func >= (i: Self, s: Unicode.Scalar) -> Bool {
270-
return i >= UInt8(ascii: s)
271-
}
272-
@inline(__always)
273-
public static func < (i: Self, s: Unicode.Scalar) -> Bool {
274-
return i < UInt8(ascii: s)
275-
}
276-
@inline(__always)
277-
public static func > (i: Self, s: Unicode.Scalar) -> Bool {
278-
return i > UInt8(ascii: s)
279-
}
280261
/// Used in switch statements
281262
@inline(__always)
282263
public static func ~= (s: Unicode.Scalar, i: Self) -> Bool {
283264
return i == UInt8(ascii: s)
284265
}
285-
/// Maybe useful now and then
286-
@inline(__always)
287-
public static func - (i: Self, s: Unicode.Scalar) -> Self {
288-
return i - Self(UInt8(ascii: s))
289-
}
290266
}
291267

292268
extension UInt8? {

0 commit comments

Comments
 (0)