clike.js 32 KB

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