mode-haml.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. define("ace/mode/ruby_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var constantOtherSymbol = exports.constantOtherSymbol = {
  6. token : "constant.other.symbol.ruby", // symbol
  7. regex : "[:](?:[A-Za-z_]|[@$](?=[a-zA-Z0-9_]))[a-zA-Z0-9_]*[!=?]?"
  8. };
  9. var qString = exports.qString = {
  10. token : "string", // single line
  11. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  12. };
  13. var qqString = exports.qqString = {
  14. token : "string", // single line
  15. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  16. };
  17. var tString = exports.tString = {
  18. token : "string", // backtick string
  19. regex : "[`](?:(?:\\\\.)|(?:[^'\\\\]))*?[`]"
  20. };
  21. var constantNumericHex = exports.constantNumericHex = {
  22. token : "constant.numeric", // hex
  23. regex : "0[xX][0-9a-fA-F](?:[0-9a-fA-F]|_(?=[0-9a-fA-F]))*\\b"
  24. };
  25. var constantNumericFloat = exports.constantNumericFloat = {
  26. token : "constant.numeric", // float
  27. regex : "[+-]?\\d(?:\\d|_(?=\\d))*(?:(?:\\.\\d(?:\\d|_(?=\\d))*)?(?:[eE][+-]?\\d+)?)?\\b"
  28. };
  29. var RubyHighlightRules = function() {
  30. var builtinFunctions = (
  31. "abort|Array|assert|assert_equal|assert_not_equal|assert_same|assert_not_same|" +
  32. "assert_nil|assert_not_nil|assert_match|assert_no_match|assert_in_delta|assert_throws|" +
  33. "assert_raise|assert_nothing_raised|assert_instance_of|assert_kind_of|assert_respond_to|" +
  34. "assert_operator|assert_send|assert_difference|assert_no_difference|assert_recognizes|" +
  35. "assert_generates|assert_response|assert_redirected_to|assert_template|assert_select|" +
  36. "assert_select_email|assert_select_rjs|assert_select_encoded|css_select|at_exit|" +
  37. "attr|attr_writer|attr_reader|attr_accessor|attr_accessible|autoload|binding|block_given?|callcc|" +
  38. "caller|catch|chomp|chomp!|chop|chop!|defined?|delete_via_redirect|eval|exec|exit|" +
  39. "exit!|fail|Float|flunk|follow_redirect!|fork|form_for|form_tag|format|gets|global_variables|gsub|" +
  40. "gsub!|get_via_redirect|host!|https?|https!|include|Integer|lambda|link_to|" +
  41. "link_to_unless_current|link_to_function|link_to_remote|load|local_variables|loop|open|open_session|" +
  42. "p|print|printf|proc|putc|puts|post_via_redirect|put_via_redirect|raise|rand|" +
  43. "raw|readline|readlines|redirect?|request_via_redirect|require|scan|select|" +
  44. "set_trace_func|sleep|split|sprintf|srand|String|stylesheet_link_tag|syscall|system|sub|sub!|test|" +
  45. "throw|trace_var|trap|untrace_var|atan2|cos|exp|frexp|ldexp|log|log10|sin|sqrt|tan|" +
  46. "render|javascript_include_tag|csrf_meta_tag|label_tag|text_field_tag|submit_tag|check_box_tag|" +
  47. "content_tag|radio_button_tag|text_area_tag|password_field_tag|hidden_field_tag|" +
  48. "fields_for|select_tag|options_for_select|options_from_collection_for_select|collection_select|" +
  49. "time_zone_select|select_date|select_time|select_datetime|date_select|time_select|datetime_select|" +
  50. "select_year|select_month|select_day|select_hour|select_minute|select_second|file_field_tag|" +
  51. "file_field|respond_to|skip_before_filter|around_filter|after_filter|verify|" +
  52. "protect_from_forgery|rescue_from|helper_method|redirect_to|before_filter|" +
  53. "send_data|send_file|validates_presence_of|validates_uniqueness_of|validates_length_of|" +
  54. "validates_format_of|validates_acceptance_of|validates_associated|validates_exclusion_of|" +
  55. "validates_inclusion_of|validates_numericality_of|validates_with|validates_each|" +
  56. "authenticate_or_request_with_http_basic|authenticate_or_request_with_http_digest|" +
  57. "filter_parameter_logging|match|get|post|resources|redirect|scope|assert_routing|" +
  58. "translate|localize|extract_locale_from_tld|caches_page|expire_page|caches_action|expire_action|" +
  59. "cache|expire_fragment|expire_cache_for|observe|cache_sweeper|" +
  60. "has_many|has_one|belongs_to|has_and_belongs_to_many"
  61. );
  62. var keywords = (
  63. "alias|and|BEGIN|begin|break|case|class|def|defined|do|else|elsif|END|end|ensure|" +
  64. "__FILE__|finally|for|gem|if|in|__LINE__|module|next|not|or|private|protected|public|" +
  65. "redo|rescue|retry|return|super|then|undef|unless|until|when|while|yield"
  66. );
  67. var buildinConstants = (
  68. "true|TRUE|false|FALSE|nil|NIL|ARGF|ARGV|DATA|ENV|RUBY_PLATFORM|RUBY_RELEASE_DATE|" +
  69. "RUBY_VERSION|STDERR|STDIN|STDOUT|TOPLEVEL_BINDING"
  70. );
  71. var builtinVariables = (
  72. "\$DEBUG|\$defout|\$FILENAME|\$LOAD_PATH|\$SAFE|\$stdin|\$stdout|\$stderr|\$VERBOSE|" +
  73. "$!|root_url|flash|session|cookies|params|request|response|logger|self"
  74. );
  75. var keywordMapper = this.$keywords = this.createKeywordMapper({
  76. "keyword": keywords,
  77. "constant.language": buildinConstants,
  78. "variable.language": builtinVariables,
  79. "support.function": builtinFunctions,
  80. "invalid.deprecated": "debugger" // TODO is this a remnant from js mode?
  81. }, "identifier");
  82. this.$rules = {
  83. "start" : [
  84. {
  85. token : "comment",
  86. regex : "#.*$"
  87. }, {
  88. token : "comment", // multi line comment
  89. regex : "^=begin(?:$|\\s.*$)",
  90. next : "comment"
  91. }, {
  92. token : "string.regexp",
  93. regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
  94. },
  95. [{
  96. regex: "[{}]", onMatch: function(val, state, stack) {
  97. this.next = val == "{" ? this.nextState : "";
  98. if (val == "{" && stack.length) {
  99. stack.unshift("start", state);
  100. return "paren.lparen";
  101. }
  102. if (val == "}" && stack.length) {
  103. stack.shift();
  104. this.next = stack.shift();
  105. if (this.next.indexOf("string") != -1)
  106. return "paren.end";
  107. }
  108. return val == "{" ? "paren.lparen" : "paren.rparen";
  109. },
  110. nextState: "start"
  111. }, {
  112. token : "string.start",
  113. regex : /"/,
  114. push : [{
  115. token : "constant.language.escape",
  116. regex : /\\(?:[nsrtvfbae'"\\]|c.|C-.|M-.(?:\\C-.)?|[0-7]{3}|x[\da-fA-F]{2}|u[\da-fA-F]{4})/
  117. }, {
  118. token : "paren.start",
  119. regex : /\#{/,
  120. push : "start"
  121. }, {
  122. token : "string.end",
  123. regex : /"/,
  124. next : "pop"
  125. }, {
  126. defaultToken: "string"
  127. }]
  128. }, {
  129. token : "string.start",
  130. regex : /`/,
  131. push : [{
  132. token : "constant.language.escape",
  133. regex : /\\(?:[nsrtvfbae'"\\]|c.|C-.|M-.(?:\\C-.)?|[0-7]{3}|x[\da-fA-F]{2}|u[\da-fA-F]{4})/
  134. }, {
  135. token : "paren.start",
  136. regex : /\#{/,
  137. push : "start"
  138. }, {
  139. token : "string.end",
  140. regex : /`/,
  141. next : "pop"
  142. }, {
  143. defaultToken: "string"
  144. }]
  145. }, {
  146. token : "string.start",
  147. regex : /'/,
  148. push : [{
  149. token : "constant.language.escape",
  150. regex : /\\['\\]/
  151. }, {
  152. token : "string.end",
  153. regex : /'/,
  154. next : "pop"
  155. }, {
  156. defaultToken: "string"
  157. }]
  158. }],
  159. {
  160. token : "text", // namespaces aren't symbols
  161. regex : "::"
  162. }, {
  163. token : "variable.instance", // instance variable
  164. regex : "@{1,2}[a-zA-Z_\\d]+"
  165. }, {
  166. token : "support.class", // class name
  167. regex : "[A-Z][a-zA-Z_\\d]+"
  168. },
  169. constantOtherSymbol,
  170. constantNumericHex,
  171. constantNumericFloat,
  172. {
  173. token : "constant.language.boolean",
  174. regex : "(?:true|false)\\b"
  175. }, {
  176. token : keywordMapper,
  177. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  178. }, {
  179. token : "punctuation.separator.key-value",
  180. regex : "=>"
  181. }, {
  182. stateName: "heredoc",
  183. onMatch : function(value, currentState, stack) {
  184. var next = value[2] == '-' ? "indentedHeredoc" : "heredoc";
  185. var tokens = value.split(this.splitRegex);
  186. stack.push(next, tokens[3]);
  187. return [
  188. {type:"constant", value: tokens[1]},
  189. {type:"string", value: tokens[2]},
  190. {type:"support.class", value: tokens[3]},
  191. {type:"string", value: tokens[4]}
  192. ];
  193. },
  194. regex : "(<<-?)(['\"`]?)([\\w]+)(['\"`]?)",
  195. rules: {
  196. heredoc: [{
  197. onMatch: function(value, currentState, stack) {
  198. if (value === stack[1]) {
  199. stack.shift();
  200. stack.shift();
  201. this.next = stack[0] || "start";
  202. return "support.class";
  203. }
  204. this.next = "";
  205. return "string";
  206. },
  207. regex: ".*$",
  208. next: "start"
  209. }],
  210. indentedHeredoc: [{
  211. token: "string",
  212. regex: "^ +"
  213. }, {
  214. onMatch: function(value, currentState, stack) {
  215. if (value === stack[1]) {
  216. stack.shift();
  217. stack.shift();
  218. this.next = stack[0] || "start";
  219. return "support.class";
  220. }
  221. this.next = "";
  222. return "string";
  223. },
  224. regex: ".*$",
  225. next: "start"
  226. }]
  227. }
  228. }, {
  229. regex : "$",
  230. token : "empty",
  231. next : function(currentState, stack) {
  232. if (stack[0] === "heredoc" || stack[0] === "indentedHeredoc")
  233. return stack[0];
  234. return currentState;
  235. }
  236. }, {
  237. token : "string.character",
  238. regex : "\\B\\?."
  239. }, {
  240. token : "keyword.operator",
  241. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  242. }, {
  243. token : "paren.lparen",
  244. regex : "[[({]"
  245. }, {
  246. token : "paren.rparen",
  247. regex : "[\\])}]"
  248. }, {
  249. token : "text",
  250. regex : "\\s+"
  251. }
  252. ],
  253. "comment" : [
  254. {
  255. token : "comment", // closing comment
  256. regex : "^=end(?:$|\\s.*$)",
  257. next : "start"
  258. }, {
  259. token : "comment", // comment spanning whole line
  260. regex : ".+"
  261. }
  262. ]
  263. };
  264. this.normalizeRules();
  265. };
  266. oop.inherits(RubyHighlightRules, TextHighlightRules);
  267. exports.RubyHighlightRules = RubyHighlightRules;
  268. });
  269. define("ace/mode/haml_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules","ace/mode/ruby_highlight_rules"], function(require, exports, module) {
  270. "use strict";
  271. var oop = require("../lib/oop");
  272. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  273. var RubyExports = require("./ruby_highlight_rules");
  274. var RubyHighlightRules = RubyExports.RubyHighlightRules;
  275. var HamlHighlightRules = function() {
  276. this.$rules =
  277. {
  278. "start": [
  279. {
  280. token : "punctuation.section.comment",
  281. regex : /^\s*\/.*/
  282. },
  283. {
  284. token : "punctuation.section.comment",
  285. regex : /^\s*#.*/
  286. },
  287. {
  288. token: "string.quoted.double",
  289. regex: "==.+?=="
  290. },
  291. {
  292. token: "keyword.other.doctype",
  293. regex: "^!!!\\s*(?:[a-zA-Z0-9-_]+)?"
  294. },
  295. RubyExports.qString,
  296. RubyExports.qqString,
  297. RubyExports.tString,
  298. {
  299. token: ["entity.name.tag.haml"],
  300. regex: /^\s*%[\w:]+/,
  301. next: "tag_single"
  302. },
  303. {
  304. token: [ "meta.escape.haml" ],
  305. regex: "^\\s*\\\\."
  306. },
  307. RubyExports.constantNumericHex,
  308. RubyExports.constantNumericFloat,
  309. RubyExports.constantOtherSymbol,
  310. {
  311. token: "text",
  312. regex: "=|-|~",
  313. next: "embedded_ruby"
  314. }
  315. ],
  316. "tag_single": [
  317. {
  318. token: "entity.other.attribute-name.class.haml",
  319. regex: "\\.[\\w-]+"
  320. },
  321. {
  322. token: "entity.other.attribute-name.id.haml",
  323. regex: "#[\\w-]+"
  324. },
  325. {
  326. token: "punctuation.section",
  327. regex: "\\{",
  328. next: "section"
  329. },
  330. RubyExports.constantOtherSymbol,
  331. {
  332. token: "text",
  333. regex: /\s/,
  334. next: "start"
  335. },
  336. {
  337. token: "empty",
  338. regex: "$|(?!\\.|#|\\{|\\[|=|-|~|\\/)",
  339. next: "start"
  340. }
  341. ],
  342. "section": [
  343. RubyExports.constantOtherSymbol,
  344. RubyExports.qString,
  345. RubyExports.qqString,
  346. RubyExports.tString,
  347. RubyExports.constantNumericHex,
  348. RubyExports.constantNumericFloat,
  349. {
  350. token: "punctuation.section",
  351. regex: "\\}",
  352. next: "start"
  353. }
  354. ],
  355. "embedded_ruby": [
  356. RubyExports.constantNumericHex,
  357. RubyExports.constantNumericFloat,
  358. {
  359. token : "support.class", // class name
  360. regex : "[A-Z][a-zA-Z_\\d]+"
  361. },
  362. {
  363. token : new RubyHighlightRules().getKeywords(),
  364. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  365. },
  366. {
  367. token : ["keyword", "text", "text"],
  368. regex : "(?:do|\\{)(?: \\|[^|]+\\|)?$",
  369. next : "start"
  370. },
  371. {
  372. token : ["text"],
  373. regex : "^$",
  374. next : "start"
  375. },
  376. {
  377. token : ["text"],
  378. regex : "^(?!.*\\|\\s*$)",
  379. next : "start"
  380. }
  381. ]
  382. }
  383. };
  384. oop.inherits(HamlHighlightRules, TextHighlightRules);
  385. exports.HamlHighlightRules = HamlHighlightRules;
  386. });
  387. define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  388. "use strict";
  389. var oop = require("../../lib/oop");
  390. var BaseFoldMode = require("./fold_mode").FoldMode;
  391. var Range = require("../../range").Range;
  392. var FoldMode = exports.FoldMode = function() {};
  393. oop.inherits(FoldMode, BaseFoldMode);
  394. (function() {
  395. this.getFoldWidgetRange = function(session, foldStyle, row) {
  396. var range = this.indentationBlock(session, row);
  397. if (range)
  398. return range;
  399. var re = /\S/;
  400. var line = session.getLine(row);
  401. var startLevel = line.search(re);
  402. if (startLevel == -1 || line[startLevel] != "#")
  403. return;
  404. var startColumn = line.length;
  405. var maxRow = session.getLength();
  406. var startRow = row;
  407. var endRow = row;
  408. while (++row < maxRow) {
  409. line = session.getLine(row);
  410. var level = line.search(re);
  411. if (level == -1)
  412. continue;
  413. if (line[level] != "#")
  414. break;
  415. endRow = row;
  416. }
  417. if (endRow > startRow) {
  418. var endColumn = session.getLine(endRow).length;
  419. return new Range(startRow, startColumn, endRow, endColumn);
  420. }
  421. };
  422. this.getFoldWidget = function(session, foldStyle, row) {
  423. var line = session.getLine(row);
  424. var indent = line.search(/\S/);
  425. var next = session.getLine(row + 1);
  426. var prev = session.getLine(row - 1);
  427. var prevIndent = prev.search(/\S/);
  428. var nextIndent = next.search(/\S/);
  429. if (indent == -1) {
  430. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  431. return "";
  432. }
  433. if (prevIndent == -1) {
  434. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  435. session.foldWidgets[row - 1] = "";
  436. session.foldWidgets[row + 1] = "";
  437. return "start";
  438. }
  439. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  440. if (session.getLine(row - 2).search(/\S/) == -1) {
  441. session.foldWidgets[row - 1] = "start";
  442. session.foldWidgets[row + 1] = "";
  443. return "";
  444. }
  445. }
  446. if (prevIndent!= -1 && prevIndent < indent)
  447. session.foldWidgets[row - 1] = "start";
  448. else
  449. session.foldWidgets[row - 1] = "";
  450. if (indent < nextIndent)
  451. return "start";
  452. else
  453. return "";
  454. };
  455. }).call(FoldMode.prototype);
  456. });
  457. define("ace/mode/haml",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/haml_highlight_rules","ace/mode/folding/coffee"], function(require, exports, module) {
  458. "use strict";
  459. var oop = require("../lib/oop");
  460. var TextMode = require("./text").Mode;
  461. var HamlHighlightRules = require("./haml_highlight_rules").HamlHighlightRules;
  462. var FoldMode = require("./folding/coffee").FoldMode;
  463. var Mode = function() {
  464. this.HighlightRules = HamlHighlightRules;
  465. this.foldingRules = new FoldMode();
  466. };
  467. oop.inherits(Mode, TextMode);
  468. (function() {
  469. this.lineCommentStart = ["//", "#"];
  470. this.$id = "ace/mode/haml";
  471. }).call(Mode.prototype);
  472. exports.Mode = Mode;
  473. });