Added basic powershell mode.
This commit is contained in:
parent
36caefe3a7
commit
58db794e8e
5 changed files with 166 additions and 1 deletions
11
demo/demo.js
11
demo/demo.js
|
|
@ -73,6 +73,7 @@ var TextMode = require("ace/mode/text").Mode;
|
|||
var GroovyMode = require("ace/mode/groovy").Mode;
|
||||
var ScalaMode = require("ace/mode/scala").Mode;
|
||||
var LatexMode = require("ace/mode/latex").Mode;
|
||||
var PowershellMode = require("ace/mode/powershell").Mode;
|
||||
var UndoManager = require("ace/undomanager").UndoManager;
|
||||
|
||||
var vim = require("ace/keyboard/keybinding/vim").Vim;
|
||||
|
|
@ -201,6 +202,10 @@ exports.launch = function(env) {
|
|||
docs.latex.setMode(new LatexMode());
|
||||
docs.latex.setUndoManager(new UndoManager());
|
||||
|
||||
docs.powershell = new EditSession(require("ace/requirejs/text!demo/docs/powershell.ps1"));
|
||||
docs.powershell.setMode(new PowershellMode());
|
||||
docs.powershell.setUndoManager(new UndoManager());
|
||||
|
||||
// Add a "name" property to all docs
|
||||
for (var doc in docs) {
|
||||
docs[doc].name = doc;
|
||||
|
|
@ -245,7 +250,8 @@ exports.launch = function(env) {
|
|||
csharp: new CSharpMode(),
|
||||
groovy: new GroovyMode(),
|
||||
scala: new ScalaMode(),
|
||||
latex: new LatexMode()
|
||||
latex: new LatexMode(),
|
||||
powershell: new PowershellMode()
|
||||
};
|
||||
|
||||
function getMode() {
|
||||
|
|
@ -352,6 +358,9 @@ exports.launch = function(env) {
|
|||
else if (mode instanceof LatexMode) {
|
||||
modeEl.value = "latex";
|
||||
}
|
||||
else if (mode instanceof PowershellMode) {
|
||||
modeEl.value = "powershell";
|
||||
}
|
||||
else {
|
||||
modeEl.value = "text";
|
||||
}
|
||||
|
|
|
|||
5
demo/docs/powershell.ps1
Normal file
5
demo/docs/powershell.ps1
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
# This is a simple comment
|
||||
function Hello($name) {
|
||||
Write-host "Hellot $name"
|
||||
}
|
||||
|
|
@ -46,6 +46,7 @@
|
|||
<option value="groovy">Groovy</option>
|
||||
<option value="scala">Scala</option>
|
||||
<option value="latex">LaTeX</option>
|
||||
<option value="powershell">Powershell</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
@ -78,6 +79,7 @@
|
|||
<option value="groovy">Groovy</option>
|
||||
<option value="scala">Scala</option>
|
||||
<option value="latex">LaTeX</option>
|
||||
<option value="powershell">Powershell</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
|||
56
lib/ace/mode/powershell.js
Normal file
56
lib/ace/mode/powershell.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop");
|
||||
var TextMode = require("ace/mode/text").Mode;
|
||||
var Tokenizer = require("ace/tokenizer").Tokenizer;
|
||||
var PowershellHighlightRules = require("ace/mode/powershell_highlight_rules").PowershellHighlightRules;
|
||||
var MatchingBraceOutdent = require("ace/mode/matching_brace_outdent").MatchingBraceOutdent;
|
||||
var CstyleBehaviour = require("ace/mode/behaviour/cstyle").CstyleBehaviour;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new PowershellHighlightRules().getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
this.$behaviour = new CstyleBehaviour();
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
|
||||
this.getNextLineIndent = function(state, line, tab) {
|
||||
var indent = this.$getIndent(line);
|
||||
|
||||
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
|
||||
var tokens = tokenizedLine.tokens;
|
||||
var endState = tokenizedLine.state;
|
||||
|
||||
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
||||
return indent;
|
||||
}
|
||||
|
||||
if (state == "start") {
|
||||
var match = line.match(/^.*[\{\(\[]\s*$/);
|
||||
if (match) {
|
||||
indent += tab;
|
||||
}
|
||||
}
|
||||
|
||||
return indent;
|
||||
};
|
||||
|
||||
this.checkOutdent = function(state, line, input) {
|
||||
return this.$outdent.checkOutdent(line, input);
|
||||
};
|
||||
|
||||
this.autoOutdent = function(state, doc, row) {
|
||||
this.$outdent.autoOutdent(doc, row);
|
||||
};
|
||||
|
||||
|
||||
this.createWorker = function(session) {
|
||||
return null;
|
||||
};
|
||||
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.Mode = Mode;
|
||||
});
|
||||
93
lib/ace/mode/powershell_highlight_rules.js
Normal file
93
lib/ace/mode/powershell_highlight_rules.js
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop");
|
||||
var lang = require("pilot/lang");
|
||||
var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
|
||||
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
||||
|
||||
var PowershellHighlightRules = function() {
|
||||
|
||||
var keywords = lang.arrayToMap(
|
||||
("function|if|else|elseif|switch|while|default|for|do|until|break|continue|foreach|return|filter|in|trap|throw|param|begin|process|end").split("|")
|
||||
);
|
||||
|
||||
var buildinConstants = lang.arrayToMap(
|
||||
("$Null|$True|$False").split("|")
|
||||
);
|
||||
|
||||
|
||||
// regexp must not have capturing parentheses. Use (?:) instead.
|
||||
// regexps are ordered -> the first match is used
|
||||
|
||||
this.$rules = {
|
||||
"start" : [
|
||||
{
|
||||
token : "comment",
|
||||
regex : "#.*$"
|
||||
}, {
|
||||
token : "string.regexp",
|
||||
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
|
||||
}, {
|
||||
token : "string", // single line
|
||||
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
||||
}, {
|
||||
token : "string", // single line
|
||||
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
||||
}, {
|
||||
token : "constant.numeric", // hex
|
||||
regex : "0[xX][0-9a-fA-F]+\\b"
|
||||
}, {
|
||||
token : "constant.numeric", // float
|
||||
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
||||
}, {
|
||||
token : "constant.language.boolean",
|
||||
regex : "(?:true|false)\\b"
|
||||
}, {
|
||||
token : function(value) {
|
||||
if (value == "this")
|
||||
return "variable.language";
|
||||
else if (keywords.hasOwnProperty(value))
|
||||
return "keyword";
|
||||
else if (buildinConstants.hasOwnProperty(value))
|
||||
return "constant.language";
|
||||
else
|
||||
return "identifier";
|
||||
},
|
||||
// TODO: Unicode escape sequences
|
||||
// TODO: Unicode identifiers
|
||||
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
|
||||
}, {
|
||||
token : "keyword.operator",
|
||||
regex : "eq|ne|ge|gt|lt|le|like|notlike|match|notmatch|replace"
|
||||
}, {
|
||||
token : "lparen",
|
||||
regex : "[[({]"
|
||||
}, {
|
||||
token : "rparen",
|
||||
regex : "[\\])}]"
|
||||
}, {
|
||||
token : "text",
|
||||
regex : "\\s+"
|
||||
}
|
||||
],
|
||||
"comment" : [
|
||||
{
|
||||
token : "comment", // closing comment
|
||||
regex : ".*?\\*\\/",
|
||||
next : "start"
|
||||
}, {
|
||||
token : "comment", // comment spanning whole line
|
||||
merge : true,
|
||||
regex : ".+"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
this.embedRules(DocCommentHighlightRules, "doc-",
|
||||
[ new DocCommentHighlightRules().getEndRule("start") ]);
|
||||
};
|
||||
|
||||
oop.inherits(PowershellHighlightRules, TextHighlightRules);
|
||||
|
||||
exports.PowershellHighlightRules = PowershellHighlightRules;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue