add livescript and django modes
This commit is contained in:
parent
77a02fc109
commit
5dc1d5c306
2 changed files with 365 additions and 0 deletions
117
lib/ace/mode/django.js
Normal file
117
lib/ace/mode/django.js
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/* ***** 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('ace/mode/django', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/html', 'ace/mode/text_highlight_rules', 'ace/tokenizer', 'ace/mode/html_highlight_rules'], function(require, exports, module) {
|
||||
|
||||
var oop = require("../lib/oop");
|
||||
var HtmlMode = require("./html").Mode;
|
||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||
var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
|
||||
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
||||
|
||||
var DjangoHighlightRules = function(){
|
||||
this.$rules = {
|
||||
'start': [{
|
||||
token: "string",
|
||||
regex: '".*?"'
|
||||
}, {
|
||||
token: "string",
|
||||
regex: "'.*?'"
|
||||
}, {
|
||||
token: "constant",
|
||||
regex: '[0-9]+'
|
||||
}, {
|
||||
token: "variable",
|
||||
regex: "[-_a-zA-Z0-9:]+"
|
||||
}],
|
||||
'comment': [{
|
||||
token : "comment.block",
|
||||
merge: true,
|
||||
regex : ".+?"
|
||||
}],
|
||||
'tag': [{
|
||||
token: "entity.name.function",
|
||||
regex: "[a-zA-Z][_a-zA-Z0-9]*",
|
||||
next: "start"
|
||||
}]
|
||||
};
|
||||
};
|
||||
|
||||
oop.inherits(DjangoHighlightRules, TextHighlightRules)
|
||||
|
||||
var DjangoHtmlHighlightRules = function() {
|
||||
this.$rules = new HtmlHighlightRules().getRules();
|
||||
|
||||
for (var i in this.$rules) {
|
||||
this.$rules[i].unshift({
|
||||
token: "comment.line",
|
||||
regex: "\\{#.*?#\\}"
|
||||
}, {
|
||||
token: "comment.block",
|
||||
regex: "\\{\\%\\s*comment\\s*\\%\\}",
|
||||
merge: true,
|
||||
next: "django-comment"
|
||||
}, {
|
||||
token: "constant.language",
|
||||
regex: "\\{\\{",
|
||||
next: "django-start"
|
||||
}, {
|
||||
token: "constant.language",
|
||||
regex: "\\{\\%",
|
||||
next: "django-tag"
|
||||
});
|
||||
this.embedRules(DjangoHighlightRules, "django-", [{
|
||||
token: "comment.block",
|
||||
regex: "\\{\\%\\s*endcomment\\s*\\%\\}",
|
||||
merge: true,
|
||||
next: "start"
|
||||
}, {
|
||||
token: "constant.language",
|
||||
regex: "\\%\\}",
|
||||
next: "start"
|
||||
}, {
|
||||
token: "constant.language",
|
||||
regex: "\\}\\}",
|
||||
next: "start"
|
||||
}]);
|
||||
}
|
||||
};
|
||||
|
||||
oop.inherits(DjangoHtmlHighlightRules, HtmlHighlightRules);
|
||||
|
||||
var Mode = function() {
|
||||
var highlighter = new DjangoHtmlHighlightRules();
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$embeds = highlighter.getEmbeds();
|
||||
};
|
||||
oop.inherits(Mode, HtmlMode);
|
||||
|
||||
exports.Mode = Mode;
|
||||
});
|
||||
248
lib/ace/mode/livescript.js
Normal file
248
lib/ace/mode/livescript.js
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
define('ace/mode/ls', function(require, exports, module){
|
||||
var identifier, LiveScriptMode, keywordend, stringfill;
|
||||
identifier = '(?![\\d\\s])[$\\w\\xAA-\\uFFDC](?:(?!\\s)[$\\w\\xAA-\\uFFDC]|-[A-Za-z])*';
|
||||
exports.Mode = LiveScriptMode = (function(superclass){
|
||||
var indenter, prototype = extend$((import$(LiveScriptMode, superclass).displayName = 'LiveScriptMode', LiveScriptMode), superclass).prototype, constructor = LiveScriptMode;
|
||||
function LiveScriptMode(){
|
||||
var that;
|
||||
this.$tokenizer = new (require('ace/tokenizer')).Tokenizer(LiveScriptMode.Rules);
|
||||
if (that = require('ace/mode/matching_brace_outdent')) {
|
||||
this.$outdent = new that.MatchingBraceOutdent;
|
||||
}
|
||||
}
|
||||
indenter = RegExp('(?:[({[=:]|[-~]>|\\b(?:e(?:lse|xport)|d(?:o|efault)|t(?:ry|hen)|finally|import(?:\\s*all)?|const|var|let|new|catch(?:\\s*' + identifier + ')?))\\s*$');
|
||||
prototype.getNextLineIndent = function(state, line, tab){
|
||||
var indent, tokens;
|
||||
indent = this.$getIndent(line);
|
||||
tokens = this.$tokenizer.getLineTokens(line, state).tokens;
|
||||
if (!(tokens.length && tokens[tokens.length - 1].type === 'comment')) {
|
||||
if (state === 'start' && indenter.test(line)) {
|
||||
indent += tab;
|
||||
}
|
||||
}
|
||||
return indent;
|
||||
};
|
||||
prototype.toggleCommentLines = function(state, doc, startRow, endRow){
|
||||
var comment, range, i$, i, out, line;
|
||||
comment = /^(\s*)#/;
|
||||
range = new (require('ace/range')).Range(0, 0, 0, 0);
|
||||
for (i$ = startRow; i$ <= endRow; ++i$) {
|
||||
i = i$;
|
||||
if (out = comment.test(line = doc.getLine(i))) {
|
||||
line = line.replace(comment, '$1');
|
||||
} else {
|
||||
line = line.replace(/^\s*/, '$&#');
|
||||
}
|
||||
range.end.row = range.start.row = i;
|
||||
range.end.column = line.length + 1;
|
||||
doc.replace(range, line);
|
||||
}
|
||||
return 1 - out * 2;
|
||||
};
|
||||
prototype.checkOutdent = function(state, line, input){
|
||||
var ref$;
|
||||
return (ref$ = this.$outdent) != null ? ref$.checkOutdent(line, input) : void 8;
|
||||
};
|
||||
prototype.autoOutdent = function(state, doc, row){
|
||||
var ref$;
|
||||
return (ref$ = this.$outdent) != null ? ref$.autoOutdent(doc, row) : void 8;
|
||||
};
|
||||
return LiveScriptMode;
|
||||
}(require('ace/mode/text').Mode));
|
||||
keywordend = '(?![$\\w]|-[A-Za-z]|\\s*:(?![:=]))';
|
||||
stringfill = {
|
||||
token: 'string',
|
||||
regex: '.+'
|
||||
};
|
||||
LiveScriptMode.Rules = {
|
||||
start: [
|
||||
{
|
||||
token: 'keyword',
|
||||
regex: '(?:t(?:h(?:is|row|en)|ry|ypeof!?)|c(?:on(?:tinue|st)|a(?:se|tch)|lass)|i(?:n(?:stanceof)?|mp(?:ort(?:\\s+all)?|lements)|[fs])|d(?:e(?:fault|lete|bugger)|o)|f(?:or(?:\\s+own)?|inally|unction)|s(?:uper|witch)|e(?:lse|x(?:tends|port)|val)|a(?:nd|rguments)|n(?:ew|ot)|un(?:less|til)|w(?:hile|ith)|o[fr]|return|break|let|var|loop)' + keywordend
|
||||
}, {
|
||||
token: 'constant.language',
|
||||
regex: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend
|
||||
}, {
|
||||
token: 'invalid.illegal',
|
||||
regex: '(?:p(?:ackage|r(?:ivate|otected)|ublic)|i(?:mplements|nterface)|enum|static|yield)' + keywordend
|
||||
}, {
|
||||
token: 'language.support.class',
|
||||
regex: '(?:R(?:e(?:gExp|ferenceError)|angeError)|S(?:tring|yntaxError)|E(?:rror|valError)|Array|Boolean|Date|Function|Number|Object|TypeError|URIError)' + keywordend
|
||||
}, {
|
||||
token: 'language.support.function',
|
||||
regex: '(?:is(?:NaN|Finite)|parse(?:Int|Float)|Math|JSON|(?:en|de)codeURI(?:Component)?)' + keywordend
|
||||
}, {
|
||||
token: 'variable.language',
|
||||
regex: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend
|
||||
}, {
|
||||
token: 'identifier',
|
||||
regex: identifier + '\\s*:(?![:=])'
|
||||
}, {
|
||||
token: 'variable',
|
||||
regex: identifier
|
||||
}, {
|
||||
token: 'keyword.operator',
|
||||
regex: '(?:\\.{3}|\\s+\\?)'
|
||||
}, {
|
||||
token: 'keyword.variable',
|
||||
regex: '(?:@+|::|\\.\\.)',
|
||||
next: 'key'
|
||||
}, {
|
||||
token: 'keyword.operator',
|
||||
regex: '\\.\\s*',
|
||||
next: 'key'
|
||||
}, {
|
||||
token: 'string',
|
||||
regex: '\\\\\\S[^\\s,;)}\\]]*'
|
||||
}, {
|
||||
token: 'string.doc',
|
||||
regex: '\'\'\'',
|
||||
next: 'qdoc'
|
||||
}, {
|
||||
token: 'string.doc',
|
||||
regex: '"""',
|
||||
next: 'qqdoc'
|
||||
}, {
|
||||
token: 'string',
|
||||
regex: '\'',
|
||||
next: 'qstring'
|
||||
}, {
|
||||
token: 'string',
|
||||
regex: '"',
|
||||
next: 'qqstring'
|
||||
}, {
|
||||
token: 'string',
|
||||
regex: '`',
|
||||
next: 'js'
|
||||
}, {
|
||||
token: 'string',
|
||||
regex: '<\\[',
|
||||
next: 'words'
|
||||
}, {
|
||||
token: 'string.regex',
|
||||
regex: '//',
|
||||
next: 'heregex'
|
||||
}, {
|
||||
token: 'comment.doc',
|
||||
regex: '/\\*',
|
||||
next: 'comment'
|
||||
}, {
|
||||
token: 'comment',
|
||||
regex: '#.*'
|
||||
}, {
|
||||
token: 'string.regex',
|
||||
regex: '\\/(?:[^[\\/\\n\\\\]*(?:(?:\\\\.|\\[[^\\]\\n\\\\]*(?:\\\\.[^\\]\\n\\\\]*)*\\])[^[\\/\\n\\\\]*)*)\\/[gimy$]{0,4}',
|
||||
next: 'key'
|
||||
}, {
|
||||
token: 'constant.numeric',
|
||||
regex: '(?:0x[\\da-fA-F][\\da-fA-F_]*|(?:[2-9]|[12]\\d|3[0-6])r[\\da-zA-Z][\\da-zA-Z_]*|(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*)(?:e[+-]?\\d[\\d_]*)?[\\w$]*)'
|
||||
}, {
|
||||
token: 'lparen',
|
||||
regex: '[({[]'
|
||||
}, {
|
||||
token: 'rparen',
|
||||
regex: '[)}\\]]',
|
||||
next: 'key'
|
||||
}, {
|
||||
token: 'keyword.operator',
|
||||
regex: '\\S+'
|
||||
}, {
|
||||
token: 'text',
|
||||
regex: '\\s+'
|
||||
}
|
||||
],
|
||||
heregex: [
|
||||
{
|
||||
token: 'string.regex',
|
||||
regex: '.*?//[gimy$?]{0,4}',
|
||||
next: 'start'
|
||||
}, {
|
||||
token: 'string.regex',
|
||||
regex: '\\s*#{'
|
||||
}, {
|
||||
token: 'comment.regex',
|
||||
regex: '\\s+(?:#.*)?'
|
||||
}, {
|
||||
token: 'string.regex',
|
||||
regex: '\\S+'
|
||||
}
|
||||
],
|
||||
key: [
|
||||
{
|
||||
token: 'keyword.operator',
|
||||
regex: '[.?@!]+'
|
||||
}, {
|
||||
token: 'identifier',
|
||||
regex: identifier,
|
||||
next: 'start'
|
||||
}, {
|
||||
token: 'text',
|
||||
regex: '.',
|
||||
next: 'start'
|
||||
}
|
||||
],
|
||||
comment: [
|
||||
{
|
||||
token: 'comment.doc',
|
||||
regex: '.*?\\*/',
|
||||
next: 'start'
|
||||
}, {
|
||||
token: 'comment.doc',
|
||||
regex: '.+'
|
||||
}
|
||||
],
|
||||
qdoc: [
|
||||
{
|
||||
token: 'string',
|
||||
regex: ".*?'''",
|
||||
next: 'key'
|
||||
}, stringfill
|
||||
],
|
||||
qqdoc: [
|
||||
{
|
||||
token: 'string',
|
||||
regex: '.*?"""',
|
||||
next: 'key'
|
||||
}, stringfill
|
||||
],
|
||||
qstring: [
|
||||
{
|
||||
token: 'string',
|
||||
regex: '[^\\\\\']*(?:\\\\.[^\\\\\']*)*\'',
|
||||
next: 'key'
|
||||
}, stringfill
|
||||
],
|
||||
qqstring: [
|
||||
{
|
||||
token: 'string',
|
||||
regex: '[^\\\\"]*(?:\\\\.[^\\\\"]*)*"',
|
||||
next: 'key'
|
||||
}, stringfill
|
||||
],
|
||||
js: [
|
||||
{
|
||||
token: 'string',
|
||||
regex: '[^\\\\`]*(?:\\\\.[^\\\\`]*)*`',
|
||||
next: 'key'
|
||||
}, stringfill
|
||||
],
|
||||
words: [
|
||||
{
|
||||
token: 'string',
|
||||
regex: '.*?\\]>',
|
||||
next: 'key'
|
||||
}, stringfill
|
||||
]
|
||||
};
|
||||
function extend$(sub, sup){
|
||||
function fun(){} fun.prototype = (sub.superclass = sup).prototype;
|
||||
(sub.prototype = new fun).constructor = sub;
|
||||
if (typeof sup.extended == 'function') sup.extended(sub);
|
||||
return sub;
|
||||
}
|
||||
function import$(obj, src){
|
||||
var own = {}.hasOwnProperty;
|
||||
for (var key in src) if (own.call(src, key)) obj[key] = src[key];
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue