 
 class JLKeywordScope: JLRegexScope {
     init(keywords: [String], prefix: String, suffix: String, tokenType: JLTokenType) {
-        let pattern = prefix + Branch(array: keywords).description + suffix
+        let pattern = prefix + Branch(character: "", array: keywords).description + suffix
         println(pattern)
         let expression = NSRegularExpression(pattern: pattern, options: nil, error: nil)
         super.init(regularExpression: expression, tokenTypes: [tokenType])

                    dictionary[firstCharacter] = [remainingString]
                }
            } else {
                children[""] = string
            }
        }
        for (key, value) in dictionary {
            if array.count == 1 {
                children[key] = value[0]
            } else {
                children[key] = Branch(array: value)
            }
        }
        
    }
    
    var pattern: String {
    var array = [String]()
        for (key, value) in children {
            array += "\(key)\(value.pattern)"
        }
        
        if children.count == 1 {
            return join("|", array)
        }
        
        return "(?:" + join("|", array) + ")"
    }
    
    var description: String {

    convenience init (keywords: [String], tokenType: JLTokenType) {
        self.init(keywords: keywords, prefix: "\\b", suffix: "\\b", tokenType: tokenType)
    }
    
    /// Create a JLKeywordScope with a space-separated keyword string
    convenience init(keywords: String, tokenType: JLTokenType) {
        self.init(keywords: keywords.componentsSeparatedByString(" "), tokenType: tokenType)
    }
}

extension String
    {
    func characterAtIndex(index:Int) -> unichar
    {
        return self.utf16[index]
    }
    
    // Allows us to use String[index] notation
    subscript(index:Int) -> unichar
        {
        return characterAtIndex(index)
    }
}

private protocol Node {
    var pattern: String {get}
}

private struct Leaf: Node {
    init() {}
    var pattern: String { return "" }
}

private struct Branch: Node, Printable {
    var children = [Node]()
    var character: String
    
    func perform(string: NSString, range: Range<Int>) {
        for i in range {
            
        }
    }
    
    init(character: String, array: [String]) {
        self.character = character
        var dictionary = [String: [String]]()
        for string in array {
            if countElements(string) > 0 {
