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.

936 lines
36KB

  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/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. },
  458. modeProps: {fold: ["brace", "import"]}
  459. });
  460. def("text/x-csharp", {
  461. name: "clike",
  462. keywords: words("abstract as async await base break case catch checked class const continue" +
  463. " default delegate do else enum event explicit extern finally fixed for" +
  464. " foreach goto if implicit in interface internal is lock namespace new" +
  465. " operator out override params private protected public readonly ref return sealed" +
  466. " sizeof stackalloc static struct switch this throw try typeof unchecked" +
  467. " unsafe using virtual void volatile while add alias ascending descending dynamic from get" +
  468. " global group into join let orderby partial remove select set value var yield"),
  469. types: words("Action Boolean Byte Char DateTime DateTimeOffset Decimal Double Func" +
  470. " Guid Int16 Int32 Int64 Object SByte Single String Task TimeSpan UInt16 UInt32" +
  471. " UInt64 bool byte char decimal double short int long object" +
  472. " sbyte float string ushort uint ulong"),
  473. blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
  474. defKeywords: words("class interface namespace struct var"),
  475. typeFirstDefinitions: true,
  476. atoms: words("true false null"),
  477. hooks: {
  478. "@": function(stream, state) {
  479. if (stream.eat('"')) {
  480. state.tokenize = tokenAtString;
  481. return tokenAtString(stream, state);
  482. }
  483. stream.eatWhile(/[\w\$_]/);
  484. return "meta";
  485. }
  486. }
  487. });
  488. function tokenTripleString(stream, state) {
  489. var escaped = false;
  490. while (!stream.eol()) {
  491. if (!escaped && stream.match('"""')) {
  492. state.tokenize = null;
  493. break;
  494. }
  495. escaped = stream.next() == "\\" && !escaped;
  496. }
  497. return "string";
  498. }
  499. function tokenNestedComment(depth) {
  500. return function (stream, state) {
  501. var ch
  502. while (ch = stream.next()) {
  503. if (ch == "*" && stream.eat("/")) {
  504. if (depth == 1) {
  505. state.tokenize = null
  506. break
  507. } else {
  508. state.tokenize = tokenNestedComment(depth - 1)
  509. return state.tokenize(stream, state)
  510. }
  511. } else if (ch == "/" && stream.eat("*")) {
  512. state.tokenize = tokenNestedComment(depth + 1)
  513. return state.tokenize(stream, state)
  514. }
  515. }
  516. return "comment"
  517. }
  518. }
  519. def("text/x-scala", {
  520. name: "clike",
  521. keywords: words(
  522. /* scala */
  523. "abstract case catch class def do else extends final finally for forSome if " +
  524. "implicit import lazy match new null object override package private protected return " +
  525. "sealed super this throw trait try type val var while with yield _ " +
  526. /* package scala */
  527. "assert assume require print println printf readLine readBoolean readByte readShort " +
  528. "readChar readInt readLong readFloat readDouble"
  529. ),
  530. types: words(
  531. "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
  532. "Enumeration Equiv Error Exception Fractional Function IndexedSeq Int Integral Iterable " +
  533. "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
  534. "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
  535. "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector " +
  536. /* package java.lang */
  537. "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
  538. "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
  539. "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
  540. "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
  541. ),
  542. multiLineStrings: true,
  543. blockKeywords: words("catch class enum do else finally for forSome if match switch try while"),
  544. defKeywords: words("class enum def object package trait type val var"),
  545. atoms: words("true false null"),
  546. indentStatements: false,
  547. indentSwitch: false,
  548. isOperatorChar: /[+\-*&%=<>!?|\/#:@]/,
  549. hooks: {
  550. "@": function(stream) {
  551. stream.eatWhile(/[\w\$_]/);
  552. return "meta";
  553. },
  554. '"': function(stream, state) {
  555. if (!stream.match('""')) return false;
  556. state.tokenize = tokenTripleString;
  557. return state.tokenize(stream, state);
  558. },
  559. "'": function(stream) {
  560. stream.eatWhile(/[\w\$_\xa1-\uffff]/);
  561. return "atom";
  562. },
  563. "=": function(stream, state) {
  564. var cx = state.context
  565. if (cx.type == "}" && cx.align && stream.eat(">")) {
  566. state.context = new Context(cx.indented, cx.column, cx.type, cx.info, null, cx.prev)
  567. return "operator"
  568. } else {
  569. return false
  570. }
  571. },
  572. "/": function(stream, state) {
  573. if (!stream.eat("*")) return false
  574. state.tokenize = tokenNestedComment(1)
  575. return state.tokenize(stream, state)
  576. }
  577. },
  578. modeProps: {closeBrackets: {pairs: '()[]{}""', triples: '"'}}
  579. });
  580. function tokenKotlinString(tripleString){
  581. return function (stream, state) {
  582. var escaped = false, next, end = false;
  583. while (!stream.eol()) {
  584. if (!tripleString && !escaped && stream.match('"') ) {end = true; break;}
  585. if (tripleString && stream.match('"""')) {end = true; break;}
  586. next = stream.next();
  587. if(!escaped && next == "$" && stream.match('{'))
  588. stream.skipTo("}");
  589. escaped = !escaped && next == "\\" && !tripleString;
  590. }
  591. if (end || !tripleString)
  592. state.tokenize = null;
  593. return "string";
  594. }
  595. }
  596. def("text/x-kotlin", {
  597. name: "clike",
  598. keywords: words(
  599. /*keywords*/
  600. "package as typealias class interface this super val operator " +
  601. "var fun for is in This throw return annotation " +
  602. "break continue object if else while do try when !in !is as? " +
  603. /*soft keywords*/
  604. "file import where by get set abstract enum open inner override private public internal " +
  605. "protected catch finally out final vararg reified dynamic companion constructor init " +
  606. "sealed field property receiver param sparam lateinit data inline noinline tailrec " +
  607. "external annotation crossinline const operator infix suspend actual expect setparam value"
  608. ),
  609. types: words(
  610. /* package java.lang */
  611. "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
  612. "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
  613. "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
  614. "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void Annotation Any BooleanArray " +
  615. "ByteArray Char CharArray DeprecationLevel DoubleArray Enum FloatArray Function Int IntArray Lazy " +
  616. "LazyThreadSafetyMode LongArray Nothing ShortArray Unit"
  617. ),
  618. intendSwitch: false,
  619. indentStatements: false,
  620. multiLineStrings: true,
  621. number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+(\.\d+)?|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i,
  622. blockKeywords: words("catch class do else finally for if where try while enum"),
  623. defKeywords: words("class val var object interface fun"),
  624. atoms: words("true false null this"),
  625. hooks: {
  626. "@": function(stream) {
  627. stream.eatWhile(/[\w\$_]/);
  628. return "meta";
  629. },
  630. '*': function(_stream, state) {
  631. return state.prevToken == '.' ? 'variable' : 'operator';
  632. },
  633. '"': function(stream, state) {
  634. state.tokenize = tokenKotlinString(stream.match('""'));
  635. return state.tokenize(stream, state);
  636. },
  637. "/": function(stream, state) {
  638. if (!stream.eat("*")) return false;
  639. state.tokenize = tokenNestedComment(1);
  640. return state.tokenize(stream, state)
  641. },
  642. indent: function(state, ctx, textAfter, indentUnit) {
  643. var firstChar = textAfter && textAfter.charAt(0);
  644. if ((state.prevToken == "}" || state.prevToken == ")") && textAfter == "")
  645. return state.indented;
  646. if ((state.prevToken == "operator" && textAfter != "}" && state.context.type != "}") ||
  647. state.prevToken == "variable" && firstChar == "." ||
  648. (state.prevToken == "}" || state.prevToken == ")") && firstChar == ".")
  649. return indentUnit * 2 + ctx.indented;
  650. if (ctx.align && ctx.type == "}")
  651. return ctx.indented + (state.context.type == (textAfter || "").charAt(0) ? 0 : indentUnit);
  652. }
  653. },
  654. modeProps: {closeBrackets: {triples: '"'}}
  655. });
  656. def(["x-shader/x-vertex", "x-shader/x-fragment"], {
  657. name: "clike",
  658. keywords: words("sampler1D sampler2D sampler3D samplerCube " +
  659. "sampler1DShadow sampler2DShadow " +
  660. "const attribute uniform varying " +
  661. "break continue discard return " +
  662. "for while do if else struct " +
  663. "in out inout"),
  664. types: words("float int bool void " +
  665. "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " +
  666. "mat2 mat3 mat4"),
  667. blockKeywords: words("for while do if else struct"),
  668. builtin: words("radians degrees sin cos tan asin acos atan " +
  669. "pow exp log exp2 sqrt inversesqrt " +
  670. "abs sign floor ceil fract mod min max clamp mix step smoothstep " +
  671. "length distance dot cross normalize ftransform faceforward " +
  672. "reflect refract matrixCompMult " +
  673. "lessThan lessThanEqual greaterThan greaterThanEqual " +
  674. "equal notEqual any all not " +
  675. "texture1D texture1DProj texture1DLod texture1DProjLod " +
  676. "texture2D texture2DProj texture2DLod texture2DProjLod " +
  677. "texture3D texture3DProj texture3DLod texture3DProjLod " +
  678. "textureCube textureCubeLod " +
  679. "shadow1D shadow2D shadow1DProj shadow2DProj " +
  680. "shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " +
  681. "dFdx dFdy fwidth " +
  682. "noise1 noise2 noise3 noise4"),
  683. atoms: words("true false " +
  684. "gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " +
  685. "gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " +
  686. "gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " +
  687. "gl_FogCoord gl_PointCoord " +
  688. "gl_Position gl_PointSize gl_ClipVertex " +
  689. "gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " +
  690. "gl_TexCoord gl_FogFragCoord " +
  691. "gl_FragCoord gl_FrontFacing " +
  692. "gl_FragData gl_FragDepth " +
  693. "gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " +
  694. "gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " +
  695. "gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " +
  696. "gl_TextureMatrixTranspose gl_ModelViewMatrixInverseTranspose " +
  697. "gl_ProjectionMatrixInverseTranspose " +
  698. "gl_ModelViewProjectionMatrixInverseTranspose " +
  699. "gl_TextureMatrixInverseTranspose " +
  700. "gl_NormalScale gl_DepthRange gl_ClipPlane " +
  701. "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " +
  702. "gl_FrontLightModelProduct gl_BackLightModelProduct " +
  703. "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " +
  704. "gl_FogParameters " +
  705. "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " +
  706. "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " +
  707. "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " +
  708. "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " +
  709. "gl_MaxDrawBuffers"),
  710. indentSwitch: false,
  711. hooks: {"#": cppHook},
  712. modeProps: {fold: ["brace", "include"]}
  713. });
  714. def("text/x-nesc", {
  715. name: "clike",
  716. keywords: words(cKeywords + " as atomic async call command component components configuration event generic " +
  717. "implementation includes interface module new norace nx_struct nx_union post provides " +
  718. "signal task uses abstract extends"),
  719. types: cTypes,
  720. blockKeywords: words(cBlockKeywords),
  721. atoms: words("null true false"),
  722. hooks: {"#": cppHook},
  723. modeProps: {fold: ["brace", "include"]}
  724. });
  725. def("text/x-objectivec", {
  726. name: "clike",
  727. keywords: words(cKeywords + " " + objCKeywords),
  728. types: objCTypes,
  729. builtin: words(objCBuiltins),
  730. blockKeywords: words(cBlockKeywords + " @synthesize @try @catch @finally @autoreleasepool @synchronized"),
  731. defKeywords: words(cDefKeywords + " @interface @implementation @protocol @class"),
  732. dontIndentStatements: /^@.*$/,
  733. typeFirstDefinitions: true,
  734. atoms: words("YES NO NULL Nil nil true false nullptr"),
  735. isReservedIdentifier: cIsReservedIdentifier,
  736. hooks: {
  737. "#": cppHook,
  738. "*": pointerHook,
  739. },
  740. modeProps: {fold: ["brace", "include"]}
  741. });
  742. def("text/x-objectivec++", {
  743. name: "clike",
  744. keywords: words(cKeywords + " " + objCKeywords + " " + cppKeywords),
  745. types: objCTypes,
  746. builtin: words(objCBuiltins),
  747. blockKeywords: words(cBlockKeywords + " @synthesize @try @catch @finally @autoreleasepool @synchronized class try catch"),
  748. defKeywords: words(cDefKeywords + " @interface @implementation @protocol @class class namespace"),
  749. dontIndentStatements: /^@.*$|^template$/,
  750. typeFirstDefinitions: true,
  751. atoms: words("YES NO NULL Nil nil true false nullptr"),
  752. isReservedIdentifier: cIsReservedIdentifier,
  753. hooks: {
  754. "#": cppHook,
  755. "*": pointerHook,
  756. "u": cpp11StringHook,
  757. "U": cpp11StringHook,
  758. "L": cpp11StringHook,
  759. "R": cpp11StringHook,
  760. "0": cpp14Literal,
  761. "1": cpp14Literal,
  762. "2": cpp14Literal,
  763. "3": cpp14Literal,
  764. "4": cpp14Literal,
  765. "5": cpp14Literal,
  766. "6": cpp14Literal,
  767. "7": cpp14Literal,
  768. "8": cpp14Literal,
  769. "9": cpp14Literal,
  770. token: function(stream, state, style) {
  771. if (style == "variable" && stream.peek() == "(" &&
  772. (state.prevToken == ";" || state.prevToken == null ||
  773. state.prevToken == "}") &&
  774. cppLooksLikeConstructor(stream.current()))
  775. return "def";
  776. }
  777. },
  778. namespaceSeparator: "::",
  779. modeProps: {fold: ["brace", "include"]}
  780. });
  781. def("text/x-squirrel", {
  782. name: "clike",
  783. keywords: words("base break clone continue const default delete enum extends function in class" +
  784. " foreach local resume return this throw typeof yield constructor instanceof static"),
  785. types: cTypes,
  786. blockKeywords: words("case catch class else for foreach if switch try while"),
  787. defKeywords: words("function local class"),
  788. typeFirstDefinitions: true,
  789. atoms: words("true false null"),
  790. hooks: {"#": cppHook},
  791. modeProps: {fold: ["brace", "include"]}
  792. });
  793. // Ceylon Strings need to deal with interpolation
  794. var stringTokenizer = null;
  795. function tokenCeylonString(type) {
  796. return function(stream, state) {
  797. var escaped = false, next, end = false;
  798. while (!stream.eol()) {
  799. if (!escaped && stream.match('"') &&
  800. (type == "single" || stream.match('""'))) {
  801. end = true;
  802. break;
  803. }
  804. if (!escaped && stream.match('``')) {
  805. stringTokenizer = tokenCeylonString(type);
  806. end = true;
  807. break;
  808. }
  809. next = stream.next();
  810. escaped = type == "single" && !escaped && next == "\\";
  811. }
  812. if (end)
  813. state.tokenize = null;
  814. return "string";
  815. }
  816. }
  817. def("text/x-ceylon", {
  818. name: "clike",
  819. keywords: words("abstracts alias assembly assert assign break case catch class continue dynamic else" +
  820. " exists extends finally for function given if import in interface is let module new" +
  821. " nonempty object of out outer package return satisfies super switch then this throw" +
  822. " try value void while"),
  823. types: function(word) {
  824. // In Ceylon all identifiers that start with an uppercase are types
  825. var first = word.charAt(0);
  826. return (first === first.toUpperCase() && first !== first.toLowerCase());
  827. },
  828. blockKeywords: words("case catch class dynamic else finally for function if interface module new object switch try while"),
  829. defKeywords: words("class dynamic function interface module object package value"),
  830. builtin: words("abstract actual aliased annotation by default deprecated doc final formal late license" +
  831. " native optional sealed see serializable shared suppressWarnings tagged throws variable"),
  832. isPunctuationChar: /[\[\]{}\(\),;\:\.`]/,
  833. isOperatorChar: /[+\-*&%=<>!?|^~:\/]/,
  834. numberStart: /[\d#$]/,
  835. number: /^(?:#[\da-fA-F_]+|\$[01_]+|[\d_]+[kMGTPmunpf]?|[\d_]+\.[\d_]+(?:[eE][-+]?\d+|[kMGTPmunpf]|)|)/i,
  836. multiLineStrings: true,
  837. typeFirstDefinitions: true,
  838. atoms: words("true false null larger smaller equal empty finished"),
  839. indentSwitch: false,
  840. styleDefs: false,
  841. hooks: {
  842. "@": function(stream) {
  843. stream.eatWhile(/[\w\$_]/);
  844. return "meta";
  845. },
  846. '"': function(stream, state) {
  847. state.tokenize = tokenCeylonString(stream.match('""') ? "triple" : "single");
  848. return state.tokenize(stream, state);
  849. },
  850. '`': function(stream, state) {
  851. if (!stringTokenizer || !stream.match('`')) return false;
  852. state.tokenize = stringTokenizer;
  853. stringTokenizer = null;
  854. return state.tokenize(stream, state);
  855. },
  856. "'": function(stream) {
  857. stream.eatWhile(/[\w\$_\xa1-\uffff]/);
  858. return "atom";
  859. },
  860. token: function(_stream, state, style) {
  861. if ((style == "variable" || style == "type") &&
  862. state.prevToken == ".") {
  863. return "variable-2";
  864. }
  865. }
  866. },
  867. modeProps: {
  868. fold: ["brace", "import"],
  869. closeBrackets: {triples: '"'}
  870. }
  871. });
  872. });