clike.js 30 KB

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