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)
// http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html
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.

View File

@ -599,6 +599,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
cx.marked = "type"
return cont(afterType)
}
if (value == "|" || value == "&") return cont(typeexpr)
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(typeprop, "}", ",;"), poplex, afterType)
@ -680,25 +681,18 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
}
function forspec(type, value) {
if (value == "await") return cont(forspec);
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
if (type == "(") return cont(pushlex(")"), forspec1, poplex);
}
function forspec1(type) {
if (type == "var") return cont(vardef, expect(";"), forspec2);
if (type == ";") return cont(forspec2);
if (type == "variable") return cont(formaybeinof);
return pass(expression, expect(";"), forspec2);
}
function formaybeinof(_type, value) {
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
return cont(maybeoperatorComma, forspec2);
if (type == "var") return cont(vardef, forspec2);
if (type == "variable") return cont(forspec2);
return pass(forspec2)
}
function forspec2(type, value) {
if (type == ";") return cont(forspec3);
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
return pass(expression, expect(";"), forspec3);
}
function forspec3(type) {
if (type != ")") cont(expression);
if (type == ")") return cont()
if (type == ";") return cont(forspec2)
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression, forspec2) }
return pass(expression, forspec2)
}
function functiondef(type, value) {
if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
@ -724,6 +718,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (value == "@") cont(expression, funarg)
if (type == "spread") 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);
}
function classExpression(type, value) {

View File

@ -23,58 +23,50 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
var uChar = "([^\\u0027\\u005C\\uD800-\\uDFFF]|[\\uD800-\\uDFFF][\\uDC00-\\uDFFF])";
var operators = parserConf.operators || wordRegexp([
"[<>]:", "[<>=]=", "<<=?", ">>>?=?", "=>", "->", "\\/\\/",
"[\\\\%*+\\-<>!=\\/^|&\\u00F7\\u22BB]=?", "\\?", "\\$", "~", ":",
"\\u00D7", "\\u2208", "\\u2209", "\\u220B", "\\u220C", "\\u2218",
"\\u221A", "\\u221B", "\\u2229", "\\u222A", "\\u2260", "\\u2264",
"\\u2265", "\\u2286", "\\u2288", "\\u228A", "\\u22C5",
"\\b(in|isa)\\b(?!\.?\\()"], "");
"[<>]:", "[<>=]=", "<<=?", ">>>?=?", "=>", "->", "\\/\\/",
"[\\\\%*+\\-<>!=\\/^|&\\u00F7\\u22BB]=?", "\\?", "\\$", "~", ":",
"\\u00D7", "\\u2208", "\\u2209", "\\u220B", "\\u220C", "\\u2218",
"\\u221A", "\\u221B", "\\u2229", "\\u222A", "\\u2260", "\\u2264",
"\\u2265", "\\u2286", "\\u2288", "\\u228A", "\\u22C5",
"\\b(in|isa)\\b(?!\.?\\()"], "");
var delimiters = parserConf.delimiters || /^[;,()[\]{}]/;
var identifiers = parserConf.identifiers ||
/^[_A-Za-z\u00A1-\u2217\u2219-\uFFFF][\w\u00A1-\u2217\u2219-\uFFFF]*!*/;
/^[_A-Za-z\u00A1-\u2217\u2219-\uFFFF][\w\u00A1-\u2217\u2219-\uFFFF]*!*/;
var chars = wordRegexp([octChar, hexChar, sChar, uChar], "'");
var commonOpeners = ["begin", "function", "type", "struct", "immutable",
"let", "macro", "for", "while", "quote", "if", "else", "elseif", "try",
"finally", "catch", "do"];
var openersList = ["begin", "function", "type", "struct", "immutable", "let",
"macro", "for", "while", "quote", "if", "else", "elseif", "try",
"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",
"let", "end", "do", "try", "catch", "finally", "return", "break",
"continue", "global", "local", "const", "export", "import", "importall",
"using", "function", "where", "macro", "module", "baremodule", "struct",
"type", "mutable", "immutable", "quote", "typealias", "abstract",
"primitive", "bitstype"];
var keywordsList = ["if", "else", "elseif", "while", "for", "begin", "let",
"end", "do", "try", "catch", "finally", "return", "break", "continue",
"global", "local", "const", "export", "import", "importall", "using",
"function", "where", "macro", "module", "baremodule", "struct", "type",
"mutable", "immutable", "quote", "typealias", "abstract", "primitive",
"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 closers = wordRegexp(commonClosers);
var keywords = wordRegexp(commonKeywords);
var builtins = wordRegexp(commonBuiltins);
var openers = wordRegexp(openersList);
var closers = wordRegexp(closersList);
var keywords = wordRegexp(keywordsList);
var builtins = wordRegexp(builtinsList);
var macro = /^@[_A-Za-z][\w]*/;
var symbol = /^:[_A-Za-z\u00A1-\uFFFF][\w\u00A1-\uFFFF]*!*/;
var stringPrefixes = /^(`|([_A-Za-z\u00A1-\uFFFF]*"("")?))/;
function inArray(state) {
return inGenerator(state, '[')
return (state.nestedArrays > 0);
}
function inGenerator(state, bracket, depth) {
if (typeof(bracket) === "undefined") { bracket = '('; }
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 inGenerator(state) {
return (state.nestedGenerators > 0);
}
function currentScope(state, n) {
@ -126,16 +118,19 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
if (ch === '[') {
state.scopes.push('[');
state.nestedArrays++;
}
if (ch === '(') {
state.scopes.push('(');
state.nestedGenerators++;
}
if (inArray(state) && ch === ']') {
if (currentScope(state) === "if") { state.scopes.pop(); }
while (currentScope(state) === "for") { state.scopes.pop(); }
state.scopes.pop();
state.nestedArrays--;
state.leavingExpr = true;
}
@ -143,6 +138,7 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
if (currentScope(state) === "if") { state.scopes.pop(); }
while (currentScope(state) === "for") { state.scopes.pop(); }
state.scopes.pop();
state.nestedGenerators--;
state.leavingExpr = true;
}
@ -156,14 +152,12 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
}
var match;
if (match = stream.match(openers)) {
if (match = stream.match(openers, false)) {
state.scopes.push(match[0]);
return "keyword";
}
if (stream.match(closers)) {
if (stream.match(closers, false)) {
state.scopes.pop();
return "keyword";
}
// Handle type annotations
@ -307,13 +301,13 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
function tokenAnnotation(stream, state) {
stream.match(/.*?(?=,|;|{|}|\(|\)|=|$|\s)/);
if (stream.match(/^{/)) {
state.nestedLevels++;
} else if (stream.match(/^}/)) {
state.nestedLevels--;
state.nestedParameters++;
} else if (stream.match(/^}/) && state.nestedParameters > 0) {
state.nestedParameters--;
}
if (state.nestedLevels > 0) {
if (state.nestedParameters > 0) {
stream.match(/.*?(?={|})/) || stream.next();
} else if (state.nestedLevels == 0) {
} else if (state.nestedParameters == 0) {
state.tokenize = tokenBase;
}
return "builtin";
@ -321,14 +315,14 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
function tokenComment(stream, state) {
if (stream.match(/^#=/)) {
state.nestedLevels++;
state.nestedComments++;
}
if (!stream.match(/.*?(?=(#=|=#))/)) {
stream.skipToEnd();
}
if (stream.match(/^=#/)) {
state.nestedLevels--;
if (state.nestedLevels == 0)
state.nestedComments--;
if (state.nestedComments == 0)
state.tokenize = tokenBase;
}
return "comment";
@ -391,7 +385,10 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
lastToken: null,
leavingExpr: false,
isDefinition: false,
nestedLevels: 0,
nestedArrays: 0,
nestedComments: 0,
nestedGenerators: 0,
nestedParameters: 0,
charsAdvanced: 0,
firstParenPos: -1
};

View File

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

File diff suppressed because one or more lines are too long

View File

@ -28,61 +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
}
func funWithStrings() {
var numLines = 3
print("This is a string!")
print("""
This is a
multi-line
string!
""")
print("The preceding string had \(numLines) lines!")
}
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

@ -73,8 +73,9 @@
stream.match("..")
return "punctuation"
}
if (ch = stream.match(/("{3}|"|')/)) {
var tokenize = tokenString(ch[0])
var stringMatch
if (stringMatch = stream.match(/("""|"|')/)) {
var tokenize = tokenString.bind(null, stringMatch[0])
state.tokenize.push(tokenize)
return tokenize(stream, state)
}
@ -115,29 +116,29 @@
}
}
function tokenString(quote) {
var singleLine = quote.length == 1
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 (stream.match(quote)) {
state.tokenize.pop()
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"
} else {
escaped = ch == "\\"
}
}
if (singleLine) {
escaped = false
} else if (stream.match(openQuote)) {
state.tokenize.pop()
return "string"
} else {
stream.next()
escaped = ch == "\\"
}
return "string"
}
if (singleLine) {
state.tokenize.pop()
}
return "string"
}
function tokenComment(stream, state) {

View File

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

View File

@ -25,16 +25,16 @@ CodeMirror.defineMode("vb", function(conf, parserConf) {
var tripleDelimiters = new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))");
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 middleKeywords = ['else','elseif','case', 'catch'];
var openingKeywords = ['class','module', 'sub','enum','select','while','if','function', 'get','set','property', 'try', 'structure', 'synclock', 'using', 'with'];
var middleKeywords = ['else','elseif','case', 'catch', 'finally'];
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 commonKeywords = ['as', 'dim', 'break', 'continue','optional', 'then', 'until',
'goto', 'byval','byref','new','handles','property', 'return',
'const','private', 'protected', 'friend', 'public', 'shared', 'static', 'true','false'];
var commontypes = ['integer','string','double','decimal','boolean','short','char', 'float','single'];
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"];
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 types = wordRegexp(commontypes);