Add support for doc doc comments:

- special highlighting
- highlight jsdoc tags
- special auto indent mode
This commit is contained in:
Fabian Jakobs 2010-04-16 12:08:03 +02:00
commit 257d80f379
7 changed files with 103 additions and 43 deletions

View file

@ -188,7 +188,7 @@ ace.KeyBinding = function(element, editor) {
case keys.TAB:
if (e.shiftKey) {
editor.blockOutdent();
} else if (selection.isMultiLineSelection()) {
} else if (selection.isMultiLine()) {
editor.blockIndent();
} else {
editor.onTextInput("\t");

View file

@ -27,11 +27,14 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
var lastIndex = 0;
var token = {
type: null,
value: ""
};
while (match = re.exec(line)) {
var token = {
type : "text",
value : match[0]
};
var type = "text";
var value = match[0];
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error"); }
lastIndex = re.lastIndex;
@ -41,10 +44,10 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
for ( var i = 0; i < state.length; i++) {
if (match[i + 1]) {
if (typeof state[i].token == "function") {
token.type = state[i].token(match[0]);
type = state[i].token(match[0]);
}
else {
token.type = state[i].token;
type = state[i].token;
}
if (state[i].next && state[i].next !== currentState) {
@ -59,9 +62,23 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
}
};
tokens.push(token);
if (token.type !== type) {
if (token.type) {
tokens.push(token);
}
token = {
type: type,
value: value
};
} else {
token.value += value;
}
};
if (token.type) {
tokens.push(token);
}
// window.LOG && console.log(tokens, currentState);
return {

View file

@ -13,18 +13,23 @@ ace.mode.JavaScript.prototype.toggleCommentLines = function(doc, range) {
return addedRows;
};
ace.mode.JavaScript.prototype.increaseIndentPatterns = {
"start" : /^(\s*).*[\{\(\[]\s*$/
};
ace.mode.JavaScript.prototype.getNextLineIndent = function(line, state, tab) {
var re = this.increaseIndentPatterns[state];
if (re) {
if (state == "start") {
var re = /^(\s*).*[\{\(\[]\s*$/;
var match = line.match(re);
if (match) {
return (match[1] || "") + tab;
}
} else if (state == "doc-comment") {
var re = /^(\s*)(\/?)\*.*$/;
var match = line.match(re);
if (match) {
var indent = match[1];
if (match[2]) {
indent += " ";
}
return indent + "* ";
}
}
var match = line.match(/^(\s+).*$/);

View file

@ -32,15 +32,16 @@ ace.mode.JavaScriptHighlightRules = function() {
// regexps are ordered -> the first match is used
this._rules = {
start : [ {
"start" : [ {
token : "comment",
regex : "\\/\\/.*$"
}, {
token : "comment", // multi line comment in one line
regex : "\\/\\*.*?\\*\\/"
token : "doc-comment", // doc comment
regex : "\\/\\*\\*",
next : "doc-comment"
}, {
token : "comment", // multi line comment start
regex : "\\/\\*.*$",
token : "comment", // multi line comment
regex : "\\/\\*",
next : "comment"
}, {
token : "string", // single line
@ -82,6 +83,23 @@ ace.mode.JavaScriptHighlightRules = function() {
token : "text",
regex : "\\s+"
} ],
"doc-comment" : [ {
token : "doc-comment", // closing comment
regex : "\\*\\/",
next : "start"
}, {
token : "doc-comment-tag",
regex : "@[\\w\\d_]+"
}, {
token : "doc-comment",
regex : "\s+"
}, {
token : "doc-comment",
regex : "[^@\\*]+"
}, {
token : "doc-comment",
regex : "."
}],
"comment" : [ {
token : "comment", // closing comment
regex : ".*?\\*\\/",