1bd8ec07cab7c3b9e5e00671ed6ddcd5.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. ace.define("ace/mode/fortran_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){/* Derived from Python highlighing rules */
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var FortranHighlightRules = function () {
  6. var keywords = ("call|case|contains|continue|cycle|do|else|elseif|end|enddo|endif|function|" +
  7. "if|implicit|in|include|inout|intent|module|none|only|out|print|program|return|" +
  8. "select|status|stop|subroutine|" +
  9. "return|then|use|while|write|" +
  10. "CALL|CASE|CONTAINS|CONTINUE|CYCLE|DO|ELSE|ELSEIF|END|ENDDO|ENDIF|FUNCTION|" +
  11. "IF|IMPLICIT|IN|INCLUDE|INOUT|INTENT|MODULE|NONE|ONLY|OUT|PRINT|PROGRAM|RETURN|" +
  12. "SELECT|STATUS|STOP|SUBROUTINE|" +
  13. "RETURN|THEN|USE|WHILE|WRITE");
  14. var keywordOperators = ("and|or|not|eq|ne|gt|ge|lt|le|" +
  15. "AND|OR|NOT|EQ|NE|GT|GE|LT|LE");
  16. var builtinConstants = ("true|false|TRUE|FALSE");
  17. var builtinFunctions = ("abs|achar|acos|acosh|adjustl|adjustr|aimag|aint|all|allocate|" +
  18. "anint|any|asin|asinh|associated|atan|atan2|atanh|" +
  19. "bessel_j0|bessel_j1|bessel_jn|bessel_y0|bessel_y1|bessel_yn|" +
  20. "bge|bgt|bit_size|ble|blt|btest|ceiling|char|cmplx|conjg|cos|cosh|" +
  21. "count|cpu_time|cshift|date_and_time|dble|deallocate|digits|dim|dot_product|dprod|" +
  22. "dshiftl|dshiftr|dsqrt|eoshift|epsilon|erf|erfc|erfc_scaled|exp|float|floor|" +
  23. "format|fraction|gamma|input|len|lge|lgt|lle|llt|log|log10|maskl|maskr|matmul|max|maxloc|maxval|" +
  24. "merge|min|minloc|minval|mod|modulo|nint|not|norm2|null|nullify|pack|parity|popcnt|poppar|" +
  25. "precision|present|product|radix|random_number|random_seed|range|repeat|reshape|round|" +
  26. "rrspacing|same_type_as|scale|scan|selected_char_kind|selected_int_kind|selected_real_kind|" +
  27. "set_exponent|shape|shifta|shiftl|shiftr|sign|sin|sinh|size|sngl|spacing|spread|" +
  28. "sqrt|sum|system_clock|tan|tanh|tiny|trailz|transfer|transpose|trim|ubound|unpack|verify|" +
  29. "ABS|ACHAR|ACOS|ACOSH|ADJUSTL|ADJUSTR|AIMAG|AINT|ALL|ALLOCATE|" +
  30. "ANINT|ANY|ASIN|ASINH|ASSOCIATED|ATAN|ATAN2|ATANH|" +
  31. "BESSEL_J0|BESSEL_J1|BESSEL_JN|BESSEL_Y0|BESSEL_Y1|BESSEL_YN|" +
  32. "BGE|BGT|BIT_SIZE|BLE|BLT|BTEST|CEILING|CHAR|CMPLX|CONJG|COS|COSH|" +
  33. "COUNT|CPU_TIME|CSHIFT|DATE_AND_TIME|DBLE|DEALLOCATE|DIGITS|DIM|DOT_PRODUCT|DPROD|" +
  34. "DSHIFTL|DSHIFTR|DSQRT|EOSHIFT|EPSILON|ERF|ERFC|ERFC_SCALED|EXP|FLOAT|FLOOR|" +
  35. "FORMAT|FRACTION|GAMMA|INPUT|LEN|LGE|LGT|LLE|LLT|LOG|LOG10|MASKL|MASKR|MATMUL|MAX|MAXLOC|MAXVAL|" +
  36. "MERGE|MIN|MINLOC|MINVAL|MOD|MODULO|NINT|NOT|NORM2|NULL|NULLIFY|PACK|PARITY|POPCNT|POPPAR|" +
  37. "PRECISION|PRESENT|PRODUCT|RADIX|RANDOM_NUMBER|RANDOM_SEED|RANGE|REPEAT|RESHAPE|ROUND|" +
  38. "RRSPACING|SAME_TYPE_AS|SCALE|SCAN|SELECTED_CHAR_KIND|SELECTED_INT_KIND|SELECTED_REAL_KIND|" +
  39. "SET_EXPONENT|SHAPE|SHIFTA|SHIFTL|SHIFTR|SIGN|SIN|SINH|SIZE|SNGL|SPACING|SPREAD|" +
  40. "SQRT|SUM|SYSTEM_CLOCK|TAN|TANH|TINY|TRAILZ|TRANSFER|TRANSPOSE|TRIM|UBOUND|UNPACK|VERIFY");
  41. var storageType = ("logical|character|integer|real|type|" +
  42. "LOGICAL|CHARACTER|INTEGER|REAL|TYPE");
  43. var storageModifiers = ("allocatable|dimension|intent|parameter|pointer|target|private|public|" +
  44. "ALLOCATABLE|DIMENSION|INTENT|PARAMETER|POINTER|TARGET|PRIVATE|PUBLIC");
  45. var keywordMapper = this.createKeywordMapper({
  46. "invalid.deprecated": "debugger",
  47. "support.function": builtinFunctions,
  48. "constant.language": builtinConstants,
  49. "keyword": keywords,
  50. "keyword.operator": keywordOperators,
  51. "storage.type": storageType,
  52. "storage.modifier": storageModifiers
  53. }, "identifier");
  54. var strPre = "(?:r|u|ur|R|U|UR|Ur|uR)?";
  55. var decimalInteger = "(?:(?:[1-9]\\d*)|(?:0))";
  56. var octInteger = "(?:0[oO]?[0-7]+)";
  57. var hexInteger = "(?:0[xX][\\dA-Fa-f]+)";
  58. var binInteger = "(?:0[bB][01]+)";
  59. var integer = "(?:" + decimalInteger + "|" + octInteger + "|" + hexInteger + "|" + binInteger + ")";
  60. var exponent = "(?:[eE][+-]?\\d+)";
  61. var fraction = "(?:\\.\\d+)";
  62. var intPart = "(?:\\d+)";
  63. var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))";
  64. var exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + exponent + ")";
  65. var floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")";
  66. var stringEscape = "\\\\(x[0-9A-Fa-f]{2}|[0-7]{3}|[\\\\abfnrtv'\"]|U[0-9A-Fa-f]{8}|u[0-9A-Fa-f]{4})";
  67. this.$rules = {
  68. "start": [{
  69. token: "comment",
  70. regex: "!.*$"
  71. }, {
  72. token: "string",
  73. regex: strPre + '"{3}',
  74. next: "qqstring3"
  75. }, {
  76. token: "string",
  77. regex: strPre + '"(?=.)',
  78. next: "qqstring"
  79. }, {
  80. token: "string",
  81. regex: strPre + "'{3}",
  82. next: "qstring3"
  83. }, {
  84. token: "string",
  85. regex: strPre + "'(?=.)",
  86. next: "qstring"
  87. }, {
  88. token: "constant.numeric",
  89. regex: "(?:" + floatNumber + "|\\d+)[jJ]\\b"
  90. }, {
  91. token: "constant.numeric",
  92. regex: floatNumber
  93. }, {
  94. token: "constant.numeric",
  95. regex: integer + "[lL]\\b"
  96. }, {
  97. token: "constant.numeric",
  98. regex: integer + "\\b"
  99. }, {
  100. token: "keyword",
  101. regex: "#\\s*(?:include|import|define|undef|INCLUDE|IMPORT|DEFINE|UNDEF)\\b"
  102. }, {
  103. token: "keyword",
  104. regex: "#\\s*(?:endif|ifdef|else|elseif|ifndef|ENDIF|IFDEF|ELSE|ELSEIF|IFNDEF)\\b"
  105. }, {
  106. token: keywordMapper,
  107. regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  108. }, {
  109. token: "keyword.operator",
  110. regex: "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|="
  111. }, {
  112. token: "paren.lparen",
  113. regex: "[\\[\\(\\{]"
  114. }, {
  115. token: "paren.rparen",
  116. regex: "[\\]\\)\\}]"
  117. }, {
  118. token: "text",
  119. regex: "\\s+"
  120. }],
  121. "qqstring3": [{
  122. token: "constant.language.escape",
  123. regex: stringEscape
  124. }, {
  125. token: "string",
  126. regex: '"{3}',
  127. next: "start"
  128. }, {
  129. defaultToken: "string"
  130. }],
  131. "qstring3": [{
  132. token: "constant.language.escape",
  133. regex: stringEscape
  134. }, {
  135. token: "string",
  136. regex: '"{3}',
  137. next: "start"
  138. }, {
  139. defaultToken: "string"
  140. }],
  141. "qqstring": [{
  142. token: "constant.language.escape",
  143. regex: stringEscape
  144. }, {
  145. token: "string",
  146. regex: "\\\\$",
  147. next: "qqstring"
  148. }, {
  149. token: "string",
  150. regex: '"|$',
  151. next: "start"
  152. }, {
  153. defaultToken: "string"
  154. }],
  155. "qstring": [{
  156. token: "constant.language.escape",
  157. regex: stringEscape
  158. }, {
  159. token: "string",
  160. regex: "\\\\$",
  161. next: "qstring"
  162. }, {
  163. token: "string",
  164. regex: "'|$",
  165. next: "start"
  166. }, {
  167. defaultToken: "string"
  168. }]
  169. };
  170. };
  171. oop.inherits(FortranHighlightRules, TextHighlightRules);
  172. exports.FortranHighlightRules = FortranHighlightRules;
  173. });
  174. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict";
  175. var oop = require("../../lib/oop");
  176. var Range = require("../../range").Range;
  177. var BaseFoldMode = require("./fold_mode").FoldMode;
  178. var FoldMode = exports.FoldMode = function (commentRegex) {
  179. if (commentRegex) {
  180. this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
  181. this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
  182. }
  183. };
  184. oop.inherits(FoldMode, BaseFoldMode);
  185. (function () {
  186. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  187. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  188. this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
  189. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  190. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  191. this._getFoldWidgetBase = this.getFoldWidget;
  192. this.getFoldWidget = function (session, foldStyle, row) {
  193. var line = session.getLine(row);
  194. if (this.singleLineBlockCommentRe.test(line)) {
  195. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  196. return "";
  197. }
  198. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  199. if (!fw && this.startRegionRe.test(line))
  200. return "start"; // lineCommentRegionStart
  201. return fw;
  202. };
  203. this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
  204. var line = session.getLine(row);
  205. if (this.startRegionRe.test(line))
  206. return this.getCommentRegionBlock(session, line, row);
  207. var match = line.match(this.foldingStartMarker);
  208. if (match) {
  209. var i = match.index;
  210. if (match[1])
  211. return this.openingBracketBlock(session, match[1], row, i);
  212. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  213. if (range && !range.isMultiLine()) {
  214. if (forceMultiline) {
  215. range = this.getSectionRange(session, row);
  216. }
  217. else if (foldStyle != "all")
  218. range = null;
  219. }
  220. return range;
  221. }
  222. if (foldStyle === "markbegin")
  223. return;
  224. var match = line.match(this.foldingStopMarker);
  225. if (match) {
  226. var i = match.index + match[0].length;
  227. if (match[1])
  228. return this.closingBracketBlock(session, match[1], row, i);
  229. return session.getCommentFoldRange(row, i, -1);
  230. }
  231. };
  232. this.getSectionRange = function (session, row) {
  233. var line = session.getLine(row);
  234. var startIndent = line.search(/\S/);
  235. var startRow = row;
  236. var startColumn = line.length;
  237. row = row + 1;
  238. var endRow = row;
  239. var maxRow = session.getLength();
  240. while (++row < maxRow) {
  241. line = session.getLine(row);
  242. var indent = line.search(/\S/);
  243. if (indent === -1)
  244. continue;
  245. if (startIndent > indent)
  246. break;
  247. var subRange = this.getFoldWidgetRange(session, "all", row);
  248. if (subRange) {
  249. if (subRange.start.row <= startRow) {
  250. break;
  251. }
  252. else if (subRange.isMultiLine()) {
  253. row = subRange.end.row;
  254. }
  255. else if (startIndent == indent) {
  256. break;
  257. }
  258. }
  259. endRow = row;
  260. }
  261. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  262. };
  263. this.getCommentRegionBlock = function (session, line, row) {
  264. var startColumn = line.search(/\s*$/);
  265. var maxRow = session.getLength();
  266. var startRow = row;
  267. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  268. var depth = 1;
  269. while (++row < maxRow) {
  270. line = session.getLine(row);
  271. var m = re.exec(line);
  272. if (!m)
  273. continue;
  274. if (m[1])
  275. depth--;
  276. else
  277. depth++;
  278. if (!depth)
  279. break;
  280. }
  281. var endRow = row;
  282. if (endRow > startRow) {
  283. return new Range(startRow, startColumn, endRow, line.length);
  284. }
  285. };
  286. }).call(FoldMode.prototype);
  287. });
  288. ace.define("ace/mode/fortran",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/fortran_highlight_rules","ace/mode/folding/cstyle","ace/range"], function(require, exports, module){/* Derived from Python rules */
  289. "use strict";
  290. var oop = require("../lib/oop");
  291. var TextMode = require("./text").Mode;
  292. var FortranHighlightRules = require("./fortran_highlight_rules").FortranHighlightRules;
  293. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  294. var Range = require("../range").Range;
  295. var Mode = function () {
  296. this.HighlightRules = FortranHighlightRules;
  297. this.foldingRules = new CStyleFoldMode();
  298. this.$behaviour = this.$defaultBehaviour;
  299. };
  300. oop.inherits(Mode, TextMode);
  301. (function () {
  302. this.lineCommentStart = "!";
  303. this.getNextLineIndent = function (state, line, tab) {
  304. var indent = this.$getIndent(line);
  305. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  306. var tokens = tokenizedLine.tokens;
  307. if (tokens.length && tokens[tokens.length - 1].type == "comment") {
  308. return indent;
  309. }
  310. if (state == "start") {
  311. var match = line.match(/^.*[\{\(\[:]\s*$/);
  312. if (match) {
  313. indent += tab;
  314. }
  315. }
  316. return indent;
  317. };
  318. var outdents = {
  319. "return": 1,
  320. "break": 1,
  321. "continue": 1,
  322. "RETURN": 1,
  323. "BREAK": 1,
  324. "CONTINUE": 1
  325. };
  326. this.checkOutdent = function (state, line, input) {
  327. if (input !== "\r\n" && input !== "\r" && input !== "\n")
  328. return false;
  329. var tokens = this.getTokenizer().getLineTokens(line.trim(), state).tokens;
  330. if (!tokens)
  331. return false;
  332. do {
  333. var last = tokens.pop();
  334. } while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/))));
  335. if (!last)
  336. return false;
  337. return (last.type == "keyword" && outdents[last.value]);
  338. };
  339. this.autoOutdent = function (state, doc, row) {
  340. row += 1;
  341. var indent = this.$getIndent(doc.getLine(row));
  342. var tab = doc.getTabString();
  343. if (indent.slice(-tab.length) == tab)
  344. doc.remove(new Range(row, indent.length - tab.length, row, indent.length));
  345. };
  346. this.$id = "ace/mode/fortran";
  347. }).call(Mode.prototype);
  348. exports.Mode = Mode;
  349. }); (function() {
  350. ace.require(["ace/mode/fortran"], function(m) {
  351. if (typeof module == "object" && typeof exports == "object" && module) {
  352. module.exports = m;
  353. }
  354. });
  355. })();