 
                 } else if c == "%" {
                     pctEncoded += c
-                    state = .ScanningLiterals
+                    state = .ScanningLiteral
 
                 } else if find(UNRESERVED, c) || find(RESERVED, c) {
                     result += c
 
                 } else {
-
-                }
-
-            case .ScanningExpressions:
-                println("")
+                    syntaxErrors += (URITemplateError.NonLiteralsCharacterFoundInLiteral, index)
+                    result += c
+                }
+
+            case .ScanningExpression:
+                if c == ")" {
+                    state = .ScanningLiteral
+                    // Process expression
+                    // ...
+                    var operator: String? = nil
+
+
+                } else {
+                    expression += c;
+                }
 
             default:
                 assert(false)
             } // switch
         }// for
 
+        // Handle ending
+        var endingIndex = countElements(template)
+        if state == .ScanningLiteral {
+            if countElements(pctEncoded) > 0 {
+                syntaxErrors += (URITemplateError.MalformedPctEncodedInLiteral, endingIndex)
+                result = appendLiteralString(pctEncoded, result)
+            }
+
+        } else if (state == .ScanningExpression) {
+            syntaxErrors += (URITemplateError.ExpressionEndedWithoutClosing, endingIndex)
+            result = result + "(" + expression
+
+        } else {
+            assert(false);
+        }
+        if expressionCount == 0 {
+            syntaxErrors += (URITemplateError.NonExpressionFound, endingIndex)
+        }
+
         return result
     } // process
 
-} // URITemplate+} // URITemplate

                        if find(HEXDIG, c) {
                            pctEncoded += c
                        } else {
                            errors[index] = URITemplateError.MalformedPctEncodedInLiterals
                            result = appendLiteralString(pctEncoded, result)
                            result = appendLiteralCharacter(c, result)
                            state = .ScanningLiterals
                            pctEncoded = ""
                        }


//    CFStringBuiltInEncodings.UTF8.toRaw())

enum URITemplateError {
    case MalformedPctEncodedInLiteral
    case NonLiteralsCharacterFoundInLiteral
    case ExpressionEndedWithoutClosing
    case NonExpressionFound
    case InvalidOperator
}

let URITemplateSyntaxErrorsKey = "SyntaxErrors"

class URITemplate {
    enum State {
        case ScanningLiteral
        case ScanningExpression
    }

    enum BehaviorAllow {
