clike.js 30 KB

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