add highlighting and folding for POD documentation

This commit is contained in:
nightwing 2013-03-06 20:31:24 +04:00
commit 5d6bc3a75d
6 changed files with 49 additions and 3 deletions

View file

@ -1,4 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
=begin
perl example code for Ace
=cut
use strict; use strict;
use warnings; use warnings;
my $num_primes = 0; my $num_primes = 0;
@ -30,3 +34,4 @@ for my $p (0 .. ($num_primes-1))
print $primes[$p], ", "; print $primes[$p], ", ";
} }
print "\n"; print "\n";

View file

@ -1,6 +1,17 @@
[[ [[
"start", "start",
["comment","#!/usr/bin/perl"] ["comment","#!/usr/bin/perl"]
],[
"block_comment",
["comment.doc","=begin"]
],[
"block_comment",
["comment.doc"," perl example code for Ace"]
],[
"start",
["comment.doc","=cut"]
],[
"start"
],[ ],[
"start", "start",
["keyword","use"], ["keyword","use"],
@ -211,4 +222,6 @@
["text",";"] ["text",";"]
],[ ],[
"start" "start"
],[
"start"
]] ]]

View file

@ -35,7 +35,16 @@ var oop = require("../../lib/oop");
var Range = require("../../range").Range; var Range = require("../../range").Range;
var BaseFoldMode = require("./fold_mode").FoldMode; 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); oop.inherits(FoldMode, BaseFoldMode);
(function() { (function() {

View file

@ -42,13 +42,18 @@ var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() { var Mode = function() {
this.$tokenizer = new Tokenizer(new PerlHighlightRules().getRules()); this.$tokenizer = new Tokenizer(new PerlHighlightRules().getRules());
this.$outdent = new MatchingBraceOutdent(); this.$outdent = new MatchingBraceOutdent();
this.foldingRules = new CStyleFoldMode(); this.foldingRules = new CStyleFoldMode({start: "^=(begin|item)\\b", end: "^=(cut)\\b"});
}; };
oop.inherits(Mode, TextMode); oop.inherits(Mode, TextMode);
(function() { (function() {
this.lineCommentStart = "#"; this.lineCommentStart = "#";
this.blockComment = [
{start: "=begin", end: "=cut"},
{start: "=item", end: "=cut"}
];
this.getNextLineIndent = function(state, line, tab) { this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line); var indent = this.$getIndent(line);

View file

@ -82,6 +82,10 @@ var PerlHighlightRules = function() {
{ {
token : "comment", token : "comment",
regex : "#.*$" regex : "#.*$"
}, {
token : "comment.doc",
regex : "^=(?:begin|item)\\b",
next : "block_comment"
}, { }, {
token : "string.regexp", token : "string.regexp",
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)" regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
@ -141,6 +145,16 @@ var PerlHighlightRules = function() {
token : "string", token : "string",
regex : '.+' regex : '.+'
} }
],
"block_comment": [
{
token: "comment.doc",
regex: "^=cut\\b",
next: "start"
},
{
defaultToken: "comment.doc"
}
] ]
}; };
}; };

View file

@ -13,7 +13,7 @@ var Mode = function() {
this.$tokenizer = new Tokenizer(new PowershellHighlightRules().getRules()); this.$tokenizer = new Tokenizer(new PowershellHighlightRules().getRules());
this.$outdent = new MatchingBraceOutdent(); this.$outdent = new MatchingBraceOutdent();
this.$behaviour = new CstyleBehaviour(); this.$behaviour = new CstyleBehaviour();
this.foldingRules = new CStyleFoldMode(); this.foldingRules = new CStyleFoldMode({start: "^\\s*(<#)", end: "^[#\\s]>\\s*$"});
}; };
oop.inherits(Mode, TextMode); oop.inherits(Mode, TextMode);