Merge pull request #1298 from ajaxorg/highlighting/logicblox
Highlighting logicblox and some cleanup
This commit is contained in:
commit
f16d0dc1d3
19 changed files with 600 additions and 35 deletions
|
|
@ -369,8 +369,11 @@ var Editor = function(renderer, session) {
|
|||
var pos = self.session.findMatchingBracket(self.getCursorPosition());
|
||||
if (pos) {
|
||||
var range = new Range(pos.row, pos.column, pos.row, pos.column+1);
|
||||
self.session.$bracketHighlight = self.session.addMarker(range, "ace_bracket", "text");
|
||||
} else if (self.session.$mode.getMatching) {
|
||||
var range = self.session.$mode.getMatching(self.session);
|
||||
}
|
||||
if (range)
|
||||
self.session.$bracketHighlight = self.session.addMarker(range, "ace_bracket", "text");
|
||||
}, 50);
|
||||
};
|
||||
|
||||
|
|
|
|||
1
lib/ace/mode/_test/text_livescript.txt
Normal file
1
lib/ace/mode/_test/text_livescript.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
# comment
|
||||
|
|
@ -1,6 +1,17 @@
|
|||
[[
|
||||
"start",
|
||||
["comment","#!/usr/bin/perl"]
|
||||
],[
|
||||
"block_comment",
|
||||
["comment.doc","=begin"]
|
||||
],[
|
||||
"block_comment",
|
||||
["comment.doc"," perl example code for Ace"]
|
||||
],[
|
||||
"start",
|
||||
["comment.doc","=cut"]
|
||||
],[
|
||||
"start"
|
||||
],[
|
||||
"start",
|
||||
["keyword","use"],
|
||||
|
|
@ -211,4 +222,6 @@
|
|||
["text",";"]
|
||||
],[
|
||||
"start"
|
||||
],[
|
||||
"start"
|
||||
]]
|
||||
|
|
@ -35,7 +35,16 @@ var oop = require("../../lib/oop");
|
|||
var Range = require("../../range").Range;
|
||||
var BaseFoldMode = require("./fold_mode").FoldMode;
|
||||
|
||||
var FoldMode = exports.FoldMode = function() {};
|
||||
var FoldMode = exports.FoldMode = function(commentRegex) {
|
||||
if (commentRegex) {
|
||||
this.foldingStartMarker = new RegExp(
|
||||
this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
|
||||
);
|
||||
this.foldingStopMarker = new RegExp(
|
||||
this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
|
||||
);
|
||||
}
|
||||
};
|
||||
oop.inherits(FoldMode, BaseFoldMode);
|
||||
|
||||
(function() {
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ oop.inherits(FoldMode, BaseFoldMode);
|
|||
return "start";
|
||||
} else if (match[2]) {
|
||||
var type = session.bgTokenizer.getState(row) || "";
|
||||
if (type.indexOf("comment") != -1 || type.indexOf("string") != -1)
|
||||
if (type[0] == "bracketedComment" || type[0] == "bracketedString")
|
||||
return "start";
|
||||
} else {
|
||||
return "start";
|
||||
|
|
@ -75,7 +75,7 @@ oop.inherits(FoldMode, BaseFoldMode);
|
|||
return "end";
|
||||
} else if (match[0][0] === "]") {
|
||||
var type = session.bgTokenizer.getState(row - 1) || "";
|
||||
if (type.indexOf("comment") != -1 || type.indexOf("string") != -1)
|
||||
if (type[0] == "bracketedComment" || type[0] == "bracketedString")
|
||||
return "end";
|
||||
} else
|
||||
return "end";
|
||||
|
|
|
|||
123
lib/ace/mode/logicql.js
Normal file
123
lib/ace/mode/logicql.js
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Distributed under the BSD license:
|
||||
*
|
||||
* Copyright (c) 2012, Ajax.org B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Ajax.org B.V. nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var oop = require("../lib/oop");
|
||||
var TextMode = require("./text").Mode;
|
||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||
var LogicQLHighlightRules = require("./logicql_highlight_rules").LogicQLHighlightRules;
|
||||
var FoldMode = require("./folding/coffee").FoldMode;
|
||||
var TokenIterator = require("ace/token_iterator").TokenIterator;
|
||||
var Range = require("ace/range").Range;
|
||||
|
||||
var Mode = function() {
|
||||
var highlighter = new LogicQLHighlightRules();
|
||||
this.foldingRules = new FoldMode();
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
this.lineCommentStart = "//";
|
||||
this.blockComment = {start: "/*", end: "*/"};
|
||||
|
||||
this.getNextLineIndent = function(state, line, tab) {
|
||||
var indent = this.$getIndent(line);
|
||||
var match = line.match();
|
||||
if (/(-->|<--|<-|->)\s*$/.test(line))
|
||||
indent += tab;
|
||||
return indent;
|
||||
};
|
||||
|
||||
this.checkOutdent = function(state, line, input) {
|
||||
if (input !== "\n" && input !== "\r\n")
|
||||
return false;
|
||||
|
||||
if (!/^\s+/.test(line))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
this.autoOutdent = function(state, doc, row) {
|
||||
var prevLine = doc.getLine(row);
|
||||
var match = prevLine.match(/^\s+/);
|
||||
var column = prevLine.lastIndexOf(".") + 1;
|
||||
if (!match || !row || !column) return 0;
|
||||
|
||||
var line = doc.getLine(row + 1);
|
||||
var startRange = this.getMatching(doc, {row: row, column: column});
|
||||
if (!startRange || startRange.start.row == row) return 0;
|
||||
|
||||
column = match[0].length;
|
||||
var indent = this.$getIndent(doc.getLine(startRange.start.row));
|
||||
doc.replace(new Range(row + 1, 0, row + 1, column), indent);
|
||||
};
|
||||
|
||||
this.getMatching = function(session, row, column) {
|
||||
if (row == undefined)
|
||||
row = session.selection.lead
|
||||
if (typeof row == "object") {
|
||||
column = row.column;
|
||||
row = row.row;
|
||||
}
|
||||
|
||||
var startToken = session.getTokenAt(row, column);
|
||||
var KW_START = "keyword.start", KW_END = "keyword.end";
|
||||
var tok;
|
||||
if (!startToken)
|
||||
return;
|
||||
if (startToken.type == KW_START) {
|
||||
var it = new TokenIterator(session, row, column);
|
||||
it.step = it.stepForward;
|
||||
} else if (startToken.type == KW_END) {
|
||||
var it = new TokenIterator(session, row, column);
|
||||
it.step = it.stepBackward;
|
||||
} else
|
||||
return;
|
||||
|
||||
while (tok = it.step()) {
|
||||
if (tok.type == KW_START || tok.type == KW_END)
|
||||
break;
|
||||
}
|
||||
if (!tok)
|
||||
return;
|
||||
|
||||
var col = it.getCurrentTokenColumn();
|
||||
var row = it.getCurrentTokenRow();
|
||||
return new Range(row, col, row, col + tok.value.length);
|
||||
};
|
||||
// Extra logic goes here.
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.Mode = Mode;
|
||||
});
|
||||
119
lib/ace/mode/logicql_highlight_rules.js
Normal file
119
lib/ace/mode/logicql_highlight_rules.js
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Distributed under the BSD license:
|
||||
*
|
||||
* Copyright (c) 2012, Ajax.org B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Ajax.org B.V. nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* THIS FILE WAS AUTOGENERATED FROM tool\LogicBlox.tmbundle\Syntaxes\LogicBlox.tmLanguage (UUID: 59bf5022-e261-453f-b1cb-9f9fa0712413) */
|
||||
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var oop = require("../lib/oop");
|
||||
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
||||
|
||||
var LogicQLHighlightRules = function() {
|
||||
// regexp must not have capturing parentheses. Use (?:) instead.
|
||||
// regexps are ordered -> the first match is used
|
||||
|
||||
this.$rules = { start:
|
||||
[ { token: 'comment.block',
|
||||
regex: '/\\*',
|
||||
push:
|
||||
[ { token: 'comment.block', regex: '\\*/', next: 'pop' },
|
||||
{ defaultToken: 'comment.block' } ],
|
||||
//A block comment.
|
||||
},
|
||||
{ token: 'comment.single',
|
||||
regex: '//.*',
|
||||
//A single line comment.
|
||||
},
|
||||
{ token: 'constant.numeric',
|
||||
regex: '\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?',
|
||||
//An integer constant.
|
||||
//Or a Real number.
|
||||
},
|
||||
{ token: 'string',
|
||||
regex: '"',
|
||||
push:
|
||||
[ { token: 'string', regex: '"', next: 'pop' },
|
||||
{ defaultToken: 'string' } ],
|
||||
//Strings
|
||||
},
|
||||
{ token: 'constant.language',
|
||||
regex: '\\b(true|false)\\b',
|
||||
//Boolean values.
|
||||
},
|
||||
{ token: 'entity.name.type.logicblox',
|
||||
regex: '`[a-zA-Z_:]+(\\d|\\a)*\\b',
|
||||
//LogicBlox Symbol
|
||||
},
|
||||
{ token: 'keyword.start', regex: '->', comment: 'Constraint' },
|
||||
{ token: 'keyword.start', regex: '-->', comment: 'Level 1 Constraint'},
|
||||
{ token: 'keyword.start', regex: '<-', comment: 'Rule' },
|
||||
{ token: 'keyword.start', regex: '<--', comment: 'Level 1 Rule' },
|
||||
{ token: 'keyword.end', regex: '\\.', comment: 'Terminator' },
|
||||
{ token: 'keyword.other', regex: '!', comment: 'Negation' },
|
||||
{ token: 'keyword.other', regex: ',', comment: 'Conjunction' },
|
||||
{ token: 'keyword.other', regex: ';', comment: 'Disjunction' },
|
||||
{ token: 'keyword.operator', regex: '<=|>=|!=|<|>', comment: 'Equality'},
|
||||
{ token: 'keyword.other', regex: '@', comment: 'Equality' },
|
||||
{ token: 'keyword.operator', regex: '\\+|-|\\*|/', comment: 'Arithmetic operations'},
|
||||
{ token: 'keyword', regex: '::', comment: 'Colon colon' },
|
||||
{ token: 'support.function',
|
||||
regex: '\\b(agg\\s*<<)',
|
||||
push:
|
||||
[ { include: '$self' },
|
||||
{ token: 'support.function',
|
||||
regex: '>>',
|
||||
next: 'pop' } ],
|
||||
//Aggregations
|
||||
},
|
||||
{ token: 'storage.modifier',
|
||||
regex: '\\b(lang:[\\w:]*)',
|
||||
//All the lang system predicates
|
||||
},
|
||||
{ token: [ 'storage.type', 'text' ],
|
||||
regex: '(export|sealed|clauses|block|alias)\\s*\\((?=`)',
|
||||
//Module keywords
|
||||
},
|
||||
{ token: 'entity.name',
|
||||
regex: '[a-zA-Z_][a-zA-Z_0-9:]*(@prev|@init|@final)?(?=(\\(|\\[))',
|
||||
//A predicate name.
|
||||
},
|
||||
{ token: 'variable.parameter',
|
||||
regex: '([a-zA-Z][a-zA-Z_0-9]*|_)\\s*(?=(,|\\.|<-|->|\\)|\\]|=))',
|
||||
//A variable to a functional predicate.
|
||||
} ] }
|
||||
|
||||
this.normalizeRules();
|
||||
};
|
||||
|
||||
oop.inherits(LogicQLHighlightRules, TextHighlightRules);
|
||||
|
||||
exports.LogicQLHighlightRules = LogicQLHighlightRules;
|
||||
});
|
||||
|
|
@ -60,12 +60,7 @@ var MatchingBraceOutdent = function() {};
|
|||
};
|
||||
|
||||
this.$getIndent = function(line) {
|
||||
var match = line.match(/^(\s+)/);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
|
||||
return "";
|
||||
return line.match(/^\s*/)[0];
|
||||
};
|
||||
|
||||
}).call(MatchingBraceOutdent.prototype);
|
||||
|
|
|
|||
|
|
@ -42,13 +42,18 @@ var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
|||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new PerlHighlightRules().getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
this.foldingRules = new CStyleFoldMode();
|
||||
this.foldingRules = new CStyleFoldMode({start: "^=(begin|item)\\b", end: "^=(cut)\\b"});
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
|
||||
this.lineCommentStart = "#";
|
||||
this.blockComment = [
|
||||
{start: "=begin", end: "=cut"},
|
||||
{start: "=item", end: "=cut"}
|
||||
];
|
||||
|
||||
|
||||
this.getNextLineIndent = function(state, line, tab) {
|
||||
var indent = this.$getIndent(line);
|
||||
|
|
|
|||
|
|
@ -82,6 +82,10 @@ var PerlHighlightRules = function() {
|
|||
{
|
||||
token : "comment",
|
||||
regex : "#.*$"
|
||||
}, {
|
||||
token : "comment.doc",
|
||||
regex : "^=(?:begin|item)\\b",
|
||||
next : "block_comment"
|
||||
}, {
|
||||
token : "string.regexp",
|
||||
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
|
||||
|
|
@ -141,6 +145,16 @@ var PerlHighlightRules = function() {
|
|||
token : "string",
|
||||
regex : '.+'
|
||||
}
|
||||
],
|
||||
"block_comment": [
|
||||
{
|
||||
token: "comment.doc",
|
||||
regex: "^=cut\\b",
|
||||
next: "start"
|
||||
},
|
||||
{
|
||||
defaultToken: "comment.doc"
|
||||
}
|
||||
]
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ var Mode = function() {
|
|||
this.$tokenizer = new Tokenizer(new PowershellHighlightRules().getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
this.$behaviour = new CstyleBehaviour();
|
||||
this.foldingRules = new CStyleFoldMode();
|
||||
this.foldingRules = new CStyleFoldMode({start: "^\\s*(<#)", end: "^[#\\s]>\\s*$"});
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
|
|
|
|||
|
|
@ -116,12 +116,7 @@ var Mode = function() {
|
|||
};
|
||||
|
||||
this.$getIndent = function(line) {
|
||||
var match = line.match(/^(\s+)/);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
|
||||
return "";
|
||||
return line.match(/^\s*/)[0];
|
||||
};
|
||||
|
||||
this.createWorker = function(session) {
|
||||
|
|
|
|||
|
|
@ -50,22 +50,22 @@ oop.inherits(Mode, TextMode);
|
|||
(function() {
|
||||
|
||||
this.getNextLineIndent = function(state, line, tab) {
|
||||
var indent = this.$getIndent(line);
|
||||
var match = line.match(/\s*(?:then|else|return|[{\(]|<\w+>)\s*$/);
|
||||
if (match)
|
||||
indent += tab;
|
||||
var indent = this.$getIndent(line);
|
||||
var match = line.match(/\s*(?:then|else|return|[{\(]|<\w+>)\s*$/);
|
||||
if (match)
|
||||
indent += tab;
|
||||
return indent;
|
||||
};
|
||||
|
||||
this.checkOutdent = function(state, line, input) {
|
||||
if (! /^\s+$/.test(line))
|
||||
if (! /^\s+$/.test(line))
|
||||
return false;
|
||||
|
||||
return /^\s*[\}\)]/.test(input);
|
||||
};
|
||||
|
||||
this.autoOutdent = function(state, doc, row) {
|
||||
var line = doc.getLine(row);
|
||||
var line = doc.getLine(row);
|
||||
var match = line.match(/^(\s*[\}\)])/);
|
||||
|
||||
if (!match) return 0;
|
||||
|
|
@ -79,15 +79,6 @@ oop.inherits(Mode, TextMode);
|
|||
doc.replace(new Range(row, 0, row, column-1), indent);
|
||||
};
|
||||
|
||||
this.$getIndent = function(line) {
|
||||
var match = line.match(/^(\s+)/);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
||||
var i, line;
|
||||
var outdent = true;
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ var Tokenizer = function(rules) {
|
|||
matchcount = 1;
|
||||
adjustedregex = this.removeCapturingGroups(rule.regex);
|
||||
}
|
||||
if (!rule.splitRegex)
|
||||
if (!rule.splitRegex && typeof rule.token != "string")
|
||||
rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +167,34 @@ var Tokenizer = function(rules) {
|
|||
};
|
||||
|
||||
this.createSplitterRegexp = function(src, flag) {
|
||||
src = src.replace(/\(\?=([^()]|\\.|\(([^()]|\\.)*?\))*\)(?=\)*$)/, "");
|
||||
if (src.indexOf("(?=") != -1) {
|
||||
var stack = 0;
|
||||
var inChClass = false;
|
||||
var lastCapture = {};
|
||||
src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([])/g, function(
|
||||
m, esc, parenOpen, parenClose, square, index
|
||||
) {
|
||||
if (inChClass) {
|
||||
inChClass = square != "]";
|
||||
} else if (square) {
|
||||
inChClass = true;
|
||||
} else if (parenClose) {
|
||||
if (stack == lastCapture.stack)
|
||||
lastCapture.end = index+1
|
||||
stack--;
|
||||
} else if (parenOpen) {
|
||||
stack++;
|
||||
if (parenOpen.length != 1) {
|
||||
lastCapture.stack = stack
|
||||
lastCapture.start = index;
|
||||
}
|
||||
}
|
||||
return m;
|
||||
});
|
||||
|
||||
if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end)))
|
||||
src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end);
|
||||
}
|
||||
return new RegExp(src, (flag||"").replace("g", ""));
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue