国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

787 lines
30KB

  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. var curPunc, isDefKeyword;
  64. function tokenBase(stream, state) {
  65. var ch = stream.next();
  66. if (hooks[ch]) {
  67. var result = hooks[ch](stream, state);
  68. if (result !== false) return result;
  69. }
  70. if (ch == '"' || ch == "'") {
  71. state.tokenize = tokenString(ch);
  72. return state.tokenize(stream, state);
  73. }
  74. if (isPunctuationChar.test(ch)) {
  75. curPunc = ch;
  76. return null;
  77. }
  78. if (numberStart.test(ch)) {
  79. stream.backUp(1)
  80. if (stream.match(number)) return "number"
  81. stream.next()
  82. }
  83. if (ch == "/") {
  84. if (stream.eat("*")) {
  85. state.tokenize = tokenComment;
  86. return tokenComment(stream, state);
  87. }
  88. if (stream.eat("/")) {
  89. stream.skipToEnd();
  90. return "comment";
  91. }
  92. }
  93. if (isOperatorChar.test(ch)) {
  94. while (!stream.match(/^\/[\/*]/, false) && stream.eat(isOperatorChar)) {}
  95. return "operator";
  96. }
  97. stream.eatWhile(/[\w\$_\xa1-\uffff]/);
  98. if (namespaceSeparator) while (stream.match(namespaceSeparator))
  99. stream.eatWhile(/[\w\$_\xa1-\uffff]/);
  100. var cur = stream.current();
  101. if (contains(keywords, cur)) {
  102. if (contains(blockKeywords, cur)) curPunc = "newstatement";
  103. if (contains(defKeywords, cur)) isDefKeyword = true;
  104. return "keyword";
  105. }
  106. if (contains(types, cur)) return "variable-3";
  107. if (contains(builtin, cur)) {
  108. if (contains(blockKeywords, cur)) curPunc = "newstatement";
  109. return "builtin";
  110. }
  111. if (contains(atoms, cur)) return "atom";
  112. return "variable";
  113. }
  114. function tokenString(quote) {
  115. return function(stream, state) {
  116. var escaped = false, next, end = false;
  117. while ((next = stream.next()) != null) {
  118. if (next == quote && !escaped) {end = true; break;}
  119. escaped = !escaped && next == "\\";
  120. }
  121. if (end || !(escaped || multiLineStrings))
  122. state.tokenize = null;
  123. return "string";
  124. };
  125. }
  126. function tokenComment(stream, state) {
  127. var maybeEnd = false, ch;
  128. while (ch = stream.next()) {
  129. if (ch == "/" && maybeEnd) {
  130. state.tokenize = null;
  131. break;
  132. }
  133. maybeEnd = (ch == "*");
  134. }
  135. return "comment";
  136. }
  137. function maybeEOL(stream, state) {
  138. if (parserConfig.typeFirstDefinitions && stream.eol() && isTopScope(state.context))
  139. state.typeAtEndOfLine = typeBefore(stream, state, stream.pos)
  140. }
  141. // Interface
  142. return {
  143. startState: function(basecolumn) {
  144. return {
  145. tokenize: null,
  146. context: new Context((basecolumn || 0) - indentUnit, 0, "top", null, false),
  147. indented: 0,
  148. startOfLine: true,
  149. prevToken: null
  150. };
  151. },
  152. token: function(stream, state) {
  153. var ctx = state.context;
  154. if (stream.sol()) {
  155. if (ctx.align == null) ctx.align = false;
  156. state.indented = stream.indentation();
  157. state.startOfLine = true;
  158. }
  159. if (stream.eatSpace()) { maybeEOL(stream, state); return null; }
  160. curPunc = isDefKeyword = null;
  161. var style = (state.tokenize || tokenBase)(stream, state);
  162. if (style == "comment" || style == "meta") return style;
  163. if (ctx.align == null) ctx.align = true;
  164. if (curPunc == ";" || curPunc == ":" || (curPunc == "," && stream.match(/^\s*(?:\/\/.*)?$/, false)))
  165. 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 @interface"),
  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 @interface"),
  398. typeFirstDefinitions: true,
  399. atoms: words("true false null"),
  400. number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+\.?\d*|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i,
  401. hooks: {
  402. "@": function(stream) {
  403. // Don't match the @interface keyword.
  404. if (stream.match('interface', false)) return false;
  405. stream.eatWhile(/[\w\$_]/);
  406. return "meta";
  407. }
  408. },
  409. modeProps: {fold: ["brace", "import"]}
  410. });
  411. def("text/x-csharp", {
  412. name: "clike",
  413. keywords: words("abstract as async await base break case catch checked class const continue" +
  414. " default delegate do else enum event explicit extern finally fixed for" +
  415. " foreach goto if implicit in interface internal is lock namespace new" +
  416. " operator out override params private protected public readonly ref return sealed" +
  417. " sizeof stackalloc static struct switch this throw try typeof unchecked" +
  418. " unsafe using virtual void volatile while add alias ascending descending dynamic from get" +
  419. " global group into join let orderby partial remove select set value var yield"),
  420. types: words("Action Boolean Byte Char DateTime DateTimeOffset Decimal Double Func" +
  421. " Guid Int16 Int32 Int64 Object SByte Single String Task TimeSpan UInt16 UInt32" +
  422. " UInt64 bool byte char decimal double short int long object" +
  423. " sbyte float string ushort uint ulong"),
  424. blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
  425. defKeywords: words("class interface namespace struct var"),
  426. typeFirstDefinitions: true,
  427. atoms: words("true false null"),
  428. hooks: {
  429. "@": function(stream, state) {
  430. if (stream.eat('"')) {
  431. state.tokenize = tokenAtString;
  432. return tokenAtString(stream, state);
  433. }
  434. stream.eatWhile(/[\w\$_]/);
  435. return "meta";
  436. }
  437. }
  438. });
  439. function tokenTripleString(stream, state) {
  440. var escaped = false;
  441. while (!stream.eol()) {
  442. if (!escaped && stream.match('"""')) {
  443. state.tokenize = null;
  444. break;
  445. }
  446. escaped = stream.next() == "\\" && !escaped;
  447. }
  448. return "string";
  449. }
  450. def("text/x-scala", {
  451. name: "clike",
  452. keywords: words(
  453. /* scala */
  454. "abstract case catch class def do else extends final finally for forSome if " +
  455. "implicit import lazy match new null object override package private protected return " +
  456. "sealed super this throw trait try type val var while with yield _ " +
  457. /* package scala */
  458. "assert assume require print println printf readLine readBoolean readByte readShort " +
  459. "readChar readInt readLong readFloat readDouble"
  460. ),
  461. types: words(
  462. "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
  463. "Enumeration Equiv Error Exception Fractional Function IndexedSeq Int Integral Iterable " +
  464. "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
  465. "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
  466. "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector " +
  467. /* package java.lang */
  468. "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
  469. "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
  470. "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
  471. "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
  472. ),
  473. multiLineStrings: true,
  474. blockKeywords: words("catch class do else finally for forSome if match switch try while"),
  475. defKeywords: words("class def object package trait type val var"),
  476. atoms: words("true false null"),
  477. indentStatements: false,
  478. indentSwitch: false,
  479. isOperatorChar: /[+\-*&%=<>!?|\/#:@]/,
  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. });