summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/mode/swift
diff options
context:
space:
mode:
authorCheng-Han, Wu2016-04-20 18:11:40 +0800
committerCheng-Han, Wu2016-04-20 18:11:40 +0800
commit8bf516263c6582771e7576e8484ca8cfaa8cb9cb (patch)
treeaba81172f554a50466a762db99f25e3650d7ff45 /public/vendor/codemirror/mode/swift
parentedc3a31dfdb03e910d7355144280e281eeb582d5 (diff)
Update CodeMirror to 5.13.5
Diffstat (limited to 'public/vendor/codemirror/mode/swift')
-rw-r--r--public/vendor/codemirror/mode/swift/swift.js47
1 files changed, 43 insertions, 4 deletions
diff --git a/public/vendor/codemirror/mode/swift/swift.js b/public/vendor/codemirror/mode/swift/swift.js
index 7a2339fc..3c28ced3 100644
--- a/public/vendor/codemirror/mode/swift/swift.js
+++ b/public/vendor/codemirror/mode/swift/swift.js
@@ -34,13 +34,13 @@
"private","extension"])
var operators = "+-/*%=|&<>#"
var punc = ";,.(){}[]"
- var delimiters = /^(?:[()\[\]{},:`=;]|\.\.?\.?)/
var number = /^-?(?:(?:[\d_]+\.[_\d]*|\.[_\d]+|0o[0-7_\.]+|0b[01_\.]+)(?:e-?[\d_]+)?|0x[\d_a-f\.]+(?:p-?[\d_]+)?)/i
var identifier = /^[_A-Za-z$][_A-Za-z$0-9]*/
var property = /^[@\.][_A-Za-z$][_A-Za-z$0-9]*/
var regexp = /^\/(?!\s)(?:\/\/)?(?:\\.|[^\/])+\//
function tokenBase(stream, state, prev) {
+ if (stream.sol()) state.indented = stream.indentation()
if (stream.eatSpace()) return null
var ch = stream.peek()
@@ -60,7 +60,8 @@
return "operator"
}
if (punc.indexOf(ch) > -1) {
- stream.match(delimiters)
+ stream.next()
+ stream.match("..")
return "punctuation"
}
if (ch == '"' || ch == "'") {
@@ -136,14 +137,35 @@
return "comment"
}
- CodeMirror.defineMode("swift", function() {
+ function Context(prev, align, indented) {
+ this.prev = prev
+ this.align = align
+ this.indented = indented
+ }
+
+ function pushContext(state, stream) {
+ var align = stream.match(/^\s*($|\/[\/\*])/, false) ? null : stream.column() + 1
+ state.context = new Context(state.context, align, state.indented)
+ }
+
+ function popContext(state) {
+ if (state.context) {
+ state.indented = state.context.indented
+ state.context = state.context.prev
+ }
+ }
+
+ CodeMirror.defineMode("swift", function(config) {
return {
startState: function() {
return {
prev: null,
+ context: null,
+ indented: 0,
tokenize: []
}
},
+
token: function(stream, state) {
var prev = state.prev
state.prev = null
@@ -151,8 +173,25 @@
var style = tokenize(stream, state, prev)
if (!style || style == "comment") state.prev = prev
else if (!state.prev) state.prev = style
+
+ if (style == "punctuation") {
+ var bracket = /[\(\[\{]|([\]\)\}])/.exec(stream.current())
+ if (bracket) (bracket[1] ? popContext : pushContext)(state, stream)
+ }
+
return style
},
+
+ indent: function(state, textAfter) {
+ var cx = state.context
+ if (!cx) return 0
+ var closing = /^[\]\}\)]/.test(textAfter)
+ if (cx.align != null) return cx.align - (closing ? 1 : 0)
+ return cx.indented + (closing ? 0 : config.indentUnit)
+ },
+
+ electricInput: /^\s*[\)\}\]]$/,
+
lineComment: "//",
blockCommentStart: "/*",
blockCommentEnd: "*/"
@@ -160,4 +199,4 @@
})
CodeMirror.defineMIME("text/x-swift","swift")
-})
+});