// Copyright (C) 2015 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.



/**
 * @fileoverview
 * Registers a language handler for Swift
 *
 *
 * To use, include prettify.js and this file in your HTML page.
 * Then put your code in an HTML tag like
 *      <pre class="prettyprint lang-swift">(my swift code)</pre>
 * This file supports the following language extensions:
 *     lang-swift - Swift
 *
 * I used https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AboutTheLanguageReference.html
 * as the basis for this. In particular, I targeted the revision from
 * 2015-04-08. Swift is still evolving, and this was the latest version 
 * available at the time. I will keep the code unoptimized to ease changes that come with new Swift standards.
 *
 * @author cerech@google.com
 */

PR['registerLangHandler'](
    PR['createSimpleLexer'](
        [
          //whitespace
          //unicodes are vertical tab, form feed, and null, respectively
          [PR['PR_PLAIN'],                /^[\s\n\r\t\u000B\u000C\u0000]+/, null, '\s\n\r\t\u000B\u000C\u0000']
        ],
        [
          //keywords
          [PR['PR_KEYWORD'],              /^\b(?:__COLUMN__|__FILE__|__FUNCTION__|__LINE__|associativity|as|break|case|class|continue|convenience|default|deinit|didSet|do|dynamic|dynamicType|enum|fallthrough|false|final|for|func|get|import|infix|init|inout|internal|in|is|lazy|left|let|mutating|nil|none|nonmutating|operator|optional|override|postfix|precedence|prefix|private|protocol|Protocol|public|required|return|right|safe|self|set|static|struct|subscript|super|switch|true|Type|typealias|unowned|unsafe|var|weak|while|willSet)\b/, null],
          //double slash comments
          [PR['PR_COMMENT'],              /^\/\/.*?[\n\r]/, null],
          //slash star comments
          [PR['PR_COMMENT'],              /^\/\*[\s\S]*?(?:\*\/|$)/, null],
          //string literals
          [PR['PR_STRING'],               /^".*?"/, null]
        ]),
    ['swift']); 


//PR['registerLangHandler'](
//    PR['createSimpleLexer'](
//        [
//         ['opn',             /^\(+/, null, '('],
//        ['clo',             /^\)+/, null, ')'],
//       // A line comment that starts with ;
//         [PR['PR_COMMENT'],     /^;[^\r\n]*/, null, ';'],
//         // Whitespace
//         [PR['PR_PLAIN'],       /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
//         // A double quoted, possibly multi-line, string.
//         [PR['PR_STRING'],      /^\"(?:[^\"\\]|\\[\s\S])*(?:\"|$)/, null, '"']
//        ],
//        [
//         [PR['PR_KEYWORD'],     /^(?:block|c[ad]+r|catch|con[ds]|def(?:ine|un)|do|eq|eql|equal|equalp|eval-when|flet|format|go|if|labels|lambda|let|load-time-value|locally|macrolet|multiple-value-call|nil|progn|progv|quote|require|return-from|setq|symbol-macrolet|t|tagbody|the|throw|unwind)\b/, null],
//         [PR['PR_LITERAL'],
//          /^[+\-]?(?:[0#]x[0-9a-f]+|\d+\/\d+|(?:\.\d+|\d+(?:\.\d*)?)(?:[ed][+\-]?\d+)?)/i],
//         // A single quote possibly followed by a word that optionally ends with
//         // = ! or ?.
//         [PR['PR_LITERAL'],
//          /^\'(?:-*(?:\w|\\[\x21-\x7e])(?:[\w-]*|\\[\x21-\x7e])[=!?]?)?/],
//         // A word that optionally ends with = ! or ?.
//         [PR['PR_PLAIN'],
//          /^-*(?:[a-z_]|\\[\x21-\x7e])(?:[\w-]*|\\[\x21-\x7e])[=!?]?/i],
//         // A printable non-space non-special character
//         [PR['PR_PUNCTUATION'], /^[^\w\t\n\r \xA0()\"\\\';]+/]
//        ]),
//    ['cl', 'el', 'lisp', 'lsp', 'scm', 'ss', 'rkt']);*/

@@ -1619,16 +1619,108 @@
 %5Cu0000'%5D
+,%0A          //string literals%0A          %5BPR%5B'PR_STRING'%5D                /%5E%22.*?%22/, null, '%22'%5D
 %0A       
@@ -2504,95 +2504,8 @@
 $)/,
- null%5D,%0A          //string literals%0A          %5BPR%5B'PR_STRING'%5D,               /%5E%22.*?%22/,
  nul

Add shortcut for string literal detection to Swift