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

                        if find(HEXDIG, c) {
                            pctEncoded += c
                            result += pctEncoded
                            state = .ScanningLiterals
                            pctEncoded = ""

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



                } else if c == "%" {
                    pctEncoded += c
                    state = .ScanningLiteral

                } else if find(UNRESERVED, c) || find(RESERVED, c) {
                    result += c

                } else {
                    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
