Straighten out Characters and CharacterSets
This commit is contained in:
parent
35a5cf1dc8
commit
59e55a39e4
3 changed files with 66 additions and 34 deletions
|
@ -9,6 +9,7 @@
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
C0496EB51E04533D0000E33E /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0496EB41E04533D0000E33E /* main.swift */; };
|
C0496EB51E04533D0000E33E /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0496EB41E04533D0000E33E /* main.swift */; };
|
||||||
C0496EBC1E04534F0000E33E /* Lexer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0496EBB1E04534F0000E33E /* Lexer.swift */; };
|
C0496EBC1E04534F0000E33E /* Lexer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0496EBB1E04534F0000E33E /* Lexer.swift */; };
|
||||||
|
C0C60EC11E084631004C1559 /* Characters.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0C60EC01E084631004C1559 /* Characters.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXCopyFilesBuildPhase section */
|
/* Begin PBXCopyFilesBuildPhase section */
|
||||||
|
@ -27,6 +28,7 @@
|
||||||
C0496EB11E04533D0000E33E /* Sibil */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Sibil; sourceTree = BUILT_PRODUCTS_DIR; };
|
C0496EB11E04533D0000E33E /* Sibil */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Sibil; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
C0496EB41E04533D0000E33E /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
C0496EB41E04533D0000E33E /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
||||||
C0496EBB1E04534F0000E33E /* Lexer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lexer.swift; sourceTree = "<group>"; };
|
C0496EBB1E04534F0000E33E /* Lexer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lexer.swift; sourceTree = "<group>"; };
|
||||||
|
C0C60EC01E084631004C1559 /* Characters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Characters.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
@ -61,6 +63,7 @@
|
||||||
children = (
|
children = (
|
||||||
C0496EB41E04533D0000E33E /* main.swift */,
|
C0496EB41E04533D0000E33E /* main.swift */,
|
||||||
C0496EBB1E04534F0000E33E /* Lexer.swift */,
|
C0496EBB1E04534F0000E33E /* Lexer.swift */,
|
||||||
|
C0C60EC01E084631004C1559 /* Characters.swift */,
|
||||||
);
|
);
|
||||||
path = Sibil;
|
path = Sibil;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -124,6 +127,7 @@
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
C0496EBC1E04534F0000E33E /* Lexer.swift in Sources */,
|
C0496EBC1E04534F0000E33E /* Lexer.swift in Sources */,
|
||||||
|
C0C60EC11E084631004C1559 /* Characters.swift in Sources */,
|
||||||
C0496EB51E04533D0000E33E /* main.swift in Sources */,
|
C0496EB51E04533D0000E33E /* main.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
@ -254,6 +258,7 @@
|
||||||
C0496EBA1E04533D0000E33E /* Release */,
|
C0496EBA1E04533D0000E33E /* Release */,
|
||||||
);
|
);
|
||||||
defaultConfigurationIsVisible = 0;
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
};
|
};
|
||||||
/* End XCConfigurationList section */
|
/* End XCConfigurationList section */
|
||||||
};
|
};
|
||||||
|
|
60
Sibil/Characters.swift
Normal file
60
Sibil/Characters.swift
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
//
|
||||||
|
// Characters.swift
|
||||||
|
// Sibil
|
||||||
|
//
|
||||||
|
// Created by Eryn Wells on 12/19/16.
|
||||||
|
// Copyright © 2016 Eryn Wells. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
|
extension CharacterSet {
|
||||||
|
static let asciiLetters: CharacterSet = {
|
||||||
|
return CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||||
|
}()
|
||||||
|
|
||||||
|
static let asciiDigits: CharacterSet = {
|
||||||
|
return CharacterSet(charactersIn: "1234567890")
|
||||||
|
}()
|
||||||
|
|
||||||
|
static let identifierInitials: CharacterSet = {
|
||||||
|
let letters = CharacterSet.asciiLetters
|
||||||
|
let extras = CharacterSet(charactersIn: "!$%&*/:<=>?~_^")
|
||||||
|
let initials = letters.union(extras)
|
||||||
|
return initials
|
||||||
|
}()
|
||||||
|
|
||||||
|
static let identifierSubsequents: CharacterSet = {
|
||||||
|
let initials = CharacterSet.identifierInitials
|
||||||
|
let digits = CharacterSet.asciiDigits
|
||||||
|
let extras = CharacterSet(charactersIn: ".+-")
|
||||||
|
let subsequents = initials.union(digits).union(extras)
|
||||||
|
return subsequents
|
||||||
|
}()
|
||||||
|
|
||||||
|
func contains(_ char: Character) -> Bool {
|
||||||
|
let cSet = CharacterSet(charactersIn: String(char))
|
||||||
|
let isSuperset = self.isSuperset(of: cSet)
|
||||||
|
return isSuperset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extension Character {
|
||||||
|
var isLeftParen: Bool {
|
||||||
|
return self == "("
|
||||||
|
}
|
||||||
|
|
||||||
|
var isRightParen: Bool {
|
||||||
|
return self == ")"
|
||||||
|
}
|
||||||
|
|
||||||
|
var isIdentifierInitial: Bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var isIdentifierSubsequent: Bool {
|
||||||
|
return CharacterSet.identifierSubsequents.contains(self)
|
||||||
|
}
|
||||||
|
}
|
|
@ -93,7 +93,7 @@ extension Lexer: Sequence, IteratorProtocol {
|
||||||
toState(.Identifier)
|
toState(.Identifier)
|
||||||
}
|
}
|
||||||
case .Identifier:
|
case .Identifier:
|
||||||
if c.isIdentifierSubsequent
|
break
|
||||||
case .Emit:
|
case .Emit:
|
||||||
// Nothing to do for this state
|
// Nothing to do for this state
|
||||||
break
|
break
|
||||||
|
@ -103,36 +103,3 @@ extension Lexer: Sequence, IteratorProtocol {
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Character {
|
|
||||||
static let identifierInitialSet: CharacterSet = {
|
|
||||||
let letters = CharacterSet.letters
|
|
||||||
let extras = CharacterSet(charactersIn: "!$%&*/:<=>?~_^")
|
|
||||||
let initials = letters.union(extras)
|
|
||||||
return initials
|
|
||||||
}()
|
|
||||||
|
|
||||||
static let identifierSubsequentSet: CharacterSet = {
|
|
||||||
let initials = Character.identifierInitialSet
|
|
||||||
let digits = CharacterSet.decimalDigits
|
|
||||||
let extras = CharacterSet(charactersIn: ".+-")
|
|
||||||
let subsequents = initials.union(digits).union(extras)
|
|
||||||
return subsequents
|
|
||||||
}()
|
|
||||||
|
|
||||||
var isLeftParen: Bool {
|
|
||||||
return self == "("
|
|
||||||
}
|
|
||||||
|
|
||||||
var isRightParen: Bool {
|
|
||||||
return self == ")"
|
|
||||||
}
|
|
||||||
|
|
||||||
var isIdentifierInitial: Bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
var isIdentifierSubsequent: Bool {
|
|
||||||
Character.identifierSubsequentSet.contains(<#T##member: UnicodeScalar##UnicodeScalar#>)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue