国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

941 lines
36KB

  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/5/LICENSE
  3. (function(mod) {
  4. if (typeof exports == "object" && typeof module == "object") // CommonJS
  5. mod(require("../../lib/codemirror"));
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror"], mod);
  8. else // Plain browser env
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. "use strict";
  12. function Context(indented, column, type, info, align, prev) {
  13. this.indented = indented;
  14. this.column = column;
  15. this.type = type;
  16. this.info = info;
  17. this.align = align;
  18. this.prev = prev;
  19. }
  20. function pushContext(state, col, type, info) {
  21. var indent = state.indented;
  22. if (state.context && state.context.type == "statement" && type != "statement")
  23. indent = state.context.indented;
  24. return state.context = new Context(indent, col, type, info, null, state.context);
  25. }
  26. function popContext(state) {
  27. var t = state.context.type;
  28. if (t == ")" || t == "]" || t == "}")
  29. state.indented = state.context.indented;
  30. return state.context = state.context.prev;
  31. }
  32. function typeBefore(stream, state, pos) {
  33. if (state.prevToken == "variable" || state.prevToken == "type") return true;
  34. if (/\S(?:[^- ]>|[*\]])\s*$|\*$/.test(stream.string.slice(0, pos))) return true;
  35. if (state.typeAtEndOfLine && stream.column() == stream.indentation()) return true;
  36. }
  37. function isTopScope(context) {
  38. for (;;) {
  39. if (!context || context.type == "top") return true;
  40. if (context.type == "}" && context.prev.info != "namespace") return false;
  41. context = context.prev;
  42. }
  43. }
  44. CodeMirror.defineMode("clike", function(config, parserConfig) {
  45. var indentUnit = config.indentUnit,
  46. statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
  47. dontAlignCalls = parserConfig.dontAlignCalls,
  48. keywords = parserConfig.keywords || {},
  49. types = parserConfig.types || {},
  50. builtin = parserConfig.builtin || {},
  51. blockKeywords = parserConfig.blockKeywords || {},
  52. defKeywords = parserConfig.defKeywords || {},
  53. atoms = parserConfig.atoms || {},
  54. hooks = parserConfig.hooks || {},
  55. multiLineStrings = parserConfig.multiLineStrings,
  56. indentStatements = parserConfig.indentStatements !== false,
  57. indentSwitch = parserConfig.indentSwitch !== false,
  58. namespaceSeparator = parserConfig.namespaceSeparator,
  59. isPunctuationChar = parserConfig.isPunctuationChar || /[\[\]{}\(\),;\:\.]/,
  60. numberStart = parserConfig.numberStart || /[\d\.]/,
  61. number = parserConfig.number || /^(?:0x[a-f\d]+|0b[01]+|(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)(u|ll?|l|f)?/i,
  62. isOperatorChar = parserConfig.isOperatorChar || /[+\-*&%=<>!?|\/]/,
  63. isIdentifierChar = parserConfig.isIdentifierChar || /[\w\$_\xa1-\uffff]/,
  64. // An optional function that takes a {string} token and returns true if it
  65. // should be treated as a builtin.
  66. isReservedIdentifier = parserConfig.isReservedIdentifier || false;
  67. var curPunc, isDefKeyword;
  68. function tokenBase(stream, state) {
  69. var ch = stream.next();
  70. if (hooks[ch]) {
  71. var result = hooks[ch](stream, state);
  72. if (result !== false) return result;
  73. }
  74. if (ch == '"' || ch == "'") {
  75. state.tokenize = tokenString(ch);
  76. return state.tokenize(stream, state);
  77. }
  78. if (numberStart.test(ch)) {
  79. stream.backUp(1)
  80. if (stream.match(number)) return "number"
  81. stream.next()
  82. }
  83. if (isPunctuationChar.test(ch)) {
  84. curPunc = ch;
  85. return null;
  86. }
  87. if (ch == "/") {
  88. if (stream.eat("*")) {
  89. state.tokenize = tokenComment;
  90. return tokenComment(stream, state);
  91. }
  92. if (stream.eat("/")) {
  93. stream.skipToEnd();
  94. return "comment";
  95. }
  96. }
  97. if (isOperatorChar.test(ch)) {
  98. while (!stream.match(/^\/[\/*]/, false) && stream.eat(isOperatorChar)) {}
  99. return "operator";
  100. }
  101. stream.eatWhile(isIdentifierChar);
  102. if (namespaceSeparator) while (stream.match(namespaceSeparator))
  103. stream.eatWhile(isIdentifierChar);
  104. var cur = stream.current();
  105. if (contains(keywords, cur)) {
  106. if (contains(blockKeywords, cur)) curPunc = "newstatement";
  107. if (contains(defKeywords, cur)) isDefKeyword = true;
  108. return "keyword";
  109. }
  110. if (contains(types, cur)) return "type";
  111. if (contains(builtin, cur)
  112. || (isReservedIdentifier && isReservedIdentifier(cur))) {
  113. if (contains(blockKeywords, cur)) curPunc = "newstatement";
  114. return "builtin";
  115. }
  116. if (contains(atoms, cur)) return "atom";
  117. return "variable";
  118. }
  119. function tokenString(quote) {
  120. return function(stream, state) {
  121. var escaped = false, next, end = false;
  122. while ((next = stream.next()) != null) {
  123. if (next == quote && !escaped) {end = true; break;}
  124. escaped = !escaped && next == "\\";
  125. }
  126. if (end || !(escaped || multiLineStrings))
  127. state.tokenize = null;
  128. return "string";
  129. };
  130. }
  131. function tokenComment(stream, state) {
  132. var maybeEnd = false, ch;
  133. while (ch = stream.next()) {
  134. if (ch == "/" && maybeEnd) {
  135. state.tokenize = null;
  136. break;
  137. }
  138. maybeEnd = (ch == "*");
  139. }
  140. return "comment";
  141. }
  142. function maybeEOL(stream, state) {
  143. if (parserConfig.typeFirstDefinitions && stream.eol() && isTopScope(state.context))
  144. state.typeAtEndOfLine = typeBefore(stream, state, stream.pos)
  145. }
  146. // Interface
  147. return {
  148. startState: function(basecolumn) {
  149. return {
  150. tokenize: null,
  151. context: new Context((basecolumn || 0) - indentUnit, 0, "top", null, false),
  152. indented: 0,
  153. startOfLine: true,
  154. prevToken: null
  155. };
  156. },
  157. token: function(stream, state) {
  158. var ctx = state.context;
  159. if (stream.sol()) {
  160. if (ctx.align == null) ctx.align = false;
  161. state.indented = stream.indentation();
  162. state.startOfLine = true;
  163. }
  164. if (stream.eatSpace()) { maybeEOL(stream, state); return null; }
  165. curPunc = isDefKeyword = null;
  166. var style = (state.tokenize || tokenBase)(stream, state);
  167. if (style == "comment" || style == "meta") return style;
  168. if (ctx.align == null) ctx.align = true;
  169. if (curPunc == ";" || curPunc == ":" || (curPunc == "," && stream.match(/^\s*(?:\/\/.*)?$/, false)))
  170. while (state.context.type == "statement") popContext(state);
  171. else if (curPunc == "{") pushContext(state, stream.column(), "}");
  172. else if (curPunc == "[") pushContext(state, stream.column(), "]");
  173. else if (curPunc == "(") pushContext(state, stream.column(), ")");
  174. else if (curPunc == "}") {
  175. while (ctx.type == "statement") ctx = popContext(state);
  176. if (ctx.type == "}") ctx = popContext(state);
  177. while (ctx.type == "statement") ctx = popContext(state);
  178. }
  179. else if (curPunc == ctx.type) popContext(state);
  180. else if (indentStatements &&
  181. (((ctx.type == "}" || ctx.type == "top") && curPunc != ";") ||
  182. (ctx.type == "statement" && curPunc == "newstatement"))) {
  183. pushContext(state, stream.column(), "statement", stream.current());
  184. }
  185. if (style == "variable" &&
  186. ((state.prevToken == "def" ||
  187. (parserConfig.typeFirstDefinitions && typeBefore(stream, state, stream.start) &&
  188. isTopScope(state.context) && stream.match(/^\s*\(/, false)))))
  189. style = "def";
  190. if (hooks.token) {
  191. var result = hooks.token(stream, state, style);
  192. if (result !== undefined) style = result;
  193. }
  194. if (style == "def" && parserConfig.styleDefs === false) style = "variable";
  195. state.startOfLine = false;
  196. state.prevToken = isDefKeyword ? "def" : style || curPunc;
  197. maybeEOL(stream, state);
  198. return style;
  199. },
  200. indent: function(state, textAfter) {
  201. if (state.tokenize != tokenBase && state.tokenize != null || state.typeAtEndOfLine) return CodeMirror.Pass;
  202. var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
  203. var closing = firstChar == ctx.type;
  204. if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
  205. if (parserConfig.dontIndentStatements)
  206. while (ctx.type == "statement" && parserConfig.dontIndentStatements.test(ctx.info))
  207. ctx = ctx.prev
  208. if (hooks.indent) {
  209. var hook = hooks.indent(state, ctx, textAfter, indentUnit);
  210. if (typeof hook == "number") return hook
  211. }
  212. var switchBlock = ctx.prev && ctx.prev.info == "switch";
  213. if (parserConfig.allmanIndentation && /[{(]/.test(firstChar)) {
  214. while (ctx.type != "top" && ctx.type != "}") ctx = ctx.prev
  215. return ctx.indented
  216. }
  217. if (ctx.type == "statement")
  218. return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
  219. if (ctx.align && (!dontAlignCalls || ctx.type != ")"))
  220. return ctx.column + (closing ? 0 : 1);
  221. if (ctx.type == ")" && !closing)
  222. return ctx.indented + statementIndentUnit;
  223. return ctx.indented + (closing ? 0 : indentUnit) +
  224. (!closing && switchBlock && !/^(?:case|default)\b/.test(textAfter) ? indentUnit : 0);
  225. },
  226. electricInput: indentSwitch ? /^\s*(?:case .*?:|default:|\{\}?|\})$/ : /^\s*[{}]$/,
  227. blockCommentStart: "/*",
  228. blockCommentEnd: "*/",
  229. blockCommentContinue: " * ",
  230. lineComment: "//",
  231. fold: "brace"
  232. };
  233. });
  234. function words(str) {
  235. var obj = {}, words = str.split(" ");
  236. for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
  237. return obj;
  238. }
  239. function contains(words, word) {
  240. if (typeof words === "function") {
  241. return words(word);
  242. } else {
  243. return words.propertyIsEnumerable(word);
  244. }
  245. }
  246. var cKeywords = "auto if break case register continue return default do sizeof " +
  247. "static else struct switch extern typedef union for goto while enum const " +
  248. "volatile inline restrict asm fortran";
  249. // Keywords from https://en.cppreference.com/w/cpp/keyword includes C++20.
  250. var cppKeywords = "alignas alignof and and_eq audit axiom bitand bitor catch " +
  251. "class compl concept constexpr const_cast decltype delete dynamic_cast " +
  252. "explicit export final friend import module mutable namespace new noexcept " +
  253. "not not_eq operator or or_eq override private protected public " +
  254. "reinterpret_cast requires static_assert static_cast template this " +
  255. "thread_local throw try typeid typename using virtual xor xor_eq";
  256. var objCKeywords = "bycopy byref in inout oneway out self super atomic nonatomic retain copy " +
  257. "readwrite readonly strong weak assign typeof nullable nonnull null_resettable _cmd " +
  258. "@interface @implementation @end @protocol @encode @property @synthesize @dynamic @class " +
  259. "@public @package @private @protected @required @optional @try @catch @finally @import " +
  260. "@selector @encode @defs @synchronized @autoreleasepool @compatibility_alias @available";
  261. var objCBuiltins = "FOUNDATION_EXPORT FOUNDATION_EXTERN NS_INLINE NS_FORMAT_FUNCTION " +
  262. " NS_RETURNS_RETAINEDNS_ERROR_ENUM NS_RETURNS_NOT_RETAINED NS_RETURNS_INNER_POINTER " +
  263. "NS_DESIGNATED_INITIALIZER NS_ENUM NS_OPTIONS NS_REQUIRES_NIL_TERMINATION " +
  264. "NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END NS_SWIFT_NAME NS_REFINED_FOR_SWIFT"
  265. // Do not use this. Use the cTypes function below. This is global just to avoid
  266. // excessive calls when cTypes is being called multiple times during a parse.
  267. var basicCTypes = words("int long char short double float unsigned signed " +
  268. "void bool");
  269. // Do not use this. Use the objCTypes function below. This is global just to avoid
  270. // excessive calls when objCTypes is being called multiple times during a parse.
  271. var basicObjCTypes = words("SEL instancetype id Class Protocol BOOL");
  272. // Returns true if identifier is a "C" type.
  273. // C type is defined as those that are reserved by the compiler (basicTypes),
  274. // and those that end in _t (Reserved by POSIX for types)
  275. // http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html
  276. function cTypes(identifier) {
  277. return contains(basicCTypes, identifier) || /.+_t$/.test(identifier);
  278. }
  279. // Returns true if identifier is a "Objective C" type.
  280. function objCTypes(identifier) {
  281. return cTypes(identifier) || contains(basicObjCTypes, identifier);
  282. }
  283. var cBlockKeywords = "case do else for if switch while struct enum union";
  284. var cDefKeywords = "struct enum union";
  285. function cppHook(stream, state) {
  286. if (!state.startOfLine) return false
  287. for (var ch, next = null; ch = stream.peek();) {
  288. if (ch == "\\" && stream.match(/^.$/)) {
  289. next = cppHook
  290. break
  291. } else if (ch == "/" && stream.match(/^\/[\/\*]/, false)) {
  292. break
  293. }
  294. stream.next()
  295. }
  296. state.tokenize = next
  297. return "meta"
  298. }
  299. function pointerHook(_stream, state) {
  300. if (state.prevToken == "type") return "type";
  301. return false;
  302. }
  303. // For C and C++ (and ObjC): identifiers starting with __
  304. // or _ followed by a capital letter are reserved for the compiler.
  305. function cIsReservedIdentifier(token) {
  306. if (!token || token.length < 2) return false;
  307. if (token[0] != '_') return false;
  308. return (token[1] == '_') || (token[1] !== token[1].toLowerCase());
  309. }
  310. function cpp14Literal(stream) {
  311. stream.eatWhile(/[\w\.']/);
  312. return "number";
  313. }
  314. function cpp11StringHook(stream, state) {
  315. stream.backUp(1);
  316. // Raw strings.
  317. if (stream.match(/^(?:R|u8R|uR|UR|LR)/)) {
  318. var match = stream.match(/^"([^\s\\()]{0,16})\(/);
  319. if (!match) {
  320. return false;
  321. }
  322. state.cpp11RawStringDelim = match[1];
  323. state.tokenize = tokenRawString;
  324. return tokenRawString(stream, state);
  325. }
  326. // Unicode strings/chars.
  327. if (stream.match(/^(?:u8|u|U|L)/)) {
  328. if (stream.match(/^["']/, /* eat */ false)) {
  329. return "string";
  330. }
  331. return false;
  332. }
  333. // Ignore this hook.
  334. stream.next();
  335. return false;
  336. }
  337. function cppLooksLikeConstructor(word) {
  338. var lastTwo = /(\w+)::~?(\w+)$/.exec(word);
  339. return lastTwo && lastTwo[1] == lastTwo[2];
  340. }
  341. // C#-style strings where "" escapes a quote.
  342. function tokenAtString(stream, state) {
  343. var next;
  344. while ((next = stream.next()) != null) {
  345. if (next == '"' && !stream.eat('"')) {
  346. state.tokenize = null;
  347. break;
  348. }
  349. }
  350. return "string";
  351. }
  352. // C++11 raw string literal is <prefix>"<delim>( anything )<delim>", where
  353. // <delim> can be a string up to 16 characters long.
  354. function tokenRawString(stream, state) {
  355. // Escape characters that have special regex meanings.
  356. var delim = state.cpp11RawStringDelim.replace(/[^\w\s]/g, '\\$&');
  357. var match = stream.match(new RegExp(".*?\\)" + delim + '"'));
  358. if (match)
  359. state.tokenize = null;
  360. else
  361. stream.skipToEnd();
  362. return "string";
  363. }
  364. function def(mimes, mode) {
  365. if (typeof mimes == "string") mimes = [mimes];
  366. var words = [];
  367. function add(obj) {
  368. if (obj) for (var prop in obj) if (obj.hasOwnProperty(prop))
  369. words.push(prop);
  370. }
  371. add(mode.keywords);
  372. add(mode.types);
  373. add(mode.builtin);
  374. add(mode.atoms);
  375. if (words.length) {
  376. mode.helperType = mimes[0];
  377. CodeMirror.registerHelper("hintWords", mimes[0], words);
  378. }
  379. for (var i = 0; i < mimes.length; ++i)
  380. CodeMirror.defineMIME(mimes[i], mode);
  381. }
  382. def(["text/x-csrc", "text/x-c", "text/x-chdr"], {
  383. name: "clike",
  384. keywords: words(cKeywords),
  385. types: cTypes,
  386. blockKeywords: words(cBlockKeywords),
  387. defKeywords: words(cDefKeywords),
  388. typeFirstDefinitions: true,
  389. atoms: words("NULL true false"),
  390. isReservedIdentifier: cIsReservedIdentifier,
  391. hooks: {
  392. "#": cppHook,
  393. "*": pointerHook,
  394. },
  395. modeProps: {fold: ["brace", "include"]}
  396. });
  397. def(["text/x-c++src", "text/x-c++hdr"], {
  398. name: "clike",
  399. keywords: words(cKeywords + " " + cppKeywords),
  400. types: cTypes,
  401. blockKeywords: words(cBlockKeywords + " class try catch"),
  402. defKeywords: words(cDefKeywords + " class namespace"),
  403. typeFirstDefinitions: true,
  404. atoms: words("true false NULL nullptr"),
  405. dontIndentStatements: /^template$/,
  406. isIdentifierChar: /[\w\$_~\xa1-\uffff]/,
  407. isReservedIdentifier: cIsReservedIdentifier,
  408. hooks: {
  409. "#": cppHook,
  410. "*": pointerHook,
  411. "u": cpp11StringHook,
  412. "U": cpp11StringHook,
  413. "L": cpp11StringHook,
  414. "R": cpp11StringHook,
  415. "0": cpp14Literal,
  416. "1": cpp14Literal,
  417. "2": cpp14Literal,
  418. "3": cpp14Literal,
  419. "4": cpp14Literal,
  420. "5": cpp14Literal,
  421. "6": cpp14Literal,
  422. "7": cpp14Literal,
  423. "8": cpp14Literal,
  424. "9": cpp14Literal,
  425. token: function(stream, state, style) {
  426. if (style == "variable" && stream.peek() == "(" &&
  427. (state.prevToken == ";" || state.prevToken == null ||
  428. state.prevToken == "}") &&
  429. cppLooksLikeConstructor(stream.current()))
  430. return "def";
  431. }
  432. },
  433. namespaceSeparator: "::",
  434. modeProps: {fold: ["brace", "include"]}
  435. });
  436. def("text/x-java", {
  437. name: "clike",
  438. keywords: words("abstract assert break case catch class const continue default " +
  439. "do else enum extends final finally for goto if implements import " +
  440. "instanceof interface native new package private protected public " +
  441. "return static strictfp super switch synchronized this throw throws transient " +
  442. "try volatile while @interface"),
  443. types: words("var byte short int long float double boolean char void Boolean Byte Character Double Float " +
  444. "Integer Long Number Object Short String StringBuffer StringBuilder Void"),
  445. blockKeywords: words("catch class do else finally for if switch try while"),
  446. defKeywords: words("class interface enum @interface"),
  447. typeFirstDefinitions: true,
  448. atoms: words("true false null"),
  449. number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+\.?\d*|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i,
  450. hooks: {
  451. "@": function(stream) {
  452. // Don't match the @interface keyword.
  453. if (stream.match('interface', false)) return false;
  454. stream.eatWhile(/[\w\$_]/);
  455. return "meta";
  456. },
  457. '"': function(stream, state) {
  458. if (!stream.match(/""$/)) return false;
  459. state.tokenize = tokenTripleString;
  460. return state.tokenize(stream, state);
  461. }
  462. },
  463. modeProps: {fold: ["brace", "import"]}
  464. });
  465. def("text/x-csharp", {
  466. name: "clike",
  467. keywords: words("abstract as async await base break case catch checked class const continue" +
  468. " default delegate do else enum event explicit extern finally fixed for" +
  469. " foreach goto if implicit in interface internal is lock namespace new" +
  470. " operator out override params private protected public readonly ref return sealed" +
  471. " sizeof stackalloc static struct switch this throw try typeof unchecked" +
  472. " unsafe using virtual void volatile while add alias ascending descending dynamic from get" +
  473. " global group into join let orderby partial remove select set value var yield"),
  474. types: words("Action Boolean Byte Char DateTime DateTimeOffset Decimal Double Func" +
  475. " Guid Int16 Int32 Int64 Object SByte Single String Task TimeSpan UInt16 UInt32" +
  476. " UInt64 bool byte char decimal double short int long object" +
  477. " sbyte float string ushort uint ulong"),
  478. blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
  479. defKeywords: words("class interface namespace struct var"),
  480. typeFirstDefinitions: true,
  481. atoms: words("true false null"),
  482. hooks: {
  483. "@": function(stream, state) {
  484. if (stream.eat('"')) {
  485. state.tokenize = tokenAtString;
  486. return tokenAtString(stream, state);
  487. }
  488. stream.eatWhile(/[\w\$_]/);
  489. return "meta";
  490. }
  491. }
  492. });
  493. function tokenTripleString(stream, state) {
  494. var escaped = false;
  495. while (!stream.eol()) {
  496. if (!escaped && stream.match('"""')) {
  497. state.tokenize = null;
  498. break;
  499. }
  500. escaped = stream.next() == "\\" && !escaped;
  501. }
  502. return "string";
  503. }
  504. function tokenNestedComment(depth) {
  505. return function (stream, state) {
  506. var ch
  507. while (ch = stream.next()) {
  508. if (ch == "*" && stream.eat("/")) {
  509. if (depth == 1) {
  510. state.tokenize = null
  511. break
  512. } else {
  513. state.tokenize = tokenNestedComment(depth - 1)
  514. return state.tokenize(stream, state)
  515. }
  516. } else if (ch == "/" && stream.eat("*")) {
  517. state.tokenize = tokenNestedComment(depth + 1)
  518. return state.tokenize(stream, state)
  519. }
  520. }
  521. return "comment"
  522. }
  523. }
  524. def("text/x-scala", {
  525. name: "clike",
  526. keywords: words(
  527. /* scala */
  528. "abstract case catch class def do else extends final finally for forSome if " +
  529. "implicit import lazy match new null object override package private protected return " +
  530. "sealed super this throw trait try type val var while with yield _ " +
  531. /* package scala */
  532. "assert assume require print println printf readLine readBoolean readByte readShort " +
  533. "readChar readInt readLong readFloat readDouble"
  534. ),
  535. types: words(
  536. "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
  537. "Enumeration Equiv Error Exception Fractional Function IndexedSeq Int Integral Iterable " +
  538. "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
  539. "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
  540. "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector " +
  541. /* package java.lang */
  542. "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
  543. "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
  544. "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
  545. "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
  546. ),
  547. multiLineStrings: true,
  548. blockKeywords: words("catch class enum do else finally for forSome if match switch try while"),
  549. defKeywords: words("class enum def object package trait type val var"),
  550. atoms: words("true false null"),
  551. indentStatements: false,
  552. indentSwitch: false,
  553. isOperatorChar: /[+\-*&%=<>!?|\/#:@]/,
  554. hooks: {
  555. "@": function(stream) {
  556. stream.eatWhile(/[\w\$_]/);
  557. return "meta";
  558. },
  559. '"': function(stream, state) {
  560. if (!stream.match('""')) return false;
  561. state.tokenize = tokenTripleString;
  562. return state.tokenize(stream, state);
  563. },
  564. "'": function(stream) {
  565. stream.eatWhile(/[\w\$_\xa1-\uffff]/);
  566. return "atom";
  567. },
  568. "=": function(stream, state) {
  569. var cx = state.context
  570. if (cx.type == "}" && cx.align && stream.eat(">")) {
  571. state.context = new Context(cx.indented, cx.column, cx.type, cx.info, null, cx.prev)
  572. return "operator"
  573. } else {
  574. return false
  575. }
  576. },
  577. "/": function(stream, state) {
  578. if (!stream.eat("*")) return false
  579. state.tokenize = tokenNestedComment(1)
  580. return state.tokenize(stream, state)
  581. }
  582. },
  583. modeProps: {closeBrackets: {pairs: '()[]{}""', triples: '"'}}
  584. });
  585. function tokenKotlinString(tripleString){
  586. return function (stream, state) {
  587. var escaped = false, next, end = false;
  588. while (!stream.eol()) {
  589. if (!tripleString && !escaped && stream.match('"') ) {end = true; break;}
  590. if (tripleString && stream.match('"""')) {end = true; break;}
  591. next = stream.next();
  592. if(!escaped && next == "$" && stream.match('{'))
  593. stream.skipTo("}");
  594. escaped = !escaped && next == "\\" && !tripleString;
  595. }
  596. if (end || !tripleString)
  597. state.tokenize = null;
  598. return "string";
  599. }
  600. }
  601. def("text/x-kotlin", {
  602. name: "clike",
  603. keywords: words(
  604. /*keywords*/
  605. "package as typealias class interface this super val operator " +
  606. "var fun for is in This throw return annotation " +
  607. "break continue object if else while do try when !in !is as? " +
  608. /*soft keywords*/
  609. "file import where by get set abstract enum open inner override private public internal " +
  610. "protected catch finally out final vararg reified dynamic companion constructor init " +
  611. "sealed field property receiver param sparam lateinit data inline noinline tailrec " +
  612. "external annotation crossinline const operator infix suspend actual expect setparam value"
  613. ),
  614. types: words(
  615. /* package java.lang */
  616. "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
  617. "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
  618. "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
  619. "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void Annotation Any BooleanArray " +
  620. "ByteArray Char CharArray DeprecationLevel DoubleArray Enum FloatArray Function Int IntArray Lazy " +
  621. "LazyThreadSafetyMode LongArray Nothing ShortArray Unit"
  622. ),
  623. intendSwitch: false,
  624. indentStatements: false,
  625. multiLineStrings: true,
  626. number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+(\.\d+)?|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i,
  627. blockKeywords: words("catch class do else finally for if where try while enum"),
  628. defKeywords: words("class val var object interface fun"),
  629. atoms: words("true false null this"),
  630. hooks: {
  631. "@": function(stream) {
  632. stream.eatWhile(/[\w\$_]/);
  633. return "meta";
  634. },
  635. '*': function(_stream, state) {
  636. return state.prevToken == '.' ? 'variable' : 'operator';
  637. },
  638. '"': function(stream, state) {
  639. state.tokenize = tokenKotlinString(stream.match('""'));
  640. return state.tokenize(stream, state);
  641. },
  642. "/": function(stream, state) {
  643. if (!stream.eat("*")) return false;
  644. state.tokenize = tokenNestedComment(1);
  645. return state.tokenize(stream, state)
  646. },
  647. indent: function(state, ctx, textAfter, indentUnit) {
  648. var firstChar = textAfter && textAfter.charAt(0);
  649. if ((state.prevToken == "}" || state.prevToken == ")") && textAfter == "")
  650. return state.indented;
  651. if ((state.prevToken == "operator" && textAfter != "}" && state.context.type != "}") ||
  652. state.prevToken == "variable" && firstChar == "." ||
  653. (state.prevToken == "}" || state.prevToken == ")") && firstChar == ".")
  654. return indentUnit * 2 + ctx.indented;
  655. if (ctx.align && ctx.type == "}")
  656. return ctx.indented + (state.context.type == (textAfter || "").charAt(0) ? 0 : indentUnit);
  657. }
  658. },
  659. modeProps: {closeBrackets: {triples: '"'}}
  660. });
  661. def(["x-shader/x-vertex", "x-shader/x-fragment"], {
  662. name: "clike",
  663. keywords: words("sampler1D sampler2D sampler3D samplerCube " +
  664. "sampler1DShadow sampler2DShadow " +
  665. "const attribute uniform varying " +
  666. "break continue discard return " +
  667. "for while do if else struct " +
  668. "in out inout"),
  669. types: words("float int bool void " +
  670. "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " +
  671. "mat2 mat3 mat4"),
  672. blockKeywords: words("for while do if else struct"),
  673. builtin: words("radians degrees sin cos tan asin acos atan " +
  674. "pow exp log exp2 sqrt inversesqrt " +
  675. "abs sign floor ceil fract mod min max clamp mix step smoothstep " +
  676. "length distance dot cross normalize ftransform faceforward " +
  677. "reflect refract matrixCompMult " +
  678. "lessThan lessThanEqual greaterThan greaterThanEqual " +
  679. "equal notEqual any all not " +
  680. "texture1D texture1DProj texture1DLod texture1DProjLod " +
  681. "texture2D texture2DProj texture2DLod texture2DProjLod " +
  682. "texture3D texture3DProj texture3DLod texture3DProjLod " +
  683. "textureCube textureCubeLod " +
  684. "shadow1D shadow2D shadow1DProj shadow2DProj " +
  685. "shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " +
  686. "dFdx dFdy fwidth " +
  687. "noise1 noise2 noise3 noise4"),
  688. atoms: words("true false " +
  689. "gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " +
  690. "gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " +
  691. "gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " +
  692. "gl_FogCoord gl_PointCoord " +
  693. "gl_Position gl_PointSize gl_ClipVertex " +
  694. "gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " +
  695. "gl_TexCoord gl_FogFragCoord " +
  696. "gl_FragCoord gl_FrontFacing " +
  697. "gl_FragData gl_FragDepth " +
  698. "gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " +
  699. "gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " +
  700. "gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " +
  701. "gl_TextureMatrixTranspose gl_ModelViewMatrixInverseTranspose " +
  702. "gl_ProjectionMatrixInverseTranspose " +
  703. "gl_ModelViewProjectionMatrixInverseTranspose " +
  704. "gl_TextureMatrixInverseTranspose " +
  705. "gl_NormalScale gl_DepthRange gl_ClipPlane " +
  706. "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " +
  707. "gl_FrontLightModelProduct gl_BackLightModelProduct " +
  708. "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " +
  709. "gl_FogParameters " +
  710. "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " +
  711. "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " +
  712. "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " +
  713. "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " +
  714. "gl_MaxDrawBuffers"),
  715. indentSwitch: false,
  716. hooks: {"#": cppHook},
  717. modeProps: {fold: ["brace", "include"]}
  718. });
  719. def("text/x-nesc", {
  720. name: "clike",
  721. keywords: words(cKeywords + " as atomic async call command component components configuration event generic " +
  722. "implementation includes interface module new norace nx_struct nx_union post provides " +
  723. "signal task uses abstract extends"),
  724. types: cTypes,
  725. blockKeywords: words(cBlockKeywords),
  726. atoms: words("null true false"),
  727. hooks: {"#": cppHook},
  728. modeProps: {fold: ["brace", "include"]}
  729. });
  730. def("text/x-objectivec", {
  731. name: "clike",
  732. keywords: words(cKeywords + " " + objCKeywords),
  733. types: objCTypes,
  734. builtin: words(objCBuiltins),
  735. blockKeywords: words(cBlockKeywords + " @synthesize @try @catch @finally @autoreleasepool @synchronized"),
  736. defKeywords: words(cDefKeywords + " @interface @implementation @protocol @class"),
  737. dontIndentStatements: /^@.*$/,
  738. typeFirstDefinitions: true,
  739. atoms: words("YES NO NULL Nil nil true false nullptr"),
  740. isReservedIdentifier: cIsReservedIdentifier,
  741. hooks: {
  742. "#": cppHook,
  743. "*": pointerHook,
  744. },
  745. modeProps: {fold: ["brace", "include"]}
  746. });
  747. def("text/x-objectivec++", {
  748. name: "clike",
  749. keywords: words(cKeywords + " " + objCKeywords + " " + cppKeywords),
  750. types: objCTypes,
  751. builtin: words(objCBuiltins),
  752. blockKeywords: words(cBlockKeywords + " @synthesize @try @catch @finally @autoreleasepool @synchronized class try catch"),
  753. defKeywords: words(cDefKeywords + " @interface @implementation @protocol @class class namespace"),
  754. dontIndentStatements: /^@.*$|^template$/,
  755. typeFirstDefinitions: true,
  756. atoms: words("YES NO NULL Nil nil true false nullptr"),
  757. isReservedIdentifier: cIsReservedIdentifier,
  758. hooks: {
  759. "#": cppHook,
  760. "*": pointerHook,
  761. "u": cpp11StringHook,
  762. "U": cpp11StringHook,
  763. "L": cpp11StringHook,
  764. "R": cpp11StringHook,
  765. "0": cpp14Literal,
  766. "1": cpp14Literal,
  767. "2": cpp14Literal,
  768. "3": cpp14Literal,
  769. "4": cpp14Literal,
  770. "5": cpp14Literal,
  771. "6": cpp14Literal,
  772. "7": cpp14Literal,
  773. "8": cpp14Literal,
  774. "9": cpp14Literal,
  775. token: function(stream, state, style) {
  776. if (style == "variable" && stream.peek() == "(" &&
  777. (state.prevToken == ";" || state.prevToken == null ||
  778. state.prevToken == "}") &&
  779. cppLooksLikeConstructor(stream.current()))
  780. return "def";
  781. }
  782. },
  783. namespaceSeparator: "::",
  784. modeProps: {fold: ["brace", "include"]}
  785. });
  786. def("text/x-squirrel", {
  787. name: "clike",
  788. keywords: words("base break clone continue const default delete enum extends function in class" +
  789. " foreach local resume return this throw typeof yield constructor instanceof static"),
  790. types: cTypes,
  791. blockKeywords: words("case catch class else for foreach if switch try while"),
  792. defKeywords: words("function local class"),
  793. typeFirstDefinitions: true,
  794. atoms: words("true false null"),
  795. hooks: {"#": cppHook},
  796. modeProps: {fold: ["brace", "include"]}
  797. });
  798. // Ceylon Strings need to deal with interpolation
  799. var stringTokenizer = null;
  800. function tokenCeylonString(type) {
  801. return function(stream, state) {
  802. var escaped = false, next, end = false;
  803. while (!stream.eol()) {
  804. if (!escaped && stream.match('"') &&
  805. (type == "single" || stream.match('""'))) {
  806. end = true;
  807. break;
  808. }
  809. if (!escaped && stream.match('``')) {
  810. stringTokenizer = tokenCeylonString(type);
  811. end = true;
  812. break;
  813. }
  814. next = stream.next();
  815. escaped = type == "single" && !escaped && next == "\\";
  816. }
  817. if (end)
  818. state.tokenize = null;
  819. return "string";
  820. }
  821. }
  822. def("text/x-ceylon", {
  823. name: "clike",
  824. keywords: words("abstracts alias assembly assert assign break case catch class continue dynamic else" +
  825. " exists extends finally for function given if import in interface is let module new" +
  826. " nonempty object of out outer package return satisfies super switch then this throw" +
  827. " try value void while"),
  828. types: function(word) {
  829. // In Ceylon all identifiers that start with an uppercase are types
  830. var first = word.charAt(0);
  831. return (first === first.toUpperCase() && first !== first.toLowerCase());
  832. },
  833. blockKeywords: words("case catch class dynamic else finally for function if interface module new object switch try while"),
  834. defKeywords: words("class dynamic function interface module object package value"),
  835. builtin: words("abstract actual aliased annotation by default deprecated doc final formal late license" +
  836. " native optional sealed see serializable shared suppressWarnings tagged throws variable"),
  837. isPunctuationChar: /[\[\]{}\(\),;\:\.`]/,
  838. isOperatorChar: /[+\-*&%=<>!?|^~:\/]/,
  839. numberStart: /[\d#$]/,
  840. number: /^(?:#[\da-fA-F_]+|\$[01_]+|[\d_]+[kMGTPmunpf]?|[\d_]+\.[\d_]+(?:[eE][-+]?\d+|[kMGTPmunpf]|)|)/i,
  841. multiLineStrings: true,
  842. typeFirstDefinitions: true,
  843. atoms: words("true false null larger smaller equal empty finished"),
  844. indentSwitch: false,
  845. styleDefs: false,
  846. hooks: {
  847. "@": function(stream) {
  848. stream.eatWhile(/[\w\$_]/);
  849. return "meta";
  850. },
  851. '"': function(stream, state) {
  852. state.tokenize = tokenCeylonString(stream.match('""') ? "triple" : "single");
  853. return state.tokenize(stream, state);
  854. },
  855. '`': function(stream, state) {
  856. if (!stringTokenizer || !stream.match('`')) return false;
  857. state.tokenize = stringTokenizer;
  858. stringTokenizer = null;
  859. return state.tokenize(stream, state);
  860. },
  861. "'": function(stream) {
  862. stream.eatWhile(/[\w\$_\xa1-\uffff]/);
  863. return "atom";
  864. },
  865. token: function(_stream, state, style) {
  866. if ((style == "variable" || style == "type") &&
  867. state.prevToken == ".") {
  868. return "variable-2";
  869. }
  870. }
  871. },
  872. modeProps: {
  873. fold: ["brace", "import"],
  874. closeBrackets: {triples: '"'}
  875. }
  876. });
  877. });