mode-livescript.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. ace.define("ace/mode/matching_brace_outdent",[], 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",[], 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. this.$behaviour = new (require("./behaviour/cstyle").CstyleBehaviour)();
  40. }
  41. indenter = RegExp('(?:[({[=:]|[-~]>|\\b(?:e(?:lse|xport)|d(?:o|efault)|t(?:ry|hen)|finally|import(?:\\s*all)?|const|var|let|new|catch(?:\\s*' + identifier + ')?))\\s*$');
  42. prototype.getNextLineIndent = function(state, line, tab){
  43. var indent, tokens;
  44. indent = this.$getIndent(line);
  45. tokens = this.$tokenizer.getLineTokens(line, state).tokens;
  46. if (!(tokens.length && tokens[tokens.length - 1].type === 'comment')) {
  47. if (state === 'start' && indenter.test(line)) {
  48. indent += tab;
  49. }
  50. }
  51. return indent;
  52. };
  53. prototype.lineCommentStart = "#";
  54. prototype.blockComment = {start: "###", end: "###"};
  55. prototype.checkOutdent = function(state, line, input){
  56. var ref$;
  57. return (ref$ = this.$outdent) != null ? ref$.checkOutdent(line, input) : void 8;
  58. };
  59. prototype.autoOutdent = function(state, doc, row){
  60. var ref$;
  61. return (ref$ = this.$outdent) != null ? ref$.autoOutdent(doc, row) : void 8;
  62. };
  63. return LiveScriptMode;
  64. }(require('../mode/text').Mode));
  65. keywordend = '(?![$\\w]|-[A-Za-z]|\\s*:(?![:=]))';
  66. stringfill = {
  67. defaultToken: 'string'
  68. };
  69. LiveScriptMode.Rules = {
  70. start: [
  71. {
  72. token: 'keyword',
  73. 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
  74. }, {
  75. token: 'constant.language',
  76. regex: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend
  77. }, {
  78. token: 'invalid.illegal',
  79. regex: '(?:p(?:ackage|r(?:ivate|otected)|ublic)|i(?:mplements|nterface)|enum|static|yield)' + keywordend
  80. }, {
  81. token: 'language.support.class',
  82. regex: '(?:R(?:e(?:gExp|ferenceError)|angeError)|S(?:tring|yntaxError)|E(?:rror|valError)|Array|Boolean|Date|Function|Number|Object|TypeError|URIError)' + keywordend
  83. }, {
  84. token: 'language.support.function',
  85. regex: '(?:is(?:NaN|Finite)|parse(?:Int|Float)|Math|JSON|(?:en|de)codeURI(?:Component)?)' + keywordend
  86. }, {
  87. token: 'variable.language',
  88. regex: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend
  89. }, {
  90. token: 'identifier',
  91. regex: identifier + '\\s*:(?![:=])'
  92. }, {
  93. token: 'variable',
  94. regex: identifier
  95. }, {
  96. token: 'keyword.operator',
  97. regex: '(?:\\.{3}|\\s+\\?)'
  98. }, {
  99. token: 'keyword.variable',
  100. regex: '(?:@+|::|\\.\\.)',
  101. next: 'key'
  102. }, {
  103. token: 'keyword.operator',
  104. regex: '\\.\\s*',
  105. next: 'key'
  106. }, {
  107. token: 'string',
  108. regex: '\\\\\\S[^\\s,;)}\\]]*'
  109. }, {
  110. token: 'string.doc',
  111. regex: '\'\'\'',
  112. next: 'qdoc'
  113. }, {
  114. token: 'string.doc',
  115. regex: '"""',
  116. next: 'qqdoc'
  117. }, {
  118. token: 'string',
  119. regex: '\'',
  120. next: 'qstring'
  121. }, {
  122. token: 'string',
  123. regex: '"',
  124. next: 'qqstring'
  125. }, {
  126. token: 'string',
  127. regex: '`',
  128. next: 'js'
  129. }, {
  130. token: 'string',
  131. regex: '<\\[',
  132. next: 'words'
  133. }, {
  134. token: 'string.regex',
  135. regex: '//',
  136. next: 'heregex'
  137. }, {
  138. token: 'comment.doc',
  139. regex: '/\\*',
  140. next: 'comment'
  141. }, {
  142. token: 'comment',
  143. regex: '#.*'
  144. }, {
  145. token: 'string.regex',
  146. regex: '\\/(?:[^[\\/\\n\\\\]*(?:(?:\\\\.|\\[[^\\]\\n\\\\]*(?:\\\\.[^\\]\\n\\\\]*)*\\])[^[\\/\\n\\\\]*)*)\\/[gimy$]{0,4}',
  147. next: 'key'
  148. }, {
  149. token: 'constant.numeric',
  150. 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$]*)'
  151. }, {
  152. token: 'lparen',
  153. regex: '[({[]'
  154. }, {
  155. token: 'rparen',
  156. regex: '[)}\\]]',
  157. next: 'key'
  158. }, {
  159. token: 'keyword.operator',
  160. regex: '[\\^!|&%+\\-]+'
  161. }, {
  162. token: 'text',
  163. regex: '\\s+'
  164. }
  165. ],
  166. heregex: [
  167. {
  168. token: 'string.regex',
  169. regex: '.*?//[gimy$?]{0,4}',
  170. next: 'start'
  171. }, {
  172. token: 'string.regex',
  173. regex: '\\s*#{'
  174. }, {
  175. token: 'comment.regex',
  176. regex: '\\s+(?:#.*)?'
  177. }, {
  178. defaultToken: 'string.regex'
  179. }
  180. ],
  181. key: [
  182. {
  183. token: 'keyword.operator',
  184. regex: '[.?@!]+'
  185. }, {
  186. token: 'identifier',
  187. regex: identifier,
  188. next: 'start'
  189. }, {
  190. token: 'text',
  191. regex: '',
  192. next: 'start'
  193. }
  194. ],
  195. comment: [
  196. {
  197. token: 'comment.doc',
  198. regex: '.*?\\*/',
  199. next: 'start'
  200. }, {
  201. defaultToken: 'comment.doc'
  202. }
  203. ],
  204. qdoc: [
  205. {
  206. token: 'string',
  207. regex: ".*?'''",
  208. next: 'key'
  209. }, stringfill
  210. ],
  211. qqdoc: [
  212. {
  213. token: 'string',
  214. regex: '.*?"""',
  215. next: 'key'
  216. }, stringfill
  217. ],
  218. qstring: [
  219. {
  220. token: 'string',
  221. regex: '[^\\\\\']*(?:\\\\.[^\\\\\']*)*\'',
  222. next: 'key'
  223. }, stringfill
  224. ],
  225. qqstring: [
  226. {
  227. token: 'string',
  228. regex: '[^\\\\"]*(?:\\\\.[^\\\\"]*)*"',
  229. next: 'key'
  230. }, stringfill
  231. ],
  232. js: [
  233. {
  234. token: 'string',
  235. regex: '[^\\\\`]*(?:\\\\.[^\\\\`]*)*`',
  236. next: 'key'
  237. }, stringfill
  238. ],
  239. words: [
  240. {
  241. token: 'string',
  242. regex: '.*?\\]>',
  243. next: 'key'
  244. }, stringfill
  245. ]
  246. };
  247. function extend$(sub, sup){
  248. function fun(){} fun.prototype = (sub.superclass = sup).prototype;
  249. (sub.prototype = new fun).constructor = sub;
  250. if (typeof sup.extended == 'function') sup.extended(sub);
  251. return sub;
  252. }
  253. function import$(obj, src){
  254. var own = {}.hasOwnProperty;
  255. for (var key in src) if (own.call(src, key)) obj[key] = src[key];
  256. return obj;
  257. }
  258. });
  259. (function() {
  260. ace.require(["ace/mode/livescript"], function(m) {
  261. if (typeof module == "object" && typeof exports == "object" && module) {
  262. module.exports = m;
  263. }
  264. });
  265. })();