extract doc comments into a separate mode
This commit is contained in:
parent
10e35ef507
commit
1a4f0cd054
12 changed files with 101 additions and 85 deletions
|
|
@ -42,7 +42,9 @@
|
||||||
|
|
||||||
<script src="../src/ace/ace.js" type="text/javascript" charset="utf-8"></script>
|
<script src="../src/ace/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="../src/ace/mode/Text.js" type="text/javascript" charset="utf-8"></script>
|
<script src="../src/ace/mode/Text.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
<script src="../src/ace/mode/TextHighlightRules.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="../src/ace/mode/JavaScript.js" type="text/javascript" charset="utf-8"></script>
|
<script src="../src/ace/mode/JavaScript.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
<script src="../src/ace/mode/DocCommentHighlightRules.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="../src/ace/mode/JavaScriptHighlightRules.js" type="text/javascript" charset="utf-8"></script>
|
<script src="../src/ace/mode/JavaScriptHighlightRules.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="../src/ace/mode/Html.js" type="text/javascript" charset="utf-8"></script>
|
<script src="../src/ace/mode/Html.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="../src/ace/mode/HtmlHighlightRules.js" type="text/javascript" charset="utf-8"></script>
|
<script src="../src/ace/mode/HtmlHighlightRules.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ load:
|
||||||
- src/ace/ace.js
|
- src/ace/ace.js
|
||||||
- src/ace/MEventEmitter.js
|
- src/ace/MEventEmitter.js
|
||||||
- src/ace/mode/Text.js
|
- src/ace/mode/Text.js
|
||||||
|
- src/ace/mode/TextHighlightRules.js
|
||||||
- src/ace/mode/*.js
|
- src/ace/mode/*.js
|
||||||
- src/ace/layer/*.js
|
- src/ace/layer/*.js
|
||||||
- src/ace/*.js
|
- src/ace/*.js
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,6 @@ ace.Document = function(text, mode) {
|
||||||
|
|
||||||
this.$detectNewLine = function(text) {
|
this.$detectNewLine = function(text) {
|
||||||
var match = text.match(/^.*?(\r?\n)/m);
|
var match = text.match(/^.*?(\r?\n)/m);
|
||||||
console.log(match);
|
|
||||||
if (match) {
|
if (match) {
|
||||||
this.$autoNewLine = match[1];
|
this.$autoNewLine = match[1];
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -175,10 +175,4 @@ ace.mode.CssHighlightRules = function() {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
(function() {
|
ace.inherits(ace.mode.CssHighlightRules, ace.mode.TextHighlightRules);
|
||||||
|
|
||||||
this.getRules = function() {
|
|
||||||
return this.$rules;
|
|
||||||
};
|
|
||||||
|
|
||||||
}).call(ace.mode.CssHighlightRules.prototype);
|
|
||||||
38
src/ace/mode/DocCommentHighlightRules.js
Normal file
38
src/ace/mode/DocCommentHighlightRules.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
ace.provide("ace.mode.DocCommentHighlightRules");
|
||||||
|
|
||||||
|
ace.mode.DocCommentHighlightRules = function() {
|
||||||
|
|
||||||
|
this.$rules = {
|
||||||
|
"start" : [ {
|
||||||
|
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 : "."
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.inherits(ace.mode.DocCommentHighlightRules, ace.mode.TextHighlightRules);
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
this.getStartRule = function(start) {
|
||||||
|
return {
|
||||||
|
token : "doc-comment", // doc comment
|
||||||
|
regex : "\\/\\*\\*",
|
||||||
|
next: start
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
}).call(ace.mode.DocCommentHighlightRules.prototype);
|
||||||
|
|
@ -114,7 +114,7 @@ ace.mode.HtmlHighlightRules = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
var jsRules = new ace.mode.JavaScriptHighlightRules().getRules();
|
var jsRules = new ace.mode.JavaScriptHighlightRules().getRules();
|
||||||
this.$addRules(jsRules, "js-");
|
this.addRules(jsRules, "js-");
|
||||||
this.$rules["js-start"].unshift({
|
this.$rules["js-start"].unshift({
|
||||||
token: "text",
|
token: "text",
|
||||||
regex: "<\\/(?=script)",
|
regex: "<\\/(?=script)",
|
||||||
|
|
@ -122,31 +122,11 @@ ace.mode.HtmlHighlightRules = function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
var cssRules = new ace.mode.CssHighlightRules().getRules();
|
var cssRules = new ace.mode.CssHighlightRules().getRules();
|
||||||
this.$addRules(cssRules, "css-");
|
this.addRules(cssRules, "css-");
|
||||||
this.$rules["css-start"].unshift({
|
this.$rules["css-start"].unshift({
|
||||||
token: "text",
|
token: "text",
|
||||||
regex: "<\\/(?=style)",
|
regex: "<\\/(?=style)",
|
||||||
next: "tag"
|
next: "tag"
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
ace.inherits(ace.mode.HtmlHighlightRules, ace.mode.TextHighlightRules);
|
||||||
(function() {
|
|
||||||
|
|
||||||
this.$addRules = function(rules, prefix) {
|
|
||||||
for (var key in rules) {
|
|
||||||
var state = rules[key];
|
|
||||||
for (var i=0; i<state.length; i++) {
|
|
||||||
var rule = state[i];
|
|
||||||
if (rule.next) {
|
|
||||||
rule.next = prefix + rule.next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.$rules[prefix + key] = state;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getRules = function() {
|
|
||||||
return this.$rules;
|
|
||||||
};
|
|
||||||
|
|
||||||
}).call(ace.mode.HtmlHighlightRules.prototype);
|
|
||||||
|
|
@ -31,7 +31,7 @@ ace.inherits(ace.mode.JavaScript, ace.mode.Text);
|
||||||
if (match) {
|
if (match) {
|
||||||
indent += tab;
|
indent += tab;
|
||||||
}
|
}
|
||||||
} else if (state == "doc-comment") {
|
} else if (state == "doc-start") {
|
||||||
if (endState == "start") {
|
if (endState == "start") {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ ace.provide("ace.mode.JavaScriptHighlightRules");
|
||||||
|
|
||||||
ace.mode.JavaScriptHighlightRules = function() {
|
ace.mode.JavaScriptHighlightRules = function() {
|
||||||
|
|
||||||
|
var docComment = new ace.mode.DocCommentHighlightRules();
|
||||||
|
|
||||||
var keywords = {
|
var keywords = {
|
||||||
"break" : 1,
|
"break" : 1,
|
||||||
"case" : 1,
|
"case" : 1,
|
||||||
|
|
@ -30,16 +32,13 @@ ace.mode.JavaScriptHighlightRules = function() {
|
||||||
|
|
||||||
// regexp must not have capturing parentheses. Use (?:) instead.
|
// regexp must not have capturing parentheses. Use (?:) instead.
|
||||||
// regexps are ordered -> the first match is used
|
// regexps are ordered -> the first match is used
|
||||||
|
|
||||||
this.$rules = {
|
this.$rules = {
|
||||||
"start" : [ {
|
"start" : [ {
|
||||||
token : "comment",
|
token : "comment",
|
||||||
regex : "\\/\\/.*$"
|
regex : "\\/\\/.*$"
|
||||||
}, {
|
},
|
||||||
token : "doc-comment", // doc comment
|
docComment.getStartRule("doc-start"),
|
||||||
regex : "\\/\\*\\*",
|
{
|
||||||
next : "doc-comment"
|
|
||||||
}, {
|
|
||||||
token : "comment", // multi line comment
|
token : "comment", // multi line comment
|
||||||
regex : "\\/\\*",
|
regex : "\\/\\*",
|
||||||
next : "comment"
|
next : "comment"
|
||||||
|
|
@ -83,23 +82,6 @@ ace.mode.JavaScriptHighlightRules = function() {
|
||||||
token : "text",
|
token : "text",
|
||||||
regex : "\\s+"
|
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" : [ {
|
"comment" : [ {
|
||||||
token : "comment", // closing comment
|
token : "comment", // closing comment
|
||||||
regex : ".*?\\*\\/",
|
regex : ".*?\\*\\/",
|
||||||
|
|
@ -125,12 +107,8 @@ ace.mode.JavaScriptHighlightRules = function() {
|
||||||
regex : '.+'
|
regex : '.+'
|
||||||
} ]
|
} ]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.addRules(docComment.getRules(), "doc-");
|
||||||
|
this.$rules["doc-start"][0].next = "start";
|
||||||
};
|
};
|
||||||
|
ace.inherits(ace.mode.JavaScriptHighlightRules, ace.mode.TextHighlightRules);
|
||||||
(function() {
|
|
||||||
|
|
||||||
this.getRules = function() {
|
|
||||||
return this.$rules;
|
|
||||||
};
|
|
||||||
|
|
||||||
}).call(ace.mode.JavaScriptHighlightRules.prototype);
|
|
||||||
|
|
@ -1,13 +1,7 @@
|
||||||
ace.provide("ace.mode.Text");
|
ace.provide("ace.mode.Text");
|
||||||
|
|
||||||
ace.mode.Text = function() {
|
ace.mode.Text = function() {
|
||||||
var rules = {
|
this.$tokenizer = new ace.Tokenizer(new ace.mode.TextHighlightRules().getRules());
|
||||||
"start" : [ {
|
|
||||||
token : "text",
|
|
||||||
regex : ".+"
|
|
||||||
} ]
|
|
||||||
};
|
|
||||||
this.$tokenizer = new ace.Tokenizer(rules);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
|
||||||
37
src/ace/mode/TextHighlightRules.js
Normal file
37
src/ace/mode/TextHighlightRules.js
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
ace.provide("ace.mode.TextHighlightRules");
|
||||||
|
|
||||||
|
ace.mode.TextHighlightRules = function() {
|
||||||
|
|
||||||
|
// regexp must not have capturing parentheses
|
||||||
|
// regexps are ordered -> the first match is used
|
||||||
|
|
||||||
|
this.$rules = {
|
||||||
|
"start" : [ {
|
||||||
|
token : "text",
|
||||||
|
regex : ".+"
|
||||||
|
} ]
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
this.addRules = function(rules, prefix) {
|
||||||
|
for (var key in rules) {
|
||||||
|
var state = rules[key];
|
||||||
|
for (var i=0; i<state.length; i++) {
|
||||||
|
var rule = state[i];
|
||||||
|
if (rule.next) {
|
||||||
|
rule.next = prefix + rule.next;
|
||||||
|
} else {
|
||||||
|
rule.next = prefix + key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.$rules[prefix + key] = state;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getRules = function() {
|
||||||
|
return this.$rules;
|
||||||
|
};
|
||||||
|
|
||||||
|
}).call(ace.mode.TextHighlightRules.prototype);
|
||||||
|
|
@ -69,11 +69,4 @@ ace.mode.XmlHighlightRules = function() {
|
||||||
} ]
|
} ]
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
ace.inherits(ace.mode.XmlHighlightRules, ace.mode.TextHighlightRules);
|
||||||
(function() {
|
|
||||||
|
|
||||||
this.getRules = function() {
|
|
||||||
return this.$rules;
|
|
||||||
};
|
|
||||||
|
|
||||||
}).call(ace.mode.XmlHighlightRules.prototype);
|
|
||||||
|
|
@ -69,15 +69,15 @@ var JavaScriptTest = new TestCase("mode.JavaScriptTest", {
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: special indent in doc comments" : function() {
|
"test: special indent in doc comments" : function() {
|
||||||
assertEquals(" * ", this.mode.getNextLineIndent("/**", "doc-comment", " "));
|
assertEquals(" * ", this.mode.getNextLineIndent("/**", "doc-start", " "));
|
||||||
assertEquals(" * ", this.mode.getNextLineIndent(" /**", "doc-comment", " "));
|
assertEquals(" * ", this.mode.getNextLineIndent(" /**", "doc-start", " "));
|
||||||
assertEquals(" * ", this.mode.getNextLineIndent(" *", "doc-comment", " "));
|
assertEquals(" * ", this.mode.getNextLineIndent(" *", "doc-start", " "));
|
||||||
assertEquals(" * ", this.mode.getNextLineIndent(" *", "doc-comment", " "));
|
assertEquals(" * ", this.mode.getNextLineIndent(" *", "doc-start", " "));
|
||||||
assertEquals(" ", this.mode.getNextLineIndent(" abc", "doc-comment", " "));
|
assertEquals(" ", this.mode.getNextLineIndent(" abc", "doc-start", " "));
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: no indent after doc comments" : function() {
|
"test: no indent after doc comments" : function() {
|
||||||
assertEquals("", this.mode.getNextLineIndent(" */", "doc-comment", " "));
|
assertEquals("", this.mode.getNextLineIndent(" */", "doc-start", " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
// "test: outdent if first non WS character in line is a closing brace" : function() {
|
// "test: outdent if first non WS character in line is a closing brace" : function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue