Skip to content

Instantly share code, notes, and snippets.


Harlan Haskins harlanhaskins

View GitHub Profile
harlanhaskins / TMNT Symbols
Created Jul 4, 2020
All the iOS 14/macOS 11/tvOS 14/watchOS 7 symbols that are singable to the TMNT theme song
View TMNT Symbols
View StringScanner.swift
import Foundation
/// `StringScanner` is a fast scanner for Strings and String-like objects.
/// It's used to extract structured bits from unstructured strings, while
/// avoiding making extra copies of string bits until absolutely necessary.
/// You can build Scanners over Substrings, allowing you to scan
/// parts of strings and use smaller, more specialized scanners to extract bits
/// of that String without needing to reuse another scanner.
public struct StringScanner<Input: StringProtocol> {
let input: Input
harlanhaskins / swift-format.swift
Created Oct 26, 2017
Simple Swift Formatter using SwiftSyntax
View swift-format.swift
import Foundation
import SwiftSyntax
func main() throws {
guard CommandLine.arguments.count > 1 else {
print("usage: swift-format [file]")
let url = URL(fileURLWithPath: CommandLine.arguments[1])
View goto.swift
func main() {
var z = 0
func goto(label: String) {
switch label {
case "start":
case "cond":
if z == 5 {
} else {
View if-configs.swift
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/Test~partial.swiftmodule -module-name Test -primary-file %s
// RUN: %target-swift-frontend -merge-modules -emit-module -o %t/Test.swiftmodule %t/Test~partial.swiftmodule
// RUN: %target-swift-ide-test -print-module -module-to-print=Test -source-filename=x -I %t | %FileCheck %s
// RUN: %target-swift-frontend -emit-interface-path %t.swiftinterface -enable-resilience -emit-module -o /dev/null %s
// RUN: %FileCheck %s < %t.swiftinterface
// CHECK: func hasClosureDefaultArg(_ x: () -> Void = {
harlanhaskins / Lexer.swift
Last active Aug 18, 2018
Building a Compiler in Swift with LLVM, Part 1: Introduction and the Lexer
View Lexer.swift
#if os(macOS)
import Darwin
#elseif os(Linux)
import Glibc
enum BinaryOperator: Character {
case plus = "+"
case minus = "-"
case times = "*"
harlanhaskins / BitArray.swift
Created Jul 20, 2018
Swift BitArray that behaves like an array of bools.
View BitArray.swift
import Foundation
extension BinaryInteger {
/// Gets the bit at the specified bit index in the receiver, reading from
/// least to most-significant bit.
/// For example,
/// ```
/// 0b0010.bit(at: 0) == false
/// 0b0010.bit(at: 1) == true
harlanhaskins / Parser.swift
Last active Jul 3, 2018
Building a Compiler in Swift with LLVM, Part 2: AST and the Parser
View Parser.swift
#if os(macOS)
import Darwin
#elseif os(Linux)
import Glibc
// MARK: Tokens
enum BinaryOperator: Character {
case plus = "+"
harlanhaskins / BitstreamWriter.swift
Created Jun 19, 2018
LLVM Bitstream Writer in Swift
View BitstreamWriter.swift
import Foundation
typealias UnsignedIntegralType = UnsignedInteger & ExpressibleByIntegerLiteral
struct BitstreamRecord {
private(set) var values = [UInt32]()
mutating func append<IntType: UnsignedIntegralType>(_ int: IntType) {
View call-of-deleted-method.swift
import Foundation
import SwiftSyntax
# Syntax Rewriting
SwiftSyntax provides a class called `SyntaxRewriter`, which will walk a Syntax tree and
perform transformations over the nodes.
By default, these transformations don't do anything. It's the subclass's job to
You can’t perform that action at this time.