mode-powershell-uncompressed.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. define('ace/mode/powershell', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/powershell_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle'], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextMode = require("./text").Mode;
  5. var Tokenizer = require("../tokenizer").Tokenizer;
  6. var PowershellHighlightRules = require("./powershell_highlight_rules").PowershellHighlightRules;
  7. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  8. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  9. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  10. var Mode = function() {
  11. this.$tokenizer = new Tokenizer(new PowershellHighlightRules().getRules());
  12. this.$outdent = new MatchingBraceOutdent();
  13. this.$behaviour = new CstyleBehaviour();
  14. this.foldingRules = new CStyleFoldMode();
  15. };
  16. oop.inherits(Mode, TextMode);
  17. (function() {
  18. this.getNextLineIndent = function(state, line, tab) {
  19. var indent = this.$getIndent(line);
  20. var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
  21. var tokens = tokenizedLine.tokens;
  22. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  23. return indent;
  24. }
  25. if (state == "start") {
  26. var match = line.match(/^.*[\{\(\[]\s*$/);
  27. if (match) {
  28. indent += tab;
  29. }
  30. }
  31. return indent;
  32. };
  33. this.checkOutdent = function(state, line, input) {
  34. return this.$outdent.checkOutdent(line, input);
  35. };
  36. this.autoOutdent = function(state, doc, row) {
  37. this.$outdent.autoOutdent(doc, row);
  38. };
  39. this.createWorker = function(session) {
  40. return null;
  41. };
  42. }).call(Mode.prototype);
  43. exports.Mode = Mode;
  44. });
  45. define('ace/mode/powershell_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
  46. "use strict";
  47. var oop = require("../lib/oop");
  48. var lang = require("../lib/lang");
  49. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  50. var PowershellHighlightRules = function() {
  51. var keywords = lang.arrayToMap(
  52. ("function|if|else|elseif|switch|while|default|for|do|until|break|continue|" +
  53. "foreach|return|filter|in|trap|throw|param|begin|process|end").split("|")
  54. );
  55. var builtinFunctions = lang.arrayToMap(
  56. ("Get-Alias|Import-Alias|New-Alias|Set-Alias|Get-AuthenticodeSignature|Set-AuthenticodeSignature|" +
  57. "Set-Location|Get-ChildItem|Clear-Item|Get-Command|Measure-Command|Trace-Command|" +
  58. "Add-Computer|Checkpoint-Computer|Remove-Computer|Restart-Computer|Restore-Computer|Stop-Computer|" +
  59. "Reset-ComputerMachinePassword|Test-ComputerSecureChannel|Add-Content|Get-Content|Set-Content|Clear-Content|" +
  60. "Get-Command|Invoke-Command|Enable-ComputerRestore|Disable-ComputerRestore|Get-ComputerRestorePoint|Test-Connection|" +
  61. "ConvertFrom-CSV|ConvertTo-CSV|ConvertTo-Html|ConvertTo-Xml|ConvertFrom-SecureString|ConvertTo-SecureString|" +
  62. "Copy-Item|Export-Counter|Get-Counter|Import-Counter|Get-Credential|Get-Culture|" +
  63. "Get-ChildItem|Get-Date|Set-Date|Remove-Item|Compare-Object|Get-Event|" +
  64. "Get-WinEvent|New-Event|Remove-Event|Unregister-Event|Wait-Event|Clear-EventLog|" +
  65. "Get-Eventlog|Limit-EventLog|New-Eventlog|Remove-EventLog|Show-EventLog|Write-EventLog|" +
  66. "Get-EventSubscriber|Register-EngineEvent|Register-ObjectEvent|Register-WmiEvent|Get-ExecutionPolicy|Set-ExecutionPolicy|" +
  67. "Export-Alias|Export-Clixml|Export-Console|Export-Csv|ForEach-Object|Format-Custom|" +
  68. "Format-List|Format-Table|Format-Wide|Export-FormatData|Get-FormatData|Get-Item|" +
  69. "Get-ChildItem|Get-Help|Add-History|Clear-History|Get-History|Invoke-History|" +
  70. "Get-Host|Read-Host|Write-Host|Get-HotFix|Import-Clixml|Import-Csv|" +
  71. "Invoke-Command|Invoke-Expression|Get-Item|Invoke-Item|New-Item|Remove-Item|" +
  72. "Set-Item|Clear-ItemProperty|Copy-ItemProperty|Get-ItemProperty|Move-ItemProperty|New-ItemProperty|" +
  73. "Remove-ItemProperty|Rename-ItemProperty|Set-ItemProperty|Get-Job|Receive-Job|Remove-Job|" +
  74. "Start-Job|Stop-Job|Wait-Job|Stop-Process|Update-List|Get-Location|" +
  75. "Pop-Location|Push-Location|Set-Location|Send-MailMessage|Add-Member|Get-Member|" +
  76. "Move-Item|Compare-Object|Group-Object|Measure-Object|New-Object|Select-Object|" +
  77. "Sort-Object|Where-Object|Out-Default|Out-File|Out-GridView|Out-Host|" +
  78. "Out-Null|Out-Printer|Out-String|Convert-Path|Join-Path|Resolve-Path|" +
  79. "Split-Path|Test-Path|Get-Pfxcertificate|Pop-Location|Push-Location|Get-Process|" +
  80. "Start-Process|Stop-Process|Wait-Process|Enable-PSBreakpoint|Disable-PSBreakpoint|Get-PSBreakpoint|" +
  81. "Set-PSBreakpoint|Remove-PSBreakpoint|Get-PSDrive|New-PSDrive|Remove-PSDrive|Get-PSProvider|" +
  82. "Set-PSdebug|Enter-PSSession|Exit-PSSession|Export-PSSession|Get-PSSession|Import-PSSession|" +
  83. "New-PSSession|Remove-PSSession|Disable-PSSessionConfiguration|Enable-PSSessionConfiguration|Get-PSSessionConfiguration|Register-PSSessionConfiguration|" +
  84. "Set-PSSessionConfiguration|Unregister-PSSessionConfiguration|New-PSSessionOption|Add-PsSnapIn|Get-PsSnapin|Remove-PSSnapin|" +
  85. "Get-Random|Read-Host|Remove-Item|Rename-Item|Rename-ItemProperty|Select-Object|" +
  86. "Select-XML|Send-MailMessage|Get-Service|New-Service|Restart-Service|Resume-Service|" +
  87. "Set-Service|Start-Service|Stop-Service|Suspend-Service|Sort-Object|Start-Sleep|" +
  88. "ConvertFrom-StringData|Select-String|Tee-Object|New-Timespan|Trace-Command|Get-Tracesource|" +
  89. "Set-Tracesource|Start-Transaction|Complete-Transaction|Get-Transaction|Use-Transaction|Undo-Transaction|" +
  90. "Start-Transcript|Stop-Transcript|Add-Type|Update-TypeData|Get-Uiculture|Get-Unique|" +
  91. "Update-Formatdata|Update-Typedata|Clear-Variable|Get-Variable|New-Variable|Remove-Variable|" +
  92. "Set-Variable|New-WebServiceProxy|Where-Object|Write-Debug|Write-Error|Write-Host|" +
  93. "Write-Output|Write-Progress|Write-Verbose|Write-Warning|Set-WmiInstance|Invoke-WmiMethod|" +
  94. "Get-WmiObject|Remove-WmiObject|Connect-WSMan|Disconnect-WSMan|Test-WSMan|Invoke-WSManAction|" +
  95. "Disable-WSManCredSSP|Enable-WSManCredSSP|Get-WSManCredSSP|New-WSManInstance|Get-WSManInstance|Set-WSManInstance|" +
  96. "Remove-WSManInstance|Set-WSManQuickConfig|New-WSManSessionOption").split("|"));
  97. var binaryOperatorsRe = "eq|ne|ge|gt|lt|le|like|notlike|match|notmatch|replace|contains|notcontains|" +
  98. "ieq|ine|ige|igt|ile|ilt|ilike|inotlike|imatch|inotmatch|ireplace|icontains|inotcontains|" +
  99. "is|isnot|as|" +
  100. "and|or|band|bor|not";
  101. // regexp must not have capturing parentheses. Use (?:) instead.
  102. // regexps are ordered -> the first match is used
  103. this.$rules = {
  104. "start" : [
  105. {
  106. token : "comment",
  107. regex : "#.*$"
  108. }, {
  109. token : "string", // single line
  110. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  111. }, {
  112. token : "string", // single line
  113. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  114. }, {
  115. token : "constant.numeric", // hex
  116. regex : "0[xX][0-9a-fA-F]+\\b"
  117. }, {
  118. token : "constant.numeric", // float
  119. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  120. }, {
  121. token : "constant.language.boolean",
  122. regex : "[$](?:[Tt]rue|[Ff]alse)\\b"
  123. }, {
  124. token : "constant.language",
  125. regex : "[$][Nn]ull\\b"
  126. }, {
  127. token : "variable.instance",
  128. regex : "[$][a-zA-Z][a-zA-Z0-9_]*\\b"
  129. }, {
  130. token : function(value) {
  131. if (keywords.hasOwnProperty(value))
  132. return "keyword";
  133. else if (builtinFunctions.hasOwnProperty(value))
  134. return "support.function";
  135. else
  136. return "identifier";
  137. },
  138. // TODO: Unicode escape sequences
  139. // TODO: Unicode identifiers
  140. regex : "[a-zA-Z_$][a-zA-Z0-9_$\\-]*\\b"
  141. }, {
  142. token : "keyword.operator",
  143. regex : "\\-(?:" + binaryOperatorsRe + ")"
  144. }, {
  145. token : "keyword.operator",
  146. regex : "&|\\*|\\+|\\-|\\=|\\+=|\\-="
  147. }, {
  148. token : "lparen",
  149. regex : "[[({]"
  150. }, {
  151. token : "rparen",
  152. regex : "[\\])}]"
  153. }, {
  154. token : "text",
  155. regex : "\\s+"
  156. }
  157. ],
  158. "comment" : [
  159. {
  160. token : "comment", // closing comment
  161. regex : ".*?\\*\\/",
  162. next : "start"
  163. }, {
  164. token : "comment", // comment spanning whole line
  165. merge : true,
  166. regex : ".+"
  167. }
  168. ]
  169. };
  170. };
  171. oop.inherits(PowershellHighlightRules, TextHighlightRules);
  172. exports.PowershellHighlightRules = PowershellHighlightRules;
  173. });
  174. /* ***** BEGIN LICENSE BLOCK *****
  175. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  176. *
  177. * The contents of this file are subject to the Mozilla Public License Version
  178. * 1.1 (the "License"); you may not use this file except in compliance with
  179. * the License. You may obtain a copy of the License at
  180. * http://www.mozilla.org/MPL/
  181. *
  182. * Software distributed under the License is distributed on an "AS IS" basis,
  183. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  184. * for the specific language governing rights and limitations under the
  185. * License.
  186. *
  187. * The Original Code is Ajax.org Code Editor (ACE).
  188. *
  189. * The Initial Developer of the Original Code is
  190. * Ajax.org B.V.
  191. * Portions created by the Initial Developer are Copyright (C) 2010
  192. * the Initial Developer. All Rights Reserved.
  193. *
  194. * Contributor(s):
  195. * Fabian Jakobs <fabian AT ajax DOT org>
  196. *
  197. * Alternatively, the contents of this file may be used under the terms of
  198. * either the GNU General Public License Version 2 or later (the "GPL"), or
  199. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  200. * in which case the provisions of the GPL or the LGPL are applicable instead
  201. * of those above. If you wish to allow use of your version of this file only
  202. * under the terms of either the GPL or the LGPL, and not to allow others to
  203. * use your version of this file under the terms of the MPL, indicate your
  204. * decision by deleting the provisions above and replace them with the notice
  205. * and other provisions required by the GPL or the LGPL. If you do not delete
  206. * the provisions above, a recipient may use your version of this file under
  207. * the terms of any one of the MPL, the GPL or the LGPL.
  208. *
  209. * ***** END LICENSE BLOCK ***** */
  210. define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  211. "use strict";
  212. var Range = require("../range").Range;
  213. var MatchingBraceOutdent = function() {};
  214. (function() {
  215. this.checkOutdent = function(line, input) {
  216. if (! /^\s+$/.test(line))
  217. return false;
  218. return /^\s*\}/.test(input);
  219. };
  220. this.autoOutdent = function(doc, row) {
  221. var line = doc.getLine(row);
  222. var match = line.match(/^(\s*\})/);
  223. if (!match) return 0;
  224. var column = match[1].length;
  225. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  226. if (!openBracePos || openBracePos.row == row) return 0;
  227. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  228. doc.replace(new Range(row, 0, row, column-1), indent);
  229. };
  230. this.$getIndent = function(line) {
  231. var match = line.match(/^(\s+)/);
  232. if (match) {
  233. return match[1];
  234. }
  235. return "";
  236. };
  237. }).call(MatchingBraceOutdent.prototype);
  238. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  239. });
  240. /* vim:ts=4:sts=4:sw=4:
  241. * ***** BEGIN LICENSE BLOCK *****
  242. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  243. *
  244. * The contents of this file are subject to the Mozilla Public License Version
  245. * 1.1 (the "License"); you may not use this file except in compliance with
  246. * the License. You may obtain a copy of the License at
  247. * http://www.mozilla.org/MPL/
  248. *
  249. * Software distributed under the License is distributed on an "AS IS" basis,
  250. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  251. * for the specific language governing rights and limitations under the
  252. * License.
  253. *
  254. * The Original Code is Ajax.org Code Editor (ACE).
  255. *
  256. * The Initial Developer of the Original Code is
  257. * Ajax.org B.V.
  258. * Portions created by the Initial Developer are Copyright (C) 2010
  259. * the Initial Developer. All Rights Reserved.
  260. *
  261. * Contributor(s):
  262. * Chris Spencer <chris.ag.spencer AT googlemail DOT com>
  263. *
  264. * Alternatively, the contents of this file may be used under the terms of
  265. * either the GNU General Public License Version 2 or later (the "GPL"), or
  266. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  267. * in which case the provisions of the GPL or the LGPL are applicable instead
  268. * of those above. If you wish to allow use of your version of this file only
  269. * under the terms of either the GPL or the LGPL, and not to allow others to
  270. * use your version of this file under the terms of the MPL, indicate your
  271. * decision by deleting the provisions above and replace them with the notice
  272. * and other provisions required by the GPL or the LGPL. If you do not delete
  273. * the provisions above, a recipient may use your version of this file under
  274. * the terms of any one of the MPL, the GPL or the LGPL.
  275. *
  276. * ***** END LICENSE BLOCK ***** */
  277. define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour'], function(require, exports, module) {
  278. "use strict";
  279. var oop = require("../../lib/oop");
  280. var Behaviour = require('../behaviour').Behaviour;
  281. var CstyleBehaviour = function () {
  282. this.add("braces", "insertion", function (state, action, editor, session, text) {
  283. if (text == '{') {
  284. var selection = editor.getSelectionRange();
  285. var selected = session.doc.getTextRange(selection);
  286. if (selected !== "") {
  287. return {
  288. text: '{' + selected + '}',
  289. selection: false
  290. };
  291. } else {
  292. return {
  293. text: '{}',
  294. selection: [1, 1]
  295. };
  296. }
  297. } else if (text == '}') {
  298. var cursor = editor.getCursorPosition();
  299. var line = session.doc.getLine(cursor.row);
  300. var rightChar = line.substring(cursor.column, cursor.column + 1);
  301. if (rightChar == '}') {
  302. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  303. if (matching !== null) {
  304. return {
  305. text: '',
  306. selection: [1, 1]
  307. };
  308. }
  309. }
  310. } else if (text == "\n") {
  311. var cursor = editor.getCursorPosition();
  312. var line = session.doc.getLine(cursor.row);
  313. var rightChar = line.substring(cursor.column, cursor.column + 1);
  314. if (rightChar == '}') {
  315. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column + 1});
  316. if (!openBracePos)
  317. return null;
  318. var indent = this.getNextLineIndent(state, line.substring(0, line.length - 1), session.getTabString());
  319. var next_indent = this.$getIndent(session.doc.getLine(openBracePos.row));
  320. return {
  321. text: '\n' + indent + '\n' + next_indent,
  322. selection: [1, indent.length, 1, indent.length]
  323. };
  324. }
  325. }
  326. });
  327. this.add("braces", "deletion", function (state, action, editor, session, range) {
  328. var selected = session.doc.getTextRange(range);
  329. if (!range.isMultiLine() && selected == '{') {
  330. var line = session.doc.getLine(range.start.row);
  331. var rightChar = line.substring(range.end.column, range.end.column + 1);
  332. if (rightChar == '}') {
  333. range.end.column++;
  334. return range;
  335. }
  336. }
  337. });
  338. this.add("parens", "insertion", function (state, action, editor, session, text) {
  339. if (text == '(') {
  340. var selection = editor.getSelectionRange();
  341. var selected = session.doc.getTextRange(selection);
  342. if (selected !== "") {
  343. return {
  344. text: '(' + selected + ')',
  345. selection: false
  346. };
  347. } else {
  348. return {
  349. text: '()',
  350. selection: [1, 1]
  351. };
  352. }
  353. } else if (text == ')') {
  354. var cursor = editor.getCursorPosition();
  355. var line = session.doc.getLine(cursor.row);
  356. var rightChar = line.substring(cursor.column, cursor.column + 1);
  357. if (rightChar == ')') {
  358. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  359. if (matching !== null) {
  360. return {
  361. text: '',
  362. selection: [1, 1]
  363. };
  364. }
  365. }
  366. }
  367. });
  368. this.add("parens", "deletion", function (state, action, editor, session, range) {
  369. var selected = session.doc.getTextRange(range);
  370. if (!range.isMultiLine() && selected == '(') {
  371. var line = session.doc.getLine(range.start.row);
  372. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  373. if (rightChar == ')') {
  374. range.end.column++;
  375. return range;
  376. }
  377. }
  378. });
  379. this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
  380. if (text == '"' || text == "'") {
  381. var quote = text;
  382. var selection = editor.getSelectionRange();
  383. var selected = session.doc.getTextRange(selection);
  384. if (selected !== "") {
  385. return {
  386. text: quote + selected + quote,
  387. selection: false
  388. };
  389. } else {
  390. var cursor = editor.getCursorPosition();
  391. var line = session.doc.getLine(cursor.row);
  392. var leftChar = line.substring(cursor.column-1, cursor.column);
  393. // We're escaped.
  394. if (leftChar == '\\') {
  395. return null;
  396. }
  397. // Find what token we're inside.
  398. var tokens = session.getTokens(selection.start.row, selection.start.row)[0].tokens;
  399. var col = 0, token;
  400. var quotepos = -1; // Track whether we're inside an open quote.
  401. for (var x = 0; x < tokens.length; x++) {
  402. token = tokens[x];
  403. if (token.type == "string") {
  404. quotepos = -1;
  405. } else if (quotepos < 0) {
  406. quotepos = token.value.indexOf(quote);
  407. }
  408. if ((token.value.length + col) > selection.start.column) {
  409. break;
  410. }
  411. col += tokens[x].value.length;
  412. }
  413. // Try and be smart about when we auto insert.
  414. if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
  415. return {
  416. text: quote + quote,
  417. selection: [1,1]
  418. };
  419. } else if (token && token.type === "string") {
  420. // Ignore input and move right one if we're typing over the closing quote.
  421. var rightChar = line.substring(cursor.column, cursor.column + 1);
  422. if (rightChar == quote) {
  423. return {
  424. text: '',
  425. selection: [1, 1]
  426. };
  427. }
  428. }
  429. }
  430. }
  431. });
  432. this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
  433. var selected = session.doc.getTextRange(range);
  434. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  435. var line = session.doc.getLine(range.start.row);
  436. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  437. if (rightChar == '"') {
  438. range.end.column++;
  439. return range;
  440. }
  441. }
  442. });
  443. };
  444. oop.inherits(CstyleBehaviour, Behaviour);
  445. exports.CstyleBehaviour = CstyleBehaviour;
  446. });/* ***** BEGIN LICENSE BLOCK *****
  447. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  448. *
  449. * The contents of this file are subject to the Mozilla Public License Version
  450. * 1.1 (the "License"); you may not use this file except in compliance with
  451. * the License. You may obtain a copy of the License at
  452. * http://www.mozilla.org/MPL/
  453. *
  454. * Software distributed under the License is distributed on an "AS IS" basis,
  455. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  456. * for the specific language governing rights and limitations under the
  457. * License.
  458. *
  459. * The Original Code is Ajax.org Code Editor (ACE).
  460. *
  461. * The Initial Developer of the Original Code is
  462. * Ajax.org B.V.
  463. * Portions created by the Initial Developer are Copyright (C) 2010
  464. * the Initial Developer. All Rights Reserved.
  465. *
  466. * Contributor(s):
  467. * Fabian Jakobs <fabian AT ajax DOT org>
  468. *
  469. * Alternatively, the contents of this file may be used under the terms of
  470. * either the GNU General Public License Version 2 or later (the "GPL"), or
  471. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  472. * in which case the provisions of the GPL or the LGPL are applicable instead
  473. * of those above. If you wish to allow use of your version of this file only
  474. * under the terms of either the GPL or the LGPL, and not to allow others to
  475. * use your version of this file under the terms of the MPL, indicate your
  476. * decision by deleting the provisions above and replace them with the notice
  477. * and other provisions required by the GPL or the LGPL. If you do not delete
  478. * the provisions above, a recipient may use your version of this file under
  479. * the terms of any one of the MPL, the GPL or the LGPL.
  480. *
  481. * ***** END LICENSE BLOCK ***** */
  482. define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
  483. "use strict";
  484. var oop = require("../../lib/oop");
  485. var Range = require("../../range").Range;
  486. var BaseFoldMode = require("./fold_mode").FoldMode;
  487. var FoldMode = exports.FoldMode = function() {};
  488. oop.inherits(FoldMode, BaseFoldMode);
  489. (function() {
  490. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  491. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  492. this.getFoldWidgetRange = function(session, foldStyle, row) {
  493. var line = session.getLine(row);
  494. var match = line.match(this.foldingStartMarker);
  495. if (match) {
  496. var i = match.index;
  497. if (match[1])
  498. return this.openingBracketBlock(session, match[1], row, i);
  499. var range = session.getCommentFoldRange(row, i + match[0].length);
  500. range.end.column -= 2;
  501. return range;
  502. }
  503. if (foldStyle !== "markbeginend")
  504. return;
  505. var match = line.match(this.foldingStopMarker);
  506. if (match) {
  507. var i = match.index + match[0].length;
  508. if (match[2]) {
  509. var range = session.getCommentFoldRange(row, i);
  510. range.end.column -= 2;
  511. return range;
  512. }
  513. var end = {row: row, column: i};
  514. var start = session.$findOpeningBracket(match[1], end);
  515. if (!start)
  516. return;
  517. start.column++;
  518. end.column--;
  519. return Range.fromPoints(start, end);
  520. }
  521. };
  522. }).call(FoldMode.prototype);
  523. });/* ***** BEGIN LICENSE BLOCK *****
  524. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  525. *
  526. * The contents of this file are subject to the Mozilla Public License Version
  527. * 1.1 (the "License"); you may not use this file except in compliance with
  528. * the License. You may obtain a copy of the License at
  529. * http://www.mozilla.org/MPL/
  530. *
  531. * Software distributed under the License is distributed on an "AS IS" basis,
  532. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  533. * for the specific language governing rights and limitations under the
  534. * License.
  535. *
  536. * The Original Code is Ajax.org Code Editor (ACE).
  537. *
  538. * The Initial Developer of the Original Code is
  539. * Ajax.org B.V.
  540. * Portions created by the Initial Developer are Copyright (C) 2010
  541. * the Initial Developer. All Rights Reserved.
  542. *
  543. * Contributor(s):
  544. * Fabian Jakobs <fabian AT ajax DOT org>
  545. *
  546. * Alternatively, the contents of this file may be used under the terms of
  547. * either the GNU General Public License Version 2 or later (the "GPL"), or
  548. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  549. * in which case the provisions of the GPL or the LGPL are applicable instead
  550. * of those above. If you wish to allow use of your version of this file only
  551. * under the terms of either the GPL or the LGPL, and not to allow others to
  552. * use your version of this file under the terms of the MPL, indicate your
  553. * decision by deleting the provisions above and replace them with the notice
  554. * and other provisions required by the GPL or the LGPL. If you do not delete
  555. * the provisions above, a recipient may use your version of this file under
  556. * the terms of any one of the MPL, the GPL or the LGPL.
  557. *
  558. * ***** END LICENSE BLOCK ***** */
  559. define('ace/mode/folding/fold_mode', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
  560. "use strict";
  561. var Range = require("../../range").Range;
  562. var FoldMode = exports.FoldMode = function() {};
  563. (function() {
  564. this.foldingStartMarker = null;
  565. this.foldingStopMarker = null;
  566. // must return "" if there's no fold, to enable caching
  567. this.getFoldWidget = function(session, foldStyle, row) {
  568. var line = session.getLine(row);
  569. if (this.foldingStartMarker.test(line))
  570. return "start";
  571. if (foldStyle == "markbeginend"
  572. && this.foldingStopMarker
  573. && this.foldingStopMarker.test(line))
  574. return "end";
  575. return "";
  576. };
  577. this.getFoldWidgetRange = function(session, foldStyle, row) {
  578. return null;
  579. };
  580. this.indentationBlock = function(session, row, column) {
  581. var re = /^\s*/;
  582. var startRow = row;
  583. var endRow = row;
  584. var line = session.getLine(row);
  585. var startColumn = column || line.length;
  586. var startLevel = line.match(re)[0].length;
  587. var maxRow = session.getLength()
  588. while (++row < maxRow) {
  589. line = session.getLine(row);
  590. var level = line.match(re)[0].length;
  591. if (level == line.length)
  592. continue;
  593. if (level <= startLevel)
  594. break;
  595. endRow = row;
  596. }
  597. if (endRow > startRow) {
  598. var endColumn = session.getLine(endRow).length;
  599. return new Range(startRow, startColumn, endRow, endColumn);
  600. }
  601. };
  602. this.openingBracketBlock = function(session, bracket, row, column) {
  603. var start = {row: row, column: column + 1};
  604. var end = session.$findClosingBracket(bracket, start);
  605. if (!end)
  606. return;
  607. var fw = session.foldWidgets[end.row];
  608. if (fw == null)
  609. fw = this.getFoldWidget(session, end.row);
  610. if (fw == "start") {
  611. end.row --;
  612. end.column = session.getLine(end.row).length;
  613. }
  614. return Range.fromPoints(start, end);
  615. };
  616. }).call(FoldMode.prototype);
  617. });