Sin descripción
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-haml.js 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. ace.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 : "keyword.operator",
  238. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  239. }, {
  240. token : "paren.lparen",
  241. regex : "[[({]"
  242. }, {
  243. token : "paren.rparen",
  244. regex : "[\\])}]"
  245. }, {
  246. token : "text",
  247. regex : "\\s+"
  248. }
  249. ],
  250. "comment" : [
  251. {
  252. token : "comment", // closing comment
  253. regex : "^=end(?:$|\\s.*$)",
  254. next : "start"
  255. }, {
  256. token : "comment", // comment spanning whole line
  257. regex : ".+"
  258. }
  259. ]
  260. };
  261. this.normalizeRules();
  262. };
  263. oop.inherits(RubyHighlightRules, TextHighlightRules);
  264. exports.RubyHighlightRules = RubyHighlightRules;
  265. });
  266. ace.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) {
  267. "use strict";
  268. var oop = require("../lib/oop");
  269. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  270. var RubyExports = require("./ruby_highlight_rules");
  271. var RubyHighlightRules = RubyExports.RubyHighlightRules;
  272. var HamlHighlightRules = function() {
  273. this.$rules =
  274. {
  275. "start": [
  276. {
  277. token : "punctuation.section.comment",
  278. regex : /^\s*\/.*/
  279. },
  280. {
  281. token : "punctuation.section.comment",
  282. regex : /^\s*#.*/
  283. },
  284. {
  285. token: "string.quoted.double",
  286. regex: "==.+?=="
  287. },
  288. {
  289. token: "keyword.other.doctype",
  290. regex: "^!!!\\s*(?:[a-zA-Z0-9-_]+)?"
  291. },
  292. RubyExports.qString,
  293. RubyExports.qqString,
  294. RubyExports.tString,
  295. {
  296. token: ["entity.name.tag.haml"],
  297. regex: /^\s*%[\w:]+/,
  298. next: "tag_single"
  299. },
  300. {
  301. token: [ "meta.escape.haml" ],
  302. regex: "^\\s*\\\\."
  303. },
  304. RubyExports.constantNumericHex,
  305. RubyExports.constantNumericFloat,
  306. RubyExports.constantOtherSymbol,
  307. {
  308. token: "text",
  309. regex: "=|-|~",
  310. next: "embedded_ruby"
  311. }
  312. ],
  313. "tag_single": [
  314. {
  315. token: "entity.other.attribute-name.class.haml",
  316. regex: "\\.[\\w-]+"
  317. },
  318. {
  319. token: "entity.other.attribute-name.id.haml",
  320. regex: "#[\\w-]+"
  321. },
  322. {
  323. token: "punctuation.section",
  324. regex: "\\{",
  325. next: "section"
  326. },
  327. RubyExports.constantOtherSymbol,
  328. {
  329. token: "text",
  330. regex: /\s/,
  331. next: "start"
  332. },
  333. {
  334. token: "empty",
  335. regex: "$|(?!\\.|#|\\{|\\[|=|-|~|\\/)",
  336. next: "start"
  337. }
  338. ],
  339. "section": [
  340. RubyExports.constantOtherSymbol,
  341. RubyExports.qString,
  342. RubyExports.qqString,
  343. RubyExports.tString,
  344. RubyExports.constantNumericHex,
  345. RubyExports.constantNumericFloat,
  346. {
  347. token: "punctuation.section",
  348. regex: "\\}",
  349. next: "start"
  350. }
  351. ],
  352. "embedded_ruby": [
  353. RubyExports.constantNumericHex,
  354. RubyExports.constantNumericFloat,
  355. {
  356. token : "support.class", // class name
  357. regex : "[A-Z][a-zA-Z_\\d]+"
  358. },
  359. {
  360. token : new RubyHighlightRules().getKeywords(),
  361. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  362. },
  363. {
  364. token : ["keyword", "text", "text"],
  365. regex : "(?:do|\\{)(?: \\|[^|]+\\|)?$",
  366. next : "start"
  367. },
  368. {
  369. token : ["text"],
  370. regex : "^$",
  371. next : "start"
  372. },
  373. {
  374. token : ["text"],
  375. regex : "^(?!.*\\|\\s*$)",
  376. next : "start"
  377. }
  378. ]
  379. }
  380. };
  381. oop.inherits(HamlHighlightRules, TextHighlightRules);
  382. exports.HamlHighlightRules = HamlHighlightRules;
  383. });
  384. ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  385. "use strict";
  386. var oop = require("../../lib/oop");
  387. var BaseFoldMode = require("./fold_mode").FoldMode;
  388. var Range = require("../../range").Range;
  389. var FoldMode = exports.FoldMode = function() {};
  390. oop.inherits(FoldMode, BaseFoldMode);
  391. (function() {
  392. this.getFoldWidgetRange = function(session, foldStyle, row) {
  393. var range = this.indentationBlock(session, row);
  394. if (range)
  395. return range;
  396. var re = /\S/;
  397. var line = session.getLine(row);
  398. var startLevel = line.search(re);
  399. if (startLevel == -1 || line[startLevel] != "#")
  400. return;
  401. var startColumn = line.length;
  402. var maxRow = session.getLength();
  403. var startRow = row;
  404. var endRow = row;
  405. while (++row < maxRow) {
  406. line = session.getLine(row);
  407. var level = line.search(re);
  408. if (level == -1)
  409. continue;
  410. if (line[level] != "#")
  411. break;
  412. endRow = row;
  413. }
  414. if (endRow > startRow) {
  415. var endColumn = session.getLine(endRow).length;
  416. return new Range(startRow, startColumn, endRow, endColumn);
  417. }
  418. };
  419. this.getFoldWidget = function(session, foldStyle, row) {
  420. var line = session.getLine(row);
  421. var indent = line.search(/\S/);
  422. var next = session.getLine(row + 1);
  423. var prev = session.getLine(row - 1);
  424. var prevIndent = prev.search(/\S/);
  425. var nextIndent = next.search(/\S/);
  426. if (indent == -1) {
  427. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  428. return "";
  429. }
  430. if (prevIndent == -1) {
  431. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  432. session.foldWidgets[row - 1] = "";
  433. session.foldWidgets[row + 1] = "";
  434. return "start";
  435. }
  436. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  437. if (session.getLine(row - 2).search(/\S/) == -1) {
  438. session.foldWidgets[row - 1] = "start";
  439. session.foldWidgets[row + 1] = "";
  440. return "";
  441. }
  442. }
  443. if (prevIndent!= -1 && prevIndent < indent)
  444. session.foldWidgets[row - 1] = "start";
  445. else
  446. session.foldWidgets[row - 1] = "";
  447. if (indent < nextIndent)
  448. return "start";
  449. else
  450. return "";
  451. };
  452. }).call(FoldMode.prototype);
  453. });
  454. ace.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) {
  455. "use strict";
  456. var oop = require("../lib/oop");
  457. var TextMode = require("./text").Mode;
  458. var HamlHighlightRules = require("./haml_highlight_rules").HamlHighlightRules;
  459. var FoldMode = require("./folding/coffee").FoldMode;
  460. var Mode = function() {
  461. this.HighlightRules = HamlHighlightRules;
  462. this.foldingRules = new FoldMode();
  463. };
  464. oop.inherits(Mode, TextMode);
  465. (function() {
  466. this.lineCommentStart = ["//", "#"];
  467. this.$id = "ace/mode/haml";
  468. }).call(Mode.prototype);
  469. exports.Mode = Mode;
  470. });