1
0
Fork 0
forked from forgejo/forgejo

Update CodeMirror to version 5.49.0 (#8381)

* Update CodeMirror to version 5.49.0

* Update CodeMirror versions in librejs and VERSIONS
This commit is contained in:
oscar.lofwenhamn 2019-10-15 10:40:42 +02:00 committed by Lauris BH
parent 6fa14ac3c8
commit 1e9b330525
352 changed files with 14625 additions and 2451 deletions

View file

@ -12,7 +12,7 @@
.CodeMirror { border: 2px inset #dee; }
</style>
<div id=nav>
<a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul>
<li><a href="../../index.html">Home</a>
@ -28,50 +28,32 @@
<article>
<h2>Swift mode</h2>
<form><textarea id="code" name="code">
//
// TipCalculatorModel.swift
// TipCalculator
//
// Created by Main Account on 12/18/14.
// Copyright (c) 2014 Razeware LLC. All rights reserved.
//
import Foundation
class TipCalculatorModel {
var total: Double
var taxPct: Double
var subtotal: Double {
get {
return total / (taxPct + 1)
}
}
init(total: Double, taxPct: Double) {
self.total = total
self.taxPct = taxPct
}
func calcTipWithTipPct(tipPct: Double) -> Double {
return subtotal * tipPct
}
func returnPossibleTips() -> [Int: Double] {
let possibleTipsInferred = [0.15, 0.18, 0.20]
let possibleTipsExplicit:[Double] = [0.15, 0.18, 0.20]
var retval = [Int: Double]()
for possibleTip in possibleTipsInferred {
let intPct = Int(possibleTip*100)
retval[intPct] = calcTipWithTipPct(possibleTip)
}
return retval
}
protocol HeaderViewProtocol {
func setTitle(_ string: String)
}
struct AnyHeaderView {
let view: UIView
let headerView: HeaderViewProtocol
init<T: UIView>(view: T) where T: HeaderViewProtocol {
self.view = view
self.headerView = view
}
}
let header = AnyHeaderView(view: myView)
header.headerView.setTitle("hi")
struct HeaderView {
let view: UIView
let setTitle: (String) -> ()
}
var label = UILabel()
let header = HeaderView(view: label) { str in
label.text = str
}
header.setTitle("hello")
</textarea></form>
<script>

View file

@ -1,5 +1,5 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Distributed under an MIT license: https://codemirror.net/LICENSE
// Swift mode created by Michael Kaminsky https://github.com/mkaminsky11
@ -19,25 +19,28 @@
return set
}
var keywords = wordSet(["var","let","class","deinit","enum","extension","func","import","init","protocol",
"static","struct","subscript","typealias","as","dynamicType","is","new","super",
"self","Self","Type","__COLUMN__","__FILE__","__FUNCTION__","__LINE__","break","case",
"continue","default","do","else","fallthrough","if","in","for","return","switch",
"where","while","associativity","didSet","get","infix","inout","left","mutating",
"none","nonmutating","operator","override","postfix","precedence","prefix","right",
"set","unowned","weak","willSet"])
var definingKeywords = wordSet(["var","let","class","enum","extension","func","import","protocol","struct",
"typealias","dynamicType","for"])
var atoms = wordSet(["Infinity","NaN","undefined","null","true","false","on","off","yes","no","nil","null",
"this","super"])
var types = wordSet(["String","bool","int","string","double","Double","Int","Float","float","public",
"private","extension"])
var operators = "+-/*%=|&<>#"
var punc = ";,.(){}[]"
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)(?:\/\/)?(?:\\.|[^\/])+\//
var keywords = wordSet(["_","var","let","class","enum","extension","import","protocol","struct","func","typealias","associatedtype",
"open","public","internal","fileprivate","private","deinit","init","new","override","self","subscript","super",
"convenience","dynamic","final","indirect","lazy","required","static","unowned","unowned(safe)","unowned(unsafe)","weak","as","is",
"break","case","continue","default","else","fallthrough","for","guard","if","in","repeat","switch","where","while",
"defer","return","inout","mutating","nonmutating","catch","do","rethrows","throw","throws","try","didSet","get","set","willSet",
"assignment","associativity","infix","left","none","operator","postfix","precedence","precedencegroup","prefix","right",
"Any","AnyObject","Type","dynamicType","Self","Protocol","__COLUMN__","__FILE__","__FUNCTION__","__LINE__"])
var definingKeywords = wordSet(["var","let","class","enum","extension","import","protocol","struct","func","typealias","associatedtype","for"])
var atoms = wordSet(["true","false","nil","self","super","_"])
var types = wordSet(["Array","Bool","Character","Dictionary","Double","Float","Int","Int8","Int16","Int32","Int64","Never","Optional","Set","String",
"UInt8","UInt16","UInt32","UInt64","Void"])
var operators = "+-/*%=|&<>~^?!"
var punc = ":;,.(){}[]"
var binary = /^\-?0b[01][01_]*/
var octal = /^\-?0o[0-7][0-7_]*/
var hexadecimal = /^\-?0x[\dA-Fa-f][\dA-Fa-f_]*(?:(?:\.[\dA-Fa-f][\dA-Fa-f_]*)?[Pp]\-?\d[\d_]*)?/
var decimal = /^\-?\d[\d_]*(?:\.\d[\d_]*)?(?:[Ee]\-?\d[\d_]*)?/
var identifier = /^\$\d+|(`?)[_A-Za-z][_A-Za-z$0-9]*\1/
var property = /^\.(?:\$\d+|(`?)[_A-Za-z][_A-Za-z$0-9]*\1)/
var instruction = /^\#[A-Za-z]+/
var attribute = /^@(?:\$\d+|(`?)[_A-Za-z][_A-Za-z$0-9]*\1)/
//var regexp = /^\/(?!\s)(?:\/\/)?(?:\\.|[^\/])+\//
function tokenBase(stream, state, prev) {
if (stream.sol()) state.indented = stream.indentation()
@ -53,8 +56,14 @@
state.tokenize.push(tokenComment)
return tokenComment(stream, state)
}
if (stream.match(regexp)) return "string-2"
}
if (stream.match(instruction)) return "builtin"
if (stream.match(attribute)) return "attribute"
if (stream.match(binary)) return "number"
if (stream.match(octal)) return "number"
if (stream.match(hexadecimal)) return "number"
if (stream.match(decimal)) return "number"
if (stream.match(property)) return "property"
if (operators.indexOf(ch) > -1) {
stream.next()
return "operator"
@ -64,25 +73,22 @@
stream.match("..")
return "punctuation"
}
if (ch == '"' || ch == "'") {
stream.next()
var tokenize = tokenString(ch)
var stringMatch
if (stringMatch = stream.match(/("""|"|')/)) {
var tokenize = tokenString.bind(null, stringMatch[0])
state.tokenize.push(tokenize)
return tokenize(stream, state)
}
if (stream.match(number)) return "number"
if (stream.match(property)) return "property"
if (stream.match(identifier)) {
var ident = stream.current()
if (types.hasOwnProperty(ident)) return "variable-2"
if (atoms.hasOwnProperty(ident)) return "atom"
if (keywords.hasOwnProperty(ident)) {
if (definingKeywords.hasOwnProperty(ident))
state.prev = "define"
return "keyword"
}
if (types.hasOwnProperty(ident)) return "variable-2"
if (atoms.hasOwnProperty(ident)) return "atom"
if (prev == "define") return "def"
return "variable"
}
@ -110,30 +116,43 @@
}
}
function tokenString(quote) {
return function(stream, state) {
var ch, escaped = false
while (ch = stream.next()) {
if (escaped) {
if (ch == "(") {
state.tokenize.push(tokenUntilClosingParen())
return "string"
}
escaped = false
} else if (ch == quote) {
break
} else {
escaped = ch == "\\"
function tokenString(openQuote, stream, state) {
var singleLine = openQuote.length == 1
var ch, escaped = false
while (ch = stream.peek()) {
if (escaped) {
stream.next()
if (ch == "(") {
state.tokenize.push(tokenUntilClosingParen())
return "string"
}
escaped = false
} else if (stream.match(openQuote)) {
state.tokenize.pop()
return "string"
} else {
stream.next()
escaped = ch == "\\"
}
state.tokenize.pop()
return "string"
}
if (singleLine) {
state.tokenize.pop()
}
return "string"
}
function tokenComment(stream, state) {
stream.match(/^(?:[^*]|\*(?!\/))*/)
if (stream.match("*/")) state.tokenize.pop()
var ch
while (true) {
stream.match(/^[^/*]+/, true)
ch = stream.next()
if (!ch) break
if (ch === "/" && stream.eat("*")) {
state.tokenize.push(tokenComment)
} else if (ch === "*" && stream.eat("/")) {
state.tokenize.pop()
}
}
return "comment"
}
@ -194,7 +213,9 @@
lineComment: "//",
blockCommentStart: "/*",
blockCommentEnd: "*/"
blockCommentEnd: "*/",
fold: "brace",
closeBrackets: "()[]{}''\"\"``"
}
})

View file

@ -0,0 +1,162 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/LICENSE
(function() {
var mode = CodeMirror.getMode({indentUnit: 2}, "swift");
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
// Ensure all number types are properly represented.
MT("numbers",
"[keyword var] [def a] [operator =] [number 17]",
"[keyword var] [def b] [operator =] [number -0.5]",
"[keyword var] [def c] [operator =] [number 0.3456e-4]",
"[keyword var] [def d] [operator =] [number 345e2]",
"[keyword var] [def e] [operator =] [number 0o7324]",
"[keyword var] [def f] [operator =] [number 0b10010]",
"[keyword var] [def g] [operator =] [number -0x35ade]",
"[keyword var] [def h] [operator =] [number 0xaea.ep-13]",
"[keyword var] [def i] [operator =] [number 0x13ep6]");
// Variable/class/etc definition.
MT("definition",
"[keyword var] [def a] [operator =] [number 5]",
"[keyword let] [def b][punctuation :] [variable-2 Int] [operator =] [number 10]",
"[keyword class] [def C] [punctuation {] [punctuation }]",
"[keyword struct] [def D] [punctuation {] [punctuation }]",
"[keyword enum] [def E] [punctuation {] [punctuation }]",
"[keyword extension] [def F] [punctuation {] [punctuation }]",
"[keyword protocol] [def G] [punctuation {] [punctuation }]",
"[keyword func] [def h][punctuation ()] [punctuation {] [punctuation }]",
"[keyword import] [def Foundation]",
"[keyword typealias] [def NewString] [operator =] [variable-2 String]",
"[keyword associatedtype] [def I]",
"[keyword for] [def j] [keyword in] [number 0][punctuation ..][operator <][number 3] [punctuation {] [punctuation }]");
// Strings and string interpolation.
MT("strings",
"[keyword var] [def a][punctuation :] [variable-2 String] [operator =] [string \"test\"]",
"[keyword var] [def b][punctuation :] [variable-2 String] [operator =] [string \"\\(][variable a][string )\"]",
"[keyword var] [def c] [operator =] [string \"\"\"]",
"[string multi]",
"[string line]",
"[string \"test\"]",
"[string \"\"\"]",
"[variable print][punctuation (][string \"\"][punctuation )]");
// Comments.
MT("comments",
"[comment // This is a comment]",
"[comment /* This is another comment */]",
"[keyword var] [def a] [operator =] [number 5] [comment // Third comment]");
// Atoms.
MT("atoms",
"[keyword class] [def FooClass] [punctuation {]",
" [keyword let] [def fooBool][punctuation :] [variable-2 Bool][operator ?]",
" [keyword let] [def fooInt][punctuation :] [variable-2 Int][operator ?]",
" [keyword func] [keyword init][punctuation (][variable fooBool][punctuation :] [variable-2 Bool][punctuation ,] [variable barBool][punctuation :] [variable-2 Bool][punctuation )] [punctuation {]",
" [atom super][property .init][punctuation ()]",
" [atom self][property .fooBool] [operator =] [variable fooBool]",
" [variable fooInt] [operator =] [atom nil]",
" [keyword if] [variable barBool] [operator ==] [atom true] [punctuation {]",
" [variable print][punctuation (][string \"True!\"][punctuation )]",
" [punctuation }] [keyword else] [keyword if] [variable barBool] [operator ==] [atom false] [punctuation {]",
" [keyword for] [atom _] [keyword in] [number 0][punctuation ...][number 5] [punctuation {]",
" [variable print][punctuation (][string \"False!\"][punctuation )]",
" [punctuation }]",
" [punctuation }]",
" [punctuation }]",
"[punctuation }]");
// Types.
MT("types",
"[keyword var] [def a] [operator =] [variable-2 Array][operator <][variable-2 Int][operator >]",
"[keyword var] [def b] [operator =] [variable-2 Set][operator <][variable-2 Bool][operator >]",
"[keyword var] [def c] [operator =] [variable-2 Dictionary][operator <][variable-2 String][punctuation ,][variable-2 Character][operator >]",
"[keyword var] [def d][punctuation :] [variable-2 Int64][operator ?] [operator =] [variable-2 Optional][punctuation (][number 8][punctuation )]",
"[keyword func] [def e][punctuation ()] [operator ->] [variable-2 Void] [punctuation {]",
" [keyword var] [def e1][punctuation :] [variable-2 Float] [operator =] [number 1.2]",
"[punctuation }]",
"[keyword func] [def f][punctuation ()] [operator ->] [variable-2 Never] [punctuation {]",
" [keyword var] [def f1][punctuation :] [variable-2 Double] [operator =] [number 2.4]",
"[punctuation }]");
// Operators.
MT("operators",
"[keyword var] [def a] [operator =] [number 1] [operator +] [number 2]",
"[keyword var] [def b] [operator =] [number 1] [operator -] [number 2]",
"[keyword var] [def c] [operator =] [number 1] [operator *] [number 2]",
"[keyword var] [def d] [operator =] [number 1] [operator /] [number 2]",
"[keyword var] [def e] [operator =] [number 1] [operator %] [number 2]",
"[keyword var] [def f] [operator =] [number 1] [operator |] [number 2]",
"[keyword var] [def g] [operator =] [number 1] [operator &] [number 2]",
"[keyword var] [def h] [operator =] [number 1] [operator <<] [number 2]",
"[keyword var] [def i] [operator =] [number 1] [operator >>] [number 2]",
"[keyword var] [def j] [operator =] [number 1] [operator ^] [number 2]",
"[keyword var] [def k] [operator =] [operator ~][number 1]",
"[keyword var] [def l] [operator =] [variable foo] [operator ?] [number 1] [punctuation :] [number 2]",
"[keyword var] [def m][punctuation :] [variable-2 Int] [operator =] [variable-2 Optional][punctuation (][number 8][punctuation )][operator !]");
// Punctuation.
MT("punctuation",
"[keyword let] [def a] [operator =] [number 1][punctuation ;] [keyword let] [def b] [operator =] [number 2]",
"[keyword let] [def testArr][punctuation :] [punctuation [[][variable-2 Int][punctuation ]]] [operator =] [punctuation [[][variable a][punctuation ,] [variable b][punctuation ]]]",
"[keyword for] [def i] [keyword in] [number 0][punctuation ..][operator <][variable testArr][property .count] [punctuation {]",
" [variable print][punctuation (][variable testArr][punctuation [[][variable i][punctuation ]])]",
"[punctuation }]");
// Identifiers.
MT("identifiers",
"[keyword let] [def abc] [operator =] [number 1]",
"[keyword let] [def ABC] [operator =] [number 2]",
"[keyword let] [def _123] [operator =] [number 3]",
"[keyword let] [def _$1$2$3] [operator =] [number 4]",
"[keyword let] [def A1$_c32_$_] [operator =] [number 5]",
"[keyword let] [def `var`] [operator =] [punctuation [[][number 1][punctuation ,] [number 2][punctuation ,] [number 3][punctuation ]]]",
"[keyword let] [def square$] [operator =] [variable `var`][property .map] [punctuation {][variable $0] [operator *] [variable $0][punctuation }]",
"$$ [number 1][variable a] $[atom _] [variable _$] [variable __] `[variable a] [variable b]`");
// Properties.
MT("properties",
"[variable print][punctuation (][variable foo][property .abc][punctuation )]",
"[variable print][punctuation (][variable foo][property .ABC][punctuation )]",
"[variable print][punctuation (][variable foo][property ._123][punctuation )]",
"[variable print][punctuation (][variable foo][property ._$1$2$3][punctuation )]",
"[variable print][punctuation (][variable foo][property .A1$_c32_$_][punctuation )]",
"[variable print][punctuation (][variable foo][property .`var`][punctuation )]",
"[variable print][punctuation (][variable foo][property .__][punctuation )]");
// Instructions or other things that start with #.
MT("instructions",
"[keyword if] [builtin #available][punctuation (][variable iOS] [number 9][punctuation ,] [operator *][punctuation )] [punctuation {}]",
"[variable print][punctuation (][builtin #file][punctuation ,] [builtin #function][punctuation )]",
"[variable print][punctuation (][builtin #line][punctuation ,] [builtin #column][punctuation )]",
"[builtin #if] [atom true]",
"[keyword import] [def A]",
"[builtin #elseif] [atom false]",
"[keyword import] [def B]",
"[builtin #endif]",
"[builtin #sourceLocation][punctuation (][variable file][punctuation :] [string \"file.swift\"][punctuation ,] [variable line][punctuation :] [number 2][punctuation )]");
// Attributes; things that start with @.
MT("attributes",
"[attribute @objc][punctuation (][variable objcFoo][punctuation :)]",
"[attribute @available][punctuation (][variable iOS][punctuation )]");
// Property/number edge case.
MT("property_number",
"[variable print][punctuation (][variable foo][property ._123][punctuation )]",
"[variable print][punctuation (]")
MT("nested_comments",
"[comment /*]",
"[comment But wait /* this is a nested comment */ for real]",
"[comment /**** let * me * show * you ****/]",
"[comment ///// let / me / show / you /////]",
"[comment */]");
// TODO: correctly identify when multiple variables are being declared
// by use of a comma-separated list.
// TODO: correctly identify when variables are being declared in a tuple.
// TODO: identify protocols as types when used before an extension?
})();