No Description
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.

mode-livescript.js 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  2. "use strict";
  3. var Range = require("../range").Range;
  4. var MatchingBraceOutdent = function() {};
  5. (function() {
  6. this.checkOutdent = function(line, input) {
  7. if (! /^\s+$/.test(line))
  8. return false;
  9. return /^\s*\}/.test(input);
  10. };
  11. this.autoOutdent = function(doc, row) {
  12. var line = doc.getLine(row);
  13. var match = line.match(/^(\s*\})/);
  14. if (!match) return 0;
  15. var column = match[1].length;
  16. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  17. if (!openBracePos || openBracePos.row == row) return 0;
  18. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  19. doc.replace(new Range(row, 0, row, column-1), indent);
  20. };
  21. this.$getIndent = function(line) {
  22. return line.match(/^\s*/)[0];
  23. };
  24. }).call(MatchingBraceOutdent.prototype);
  25. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  26. });
  27. ace.define("ace/mode/livescript",["require","exports","module","ace/tokenizer","ace/mode/matching_brace_outdent","ace/range","ace/mode/text"], function(require, exports, module){
  28. var identifier, LiveScriptMode, keywordend, stringfill;
  29. identifier = '(?![\\d\\s])[$\\w\\xAA-\\uFFDC](?:(?!\\s)[$\\w\\xAA-\\uFFDC]|-[A-Za-z])*';
  30. exports.Mode = LiveScriptMode = (function(superclass){
  31. var indenter, prototype = extend$((import$(LiveScriptMode, superclass).displayName = 'LiveScriptMode', LiveScriptMode), superclass).prototype, constructor = LiveScriptMode;
  32. function LiveScriptMode(){
  33. var that;
  34. this.$tokenizer = new (require('../tokenizer')).Tokenizer(LiveScriptMode.Rules);
  35. if (that = require('../mode/matching_brace_outdent')) {
  36. this.$outdent = new that.MatchingBraceOutdent;
  37. }
  38. this.$id = "ace/mode/livescript";
  39. }
  40. indenter = RegExp('(?:[({[=:]|[-~]>|\\b(?:e(?:lse|xport)|d(?:o|efault)|t(?:ry|hen)|finally|import(?:\\s*all)?|const|var|let|new|catch(?:\\s*' + identifier + ')?))\\s*$');
  41. prototype.getNextLineIndent = function(state, line, tab){
  42. var indent, tokens;
  43. indent = this.$getIndent(line);
  44. tokens = this.$tokenizer.getLineTokens(line, state).tokens;
  45. if (!(tokens.length && tokens[tokens.length - 1].type === 'comment')) {
  46. if (state === 'start' && indenter.test(line)) {
  47. indent += tab;
  48. }
  49. }
  50. return indent;
  51. };
  52. prototype.toggleCommentLines = function(state, doc, startRow, endRow){
  53. var comment, range, i$, i, out, line;
  54. comment = /^(\s*)#/;
  55. range = new (require('../range')).Range(0, 0, 0, 0);
  56. for (i$ = startRow; i$ <= endRow; ++i$) {
  57. i = i$;
  58. if (out = comment.test(line = doc.getLine(i))) {
  59. line = line.replace(comment, '$1');
  60. } else {
  61. line = line.replace(/^\s*/, '$&#');
  62. }
  63. range.end.row = range.start.row = i;
  64. range.end.column = line.length + 1;
  65. doc.replace(range, line);
  66. }
  67. return 1 - out * 2;
  68. };
  69. prototype.checkOutdent = function(state, line, input){
  70. var ref$;
  71. return (ref$ = this.$outdent) != null ? ref$.checkOutdent(line, input) : void 8;
  72. };
  73. prototype.autoOutdent = function(state, doc, row){
  74. var ref$;
  75. return (ref$ = this.$outdent) != null ? ref$.autoOutdent(doc, row) : void 8;
  76. };
  77. return LiveScriptMode;
  78. }(require('../mode/text').Mode));
  79. keywordend = '(?![$\\w]|-[A-Za-z]|\\s*:(?![:=]))';
  80. stringfill = {
  81. token: 'string',
  82. regex: '.+'
  83. };
  84. LiveScriptMode.Rules = {
  85. start: [
  86. {
  87. token: 'keyword',
  88. regex: '(?:t(?:h(?:is|row|en)|ry|ypeof!?)|c(?:on(?:tinue|st)|a(?:se|tch)|lass)|i(?:n(?:stanceof)?|mp(?:ort(?:\\s+all)?|lements)|[fs])|d(?:e(?:fault|lete|bugger)|o)|f(?:or(?:\\s+own)?|inally|unction)|s(?:uper|witch)|e(?:lse|x(?:tends|port)|val)|a(?:nd|rguments)|n(?:ew|ot)|un(?:less|til)|w(?:hile|ith)|o[fr]|return|break|let|var|loop)' + keywordend
  89. }, {
  90. token: 'constant.language',
  91. regex: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend
  92. }, {
  93. token: 'invalid.illegal',
  94. regex: '(?:p(?:ackage|r(?:ivate|otected)|ublic)|i(?:mplements|nterface)|enum|static|yield)' + keywordend
  95. }, {
  96. token: 'language.support.class',
  97. regex: '(?:R(?:e(?:gExp|ferenceError)|angeError)|S(?:tring|yntaxError)|E(?:rror|valError)|Array|Boolean|Date|Function|Number|Object|TypeError|URIError)' + keywordend
  98. }, {
  99. token: 'language.support.function',
  100. regex: '(?:is(?:NaN|Finite)|parse(?:Int|Float)|Math|JSON|(?:en|de)codeURI(?:Component)?)' + keywordend
  101. }, {
  102. token: 'variable.language',
  103. regex: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend
  104. }, {
  105. token: 'identifier',
  106. regex: identifier + '\\s*:(?![:=])'
  107. }, {
  108. token: 'variable',
  109. regex: identifier
  110. }, {
  111. token: 'keyword.operator',
  112. regex: '(?:\\.{3}|\\s+\\?)'
  113. }, {
  114. token: 'keyword.variable',
  115. regex: '(?:@+|::|\\.\\.)',
  116. next: 'key'
  117. }, {
  118. token: 'keyword.operator',
  119. regex: '\\.\\s*',
  120. next: 'key'
  121. }, {
  122. token: 'string',
  123. regex: '\\\\\\S[^\\s,;)}\\]]*'
  124. }, {
  125. token: 'string.doc',
  126. regex: '\'\'\'',
  127. next: 'qdoc'
  128. }, {
  129. token: 'string.doc',
  130. regex: '"""',
  131. next: 'qqdoc'
  132. }, {
  133. token: 'string',
  134. regex: '\'',
  135. next: 'qstring'
  136. }, {
  137. token: 'string',
  138. regex: '"',
  139. next: 'qqstring'
  140. }, {
  141. token: 'string',
  142. regex: '`',
  143. next: 'js'
  144. }, {
  145. token: 'string',
  146. regex: '<\\[',
  147. next: 'words'
  148. }, {
  149. token: 'string.regex',
  150. regex: '//',
  151. next: 'heregex'
  152. }, {
  153. token: 'comment.doc',
  154. regex: '/\\*',
  155. next: 'comment'
  156. }, {
  157. token: 'comment',
  158. regex: '#.*'
  159. }, {
  160. token: 'string.regex',
  161. regex: '\\/(?:[^[\\/\\n\\\\]*(?:(?:\\\\.|\\[[^\\]\\n\\\\]*(?:\\\\.[^\\]\\n\\\\]*)*\\])[^[\\/\\n\\\\]*)*)\\/[gimy$]{0,4}',
  162. next: 'key'
  163. }, {
  164. token: 'constant.numeric',
  165. regex: '(?:0x[\\da-fA-F][\\da-fA-F_]*|(?:[2-9]|[12]\\d|3[0-6])r[\\da-zA-Z][\\da-zA-Z_]*|(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*)(?:e[+-]?\\d[\\d_]*)?[\\w$]*)'
  166. }, {
  167. token: 'lparen',
  168. regex: '[({[]'
  169. }, {
  170. token: 'rparen',
  171. regex: '[)}\\]]',
  172. next: 'key'
  173. }, {
  174. token: 'keyword.operator',
  175. regex: '\\S+'
  176. }, {
  177. token: 'text',
  178. regex: '\\s+'
  179. }
  180. ],
  181. heregex: [
  182. {
  183. token: 'string.regex',
  184. regex: '.*?//[gimy$?]{0,4}',
  185. next: 'start'
  186. }, {
  187. token: 'string.regex',
  188. regex: '\\s*#{'
  189. }, {
  190. token: 'comment.regex',
  191. regex: '\\s+(?:#.*)?'
  192. }, {
  193. token: 'string.regex',
  194. regex: '\\S+'
  195. }
  196. ],
  197. key: [
  198. {
  199. token: 'keyword.operator',
  200. regex: '[.?@!]+'
  201. }, {
  202. token: 'identifier',
  203. regex: identifier,
  204. next: 'start'
  205. }, {
  206. token: 'text',
  207. regex: '.',
  208. next: 'start'
  209. }
  210. ],
  211. comment: [
  212. {
  213. token: 'comment.doc',
  214. regex: '.*?\\*/',
  215. next: 'start'
  216. }, {
  217. token: 'comment.doc',
  218. regex: '.+'
  219. }
  220. ],
  221. qdoc: [
  222. {
  223. token: 'string',
  224. regex: ".*?'''",
  225. next: 'key'
  226. }, stringfill
  227. ],
  228. qqdoc: [
  229. {
  230. token: 'string',
  231. regex: '.*?"""',
  232. next: 'key'
  233. }, stringfill
  234. ],
  235. qstring: [
  236. {
  237. token: 'string',
  238. regex: '[^\\\\\']*(?:\\\\.[^\\\\\']*)*\'',
  239. next: 'key'
  240. }, stringfill
  241. ],
  242. qqstring: [
  243. {
  244. token: 'string',
  245. regex: '[^\\\\"]*(?:\\\\.[^\\\\"]*)*"',
  246. next: 'key'
  247. }, stringfill
  248. ],
  249. js: [
  250. {
  251. token: 'string',
  252. regex: '[^\\\\`]*(?:\\\\.[^\\\\`]*)*`',
  253. next: 'key'
  254. }, stringfill
  255. ],
  256. words: [
  257. {
  258. token: 'string',
  259. regex: '.*?\\]>',
  260. next: 'key'
  261. }, stringfill
  262. ]
  263. };
  264. function extend$(sub, sup){
  265. function fun(){} fun.prototype = (sub.superclass = sup).prototype;
  266. (sub.prototype = new fun).constructor = sub;
  267. if (typeof sup.extended == 'function') sup.extended(sub);
  268. return sub;
  269. }
  270. function import$(obj, src){
  271. var own = {}.hasOwnProperty;
  272. for (var key in src) if (own.call(src, key)) obj[key] = src[key];
  273. return obj;
  274. }
  275. });