datagram 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,664 @@
1
+ /* ***** BEGIN LICENSE BLOCK *****
2
+ * Distributed under the BSD license:
3
+ *
4
+ * Copyright (c) 2012, Ajax.org B.V.
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ * * Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * * Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ * * Neither the name of Ajax.org B.V. nor the
15
+ * names of its contributors may be used to endorse or promote products
16
+ * derived from this software without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ *
29
+ * ***** END LICENSE BLOCK ***** */
30
+
31
+ define('ace/mode/logiql', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/logiql_highlight_rules', 'ace/mode/folding/coffee', 'ace/token_iterator', 'ace/range', 'ace/mode/behaviour/cstyle', 'ace/mode/matching_brace_outdent'], function(require, exports, module) {
32
+
33
+
34
+ var oop = require("../lib/oop");
35
+ var TextMode = require("./text").Mode;
36
+ var Tokenizer = require("../tokenizer").Tokenizer;
37
+ var LogiQLHighlightRules = require("./logiql_highlight_rules").LogiQLHighlightRules;
38
+ var FoldMode = require("./folding/coffee").FoldMode;
39
+ var TokenIterator = require("../token_iterator").TokenIterator;
40
+ var Range = require("../range").Range;
41
+ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
42
+ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
43
+
44
+ var Mode = function() {
45
+ var highlighter = new LogiQLHighlightRules();
46
+ this.foldingRules = new FoldMode();
47
+ this.$tokenizer = new Tokenizer(highlighter.getRules());
48
+ this.$outdent = new MatchingBraceOutdent();
49
+ this.$behaviour = new CstyleBehaviour();
50
+ };
51
+ oop.inherits(Mode, TextMode);
52
+
53
+ (function() {
54
+ this.lineCommentStart = "//";
55
+ this.blockComment = {start: "/*", end: "*/"};
56
+
57
+ this.getNextLineIndent = function(state, line, tab) {
58
+ var indent = this.$getIndent(line);
59
+
60
+ var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
61
+ var tokens = tokenizedLine.tokens;
62
+ var endState = tokenizedLine.state;
63
+ if (/comment|string/.test(endState))
64
+ return indent;
65
+ if (tokens.length && tokens[tokens.length - 1].type == "comment.single")
66
+ return indent;
67
+
68
+ var match = line.match();
69
+ if (/(-->|<--|<-|->|{)\s*$/.test(line))
70
+ indent += tab;
71
+ return indent;
72
+ };
73
+
74
+ this.checkOutdent = function(state, line, input) {
75
+ if (this.$outdent.checkOutdent(line, input))
76
+ return true;
77
+
78
+ if (input !== "\n" && input !== "\r\n")
79
+ return false;
80
+
81
+ if (!/^\s+/.test(line))
82
+ return false;
83
+
84
+ return true;
85
+ };
86
+
87
+ this.autoOutdent = function(state, doc, row) {
88
+ if (this.$outdent.autoOutdent(doc, row))
89
+ return;
90
+ var prevLine = doc.getLine(row);
91
+ var match = prevLine.match(/^\s+/);
92
+ var column = prevLine.lastIndexOf(".") + 1;
93
+ if (!match || !row || !column) return 0;
94
+
95
+ var line = doc.getLine(row + 1);
96
+ var startRange = this.getMatching(doc, {row: row, column: column});
97
+ if (!startRange || startRange.start.row == row) return 0;
98
+
99
+ column = match[0].length;
100
+ var indent = this.$getIndent(doc.getLine(startRange.start.row));
101
+ doc.replace(new Range(row + 1, 0, row + 1, column), indent);
102
+ };
103
+
104
+ this.getMatching = function(session, row, column) {
105
+ if (row == undefined)
106
+ row = session.selection.lead
107
+ if (typeof row == "object") {
108
+ column = row.column;
109
+ row = row.row;
110
+ }
111
+
112
+ var startToken = session.getTokenAt(row, column);
113
+ var KW_START = "keyword.start", KW_END = "keyword.end";
114
+ var tok;
115
+ if (!startToken)
116
+ return;
117
+ if (startToken.type == KW_START) {
118
+ var it = new TokenIterator(session, row, column);
119
+ it.step = it.stepForward;
120
+ } else if (startToken.type == KW_END) {
121
+ var it = new TokenIterator(session, row, column);
122
+ it.step = it.stepBackward;
123
+ } else
124
+ return;
125
+
126
+ while (tok = it.step()) {
127
+ if (tok.type == KW_START || tok.type == KW_END)
128
+ break;
129
+ }
130
+ if (!tok || tok.type == startToken.type)
131
+ return;
132
+
133
+ var col = it.getCurrentTokenColumn();
134
+ var row = it.getCurrentTokenRow();
135
+ return new Range(row, col, row, col + tok.value.length);
136
+ };
137
+ }).call(Mode.prototype);
138
+
139
+ exports.Mode = Mode;
140
+ });
141
+
142
+ define('ace/mode/logiql_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
143
+
144
+
145
+ var oop = require("../lib/oop");
146
+ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
147
+
148
+ var LogiQLHighlightRules = function() {
149
+
150
+ this.$rules = { start:
151
+ [ { token: 'comment.block',
152
+ regex: '/\\*',
153
+ push:
154
+ [ { token: 'comment.block', regex: '\\*/', next: 'pop' },
155
+ { defaultToken: 'comment.block' } ],
156
+ },
157
+ { token: 'comment.single',
158
+ regex: '//.*',
159
+ },
160
+ { token: 'constant.numeric',
161
+ regex: '\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?',
162
+ },
163
+ { token: 'string',
164
+ regex: '"',
165
+ push:
166
+ [ { token: 'string', regex: '"', next: 'pop' },
167
+ { defaultToken: 'string' } ],
168
+ },
169
+ { token: 'constant.language',
170
+ regex: '\\b(true|false)\\b',
171
+ },
172
+ { token: 'entity.name.type.logicblox',
173
+ regex: '`[a-zA-Z_:]+(\\d|\\a)*\\b',
174
+ },
175
+ { token: 'keyword.start', regex: '->', comment: 'Constraint' },
176
+ { token: 'keyword.start', regex: '-->', comment: 'Level 1 Constraint'},
177
+ { token: 'keyword.start', regex: '<-', comment: 'Rule' },
178
+ { token: 'keyword.start', regex: '<--', comment: 'Level 1 Rule' },
179
+ { token: 'keyword.end', regex: '\\.', comment: 'Terminator' },
180
+ { token: 'keyword.other', regex: '!', comment: 'Negation' },
181
+ { token: 'keyword.other', regex: ',', comment: 'Conjunction' },
182
+ { token: 'keyword.other', regex: ';', comment: 'Disjunction' },
183
+ { token: 'keyword.operator', regex: '<=|>=|!=|<|>', comment: 'Equality'},
184
+ { token: 'keyword.other', regex: '@', comment: 'Equality' },
185
+ { token: 'keyword.operator', regex: '\\+|-|\\*|/', comment: 'Arithmetic operations'},
186
+ { token: 'keyword', regex: '::', comment: 'Colon colon' },
187
+ { token: 'support.function',
188
+ regex: '\\b(agg\\s*<<)',
189
+ push:
190
+ [ { include: '$self' },
191
+ { token: 'support.function',
192
+ regex: '>>',
193
+ next: 'pop' } ],
194
+ },
195
+ { token: 'storage.modifier',
196
+ regex: '\\b(lang:[\\w:]*)',
197
+ },
198
+ { token: [ 'storage.type', 'text' ],
199
+ regex: '(export|sealed|clauses|block|alias)(\\s*\\()(?=`)',
200
+ },
201
+ { token: 'entity.name',
202
+ regex: '[a-zA-Z_][a-zA-Z_0-9:]*(@prev|@init|@final)?(?=(\\(|\\[))',
203
+ },
204
+ { token: 'variable.parameter',
205
+ regex: '([a-zA-Z][a-zA-Z_0-9]*|_)\\s*(?=(,|\\.|<-|->|\\)|\\]|=))',
206
+ } ] }
207
+
208
+ this.normalizeRules();
209
+ };
210
+
211
+ oop.inherits(LogiQLHighlightRules, TextHighlightRules);
212
+
213
+ exports.LogiQLHighlightRules = LogiQLHighlightRules;
214
+ });
215
+
216
+ define('ace/mode/folding/coffee', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/folding/fold_mode', 'ace/range'], function(require, exports, module) {
217
+
218
+
219
+ var oop = require("../../lib/oop");
220
+ var BaseFoldMode = require("./fold_mode").FoldMode;
221
+ var Range = require("../../range").Range;
222
+
223
+ var FoldMode = exports.FoldMode = function() {};
224
+ oop.inherits(FoldMode, BaseFoldMode);
225
+
226
+ (function() {
227
+
228
+ this.getFoldWidgetRange = function(session, foldStyle, row) {
229
+ var range = this.indentationBlock(session, row);
230
+ if (range)
231
+ return range;
232
+
233
+ var re = /\S/;
234
+ var line = session.getLine(row);
235
+ var startLevel = line.search(re);
236
+ if (startLevel == -1 || line[startLevel] != "#")
237
+ return;
238
+
239
+ var startColumn = line.length;
240
+ var maxRow = session.getLength();
241
+ var startRow = row;
242
+ var endRow = row;
243
+
244
+ while (++row < maxRow) {
245
+ line = session.getLine(row);
246
+ var level = line.search(re);
247
+
248
+ if (level == -1)
249
+ continue;
250
+
251
+ if (line[level] != "#")
252
+ break;
253
+
254
+ endRow = row;
255
+ }
256
+
257
+ if (endRow > startRow) {
258
+ var endColumn = session.getLine(endRow).length;
259
+ return new Range(startRow, startColumn, endRow, endColumn);
260
+ }
261
+ };
262
+ this.getFoldWidget = function(session, foldStyle, row) {
263
+ var line = session.getLine(row);
264
+ var indent = line.search(/\S/);
265
+ var next = session.getLine(row + 1);
266
+ var prev = session.getLine(row - 1);
267
+ var prevIndent = prev.search(/\S/);
268
+ var nextIndent = next.search(/\S/);
269
+
270
+ if (indent == -1) {
271
+ session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
272
+ return "";
273
+ }
274
+ if (prevIndent == -1) {
275
+ if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
276
+ session.foldWidgets[row - 1] = "";
277
+ session.foldWidgets[row + 1] = "";
278
+ return "start";
279
+ }
280
+ } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
281
+ if (session.getLine(row - 2).search(/\S/) == -1) {
282
+ session.foldWidgets[row - 1] = "start";
283
+ session.foldWidgets[row + 1] = "";
284
+ return "";
285
+ }
286
+ }
287
+
288
+ if (prevIndent!= -1 && prevIndent < indent)
289
+ session.foldWidgets[row - 1] = "start";
290
+ else
291
+ session.foldWidgets[row - 1] = "";
292
+
293
+ if (indent < nextIndent)
294
+ return "start";
295
+ else
296
+ return "";
297
+ };
298
+
299
+ }).call(FoldMode.prototype);
300
+
301
+ });
302
+
303
+ define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
304
+
305
+
306
+ var oop = require("../../lib/oop");
307
+ var Behaviour = require("../behaviour").Behaviour;
308
+ var TokenIterator = require("../../token_iterator").TokenIterator;
309
+ var lang = require("../../lib/lang");
310
+
311
+ var SAFE_INSERT_IN_TOKENS =
312
+ ["text", "paren.rparen", "punctuation.operator"];
313
+ var SAFE_INSERT_BEFORE_TOKENS =
314
+ ["text", "paren.rparen", "punctuation.operator", "comment"];
315
+
316
+
317
+ var autoInsertedBrackets = 0;
318
+ var autoInsertedRow = -1;
319
+ var autoInsertedLineEnd = "";
320
+ var maybeInsertedBrackets = 0;
321
+ var maybeInsertedRow = -1;
322
+ var maybeInsertedLineStart = "";
323
+ var maybeInsertedLineEnd = "";
324
+
325
+ var CstyleBehaviour = function () {
326
+
327
+ CstyleBehaviour.isSaneInsertion = function(editor, session) {
328
+ var cursor = editor.getCursorPosition();
329
+ var iterator = new TokenIterator(session, cursor.row, cursor.column);
330
+ if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
331
+ var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
332
+ if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
333
+ return false;
334
+ }
335
+ iterator.stepForward();
336
+ return iterator.getCurrentTokenRow() !== cursor.row ||
337
+ this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
338
+ };
339
+
340
+ CstyleBehaviour.$matchTokenType = function(token, types) {
341
+ return types.indexOf(token.type || token) > -1;
342
+ };
343
+
344
+ CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
345
+ var cursor = editor.getCursorPosition();
346
+ var line = session.doc.getLine(cursor.row);
347
+ if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
348
+ autoInsertedBrackets = 0;
349
+ autoInsertedRow = cursor.row;
350
+ autoInsertedLineEnd = bracket + line.substr(cursor.column);
351
+ autoInsertedBrackets++;
352
+ };
353
+
354
+ CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
355
+ var cursor = editor.getCursorPosition();
356
+ var line = session.doc.getLine(cursor.row);
357
+ if (!this.isMaybeInsertedClosing(cursor, line))
358
+ maybeInsertedBrackets = 0;
359
+ maybeInsertedRow = cursor.row;
360
+ maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
361
+ maybeInsertedLineEnd = line.substr(cursor.column);
362
+ maybeInsertedBrackets++;
363
+ };
364
+
365
+ CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
366
+ return autoInsertedBrackets > 0 &&
367
+ cursor.row === autoInsertedRow &&
368
+ bracket === autoInsertedLineEnd[0] &&
369
+ line.substr(cursor.column) === autoInsertedLineEnd;
370
+ };
371
+
372
+ CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
373
+ return maybeInsertedBrackets > 0 &&
374
+ cursor.row === maybeInsertedRow &&
375
+ line.substr(cursor.column) === maybeInsertedLineEnd &&
376
+ line.substr(0, cursor.column) == maybeInsertedLineStart;
377
+ };
378
+
379
+ CstyleBehaviour.popAutoInsertedClosing = function() {
380
+ autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
381
+ autoInsertedBrackets--;
382
+ };
383
+
384
+ CstyleBehaviour.clearMaybeInsertedClosing = function() {
385
+ maybeInsertedBrackets = 0;
386
+ maybeInsertedRow = -1;
387
+ };
388
+
389
+ this.add("braces", "insertion", function (state, action, editor, session, text) {
390
+ var cursor = editor.getCursorPosition();
391
+ var line = session.doc.getLine(cursor.row);
392
+ if (text == '{') {
393
+ var selection = editor.getSelectionRange();
394
+ var selected = session.doc.getTextRange(selection);
395
+ if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
396
+ return {
397
+ text: '{' + selected + '}',
398
+ selection: false
399
+ };
400
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
401
+ if (/[\]\}\)]/.test(line[cursor.column])) {
402
+ CstyleBehaviour.recordAutoInsert(editor, session, "}");
403
+ return {
404
+ text: '{}',
405
+ selection: [1, 1]
406
+ };
407
+ } else {
408
+ CstyleBehaviour.recordMaybeInsert(editor, session, "{");
409
+ return {
410
+ text: '{',
411
+ selection: [1, 1]
412
+ };
413
+ }
414
+ }
415
+ } else if (text == '}') {
416
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
417
+ if (rightChar == '}') {
418
+ var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
419
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
420
+ CstyleBehaviour.popAutoInsertedClosing();
421
+ return {
422
+ text: '',
423
+ selection: [1, 1]
424
+ };
425
+ }
426
+ }
427
+ } else if (text == "\n" || text == "\r\n") {
428
+ var closing = "";
429
+ if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
430
+ closing = lang.stringRepeat("}", maybeInsertedBrackets);
431
+ CstyleBehaviour.clearMaybeInsertedClosing();
432
+ }
433
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
434
+ if (rightChar == '}' || closing !== "") {
435
+ var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
436
+ if (!openBracePos)
437
+ return null;
438
+
439
+ var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
440
+ var next_indent = this.$getIndent(line);
441
+
442
+ return {
443
+ text: '\n' + indent + '\n' + next_indent + closing,
444
+ selection: [1, indent.length, 1, indent.length]
445
+ };
446
+ }
447
+ }
448
+ });
449
+
450
+ this.add("braces", "deletion", function (state, action, editor, session, range) {
451
+ var selected = session.doc.getTextRange(range);
452
+ if (!range.isMultiLine() && selected == '{') {
453
+ var line = session.doc.getLine(range.start.row);
454
+ var rightChar = line.substring(range.end.column, range.end.column + 1);
455
+ if (rightChar == '}') {
456
+ range.end.column++;
457
+ return range;
458
+ } else {
459
+ maybeInsertedBrackets--;
460
+ }
461
+ }
462
+ });
463
+
464
+ this.add("parens", "insertion", function (state, action, editor, session, text) {
465
+ if (text == '(') {
466
+ var selection = editor.getSelectionRange();
467
+ var selected = session.doc.getTextRange(selection);
468
+ if (selected !== "" && editor.getWrapBehavioursEnabled()) {
469
+ return {
470
+ text: '(' + selected + ')',
471
+ selection: false
472
+ };
473
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
474
+ CstyleBehaviour.recordAutoInsert(editor, session, ")");
475
+ return {
476
+ text: '()',
477
+ selection: [1, 1]
478
+ };
479
+ }
480
+ } else if (text == ')') {
481
+ var cursor = editor.getCursorPosition();
482
+ var line = session.doc.getLine(cursor.row);
483
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
484
+ if (rightChar == ')') {
485
+ var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
486
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
487
+ CstyleBehaviour.popAutoInsertedClosing();
488
+ return {
489
+ text: '',
490
+ selection: [1, 1]
491
+ };
492
+ }
493
+ }
494
+ }
495
+ });
496
+
497
+ this.add("parens", "deletion", function (state, action, editor, session, range) {
498
+ var selected = session.doc.getTextRange(range);
499
+ if (!range.isMultiLine() && selected == '(') {
500
+ var line = session.doc.getLine(range.start.row);
501
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
502
+ if (rightChar == ')') {
503
+ range.end.column++;
504
+ return range;
505
+ }
506
+ }
507
+ });
508
+
509
+ this.add("brackets", "insertion", function (state, action, editor, session, text) {
510
+ if (text == '[') {
511
+ var selection = editor.getSelectionRange();
512
+ var selected = session.doc.getTextRange(selection);
513
+ if (selected !== "" && editor.getWrapBehavioursEnabled()) {
514
+ return {
515
+ text: '[' + selected + ']',
516
+ selection: false
517
+ };
518
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
519
+ CstyleBehaviour.recordAutoInsert(editor, session, "]");
520
+ return {
521
+ text: '[]',
522
+ selection: [1, 1]
523
+ };
524
+ }
525
+ } else if (text == ']') {
526
+ var cursor = editor.getCursorPosition();
527
+ var line = session.doc.getLine(cursor.row);
528
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
529
+ if (rightChar == ']') {
530
+ var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
531
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
532
+ CstyleBehaviour.popAutoInsertedClosing();
533
+ return {
534
+ text: '',
535
+ selection: [1, 1]
536
+ };
537
+ }
538
+ }
539
+ }
540
+ });
541
+
542
+ this.add("brackets", "deletion", function (state, action, editor, session, range) {
543
+ var selected = session.doc.getTextRange(range);
544
+ if (!range.isMultiLine() && selected == '[') {
545
+ var line = session.doc.getLine(range.start.row);
546
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
547
+ if (rightChar == ']') {
548
+ range.end.column++;
549
+ return range;
550
+ }
551
+ }
552
+ });
553
+
554
+ this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
555
+ if (text == '"' || text == "'") {
556
+ var quote = text;
557
+ var selection = editor.getSelectionRange();
558
+ var selected = session.doc.getTextRange(selection);
559
+ if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
560
+ return {
561
+ text: quote + selected + quote,
562
+ selection: false
563
+ };
564
+ } else {
565
+ var cursor = editor.getCursorPosition();
566
+ var line = session.doc.getLine(cursor.row);
567
+ var leftChar = line.substring(cursor.column-1, cursor.column);
568
+ if (leftChar == '\\') {
569
+ return null;
570
+ }
571
+ var tokens = session.getTokens(selection.start.row);
572
+ var col = 0, token;
573
+ var quotepos = -1; // Track whether we're inside an open quote.
574
+
575
+ for (var x = 0; x < tokens.length; x++) {
576
+ token = tokens[x];
577
+ if (token.type == "string") {
578
+ quotepos = -1;
579
+ } else if (quotepos < 0) {
580
+ quotepos = token.value.indexOf(quote);
581
+ }
582
+ if ((token.value.length + col) > selection.start.column) {
583
+ break;
584
+ }
585
+ col += tokens[x].value.length;
586
+ }
587
+ 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)))) {
588
+ if (!CstyleBehaviour.isSaneInsertion(editor, session))
589
+ return;
590
+ return {
591
+ text: quote + quote,
592
+ selection: [1,1]
593
+ };
594
+ } else if (token && token.type === "string") {
595
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
596
+ if (rightChar == quote) {
597
+ return {
598
+ text: '',
599
+ selection: [1, 1]
600
+ };
601
+ }
602
+ }
603
+ }
604
+ }
605
+ });
606
+
607
+ this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
608
+ var selected = session.doc.getTextRange(range);
609
+ if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
610
+ var line = session.doc.getLine(range.start.row);
611
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
612
+ if (rightChar == selected) {
613
+ range.end.column++;
614
+ return range;
615
+ }
616
+ }
617
+ });
618
+
619
+ };
620
+
621
+ oop.inherits(CstyleBehaviour, Behaviour);
622
+
623
+ exports.CstyleBehaviour = CstyleBehaviour;
624
+ });
625
+
626
+ define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
627
+
628
+
629
+ var Range = require("../range").Range;
630
+
631
+ var MatchingBraceOutdent = function() {};
632
+
633
+ (function() {
634
+
635
+ this.checkOutdent = function(line, input) {
636
+ if (! /^\s+$/.test(line))
637
+ return false;
638
+
639
+ return /^\s*\}/.test(input);
640
+ };
641
+
642
+ this.autoOutdent = function(doc, row) {
643
+ var line = doc.getLine(row);
644
+ var match = line.match(/^(\s*\})/);
645
+
646
+ if (!match) return 0;
647
+
648
+ var column = match[1].length;
649
+ var openBracePos = doc.findMatchingBracket({row: row, column: column});
650
+
651
+ if (!openBracePos || openBracePos.row == row) return 0;
652
+
653
+ var indent = this.$getIndent(doc.getLine(openBracePos.row));
654
+ doc.replace(new Range(row, 0, row, column-1), indent);
655
+ };
656
+
657
+ this.$getIndent = function(line) {
658
+ return line.match(/^\s*/)[0];
659
+ };
660
+
661
+ }).call(MatchingBraceOutdent.prototype);
662
+
663
+ exports.MatchingBraceOutdent = MatchingBraceOutdent;
664
+ });