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,455 @@
1
+ /* ***** BEGIN LICENSE BLOCK *****
2
+ * Distributed under the BSD license:
3
+ *
4
+ * Copyright (c) 2010, 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/lua', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/lua_highlight_rules', 'ace/mode/folding/lua', 'ace/range', 'ace/worker/worker_client'], 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 LuaHighlightRules = require("./lua_highlight_rules").LuaHighlightRules;
38
+ var LuaFoldMode = require("./folding/lua").FoldMode;
39
+ var Range = require("../range").Range;
40
+ var WorkerClient = require("../worker/worker_client").WorkerClient;
41
+
42
+ var Mode = function() {
43
+ this.$tokenizer = new Tokenizer(new LuaHighlightRules().getRules());
44
+ this.foldingRules = new LuaFoldMode();
45
+ };
46
+ oop.inherits(Mode, TextMode);
47
+
48
+ (function() {
49
+
50
+ this.lineCommentStart = "--";
51
+ this.blockComment = {start: "--[", end: "]--"};
52
+
53
+ var indentKeywords = {
54
+ "function": 1,
55
+ "then": 1,
56
+ "do": 1,
57
+ "else": 1,
58
+ "elseif": 1,
59
+ "repeat": 1,
60
+ "end": -1,
61
+ "until": -1
62
+ };
63
+ var outdentKeywords = [
64
+ "else",
65
+ "elseif",
66
+ "end",
67
+ "until"
68
+ ];
69
+
70
+ function getNetIndentLevel(tokens) {
71
+ var level = 0;
72
+ for (var i = 0; i < tokens.length; i++) {
73
+ var token = tokens[i];
74
+ if (token.type == "keyword") {
75
+ if (token.value in indentKeywords) {
76
+ level += indentKeywords[token.value];
77
+ }
78
+ } else if (token.type == "paren.lparen") {
79
+ level ++;
80
+ } else if (token.type == "paren.rparen") {
81
+ level --;
82
+ }
83
+ }
84
+ if (level < 0) {
85
+ return -1;
86
+ } else if (level > 0) {
87
+ return 1;
88
+ } else {
89
+ return 0;
90
+ }
91
+ }
92
+
93
+ this.getNextLineIndent = function(state, line, tab) {
94
+ var indent = this.$getIndent(line);
95
+ var level = 0;
96
+
97
+ var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
98
+ var tokens = tokenizedLine.tokens;
99
+
100
+ if (state == "start") {
101
+ level = getNetIndentLevel(tokens);
102
+ }
103
+ if (level > 0) {
104
+ return indent + tab;
105
+ } else if (level < 0 && indent.substr(indent.length - tab.length) == tab) {
106
+ if (!this.checkOutdent(state, line, "\n")) {
107
+ return indent.substr(0, indent.length - tab.length);
108
+ }
109
+ }
110
+ return indent;
111
+ };
112
+
113
+ this.checkOutdent = function(state, line, input) {
114
+ if (input != "\n" && input != "\r" && input != "\r\n")
115
+ return false;
116
+
117
+ if (line.match(/^\s*[\)\}\]]$/))
118
+ return true;
119
+
120
+ var tokens = this.$tokenizer.getLineTokens(line.trim(), state).tokens;
121
+
122
+ if (!tokens || !tokens.length)
123
+ return false;
124
+
125
+ return (tokens[0].type == "keyword" && outdentKeywords.indexOf(tokens[0].value) != -1);
126
+ };
127
+
128
+ this.autoOutdent = function(state, session, row) {
129
+ var prevLine = session.getLine(row - 1);
130
+ var prevIndent = this.$getIndent(prevLine).length;
131
+ var prevTokens = this.$tokenizer.getLineTokens(prevLine, "start").tokens;
132
+ var tabLength = session.getTabString().length;
133
+ var expectedIndent = prevIndent + tabLength * getNetIndentLevel(prevTokens);
134
+ var curIndent = this.$getIndent(session.getLine(row)).length;
135
+ if (curIndent < expectedIndent) {
136
+ return;
137
+ }
138
+ session.outdentRows(new Range(row, 0, row + 2, 0));
139
+ };
140
+
141
+ this.createWorker = function(session) {
142
+ var worker = new WorkerClient(["ace"], "ace/mode/lua_worker", "Worker");
143
+ worker.attachToDocument(session.getDocument());
144
+
145
+ worker.on("error", function(e) {
146
+ session.setAnnotations([e.data]);
147
+ });
148
+
149
+ worker.on("ok", function(e) {
150
+ session.clearAnnotations();
151
+ });
152
+
153
+ return worker;
154
+ };
155
+
156
+ }).call(Mode.prototype);
157
+
158
+ exports.Mode = Mode;
159
+ });
160
+
161
+ define('ace/mode/lua_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
162
+
163
+
164
+ var oop = require("../lib/oop");
165
+ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
166
+
167
+ var LuaHighlightRules = function() {
168
+
169
+ var keywords = (
170
+ "break|do|else|elseif|end|for|function|if|in|local|repeat|"+
171
+ "return|then|until|while|or|and|not"
172
+ );
173
+
174
+ var builtinConstants = ("true|false|nil|_G|_VERSION");
175
+
176
+ var functions = (
177
+ "string|xpcall|package|tostring|print|os|unpack|require|"+
178
+ "getfenv|setmetatable|next|assert|tonumber|io|rawequal|"+
179
+ "collectgarbage|getmetatable|module|rawset|math|debug|"+
180
+ "pcall|table|newproxy|type|coroutine|_G|select|gcinfo|"+
181
+ "pairs|rawget|loadstring|ipairs|_VERSION|dofile|setfenv|"+
182
+ "load|error|loadfile|"+
183
+
184
+ "sub|upper|len|gfind|rep|find|match|char|dump|gmatch|"+
185
+ "reverse|byte|format|gsub|lower|preload|loadlib|loaded|"+
186
+ "loaders|cpath|config|path|seeall|exit|setlocale|date|"+
187
+ "getenv|difftime|remove|time|clock|tmpname|rename|execute|"+
188
+ "lines|write|close|flush|open|output|type|read|stderr|"+
189
+ "stdin|input|stdout|popen|tmpfile|log|max|acos|huge|"+
190
+ "ldexp|pi|cos|tanh|pow|deg|tan|cosh|sinh|random|randomseed|"+
191
+ "frexp|ceil|floor|rad|abs|sqrt|modf|asin|min|mod|fmod|log10|"+
192
+ "atan2|exp|sin|atan|getupvalue|debug|sethook|getmetatable|"+
193
+ "gethook|setmetatable|setlocal|traceback|setfenv|getinfo|"+
194
+ "setupvalue|getlocal|getregistry|getfenv|setn|insert|getn|"+
195
+ "foreachi|maxn|foreach|concat|sort|remove|resume|yield|"+
196
+ "status|wrap|create|running|"+
197
+ "__add|__sub|__mod|__unm|__concat|__lt|__index|__call|__gc|__metatable|"+
198
+ "__mul|__div|__pow|__len|__eq|__le|__newindex|__tostring|__mode|__tonumber"
199
+ );
200
+
201
+ var stdLibaries = ("string|package|os|io|math|debug|table|coroutine");
202
+
203
+ var futureReserved = "";
204
+
205
+ var deprecatedIn5152 = ("setn|foreach|foreachi|gcinfo|log10|maxn");
206
+
207
+ var keywordMapper = this.createKeywordMapper({
208
+ "keyword": keywords,
209
+ "support.function": functions,
210
+ "invalid.deprecated": deprecatedIn5152,
211
+ "constant.library": stdLibaries,
212
+ "constant.language": builtinConstants,
213
+ "invalid.illegal": futureReserved,
214
+ "variable.language": "this"
215
+ }, "identifier");
216
+
217
+ var decimalInteger = "(?:(?:[1-9]\\d*)|(?:0))";
218
+ var hexInteger = "(?:0[xX][\\dA-Fa-f]+)";
219
+ var integer = "(?:" + decimalInteger + "|" + hexInteger + ")";
220
+
221
+ var fraction = "(?:\\.\\d+)";
222
+ var intPart = "(?:\\d+)";
223
+ var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))";
224
+ var floatNumber = "(?:" + pointFloat + ")";
225
+
226
+ this.$rules = {
227
+ "start" : [{
228
+ stateName: "bracketedComment",
229
+ onMatch : function(value, currentState, stack){
230
+ stack.unshift(this.next, value.length, currentState);
231
+ return "comment";
232
+ },
233
+ regex : /\-\-\[=*\[/,
234
+ next : [
235
+ {
236
+ onMatch : function(value, currentState, stack) {
237
+ if (value.length == stack[1]) {
238
+ stack.shift();
239
+ stack.shift();
240
+ this.next = stack.shift();
241
+ } else {
242
+ this.next = "";
243
+ }
244
+ return "comment";
245
+ },
246
+ regex : /(?:[^\\]|\\.)*?\]=*\]/,
247
+ next : "start"
248
+ }, {
249
+ defaultToken : "comment"
250
+ }
251
+ ]
252
+ },
253
+
254
+ {
255
+ token : "comment",
256
+ regex : "\\-\\-.*$"
257
+ },
258
+ {
259
+ stateName: "bracketedString",
260
+ onMatch : function(value, currentState, stack){
261
+ stack.unshift(this.next, value.length, currentState);
262
+ return "comment";
263
+ },
264
+ regex : /\[=*\[/,
265
+ next : [
266
+ {
267
+ onMatch : function(value, currentState, stack) {
268
+ if (value.length == stack[1]) {
269
+ stack.shift();
270
+ stack.shift();
271
+ this.next = stack.shift();
272
+ } else {
273
+ this.next = "";
274
+ }
275
+ return "comment";
276
+ },
277
+
278
+ regex : /(?:[^\\]|\\.)*?\]=*\]/,
279
+ next : "start"
280
+ }, {
281
+ defaultToken : "comment"
282
+ }
283
+ ]
284
+ },
285
+ {
286
+ token : "string", // " string
287
+ regex : '"(?:[^\\\\]|\\\\.)*?"'
288
+ }, {
289
+ token : "string", // ' string
290
+ regex : "'(?:[^\\\\]|\\\\.)*?'"
291
+ }, {
292
+ token : "constant.numeric", // float
293
+ regex : floatNumber
294
+ }, {
295
+ token : "constant.numeric", // integer
296
+ regex : integer + "\\b"
297
+ }, {
298
+ token : keywordMapper,
299
+ regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
300
+ }, {
301
+ token : "keyword.operator",
302
+ regex : "\\+|\\-|\\*|\\/|%|\\#|\\^|~|<|>|<=|=>|==|~=|=|\\:|\\.\\.\\.|\\.\\."
303
+ }, {
304
+ token : "paren.lparen",
305
+ regex : "[\\[\\(\\{]"
306
+ }, {
307
+ token : "paren.rparen",
308
+ regex : "[\\]\\)\\}]"
309
+ }, {
310
+ token : "text",
311
+ regex : "\\s+|\\w+"
312
+ } ]
313
+ };
314
+
315
+ this.normalizeRules();
316
+ }
317
+
318
+ oop.inherits(LuaHighlightRules, TextHighlightRules);
319
+
320
+ exports.LuaHighlightRules = LuaHighlightRules;
321
+ });
322
+
323
+ define('ace/mode/folding/lua', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/folding/fold_mode', 'ace/range', 'ace/token_iterator'], function(require, exports, module) {
324
+
325
+
326
+ var oop = require("../../lib/oop");
327
+ var BaseFoldMode = require("./fold_mode").FoldMode;
328
+ var Range = require("../../range").Range;
329
+ var TokenIterator = require("../../token_iterator").TokenIterator;
330
+
331
+
332
+ var FoldMode = exports.FoldMode = function() {};
333
+
334
+ oop.inherits(FoldMode, BaseFoldMode);
335
+
336
+ (function() {
337
+
338
+ this.foldingStartMarker = /\b(function|then|do|repeat)\b|{\s*$|(\[=*\[)/;
339
+ this.foldingStopMarker = /\bend\b|^\s*}|\]=*\]/;
340
+
341
+ this.getFoldWidget = function(session, foldStyle, row) {
342
+ var line = session.getLine(row);
343
+ var isStart = this.foldingStartMarker.test(line);
344
+ var isEnd = this.foldingStopMarker.test(line);
345
+
346
+ if (isStart && !isEnd) {
347
+ var match = line.match(this.foldingStartMarker);
348
+ if (match[1] == "then" && /\belseif\b/.test(line))
349
+ return;
350
+ if (match[1]) {
351
+ if (session.getTokenAt(row, match.index + 1).type === "keyword")
352
+ return "start";
353
+ } else if (match[2]) {
354
+ var type = session.bgTokenizer.getState(row) || "";
355
+ if (type[0] == "bracketedComment" || type[0] == "bracketedString")
356
+ return "start";
357
+ } else {
358
+ return "start";
359
+ }
360
+ }
361
+ if (foldStyle != "markbeginend" || !isEnd || isStart && isEnd)
362
+ return "";
363
+
364
+ var match = line.match(this.foldingStopMarker);
365
+ if (match[0] === "end") {
366
+ if (session.getTokenAt(row, match.index + 1).type === "keyword")
367
+ return "end";
368
+ } else if (match[0][0] === "]") {
369
+ var type = session.bgTokenizer.getState(row - 1) || "";
370
+ if (type[0] == "bracketedComment" || type[0] == "bracketedString")
371
+ return "end";
372
+ } else
373
+ return "end";
374
+ };
375
+
376
+ this.getFoldWidgetRange = function(session, foldStyle, row) {
377
+ var line = session.doc.getLine(row);
378
+ var match = this.foldingStartMarker.exec(line);
379
+ if (match) {
380
+ if (match[1])
381
+ return this.luaBlock(session, row, match.index + 1);
382
+
383
+ if (match[2])
384
+ return session.getCommentFoldRange(row, match.index + 1);
385
+
386
+ return this.openingBracketBlock(session, "{", row, match.index);
387
+ }
388
+
389
+ var match = this.foldingStopMarker.exec(line);
390
+ if (match) {
391
+ if (match[0] === "end") {
392
+ if (session.getTokenAt(row, match.index + 1).type === "keyword")
393
+ return this.luaBlock(session, row, match.index + 1);
394
+ }
395
+
396
+ if (match[0][0] === "]")
397
+ return session.getCommentFoldRange(row, match.index + 1);
398
+
399
+ return this.closingBracketBlock(session, "}", row, match.index + match[0].length);
400
+ }
401
+ };
402
+
403
+ this.luaBlock = function(session, row, column) {
404
+ var stream = new TokenIterator(session, row, column);
405
+ var indentKeywords = {
406
+ "function": 1,
407
+ "do": 1,
408
+ "then": 1,
409
+ "elseif": -1,
410
+ "end": -1,
411
+ "repeat": 1,
412
+ "until": -1
413
+ };
414
+
415
+ var token = stream.getCurrentToken();
416
+ if (!token || token.type != "keyword")
417
+ return;
418
+
419
+ var val = token.value;
420
+ var stack = [val];
421
+ var dir = indentKeywords[val];
422
+
423
+ if (!dir)
424
+ return;
425
+
426
+ var startColumn = dir === -1 ? stream.getCurrentTokenColumn() : session.getLine(row).length;
427
+ var startRow = row;
428
+
429
+ stream.step = dir === -1 ? stream.stepBackward : stream.stepForward;
430
+ while(token = stream.step()) {
431
+ if (token.type !== "keyword")
432
+ continue;
433
+ var level = dir * indentKeywords[token.value];
434
+
435
+ if (level > 0) {
436
+ stack.unshift(token.value);
437
+ } else if (level <= 0) {
438
+ stack.shift();
439
+ if (!stack.length && token.value != "elseif")
440
+ break;
441
+ if (level === 0)
442
+ stack.unshift(token.value);
443
+ }
444
+ }
445
+
446
+ var row = stream.getCurrentTokenRow();
447
+ if (dir === -1)
448
+ return new Range(row, session.getLine(row).length, startRow, startColumn);
449
+ else
450
+ return new Range(startRow, startColumn, row, stream.getCurrentTokenColumn());
451
+ };
452
+
453
+ }).call(FoldMode.prototype);
454
+
455
+ });