mode-fortran.js 15 KB

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