1
/* ***** BEGIN LICENSE BLOCK *****
2
* Distributed under the BSD license:
4
* Copyright (c) 2012, Ajax.org B.V.
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.
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.
29
* ***** END LICENSE BLOCK ***** */
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'], function(require, exports, module) {
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("ace/token_iterator").TokenIterator;
40
var Range = require("ace/range").Range;
42
var Mode = function() {
43
var highlighter = new LogiQLHighlightRules();
44
this.foldingRules = new FoldMode();
45
this.$tokenizer = new Tokenizer(highlighter.getRules());
47
oop.inherits(Mode, TextMode);
50
this.lineCommentStart = "//";
51
this.blockComment = {start: "/*", end: "*/"};
53
this.getNextLineIndent = function(state, line, tab) {
54
var indent = this.$getIndent(line);
55
var match = line.match();
56
if (/(-->|<--|<-|->)\s*$/.test(line))
61
this.checkOutdent = function(state, line, input) {
62
if (input !== "\n" && input !== "\r\n")
65
if (!/^\s+/.test(line))
71
this.autoOutdent = function(state, doc, row) {
72
var prevLine = doc.getLine(row);
73
var match = prevLine.match(/^\s+/);
74
var column = prevLine.lastIndexOf(".") + 1;
75
if (!match || !row || !column) return 0;
77
var line = doc.getLine(row + 1);
78
var startRange = this.getMatching(doc, {row: row, column: column});
79
if (!startRange || startRange.start.row == row) return 0;
81
column = match[0].length;
82
var indent = this.$getIndent(doc.getLine(startRange.start.row));
83
doc.replace(new Range(row + 1, 0, row + 1, column), indent);
86
this.getMatching = function(session, row, column) {
88
row = session.selection.lead
89
if (typeof row == "object") {
94
var startToken = session.getTokenAt(row, column);
95
var KW_START = "keyword.start", KW_END = "keyword.end";
99
if (startToken.type == KW_START) {
100
var it = new TokenIterator(session, row, column);
101
it.step = it.stepForward;
102
} else if (startToken.type == KW_END) {
103
var it = new TokenIterator(session, row, column);
104
it.step = it.stepBackward;
108
while (tok = it.step()) {
109
if (tok.type == KW_START || tok.type == KW_END)
115
var col = it.getCurrentTokenColumn();
116
var row = it.getCurrentTokenRow();
117
return new Range(row, col, row, col + tok.value.length);
119
}).call(Mode.prototype);
124
define('ace/mode/logiql_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
127
var oop = require("../lib/oop");
128
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
130
var LogiQLHighlightRules = function() {
132
this.$rules = { start:
133
[ { token: 'comment.block',
136
[ { token: 'comment.block', regex: '\\*/', next: 'pop' },
137
{ defaultToken: 'comment.block' } ],
139
{ token: 'comment.single',
142
{ token: 'constant.numeric',
143
regex: '\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?',
148
[ { token: 'string', regex: '"', next: 'pop' },
149
{ defaultToken: 'string' } ],
151
{ token: 'constant.language',
152
regex: '\\b(true|false)\\b',
154
{ token: 'entity.name.type.logicblox',
155
regex: '`[a-zA-Z_:]+(\\d|\\a)*\\b',
157
{ token: 'keyword.start', regex: '->', comment: 'Constraint' },
158
{ token: 'keyword.start', regex: '-->', comment: 'Level 1 Constraint'},
159
{ token: 'keyword.start', regex: '<-', comment: 'Rule' },
160
{ token: 'keyword.start', regex: '<--', comment: 'Level 1 Rule' },
161
{ token: 'keyword.end', regex: '\\.', comment: 'Terminator' },
162
{ token: 'keyword.other', regex: '!', comment: 'Negation' },
163
{ token: 'keyword.other', regex: ',', comment: 'Conjunction' },
164
{ token: 'keyword.other', regex: ';', comment: 'Disjunction' },
165
{ token: 'keyword.operator', regex: '<=|>=|!=|<|>', comment: 'Equality'},
166
{ token: 'keyword.other', regex: '@', comment: 'Equality' },
167
{ token: 'keyword.operator', regex: '\\+|-|\\*|/', comment: 'Arithmetic operations'},
168
{ token: 'keyword', regex: '::', comment: 'Colon colon' },
169
{ token: 'support.function',
170
regex: '\\b(agg\\s*<<)',
172
[ { include: '$self' },
173
{ token: 'support.function',
177
{ token: 'storage.modifier',
178
regex: '\\b(lang:[\\w:]*)',
180
{ token: [ 'storage.type', 'text' ],
181
regex: '(export|sealed|clauses|block|alias)\\s*\\((?=`)',
183
{ token: 'entity.name',
184
regex: '[a-zA-Z_][a-zA-Z_0-9:]*(@prev|@init|@final)?(?=(\\(|\\[))',
186
{ token: 'variable.parameter',
187
regex: '([a-zA-Z][a-zA-Z_0-9]*|_)\\s*(?=(,|\\.|<-|->|\\)|\\]|=))',
190
this.normalizeRules();
193
oop.inherits(LogiQLHighlightRules, TextHighlightRules);
195
exports.LogiQLHighlightRules = LogiQLHighlightRules;
198
define('ace/mode/folding/coffee', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/folding/fold_mode', 'ace/range'], function(require, exports, module) {
201
var oop = require("../../lib/oop");
202
var BaseFoldMode = require("./fold_mode").FoldMode;
203
var Range = require("../../range").Range;
205
var FoldMode = exports.FoldMode = function() {};
206
oop.inherits(FoldMode, BaseFoldMode);
210
this.getFoldWidgetRange = function(session, foldStyle, row) {
211
var range = this.indentationBlock(session, row);
216
var line = session.getLine(row);
217
var startLevel = line.search(re);
218
if (startLevel == -1 || line[startLevel] != "#")
221
var startColumn = line.length;
222
var maxRow = session.getLength();
226
while (++row < maxRow) {
227
line = session.getLine(row);
228
var level = line.search(re);
233
if (line[level] != "#")
239
if (endRow > startRow) {
240
var endColumn = session.getLine(endRow).length;
241
return new Range(startRow, startColumn, endRow, endColumn);
244
this.getFoldWidget = function(session, foldStyle, row) {
245
var line = session.getLine(row);
246
var indent = line.search(/\S/);
247
var next = session.getLine(row + 1);
248
var prev = session.getLine(row - 1);
249
var prevIndent = prev.search(/\S/);
250
var nextIndent = next.search(/\S/);
253
session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
256
if (prevIndent == -1) {
257
if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
258
session.foldWidgets[row - 1] = "";
259
session.foldWidgets[row + 1] = "";
262
} else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
263
if (session.getLine(row - 2).search(/\S/) == -1) {
264
session.foldWidgets[row - 1] = "start";
265
session.foldWidgets[row + 1] = "";
270
if (prevIndent!= -1 && prevIndent < indent)
271
session.foldWidgets[row - 1] = "start";
273
session.foldWidgets[row - 1] = "";
275
if (indent < nextIndent)
281
}).call(FoldMode.prototype);