datagram 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/.env.sample +7 -0
  2. data/.gitignore +20 -0
  3. data/.rbenv-version +1 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE.txt +22 -0
  6. data/Procfile +1 -0
  7. data/README.md +29 -0
  8. data/Rakefile +1 -0
  9. data/config.ru +5 -0
  10. data/datagram.gemspec +23 -0
  11. data/db/migrate/1_create_queries.rb +9 -0
  12. data/db/migrate/2_add_name_to_queries.rb +5 -0
  13. data/lib/datagram/version.rb +3 -0
  14. data/lib/datagram.rb +135 -0
  15. data/lib/views/application.coffee +222 -0
  16. data/lib/views/index.haml +47 -0
  17. data/lib/views/layout.haml +17 -0
  18. data/lib/views/style.sass +179 -0
  19. data/public/ace/ace.js +15209 -0
  20. data/public/ace/ext-elastic_tabstops_lite.js +301 -0
  21. data/public/ace/ext-emmet.js +253 -0
  22. data/public/ace/ext-searchbox.js +441 -0
  23. data/public/ace/ext-spellcheck.js +67 -0
  24. data/public/ace/ext-static_highlight.js +96 -0
  25. data/public/ace/ext-textarea.js +492 -0
  26. data/public/ace/ext-whitespace.js +204 -0
  27. data/public/ace/keybinding-emacs.js +962 -0
  28. data/public/ace/keybinding-vim.js +1704 -0
  29. data/public/ace/mode-abap.js +260 -0
  30. data/public/ace/mode-asciidoc.js +372 -0
  31. data/public/ace/mode-c9search.js +182 -0
  32. data/public/ace/mode-c_cpp.js +737 -0
  33. data/public/ace/mode-clojure.js +299 -0
  34. data/public/ace/mode-coffee.js +426 -0
  35. data/public/ace/mode-coldfusion.js +1753 -0
  36. data/public/ace/mode-csharp.js +612 -0
  37. data/public/ace/mode-css.js +773 -0
  38. data/public/ace/mode-curly.js +1950 -0
  39. data/public/ace/mode-dart.js +945 -0
  40. data/public/ace/mode-diff.js +166 -0
  41. data/public/ace/mode-django.js +1969 -0
  42. data/public/ace/mode-dot.js +320 -0
  43. data/public/ace/mode-ftl.js +907 -0
  44. data/public/ace/mode-glsl.js +810 -0
  45. data/public/ace/mode-golang.js +632 -0
  46. data/public/ace/mode-groovy.js +1037 -0
  47. data/public/ace/mode-haml.js +487 -0
  48. data/public/ace/mode-haxe.js +609 -0
  49. data/public/ace/mode-html.js +1881 -0
  50. data/public/ace/mode-jade.js +1951 -0
  51. data/public/ace/mode-java.js +996 -0
  52. data/public/ace/mode-javascript.js +876 -0
  53. data/public/ace/mode-json.js +578 -0
  54. data/public/ace/mode-jsp.js +1351 -0
  55. data/public/ace/mode-jsx.js +635 -0
  56. data/public/ace/mode-latex.js +189 -0
  57. data/public/ace/mode-less.js +807 -0
  58. data/public/ace/mode-liquid.js +862 -0
  59. data/public/ace/mode-lisp.js +138 -0
  60. data/public/ace/mode-livescript.js +288 -0
  61. data/public/ace/mode-logiql.js +664 -0
  62. data/public/ace/mode-lsl.js +828 -0
  63. data/public/ace/mode-lua.js +455 -0
  64. data/public/ace/mode-luapage.js +2340 -0
  65. data/public/ace/mode-lucene.js +64 -0
  66. data/public/ace/mode-makefile.js +313 -0
  67. data/public/ace/mode-markdown.js +2280 -0
  68. data/public/ace/mode-mushcode.js +704 -0
  69. data/public/ace/mode-mushcode_high_rules.js +569 -0
  70. data/public/ace/mode-objectivec.js +659 -0
  71. data/public/ace/mode-ocaml.js +443 -0
  72. data/public/ace/mode-pascal.js +233 -0
  73. data/public/ace/mode-perl.js +316 -0
  74. data/public/ace/mode-pgsql.js +908 -0
  75. data/public/ace/mode-php.js +2291 -0
  76. data/public/ace/mode-powershell.js +618 -0
  77. data/public/ace/mode-python.js +264 -0
  78. data/public/ace/mode-r.js +404 -0
  79. data/public/ace/mode-rdoc.js +184 -0
  80. data/public/ace/mode-rhtml.js +2168 -0
  81. data/public/ace/mode-ruby.js +431 -0
  82. data/public/ace/mode-sass.js +442 -0
  83. data/public/ace/mode-scad.js +670 -0
  84. data/public/ace/mode-scala.js +1025 -0
  85. data/public/ace/mode-scheme.js +144 -0
  86. data/public/ace/mode-scss.js +832 -0
  87. data/public/ace/mode-sh.js +204 -0
  88. data/public/ace/mode-sql.js +118 -0
  89. data/public/ace/mode-stylus.js +483 -0
  90. data/public/ace/mode-svg.js +1442 -0
  91. data/public/ace/mode-tcl.js +319 -0
  92. data/public/ace/mode-tex.js +166 -0
  93. data/public/ace/mode-text.js +0 -0
  94. data/public/ace/mode-textile.js +170 -0
  95. data/public/ace/mode-tmsnippet.js +200 -0
  96. data/public/ace/mode-toml.js +180 -0
  97. data/public/ace/mode-typescript.js +961 -0
  98. data/public/ace/mode-vbscript.js +281 -0
  99. data/public/ace/mode-velocity.js +962 -0
  100. data/public/ace/mode-xml.js +789 -0
  101. data/public/ace/mode-xquery.js +2750 -0
  102. data/public/ace/mode-yaml.js +289 -0
  103. data/public/ace/theme-ambiance.js +202 -0
  104. data/public/ace/theme-chaos.js +182 -0
  105. data/public/ace/theme-chrome.js +161 -0
  106. data/public/ace/theme-clouds.js +135 -0
  107. data/public/ace/theme-clouds_midnight.js +136 -0
  108. data/public/ace/theme-cobalt.js +150 -0
  109. data/public/ace/theme-crimson_editor.js +154 -0
  110. data/public/ace/theme-dawn.js +146 -0
  111. data/public/ace/theme-dreamweaver.js +173 -0
  112. data/public/ace/theme-eclipse.js +122 -0
  113. data/public/ace/theme-github.js +136 -0
  114. data/public/ace/theme-idle_fingers.js +136 -0
  115. data/public/ace/theme-kr.js +143 -0
  116. data/public/ace/theme-merbivore.js +135 -0
  117. data/public/ace/theme-merbivore_soft.js +136 -0
  118. data/public/ace/theme-mono_industrial.js +148 -0
  119. data/public/ace/theme-monokai.js +140 -0
  120. data/public/ace/theme-pastel_on_dark.js +148 -0
  121. data/public/ace/theme-solarized_dark.js +128 -0
  122. data/public/ace/theme-solarized_light.js +131 -0
  123. data/public/ace/theme-terminal.js +154 -0
  124. data/public/ace/theme-textmate.js +0 -0
  125. data/public/ace/theme-tomorrow.js +147 -0
  126. data/public/ace/theme-tomorrow_night.js +147 -0
  127. data/public/ace/theme-tomorrow_night_blue.js +145 -0
  128. data/public/ace/theme-tomorrow_night_bright.js +147 -0
  129. data/public/ace/theme-tomorrow_night_eighties.js +144 -0
  130. data/public/ace/theme-twilight.js +147 -0
  131. data/public/ace/theme-vibrant_ink.js +131 -0
  132. data/public/ace/theme-xcode.js +125 -0
  133. data/public/ace/worker-coffee.js +7091 -0
  134. data/public/ace/worker-css.js +8289 -0
  135. data/public/ace/worker-javascript.js +6496 -0
  136. data/public/ace/worker-json.js +2305 -0
  137. data/public/ace/worker-lua.js +3313 -0
  138. data/public/ace/worker-php.js +6743 -0
  139. data/public/ace/worker-xquery.js +21897 -0
  140. data/public/font/FontAwesome.otf +0 -0
  141. data/public/font/fontawesome-webfont.eot +0 -0
  142. data/public/font/fontawesome-webfont.svg +284 -0
  143. data/public/font/fontawesome-webfont.ttf +0 -0
  144. data/public/font/fontawesome-webfont.woff +0 -0
  145. data/public/font-awesome.css +540 -0
  146. data/public/jquery.js +9597 -0
  147. data/script/migrate.sh +2 -0
  148. metadata +242 -0
@@ -0,0 +1,618 @@
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
+
3
+
4
+ var oop = require("../lib/oop");
5
+ var TextMode = require("./text").Mode;
6
+ var Tokenizer = require("../tokenizer").Tokenizer;
7
+ var PowershellHighlightRules = require("./powershell_highlight_rules").PowershellHighlightRules;
8
+ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
9
+ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
10
+ var CStyleFoldMode = require("./folding/cstyle").FoldMode;
11
+
12
+ var Mode = function() {
13
+ this.$tokenizer = new Tokenizer(new PowershellHighlightRules().getRules());
14
+ this.$outdent = new MatchingBraceOutdent();
15
+ this.$behaviour = new CstyleBehaviour();
16
+ this.foldingRules = new CStyleFoldMode({start: "^\\s*(<#)", end: "^[#\\s]>\\s*$"});
17
+ };
18
+ oop.inherits(Mode, TextMode);
19
+
20
+ (function() {
21
+
22
+ this.lineCommentStart = "#";
23
+ this.blockComment = {start: "<#", end: "#>"};
24
+
25
+ this.getNextLineIndent = function(state, line, tab) {
26
+ var indent = this.$getIndent(line);
27
+
28
+ var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
29
+ var tokens = tokenizedLine.tokens;
30
+
31
+ if (tokens.length && tokens[tokens.length-1].type == "comment") {
32
+ return indent;
33
+ }
34
+
35
+ if (state == "start") {
36
+ var match = line.match(/^.*[\{\(\[]\s*$/);
37
+ if (match) {
38
+ indent += tab;
39
+ }
40
+ }
41
+
42
+ return indent;
43
+ };
44
+
45
+ this.checkOutdent = function(state, line, input) {
46
+ return this.$outdent.checkOutdent(line, input);
47
+ };
48
+
49
+ this.autoOutdent = function(state, doc, row) {
50
+ this.$outdent.autoOutdent(doc, row);
51
+ };
52
+
53
+
54
+ this.createWorker = function(session) {
55
+ return null;
56
+ };
57
+
58
+ }).call(Mode.prototype);
59
+
60
+ exports.Mode = Mode;
61
+ });
62
+ define('ace/mode/powershell_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
63
+
64
+
65
+ var oop = require("../lib/oop");
66
+ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
67
+
68
+ var PowershellHighlightRules = function() {
69
+
70
+ var keywords = (
71
+ "function|if|else|elseif|switch|while|default|for|do|until|break|continue|" +
72
+ "foreach|return|filter|in|trap|throw|param|begin|process|end"
73
+ );
74
+
75
+ var builtinFunctions = (
76
+ "Get-Alias|Import-Alias|New-Alias|Set-Alias|Get-AuthenticodeSignature|Set-AuthenticodeSignature|" +
77
+ "Set-Location|Get-ChildItem|Clear-Item|Get-Command|Measure-Command|Trace-Command|" +
78
+ "Add-Computer|Checkpoint-Computer|Remove-Computer|Restart-Computer|Restore-Computer|Stop-Computer|" +
79
+ "Reset-ComputerMachinePassword|Test-ComputerSecureChannel|Add-Content|Get-Content|Set-Content|Clear-Content|" +
80
+ "Get-Command|Invoke-Command|Enable-ComputerRestore|Disable-ComputerRestore|Get-ComputerRestorePoint|Test-Connection|" +
81
+ "ConvertFrom-CSV|ConvertTo-CSV|ConvertTo-Html|ConvertTo-Xml|ConvertFrom-SecureString|ConvertTo-SecureString|" +
82
+ "Copy-Item|Export-Counter|Get-Counter|Import-Counter|Get-Credential|Get-Culture|" +
83
+ "Get-ChildItem|Get-Date|Set-Date|Remove-Item|Compare-Object|Get-Event|" +
84
+ "Get-WinEvent|New-Event|Remove-Event|Unregister-Event|Wait-Event|Clear-EventLog|" +
85
+ "Get-Eventlog|Limit-EventLog|New-Eventlog|Remove-EventLog|Show-EventLog|Write-EventLog|" +
86
+ "Get-EventSubscriber|Register-EngineEvent|Register-ObjectEvent|Register-WmiEvent|Get-ExecutionPolicy|Set-ExecutionPolicy|" +
87
+ "Export-Alias|Export-Clixml|Export-Console|Export-Csv|ForEach-Object|Format-Custom|" +
88
+ "Format-List|Format-Table|Format-Wide|Export-FormatData|Get-FormatData|Get-Item|" +
89
+ "Get-ChildItem|Get-Help|Add-History|Clear-History|Get-History|Invoke-History|" +
90
+ "Get-Host|Read-Host|Write-Host|Get-HotFix|Import-Clixml|Import-Csv|" +
91
+ "Invoke-Command|Invoke-Expression|Get-Item|Invoke-Item|New-Item|Remove-Item|" +
92
+ "Set-Item|Clear-ItemProperty|Copy-ItemProperty|Get-ItemProperty|Move-ItemProperty|New-ItemProperty|" +
93
+ "Remove-ItemProperty|Rename-ItemProperty|Set-ItemProperty|Get-Job|Receive-Job|Remove-Job|" +
94
+ "Start-Job|Stop-Job|Wait-Job|Stop-Process|Update-List|Get-Location|" +
95
+ "Pop-Location|Push-Location|Set-Location|Send-MailMessage|Add-Member|Get-Member|" +
96
+ "Move-Item|Compare-Object|Group-Object|Measure-Object|New-Object|Select-Object|" +
97
+ "Sort-Object|Where-Object|Out-Default|Out-File|Out-GridView|Out-Host|" +
98
+ "Out-Null|Out-Printer|Out-String|Convert-Path|Join-Path|Resolve-Path|" +
99
+ "Split-Path|Test-Path|Get-Pfxcertificate|Pop-Location|Push-Location|Get-Process|" +
100
+ "Start-Process|Stop-Process|Wait-Process|Enable-PSBreakpoint|Disable-PSBreakpoint|Get-PSBreakpoint|" +
101
+ "Set-PSBreakpoint|Remove-PSBreakpoint|Get-PSDrive|New-PSDrive|Remove-PSDrive|Get-PSProvider|" +
102
+ "Set-PSdebug|Enter-PSSession|Exit-PSSession|Export-PSSession|Get-PSSession|Import-PSSession|" +
103
+ "New-PSSession|Remove-PSSession|Disable-PSSessionConfiguration|Enable-PSSessionConfiguration|Get-PSSessionConfiguration|Register-PSSessionConfiguration|" +
104
+ "Set-PSSessionConfiguration|Unregister-PSSessionConfiguration|New-PSSessionOption|Add-PsSnapIn|Get-PsSnapin|Remove-PSSnapin|" +
105
+ "Get-Random|Read-Host|Remove-Item|Rename-Item|Rename-ItemProperty|Select-Object|" +
106
+ "Select-XML|Send-MailMessage|Get-Service|New-Service|Restart-Service|Resume-Service|" +
107
+ "Set-Service|Start-Service|Stop-Service|Suspend-Service|Sort-Object|Start-Sleep|" +
108
+ "ConvertFrom-StringData|Select-String|Tee-Object|New-Timespan|Trace-Command|Get-Tracesource|" +
109
+ "Set-Tracesource|Start-Transaction|Complete-Transaction|Get-Transaction|Use-Transaction|Undo-Transaction|" +
110
+ "Start-Transcript|Stop-Transcript|Add-Type|Update-TypeData|Get-Uiculture|Get-Unique|" +
111
+ "Update-Formatdata|Update-Typedata|Clear-Variable|Get-Variable|New-Variable|Remove-Variable|" +
112
+ "Set-Variable|New-WebServiceProxy|Where-Object|Write-Debug|Write-Error|Write-Host|" +
113
+ "Write-Output|Write-Progress|Write-Verbose|Write-Warning|Set-WmiInstance|Invoke-WmiMethod|" +
114
+ "Get-WmiObject|Remove-WmiObject|Connect-WSMan|Disconnect-WSMan|Test-WSMan|Invoke-WSManAction|" +
115
+ "Disable-WSManCredSSP|Enable-WSManCredSSP|Get-WSManCredSSP|New-WSManInstance|Get-WSManInstance|Set-WSManInstance|" +
116
+ "Remove-WSManInstance|Set-WSManQuickConfig|New-WSManSessionOption"
117
+ );
118
+
119
+ var keywordMapper = this.createKeywordMapper({
120
+ "support.function": builtinFunctions,
121
+ "keyword": keywords
122
+ }, "identifier");
123
+
124
+ var binaryOperatorsRe = "eq|ne|ge|gt|lt|le|like|notlike|match|notmatch|replace|contains|notcontains|" +
125
+ "ieq|ine|ige|igt|ile|ilt|ilike|inotlike|imatch|inotmatch|ireplace|icontains|inotcontains|" +
126
+ "is|isnot|as|" +
127
+ "and|or|band|bor|not";
128
+
129
+ this.$rules = {
130
+ "start" : [
131
+ {
132
+ token : "comment",
133
+ regex : "#.*$"
134
+ }, {
135
+ token : "comment.start",
136
+ regex : "<#",
137
+ next : "comment"
138
+ }, {
139
+ token : "string", // single line
140
+ regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
141
+ }, {
142
+ token : "string", // single line
143
+ regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
144
+ }, {
145
+ token : "constant.numeric", // hex
146
+ regex : "0[xX][0-9a-fA-F]+\\b"
147
+ }, {
148
+ token : "constant.numeric", // float
149
+ regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
150
+ }, {
151
+ token : "constant.language.boolean",
152
+ regex : "[$](?:[Tt]rue|[Ff]alse)\\b"
153
+ }, {
154
+ token : "constant.language",
155
+ regex : "[$][Nn]ull\\b"
156
+ }, {
157
+ token : "variable.instance",
158
+ regex : "[$][a-zA-Z][a-zA-Z0-9_]*\\b"
159
+ }, {
160
+ token : keywordMapper,
161
+ regex : "[a-zA-Z_$][a-zA-Z0-9_$\\-]*\\b"
162
+ }, {
163
+ token : "keyword.operator",
164
+ regex : "\\-(?:" + binaryOperatorsRe + ")"
165
+ }, {
166
+ token : "keyword.operator",
167
+ regex : "&|\\*|\\+|\\-|\\=|\\+=|\\-="
168
+ }, {
169
+ token : "lparen",
170
+ regex : "[[({]"
171
+ }, {
172
+ token : "rparen",
173
+ regex : "[\\])}]"
174
+ }, {
175
+ token : "text",
176
+ regex : "\\s+"
177
+ }
178
+ ],
179
+ "comment" : [
180
+ {
181
+ token : "comment.end",
182
+ regex : "#>",
183
+ next : "start"
184
+ }, {
185
+ token : "doc.comment.tag",
186
+ regex : "^\\.\\w+"
187
+ }, {
188
+ token : "comment",
189
+ regex : "\\w+"
190
+ }, {
191
+ token : "comment",
192
+ regex : "."
193
+ }
194
+ ]
195
+ };
196
+ };
197
+
198
+ oop.inherits(PowershellHighlightRules, TextHighlightRules);
199
+
200
+ exports.PowershellHighlightRules = PowershellHighlightRules;
201
+ });
202
+
203
+ define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
204
+
205
+
206
+ var Range = require("../range").Range;
207
+
208
+ var MatchingBraceOutdent = function() {};
209
+
210
+ (function() {
211
+
212
+ this.checkOutdent = function(line, input) {
213
+ if (! /^\s+$/.test(line))
214
+ return false;
215
+
216
+ return /^\s*\}/.test(input);
217
+ };
218
+
219
+ this.autoOutdent = function(doc, row) {
220
+ var line = doc.getLine(row);
221
+ var match = line.match(/^(\s*\})/);
222
+
223
+ if (!match) return 0;
224
+
225
+ var column = match[1].length;
226
+ var openBracePos = doc.findMatchingBracket({row: row, column: column});
227
+
228
+ if (!openBracePos || openBracePos.row == row) return 0;
229
+
230
+ var indent = this.$getIndent(doc.getLine(openBracePos.row));
231
+ doc.replace(new Range(row, 0, row, column-1), indent);
232
+ };
233
+
234
+ this.$getIndent = function(line) {
235
+ return line.match(/^\s*/)[0];
236
+ };
237
+
238
+ }).call(MatchingBraceOutdent.prototype);
239
+
240
+ exports.MatchingBraceOutdent = MatchingBraceOutdent;
241
+ });
242
+
243
+ define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
244
+
245
+
246
+ var oop = require("../../lib/oop");
247
+ var Behaviour = require("../behaviour").Behaviour;
248
+ var TokenIterator = require("../../token_iterator").TokenIterator;
249
+ var lang = require("../../lib/lang");
250
+
251
+ var SAFE_INSERT_IN_TOKENS =
252
+ ["text", "paren.rparen", "punctuation.operator"];
253
+ var SAFE_INSERT_BEFORE_TOKENS =
254
+ ["text", "paren.rparen", "punctuation.operator", "comment"];
255
+
256
+
257
+ var autoInsertedBrackets = 0;
258
+ var autoInsertedRow = -1;
259
+ var autoInsertedLineEnd = "";
260
+ var maybeInsertedBrackets = 0;
261
+ var maybeInsertedRow = -1;
262
+ var maybeInsertedLineStart = "";
263
+ var maybeInsertedLineEnd = "";
264
+
265
+ var CstyleBehaviour = function () {
266
+
267
+ CstyleBehaviour.isSaneInsertion = function(editor, session) {
268
+ var cursor = editor.getCursorPosition();
269
+ var iterator = new TokenIterator(session, cursor.row, cursor.column);
270
+ if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
271
+ var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
272
+ if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
273
+ return false;
274
+ }
275
+ iterator.stepForward();
276
+ return iterator.getCurrentTokenRow() !== cursor.row ||
277
+ this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
278
+ };
279
+
280
+ CstyleBehaviour.$matchTokenType = function(token, types) {
281
+ return types.indexOf(token.type || token) > -1;
282
+ };
283
+
284
+ CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
285
+ var cursor = editor.getCursorPosition();
286
+ var line = session.doc.getLine(cursor.row);
287
+ if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
288
+ autoInsertedBrackets = 0;
289
+ autoInsertedRow = cursor.row;
290
+ autoInsertedLineEnd = bracket + line.substr(cursor.column);
291
+ autoInsertedBrackets++;
292
+ };
293
+
294
+ CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
295
+ var cursor = editor.getCursorPosition();
296
+ var line = session.doc.getLine(cursor.row);
297
+ if (!this.isMaybeInsertedClosing(cursor, line))
298
+ maybeInsertedBrackets = 0;
299
+ maybeInsertedRow = cursor.row;
300
+ maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
301
+ maybeInsertedLineEnd = line.substr(cursor.column);
302
+ maybeInsertedBrackets++;
303
+ };
304
+
305
+ CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
306
+ return autoInsertedBrackets > 0 &&
307
+ cursor.row === autoInsertedRow &&
308
+ bracket === autoInsertedLineEnd[0] &&
309
+ line.substr(cursor.column) === autoInsertedLineEnd;
310
+ };
311
+
312
+ CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
313
+ return maybeInsertedBrackets > 0 &&
314
+ cursor.row === maybeInsertedRow &&
315
+ line.substr(cursor.column) === maybeInsertedLineEnd &&
316
+ line.substr(0, cursor.column) == maybeInsertedLineStart;
317
+ };
318
+
319
+ CstyleBehaviour.popAutoInsertedClosing = function() {
320
+ autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
321
+ autoInsertedBrackets--;
322
+ };
323
+
324
+ CstyleBehaviour.clearMaybeInsertedClosing = function() {
325
+ maybeInsertedBrackets = 0;
326
+ maybeInsertedRow = -1;
327
+ };
328
+
329
+ this.add("braces", "insertion", function (state, action, editor, session, text) {
330
+ var cursor = editor.getCursorPosition();
331
+ var line = session.doc.getLine(cursor.row);
332
+ if (text == '{') {
333
+ var selection = editor.getSelectionRange();
334
+ var selected = session.doc.getTextRange(selection);
335
+ if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
336
+ return {
337
+ text: '{' + selected + '}',
338
+ selection: false
339
+ };
340
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
341
+ if (/[\]\}\)]/.test(line[cursor.column])) {
342
+ CstyleBehaviour.recordAutoInsert(editor, session, "}");
343
+ return {
344
+ text: '{}',
345
+ selection: [1, 1]
346
+ };
347
+ } else {
348
+ CstyleBehaviour.recordMaybeInsert(editor, session, "{");
349
+ return {
350
+ text: '{',
351
+ selection: [1, 1]
352
+ };
353
+ }
354
+ }
355
+ } else if (text == '}') {
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 && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
360
+ CstyleBehaviour.popAutoInsertedClosing();
361
+ return {
362
+ text: '',
363
+ selection: [1, 1]
364
+ };
365
+ }
366
+ }
367
+ } else if (text == "\n" || text == "\r\n") {
368
+ var closing = "";
369
+ if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
370
+ closing = lang.stringRepeat("}", maybeInsertedBrackets);
371
+ CstyleBehaviour.clearMaybeInsertedClosing();
372
+ }
373
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
374
+ if (rightChar == '}' || closing !== "") {
375
+ var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
376
+ if (!openBracePos)
377
+ return null;
378
+
379
+ var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
380
+ var next_indent = this.$getIndent(line);
381
+
382
+ return {
383
+ text: '\n' + indent + '\n' + next_indent + closing,
384
+ selection: [1, indent.length, 1, indent.length]
385
+ };
386
+ }
387
+ }
388
+ });
389
+
390
+ this.add("braces", "deletion", function (state, action, editor, session, range) {
391
+ var selected = session.doc.getTextRange(range);
392
+ if (!range.isMultiLine() && selected == '{') {
393
+ var line = session.doc.getLine(range.start.row);
394
+ var rightChar = line.substring(range.end.column, range.end.column + 1);
395
+ if (rightChar == '}') {
396
+ range.end.column++;
397
+ return range;
398
+ } else {
399
+ maybeInsertedBrackets--;
400
+ }
401
+ }
402
+ });
403
+
404
+ this.add("parens", "insertion", function (state, action, editor, session, text) {
405
+ if (text == '(') {
406
+ var selection = editor.getSelectionRange();
407
+ var selected = session.doc.getTextRange(selection);
408
+ if (selected !== "" && editor.getWrapBehavioursEnabled()) {
409
+ return {
410
+ text: '(' + selected + ')',
411
+ selection: false
412
+ };
413
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
414
+ CstyleBehaviour.recordAutoInsert(editor, session, ")");
415
+ return {
416
+ text: '()',
417
+ selection: [1, 1]
418
+ };
419
+ }
420
+ } else if (text == ')') {
421
+ var cursor = editor.getCursorPosition();
422
+ var line = session.doc.getLine(cursor.row);
423
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
424
+ if (rightChar == ')') {
425
+ var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
426
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
427
+ CstyleBehaviour.popAutoInsertedClosing();
428
+ return {
429
+ text: '',
430
+ selection: [1, 1]
431
+ };
432
+ }
433
+ }
434
+ }
435
+ });
436
+
437
+ this.add("parens", "deletion", function (state, action, editor, session, range) {
438
+ var selected = session.doc.getTextRange(range);
439
+ if (!range.isMultiLine() && selected == '(') {
440
+ var line = session.doc.getLine(range.start.row);
441
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
442
+ if (rightChar == ')') {
443
+ range.end.column++;
444
+ return range;
445
+ }
446
+ }
447
+ });
448
+
449
+ this.add("brackets", "insertion", function (state, action, editor, session, text) {
450
+ if (text == '[') {
451
+ var selection = editor.getSelectionRange();
452
+ var selected = session.doc.getTextRange(selection);
453
+ if (selected !== "" && editor.getWrapBehavioursEnabled()) {
454
+ return {
455
+ text: '[' + selected + ']',
456
+ selection: false
457
+ };
458
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
459
+ CstyleBehaviour.recordAutoInsert(editor, session, "]");
460
+ return {
461
+ text: '[]',
462
+ selection: [1, 1]
463
+ };
464
+ }
465
+ } else if (text == ']') {
466
+ var cursor = editor.getCursorPosition();
467
+ var line = session.doc.getLine(cursor.row);
468
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
469
+ if (rightChar == ']') {
470
+ var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
471
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
472
+ CstyleBehaviour.popAutoInsertedClosing();
473
+ return {
474
+ text: '',
475
+ selection: [1, 1]
476
+ };
477
+ }
478
+ }
479
+ }
480
+ });
481
+
482
+ this.add("brackets", "deletion", function (state, action, editor, session, range) {
483
+ var selected = session.doc.getTextRange(range);
484
+ if (!range.isMultiLine() && selected == '[') {
485
+ var line = session.doc.getLine(range.start.row);
486
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
487
+ if (rightChar == ']') {
488
+ range.end.column++;
489
+ return range;
490
+ }
491
+ }
492
+ });
493
+
494
+ this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
495
+ if (text == '"' || text == "'") {
496
+ var quote = text;
497
+ var selection = editor.getSelectionRange();
498
+ var selected = session.doc.getTextRange(selection);
499
+ if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
500
+ return {
501
+ text: quote + selected + quote,
502
+ selection: false
503
+ };
504
+ } else {
505
+ var cursor = editor.getCursorPosition();
506
+ var line = session.doc.getLine(cursor.row);
507
+ var leftChar = line.substring(cursor.column-1, cursor.column);
508
+ if (leftChar == '\\') {
509
+ return null;
510
+ }
511
+ var tokens = session.getTokens(selection.start.row);
512
+ var col = 0, token;
513
+ var quotepos = -1; // Track whether we're inside an open quote.
514
+
515
+ for (var x = 0; x < tokens.length; x++) {
516
+ token = tokens[x];
517
+ if (token.type == "string") {
518
+ quotepos = -1;
519
+ } else if (quotepos < 0) {
520
+ quotepos = token.value.indexOf(quote);
521
+ }
522
+ if ((token.value.length + col) > selection.start.column) {
523
+ break;
524
+ }
525
+ col += tokens[x].value.length;
526
+ }
527
+ 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)))) {
528
+ if (!CstyleBehaviour.isSaneInsertion(editor, session))
529
+ return;
530
+ return {
531
+ text: quote + quote,
532
+ selection: [1,1]
533
+ };
534
+ } else if (token && token.type === "string") {
535
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
536
+ if (rightChar == quote) {
537
+ return {
538
+ text: '',
539
+ selection: [1, 1]
540
+ };
541
+ }
542
+ }
543
+ }
544
+ }
545
+ });
546
+
547
+ this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
548
+ var selected = session.doc.getTextRange(range);
549
+ if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
550
+ var line = session.doc.getLine(range.start.row);
551
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
552
+ if (rightChar == selected) {
553
+ range.end.column++;
554
+ return range;
555
+ }
556
+ }
557
+ });
558
+
559
+ };
560
+
561
+ oop.inherits(CstyleBehaviour, Behaviour);
562
+
563
+ exports.CstyleBehaviour = CstyleBehaviour;
564
+ });
565
+
566
+ define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
567
+
568
+
569
+ var oop = require("../../lib/oop");
570
+ var Range = require("../../range").Range;
571
+ var BaseFoldMode = require("./fold_mode").FoldMode;
572
+
573
+ var FoldMode = exports.FoldMode = function(commentRegex) {
574
+ if (commentRegex) {
575
+ this.foldingStartMarker = new RegExp(
576
+ this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
577
+ );
578
+ this.foldingStopMarker = new RegExp(
579
+ this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
580
+ );
581
+ }
582
+ };
583
+ oop.inherits(FoldMode, BaseFoldMode);
584
+
585
+ (function() {
586
+
587
+ this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
588
+ this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
589
+
590
+ this.getFoldWidgetRange = function(session, foldStyle, row) {
591
+ var line = session.getLine(row);
592
+ var match = line.match(this.foldingStartMarker);
593
+ if (match) {
594
+ var i = match.index;
595
+
596
+ if (match[1])
597
+ return this.openingBracketBlock(session, match[1], row, i);
598
+
599
+ return session.getCommentFoldRange(row, i + match[0].length, 1);
600
+ }
601
+
602
+ if (foldStyle !== "markbeginend")
603
+ return;
604
+
605
+ var match = line.match(this.foldingStopMarker);
606
+ if (match) {
607
+ var i = match.index + match[0].length;
608
+
609
+ if (match[1])
610
+ return this.closingBracketBlock(session, match[1], row, i);
611
+
612
+ return session.getCommentFoldRange(row, i, -1);
613
+ }
614
+ };
615
+
616
+ }).call(FoldMode.prototype);
617
+
618
+ });