Update CodeMirror

This commit is contained in:
Konrad Borowski 2019-04-23 07:15:56 +02:00
parent f7aa492603
commit 23d58b5a0a
10 changed files with 117 additions and 151 deletions

File diff suppressed because one or more lines are too long

View File

@ -284,7 +284,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
// and those that end in _t (Reserved by POSIX for types) // and those that end in _t (Reserved by POSIX for types)
// http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html // http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html
function cTypes(identifier) { function cTypes(identifier) {
return contains(basicCTypes, identifier) || /.+_t/.test(identifier); return contains(basicCTypes, identifier) || /.+_t$/.test(identifier);
} }
// Returns true if identifier is a "Objective C" type. // Returns true if identifier is a "Objective C" type.

View File

@ -599,6 +599,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
cx.marked = "type" cx.marked = "type"
return cont(afterType) return cont(afterType)
} }
if (value == "|" || value == "&") return cont(typeexpr)
if (type == "string" || type == "number" || type == "atom") return cont(afterType); if (type == "string" || type == "number" || type == "atom") return cont(afterType);
if (type == "[") return cont(pushlex("]"), commasep(typeexpr, "]", ","), poplex, afterType) if (type == "[") return cont(pushlex("]"), commasep(typeexpr, "]", ","), poplex, afterType)
if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType) if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType)
@ -680,25 +681,18 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
} }
function forspec(type, value) { function forspec(type, value) {
if (value == "await") return cont(forspec); if (value == "await") return cont(forspec);
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex); if (type == "(") return cont(pushlex(")"), forspec1, poplex);
} }
function forspec1(type) { function forspec1(type) {
if (type == "var") return cont(vardef, expect(";"), forspec2); if (type == "var") return cont(vardef, forspec2);
if (type == ";") return cont(forspec2); if (type == "variable") return cont(forspec2);
if (type == "variable") return cont(formaybeinof); return pass(forspec2)
return pass(expression, expect(";"), forspec2);
}
function formaybeinof(_type, value) {
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
return cont(maybeoperatorComma, forspec2);
} }
function forspec2(type, value) { function forspec2(type, value) {
if (type == ";") return cont(forspec3); if (type == ")") return cont()
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); } if (type == ";") return cont(forspec2)
return pass(expression, expect(";"), forspec3); if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression, forspec2) }
} return pass(expression, forspec2)
function forspec3(type) {
if (type != ")") cont(expression);
} }
function functiondef(type, value) { function functiondef(type, value) {
if (value == "*") {cx.marked = "keyword"; return cont(functiondef);} if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
@ -724,6 +718,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (value == "@") cont(expression, funarg) if (value == "@") cont(expression, funarg)
if (type == "spread") return cont(funarg); if (type == "spread") return cont(funarg);
if (isTS && isModifier(value)) { cx.marked = "keyword"; return cont(funarg); } if (isTS && isModifier(value)) { cx.marked = "keyword"; return cont(funarg); }
if (isTS && type == "this") return cont(maybetype, maybeAssign)
return pass(pattern, maybetype, maybeAssign); return pass(pattern, maybetype, maybeAssign);
} }
function classExpression(type, value) { function classExpression(type, value) {

View File

@ -35,46 +35,38 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
var chars = wordRegexp([octChar, hexChar, sChar, uChar], "'"); var chars = wordRegexp([octChar, hexChar, sChar, uChar], "'");
var commonOpeners = ["begin", "function", "type", "struct", "immutable", var openersList = ["begin", "function", "type", "struct", "immutable", "let",
"let", "macro", "for", "while", "quote", "if", "else", "elseif", "try", "macro", "for", "while", "quote", "if", "else", "elseif", "try",
"finally", "catch", "do"]; "finally", "catch", "do"];
var commonClosers = ["end", "else", "elseif", "catch", "finally"]; var closersList = ["end", "else", "elseif", "catch", "finally"];
var commonKeywords = ["if", "else", "elseif", "while", "for", "begin", var keywordsList = ["if", "else", "elseif", "while", "for", "begin", "let",
"let", "end", "do", "try", "catch", "finally", "return", "break", "end", "do", "try", "catch", "finally", "return", "break", "continue",
"continue", "global", "local", "const", "export", "import", "importall", "global", "local", "const", "export", "import", "importall", "using",
"using", "function", "where", "macro", "module", "baremodule", "struct", "function", "where", "macro", "module", "baremodule", "struct", "type",
"type", "mutable", "immutable", "quote", "typealias", "abstract", "mutable", "immutable", "quote", "typealias", "abstract", "primitive",
"primitive", "bitstype"]; "bitstype"];
var commonBuiltins = ["true", "false", "nothing", "NaN", "Inf"]; var builtinsList = ["true", "false", "nothing", "NaN", "Inf"];
CodeMirror.registerHelper("hintWords", "julia", commonKeywords.concat(commonBuiltins)); CodeMirror.registerHelper("hintWords", "julia", keywordsList.concat(builtinsList));
var openers = wordRegexp(commonOpeners); var openers = wordRegexp(openersList);
var closers = wordRegexp(commonClosers); var closers = wordRegexp(closersList);
var keywords = wordRegexp(commonKeywords); var keywords = wordRegexp(keywordsList);
var builtins = wordRegexp(commonBuiltins); var builtins = wordRegexp(builtinsList);
var macro = /^@[_A-Za-z][\w]*/; var macro = /^@[_A-Za-z][\w]*/;
var symbol = /^:[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/; var symbol = /^:[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/;
var stringPrefixes = /^(`|([_A-Za-z\u00A1-\uFFFF]*"("")?))/; var stringPrefixes = /^(`|([_A-Za-z\u00A1-\uFFFF]*"("")?))/;
function inArray(state) { function inArray(state) {
return inGenerator(state, '[') return (state.nestedArrays > 0);
} }
function inGenerator(state, bracket, depth) { function inGenerator(state) {
if (typeof(bracket) === "undefined") { bracket = '('; } return (state.nestedGenerators > 0);
if (typeof(depth) === "undefined") { depth = 0; }
var scope = currentScope(state, depth);
if ((depth == 0 && scope === "if" && inGenerator(state, bracket, depth + 1)) ||
(scope === "for" && inGenerator(state, bracket, depth + 1)) ||
(scope === bracket)) {
return true;
}
return false;
} }
function currentScope(state, n) { function currentScope(state, n) {
@ -126,16 +118,19 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
if (ch === '[') { if (ch === '[') {
state.scopes.push('['); state.scopes.push('[');
state.nestedArrays++;
} }
if (ch === '(') { if (ch === '(') {
state.scopes.push('('); state.scopes.push('(');
state.nestedGenerators++;
} }
if (inArray(state) && ch === ']') { if (inArray(state) && ch === ']') {
if (currentScope(state) === "if") { state.scopes.pop(); } if (currentScope(state) === "if") { state.scopes.pop(); }
while (currentScope(state) === "for") { state.scopes.pop(); } while (currentScope(state) === "for") { state.scopes.pop(); }
state.scopes.pop(); state.scopes.pop();
state.nestedArrays--;
state.leavingExpr = true; state.leavingExpr = true;
} }
@ -143,6 +138,7 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
if (currentScope(state) === "if") { state.scopes.pop(); } if (currentScope(state) === "if") { state.scopes.pop(); }
while (currentScope(state) === "for") { state.scopes.pop(); } while (currentScope(state) === "for") { state.scopes.pop(); }
state.scopes.pop(); state.scopes.pop();
state.nestedGenerators--;
state.leavingExpr = true; state.leavingExpr = true;
} }
@ -156,14 +152,12 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
} }
var match; var match;
if (match = stream.match(openers)) { if (match = stream.match(openers, false)) {
state.scopes.push(match[0]); state.scopes.push(match[0]);
return "keyword";
} }
if (stream.match(closers)) { if (stream.match(closers, false)) {
state.scopes.pop(); state.scopes.pop();
return "keyword";
} }
// Handle type annotations // Handle type annotations
@ -307,13 +301,13 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
function tokenAnnotation(stream, state) { function tokenAnnotation(stream, state) {
stream.match(/.*?(?=,|;|{|}|\(|\)|=|$|\s)/); stream.match(/.*?(?=,|;|{|}|\(|\)|=|$|\s)/);
if (stream.match(/^{/)) { if (stream.match(/^{/)) {
state.nestedLevels++; state.nestedParameters++;
} else if (stream.match(/^}/)) { } else if (stream.match(/^}/) && state.nestedParameters > 0) {
state.nestedLevels--; state.nestedParameters--;
} }
if (state.nestedLevels > 0) { if (state.nestedParameters > 0) {
stream.match(/.*?(?={|})/) || stream.next(); stream.match(/.*?(?={|})/) || stream.next();
} else if (state.nestedLevels == 0) { } else if (state.nestedParameters == 0) {
state.tokenize = tokenBase; state.tokenize = tokenBase;
} }
return "builtin"; return "builtin";
@ -321,14 +315,14 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
function tokenComment(stream, state) { function tokenComment(stream, state) {
if (stream.match(/^#=/)) { if (stream.match(/^#=/)) {
state.nestedLevels++; state.nestedComments++;
} }
if (!stream.match(/.*?(?=(#=|=#))/)) { if (!stream.match(/.*?(?=(#=|=#))/)) {
stream.skipToEnd(); stream.skipToEnd();
} }
if (stream.match(/^=#/)) { if (stream.match(/^=#/)) {
state.nestedLevels--; state.nestedComments--;
if (state.nestedLevels == 0) if (state.nestedComments == 0)
state.tokenize = tokenBase; state.tokenize = tokenBase;
} }
return "comment"; return "comment";
@ -391,7 +385,10 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
lastToken: null, lastToken: null,
leavingExpr: false, leavingExpr: false,
isDefinition: false, isDefinition: false,
nestedLevels: 0, nestedArrays: 0,
nestedComments: 0,
nestedGenerators: 0,
nestedParameters: 0,
charsAdvanced: 0, charsAdvanced: 0,
firstParenPos: -1 firstParenPos: -1
}; };

View File

@ -13,7 +13,7 @@
var indentingTags = ["template", "literal", "msg", "fallbackmsg", "let", "if", "elseif", var indentingTags = ["template", "literal", "msg", "fallbackmsg", "let", "if", "elseif",
"else", "switch", "case", "default", "foreach", "ifempty", "for", "else", "switch", "case", "default", "foreach", "ifempty", "for",
"call", "param", "deltemplate", "delcall", "log"]; "call", "param", "deltemplate", "delcall", "log", "element"];
CodeMirror.defineMode("soy", function(config) { CodeMirror.defineMode("soy", function(config) {
var textMode = CodeMirror.getMode(config, "text/plain"); var textMode = CodeMirror.getMode(config, "text/plain");
@ -328,7 +328,7 @@
if (!state.scopes) { if (!state.scopes) {
state.variables = prepend(null, 'ij'); state.variables = prepend(null, 'ij');
} }
} else if (state.tag.match(/^@(?:param\??|inject|prop)/)) { } else if (state.tag.match(/^@(?:param\??|inject|state)/)) {
state.soyState.push("param-def"); state.soyState.push("param-def");
} else if (state.tag.match(/^(?:param)/)) { } else if (state.tag.match(/^(?:param)/)) {
state.soyState.push("param-ref"); state.soyState.push("param-ref");

File diff suppressed because one or more lines are too long

View File

@ -28,61 +28,32 @@
<article> <article>
<h2>Swift mode</h2> <h2>Swift mode</h2>
<form><textarea id="code" name="code"> <form><textarea id="code" name="code">
// protocol HeaderViewProtocol {
// TipCalculatorModel.swift func setTitle(_ string: String)
// 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
}
func funWithStrings() {
var numLines = 3
print("This is a string!")
print("""
This is a
multi-line
string!
""")
print("The preceding string had \(numLines) lines!")
}
} }
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> </textarea></form>
<script> <script>

View File

@ -73,8 +73,9 @@
stream.match("..") stream.match("..")
return "punctuation" return "punctuation"
} }
if (ch = stream.match(/("{3}|"|')/)) { var stringMatch
var tokenize = tokenString(ch[0]) if (stringMatch = stream.match(/("""|"|')/)) {
var tokenize = tokenString.bind(null, stringMatch[0])
state.tokenize.push(tokenize) state.tokenize.push(tokenize)
return tokenize(stream, state) return tokenize(stream, state)
} }
@ -115,21 +116,22 @@
} }
} }
function tokenString(quote) { function tokenString(openQuote, stream, state) {
var singleLine = quote.length == 1 var singleLine = openQuote.length == 1
return function(stream, state) {
var ch, escaped = false var ch, escaped = false
while (ch = stream.next()) { while (ch = stream.peek()) {
if (escaped) { if (escaped) {
stream.next()
if (ch == "(") { if (ch == "(") {
state.tokenize.push(tokenUntilClosingParen()) state.tokenize.push(tokenUntilClosingParen())
return "string" return "string"
} }
escaped = false escaped = false
} else if (stream.match(quote)) { } else if (stream.match(openQuote)) {
state.tokenize.pop() state.tokenize.pop()
return "string" return "string"
} else { } else {
stream.next()
escaped = ch == "\\" escaped = ch == "\\"
} }
} }
@ -138,7 +140,6 @@
} }
return "string" return "string"
} }
}
function tokenComment(stream, state) { function tokenComment(stream, state) {
var ch var ch

View File

@ -40,7 +40,8 @@
"[string multi]", "[string multi]",
"[string line]", "[string line]",
"[string \"test\"]", "[string \"test\"]",
"[string \"\"\"]"); "[string \"\"\"]",
"[variable print][punctuation (][string \"\"][punctuation )]");
// Comments. // Comments.
MT("comments", MT("comments",

View File

@ -25,16 +25,16 @@ CodeMirror.defineMode("vb", function(conf, parserConf) {
var tripleDelimiters = new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))"); var tripleDelimiters = new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))");
var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*"); var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
var openingKeywords = ['class','module', 'sub','enum','select','while','if','function', 'get','set','property', 'try']; var openingKeywords = ['class','module', 'sub','enum','select','while','if','function', 'get','set','property', 'try', 'structure', 'synclock', 'using', 'with'];
var middleKeywords = ['else','elseif','case', 'catch']; var middleKeywords = ['else','elseif','case', 'catch', 'finally'];
var endKeywords = ['next','loop']; var endKeywords = ['next','loop'];
var operatorKeywords = ['and', 'or', 'not', 'xor', 'in']; var operatorKeywords = ['and', "andalso", 'or', 'orelse', 'xor', 'in', 'not', 'is', 'isnot', 'like'];
var wordOperators = wordRegexp(operatorKeywords); var wordOperators = wordRegexp(operatorKeywords);
var commonKeywords = ['as', 'dim', 'break', 'continue','optional', 'then', 'until',
'goto', 'byval','byref','new','handles','property', 'return', var commonKeywords = ["#const", "#else", "#elseif", "#end", "#if", "#region", "addhandler", "addressof", "alias", "as", "byref", "byval", "cbool", "cbyte", "cchar", "cdate", "cdbl", "cdec", "cint", "clng", "cobj", "compare", "const", "continue", "csbyte", "cshort", "csng", "cstr", "cuint", "culng", "cushort", "declare", "default", "delegate", "dim", "directcast", "each", "erase", "error", "event", "exit", "explicit", "false", "for", "friend", "gettype", "goto", "handles", "implements", "imports", "infer", "inherits", "interface", "isfalse", "istrue", "lib", "me", "mod", "mustinherit", "mustoverride", "my", "mybase", "myclass", "namespace", "narrowing", "new", "nothing", "notinheritable", "notoverridable", "of", "off", "on", "operator", "option", "optional", "out", "overloads", "overridable", "overrides", "paramarray", "partial", "private", "protected", "public", "raiseevent", "readonly", "redim", "removehandler", "resume", "return", "shadows", "shared", "static", "step", "stop", "strict", "then", "throw", "to", "true", "trycast", "typeof", "until", "until", "when", "widening", "withevents", "writeonly"];
'const','private', 'protected', 'friend', 'public', 'shared', 'static', 'true','false'];
var commontypes = ['integer','string','double','decimal','boolean','short','char', 'float','single']; var commontypes = ['object', 'boolean', 'char', 'string', 'byte', 'sbyte', 'short', 'ushort', 'int16', 'uint16', 'integer', 'uinteger', 'int32', 'uint32', 'long', 'ulong', 'int64', 'uint64', 'decimal', 'single', 'double', 'float', 'date', 'datetime', 'intptr', 'uintptr'];
var keywords = wordRegexp(commonKeywords); var keywords = wordRegexp(commonKeywords);
var types = wordRegexp(commontypes); var types = wordRegexp(commontypes);