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,632 @@
1
+ define('ace/mode/golang', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/golang_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/behaviour/cstyle', 'ace/mode/folding/cstyle'], function(require, exports, module) {
2
+
3
+ var oop = require("../lib/oop");
4
+ var TextMode = require("./text").Mode;
5
+ var Tokenizer = require("../tokenizer").Tokenizer;
6
+ var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
7
+ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
8
+ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
9
+ var CStyleFoldMode = require("./folding/cstyle").FoldMode;
10
+
11
+ var Mode = function() {
12
+ this.$tokenizer = new Tokenizer(new GolangHighlightRules().getRules());
13
+ this.$outdent = new MatchingBraceOutdent();
14
+ this.foldingRules = new CStyleFoldMode();
15
+ };
16
+ oop.inherits(Mode, TextMode);
17
+
18
+ (function() {
19
+
20
+ this.lineCommentStart = "//";
21
+ this.blockComment = {start: "/*", end: "*/"};
22
+
23
+ this.getNextLineIndent = function(state, line, tab) {
24
+ var indent = this.$getIndent(line);
25
+
26
+ var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
27
+ var tokens = tokenizedLine.tokens;
28
+ var endState = tokenizedLine.state;
29
+
30
+ if (tokens.length && tokens[tokens.length-1].type == "comment") {
31
+ return indent;
32
+ }
33
+
34
+ if (state == "start") {
35
+ var match = line.match(/^.*[\{\(\[]\s*$/);
36
+ if (match) {
37
+ indent += tab;
38
+ }
39
+ }
40
+
41
+ return indent;
42
+ };//end getNextLineIndent
43
+
44
+ this.checkOutdent = function(state, line, input) {
45
+ return this.$outdent.checkOutdent(line, input);
46
+ };
47
+
48
+ this.autoOutdent = function(state, doc, row) {
49
+ this.$outdent.autoOutdent(doc, row);
50
+ };
51
+
52
+ }).call(Mode.prototype);
53
+
54
+ exports.Mode = Mode;
55
+ });
56
+ define('ace/mode/golang_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/doc_comment_highlight_rules', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
57
+ var oop = require("../lib/oop");
58
+ var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
59
+ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
60
+
61
+ var GolangHighlightRules = function() {
62
+ var keywords = (
63
+ "true|else|false|break|case|return|goto|if|const|" +
64
+ "continue|struct|default|switch|for|" +
65
+ "func|import|package|chan|defer|fallthrough|go|interface|map|range" +
66
+ "select|type|var"
67
+ );
68
+ var buildinConstants = ("nil|true|false|iota");
69
+
70
+ var keywordMapper = this.createKeywordMapper({
71
+ "variable.language": "this",
72
+ "keyword": keywords,
73
+ "constant.language": buildinConstants
74
+ }, "identifier");
75
+
76
+ this.$rules = {
77
+ "start" : [
78
+ {
79
+ token : "comment",
80
+ regex : "\\/\\/.*$"
81
+ },
82
+ DocCommentHighlightRules.getStartRule("doc-start"),
83
+ {
84
+ token : "comment", // multi line comment
85
+ regex : "\\/\\*",
86
+ next : "comment"
87
+ }, {
88
+ token : "string", // single line
89
+ regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
90
+ }, {
91
+ token : "string", // multi line string start
92
+ regex : '["].*\\\\$',
93
+ next : "qqstring"
94
+ }, {
95
+ token : "string", // single line
96
+ regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
97
+ }, {
98
+ token : "string", // multi line string start
99
+ regex : "['].*\\\\$",
100
+ next : "qstring"
101
+ }, {
102
+ token : "constant.numeric", // hex
103
+ regex : "0[xX][0-9a-fA-F]+\\b"
104
+ }, {
105
+ token : "constant.numeric", // float
106
+ regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
107
+ }, {
108
+ token : "constant", // <CONSTANT>
109
+ regex : "<[a-zA-Z0-9.]+>"
110
+ }, {
111
+ token : "keyword", // pre-compiler directivs
112
+ regex : "(?:#include|#pragma|#line|#define|#undef|#ifdef|#else|#elif|#endif|#ifndef)"
113
+ }, {
114
+ token : keywordMapper,
115
+ regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
116
+ }, {
117
+ token : "keyword.operator",
118
+ regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|new|delete|typeof|void)"
119
+ }, {
120
+ token : "punctuation.operator",
121
+ regex : "\\?|\\:|\\,|\\;|\\."
122
+ }, {
123
+ token : "paren.lparen",
124
+ regex : "[[({]"
125
+ }, {
126
+ token : "paren.rparen",
127
+ regex : "[\\])}]"
128
+ }, {
129
+ token : "text",
130
+ regex : "\\s+"
131
+ }
132
+ ],
133
+ "comment" : [
134
+ {
135
+ token : "comment", // closing comment
136
+ regex : ".*?\\*\\/",
137
+ next : "start"
138
+ }, {
139
+ token : "comment", // comment spanning whole line
140
+ regex : ".+"
141
+ }
142
+ ],
143
+ "qqstring" : [
144
+ {
145
+ token : "string",
146
+ regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
147
+ next : "start"
148
+ }, {
149
+ token : "string",
150
+ regex : '.+'
151
+ }
152
+ ],
153
+ "qstring" : [
154
+ {
155
+ token : "string",
156
+ regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
157
+ next : "start"
158
+ }, {
159
+ token : "string",
160
+ regex : '.+'
161
+ }
162
+ ]
163
+ };
164
+
165
+ this.embedRules(DocCommentHighlightRules, "doc-",
166
+ [ DocCommentHighlightRules.getEndRule("start") ]);
167
+ }
168
+ oop.inherits(GolangHighlightRules, TextHighlightRules);
169
+
170
+ exports.GolangHighlightRules = GolangHighlightRules;
171
+ });
172
+
173
+ define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
174
+
175
+
176
+ var oop = require("../lib/oop");
177
+ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
178
+
179
+ var DocCommentHighlightRules = function() {
180
+
181
+ this.$rules = {
182
+ "start" : [ {
183
+ token : "comment.doc.tag",
184
+ regex : "@[\\w\\d_]+" // TODO: fix email addresses
185
+ }, {
186
+ token : "comment.doc.tag",
187
+ regex : "\\bTODO\\b"
188
+ }, {
189
+ defaultToken : "comment.doc"
190
+ }]
191
+ };
192
+ };
193
+
194
+ oop.inherits(DocCommentHighlightRules, TextHighlightRules);
195
+
196
+ DocCommentHighlightRules.getStartRule = function(start) {
197
+ return {
198
+ token : "comment.doc", // doc comment
199
+ regex : "\\/\\*(?=\\*)",
200
+ next : start
201
+ };
202
+ };
203
+
204
+ DocCommentHighlightRules.getEndRule = function (start) {
205
+ return {
206
+ token : "comment.doc", // closing comment
207
+ regex : "\\*\\/",
208
+ next : start
209
+ };
210
+ };
211
+
212
+
213
+ exports.DocCommentHighlightRules = DocCommentHighlightRules;
214
+
215
+ });
216
+
217
+ define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
218
+
219
+
220
+ var Range = require("../range").Range;
221
+
222
+ var MatchingBraceOutdent = function() {};
223
+
224
+ (function() {
225
+
226
+ this.checkOutdent = function(line, input) {
227
+ if (! /^\s+$/.test(line))
228
+ return false;
229
+
230
+ return /^\s*\}/.test(input);
231
+ };
232
+
233
+ this.autoOutdent = function(doc, row) {
234
+ var line = doc.getLine(row);
235
+ var match = line.match(/^(\s*\})/);
236
+
237
+ if (!match) return 0;
238
+
239
+ var column = match[1].length;
240
+ var openBracePos = doc.findMatchingBracket({row: row, column: column});
241
+
242
+ if (!openBracePos || openBracePos.row == row) return 0;
243
+
244
+ var indent = this.$getIndent(doc.getLine(openBracePos.row));
245
+ doc.replace(new Range(row, 0, row, column-1), indent);
246
+ };
247
+
248
+ this.$getIndent = function(line) {
249
+ return line.match(/^\s*/)[0];
250
+ };
251
+
252
+ }).call(MatchingBraceOutdent.prototype);
253
+
254
+ exports.MatchingBraceOutdent = MatchingBraceOutdent;
255
+ });
256
+
257
+ define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) {
258
+
259
+
260
+ var oop = require("../../lib/oop");
261
+ var Behaviour = require("../behaviour").Behaviour;
262
+ var TokenIterator = require("../../token_iterator").TokenIterator;
263
+ var lang = require("../../lib/lang");
264
+
265
+ var SAFE_INSERT_IN_TOKENS =
266
+ ["text", "paren.rparen", "punctuation.operator"];
267
+ var SAFE_INSERT_BEFORE_TOKENS =
268
+ ["text", "paren.rparen", "punctuation.operator", "comment"];
269
+
270
+
271
+ var autoInsertedBrackets = 0;
272
+ var autoInsertedRow = -1;
273
+ var autoInsertedLineEnd = "";
274
+ var maybeInsertedBrackets = 0;
275
+ var maybeInsertedRow = -1;
276
+ var maybeInsertedLineStart = "";
277
+ var maybeInsertedLineEnd = "";
278
+
279
+ var CstyleBehaviour = function () {
280
+
281
+ CstyleBehaviour.isSaneInsertion = function(editor, session) {
282
+ var cursor = editor.getCursorPosition();
283
+ var iterator = new TokenIterator(session, cursor.row, cursor.column);
284
+ if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
285
+ var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
286
+ if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
287
+ return false;
288
+ }
289
+ iterator.stepForward();
290
+ return iterator.getCurrentTokenRow() !== cursor.row ||
291
+ this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
292
+ };
293
+
294
+ CstyleBehaviour.$matchTokenType = function(token, types) {
295
+ return types.indexOf(token.type || token) > -1;
296
+ };
297
+
298
+ CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
299
+ var cursor = editor.getCursorPosition();
300
+ var line = session.doc.getLine(cursor.row);
301
+ if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0]))
302
+ autoInsertedBrackets = 0;
303
+ autoInsertedRow = cursor.row;
304
+ autoInsertedLineEnd = bracket + line.substr(cursor.column);
305
+ autoInsertedBrackets++;
306
+ };
307
+
308
+ CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
309
+ var cursor = editor.getCursorPosition();
310
+ var line = session.doc.getLine(cursor.row);
311
+ if (!this.isMaybeInsertedClosing(cursor, line))
312
+ maybeInsertedBrackets = 0;
313
+ maybeInsertedRow = cursor.row;
314
+ maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
315
+ maybeInsertedLineEnd = line.substr(cursor.column);
316
+ maybeInsertedBrackets++;
317
+ };
318
+
319
+ CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
320
+ return autoInsertedBrackets > 0 &&
321
+ cursor.row === autoInsertedRow &&
322
+ bracket === autoInsertedLineEnd[0] &&
323
+ line.substr(cursor.column) === autoInsertedLineEnd;
324
+ };
325
+
326
+ CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
327
+ return maybeInsertedBrackets > 0 &&
328
+ cursor.row === maybeInsertedRow &&
329
+ line.substr(cursor.column) === maybeInsertedLineEnd &&
330
+ line.substr(0, cursor.column) == maybeInsertedLineStart;
331
+ };
332
+
333
+ CstyleBehaviour.popAutoInsertedClosing = function() {
334
+ autoInsertedLineEnd = autoInsertedLineEnd.substr(1);
335
+ autoInsertedBrackets--;
336
+ };
337
+
338
+ CstyleBehaviour.clearMaybeInsertedClosing = function() {
339
+ maybeInsertedBrackets = 0;
340
+ maybeInsertedRow = -1;
341
+ };
342
+
343
+ this.add("braces", "insertion", function (state, action, editor, session, text) {
344
+ var cursor = editor.getCursorPosition();
345
+ var line = session.doc.getLine(cursor.row);
346
+ if (text == '{') {
347
+ var selection = editor.getSelectionRange();
348
+ var selected = session.doc.getTextRange(selection);
349
+ if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
350
+ return {
351
+ text: '{' + selected + '}',
352
+ selection: false
353
+ };
354
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
355
+ if (/[\]\}\)]/.test(line[cursor.column])) {
356
+ CstyleBehaviour.recordAutoInsert(editor, session, "}");
357
+ return {
358
+ text: '{}',
359
+ selection: [1, 1]
360
+ };
361
+ } else {
362
+ CstyleBehaviour.recordMaybeInsert(editor, session, "{");
363
+ return {
364
+ text: '{',
365
+ selection: [1, 1]
366
+ };
367
+ }
368
+ }
369
+ } else if (text == '}') {
370
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
371
+ if (rightChar == '}') {
372
+ var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
373
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
374
+ CstyleBehaviour.popAutoInsertedClosing();
375
+ return {
376
+ text: '',
377
+ selection: [1, 1]
378
+ };
379
+ }
380
+ }
381
+ } else if (text == "\n" || text == "\r\n") {
382
+ var closing = "";
383
+ if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
384
+ closing = lang.stringRepeat("}", maybeInsertedBrackets);
385
+ CstyleBehaviour.clearMaybeInsertedClosing();
386
+ }
387
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
388
+ if (rightChar == '}' || closing !== "") {
389
+ var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column}, '}');
390
+ if (!openBracePos)
391
+ return null;
392
+
393
+ var indent = this.getNextLineIndent(state, line.substring(0, cursor.column), session.getTabString());
394
+ var next_indent = this.$getIndent(line);
395
+
396
+ return {
397
+ text: '\n' + indent + '\n' + next_indent + closing,
398
+ selection: [1, indent.length, 1, indent.length]
399
+ };
400
+ }
401
+ }
402
+ });
403
+
404
+ this.add("braces", "deletion", function (state, action, editor, session, range) {
405
+ var selected = session.doc.getTextRange(range);
406
+ if (!range.isMultiLine() && selected == '{') {
407
+ var line = session.doc.getLine(range.start.row);
408
+ var rightChar = line.substring(range.end.column, range.end.column + 1);
409
+ if (rightChar == '}') {
410
+ range.end.column++;
411
+ return range;
412
+ } else {
413
+ maybeInsertedBrackets--;
414
+ }
415
+ }
416
+ });
417
+
418
+ this.add("parens", "insertion", function (state, action, editor, session, text) {
419
+ if (text == '(') {
420
+ var selection = editor.getSelectionRange();
421
+ var selected = session.doc.getTextRange(selection);
422
+ if (selected !== "" && editor.getWrapBehavioursEnabled()) {
423
+ return {
424
+ text: '(' + selected + ')',
425
+ selection: false
426
+ };
427
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
428
+ CstyleBehaviour.recordAutoInsert(editor, session, ")");
429
+ return {
430
+ text: '()',
431
+ selection: [1, 1]
432
+ };
433
+ }
434
+ } else if (text == ')') {
435
+ var cursor = editor.getCursorPosition();
436
+ var line = session.doc.getLine(cursor.row);
437
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
438
+ if (rightChar == ')') {
439
+ var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
440
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
441
+ CstyleBehaviour.popAutoInsertedClosing();
442
+ return {
443
+ text: '',
444
+ selection: [1, 1]
445
+ };
446
+ }
447
+ }
448
+ }
449
+ });
450
+
451
+ this.add("parens", "deletion", function (state, action, editor, session, range) {
452
+ var selected = session.doc.getTextRange(range);
453
+ if (!range.isMultiLine() && selected == '(') {
454
+ var line = session.doc.getLine(range.start.row);
455
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
456
+ if (rightChar == ')') {
457
+ range.end.column++;
458
+ return range;
459
+ }
460
+ }
461
+ });
462
+
463
+ this.add("brackets", "insertion", function (state, action, editor, session, text) {
464
+ if (text == '[') {
465
+ var selection = editor.getSelectionRange();
466
+ var selected = session.doc.getTextRange(selection);
467
+ if (selected !== "" && editor.getWrapBehavioursEnabled()) {
468
+ return {
469
+ text: '[' + selected + ']',
470
+ selection: false
471
+ };
472
+ } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
473
+ CstyleBehaviour.recordAutoInsert(editor, session, "]");
474
+ return {
475
+ text: '[]',
476
+ selection: [1, 1]
477
+ };
478
+ }
479
+ } else if (text == ']') {
480
+ var cursor = editor.getCursorPosition();
481
+ var line = session.doc.getLine(cursor.row);
482
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
483
+ if (rightChar == ']') {
484
+ var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
485
+ if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
486
+ CstyleBehaviour.popAutoInsertedClosing();
487
+ return {
488
+ text: '',
489
+ selection: [1, 1]
490
+ };
491
+ }
492
+ }
493
+ }
494
+ });
495
+
496
+ this.add("brackets", "deletion", function (state, action, editor, session, range) {
497
+ var selected = session.doc.getTextRange(range);
498
+ if (!range.isMultiLine() && selected == '[') {
499
+ var line = session.doc.getLine(range.start.row);
500
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
501
+ if (rightChar == ']') {
502
+ range.end.column++;
503
+ return range;
504
+ }
505
+ }
506
+ });
507
+
508
+ this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
509
+ if (text == '"' || text == "'") {
510
+ var quote = text;
511
+ var selection = editor.getSelectionRange();
512
+ var selected = session.doc.getTextRange(selection);
513
+ if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
514
+ return {
515
+ text: quote + selected + quote,
516
+ selection: false
517
+ };
518
+ } else {
519
+ var cursor = editor.getCursorPosition();
520
+ var line = session.doc.getLine(cursor.row);
521
+ var leftChar = line.substring(cursor.column-1, cursor.column);
522
+ if (leftChar == '\\') {
523
+ return null;
524
+ }
525
+ var tokens = session.getTokens(selection.start.row);
526
+ var col = 0, token;
527
+ var quotepos = -1; // Track whether we're inside an open quote.
528
+
529
+ for (var x = 0; x < tokens.length; x++) {
530
+ token = tokens[x];
531
+ if (token.type == "string") {
532
+ quotepos = -1;
533
+ } else if (quotepos < 0) {
534
+ quotepos = token.value.indexOf(quote);
535
+ }
536
+ if ((token.value.length + col) > selection.start.column) {
537
+ break;
538
+ }
539
+ col += tokens[x].value.length;
540
+ }
541
+ 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)))) {
542
+ if (!CstyleBehaviour.isSaneInsertion(editor, session))
543
+ return;
544
+ return {
545
+ text: quote + quote,
546
+ selection: [1,1]
547
+ };
548
+ } else if (token && token.type === "string") {
549
+ var rightChar = line.substring(cursor.column, cursor.column + 1);
550
+ if (rightChar == quote) {
551
+ return {
552
+ text: '',
553
+ selection: [1, 1]
554
+ };
555
+ }
556
+ }
557
+ }
558
+ }
559
+ });
560
+
561
+ this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
562
+ var selected = session.doc.getTextRange(range);
563
+ if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
564
+ var line = session.doc.getLine(range.start.row);
565
+ var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
566
+ if (rightChar == selected) {
567
+ range.end.column++;
568
+ return range;
569
+ }
570
+ }
571
+ });
572
+
573
+ };
574
+
575
+ oop.inherits(CstyleBehaviour, Behaviour);
576
+
577
+ exports.CstyleBehaviour = CstyleBehaviour;
578
+ });
579
+
580
+ define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
581
+
582
+
583
+ var oop = require("../../lib/oop");
584
+ var Range = require("../../range").Range;
585
+ var BaseFoldMode = require("./fold_mode").FoldMode;
586
+
587
+ var FoldMode = exports.FoldMode = function(commentRegex) {
588
+ if (commentRegex) {
589
+ this.foldingStartMarker = new RegExp(
590
+ this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
591
+ );
592
+ this.foldingStopMarker = new RegExp(
593
+ this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
594
+ );
595
+ }
596
+ };
597
+ oop.inherits(FoldMode, BaseFoldMode);
598
+
599
+ (function() {
600
+
601
+ this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
602
+ this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
603
+
604
+ this.getFoldWidgetRange = function(session, foldStyle, row) {
605
+ var line = session.getLine(row);
606
+ var match = line.match(this.foldingStartMarker);
607
+ if (match) {
608
+ var i = match.index;
609
+
610
+ if (match[1])
611
+ return this.openingBracketBlock(session, match[1], row, i);
612
+
613
+ return session.getCommentFoldRange(row, i + match[0].length, 1);
614
+ }
615
+
616
+ if (foldStyle !== "markbeginend")
617
+ return;
618
+
619
+ var match = line.match(this.foldingStopMarker);
620
+ if (match) {
621
+ var i = match.index + match[0].length;
622
+
623
+ if (match[1])
624
+ return this.closingBracketBlock(session, match[1], row, i);
625
+
626
+ return session.getCommentFoldRange(row, i, -1);
627
+ }
628
+ };
629
+
630
+ }).call(FoldMode.prototype);
631
+
632
+ });