58983298ac91ce650355425827300ad706a394d6.svn-base 34 KB

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