1
/* ***** BEGIN LICENSE BLOCK *****
2
* Distributed under the BSD license:
4
* Copyright (c) 2010, Ajax.org B.V.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* * Neither the name of Ajax.org B.V. nor the
15
* names of its contributors may be used to endorse or promote products
16
* derived from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
* ***** END LICENSE BLOCK ***** */
31
ace.define('ace/mode/sh', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/sh_highlight_rules', 'ace/range'], function(require, exports, module) {
34
var oop = require("../lib/oop");
35
var TextMode = require("./text").Mode;
36
var Tokenizer = require("../tokenizer").Tokenizer;
37
var ShHighlightRules = require("./sh_highlight_rules").ShHighlightRules;
38
var Range = require("../range").Range;
40
var Mode = function() {
41
var highlighter = new ShHighlightRules();
43
this.$tokenizer = new Tokenizer(highlighter.getRules());
44
this.$keywordList = highlighter.$keywordList;
46
oop.inherits(Mode, TextMode);
51
this.lineCommentStart = "#";
53
this.getNextLineIndent = function(state, line, tab) {
54
var indent = this.$getIndent(line);
56
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
57
var tokens = tokenizedLine.tokens;
59
if (tokens.length && tokens[tokens.length-1].type == "comment") {
63
if (state == "start") {
64
var match = line.match(/^.*[\{\(\[\:]\s*$/);
81
this.checkOutdent = function(state, line, input) {
82
if (input !== "\r\n" && input !== "\r" && input !== "\n")
85
var tokens = this.$tokenizer.getLineTokens(line.trim(), state).tokens;
90
var last = tokens.pop();
91
} while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/))));
96
return (last.type == "keyword" && outdents[last.value]);
99
this.autoOutdent = function(state, doc, row) {
102
var indent = this.$getIndent(doc.getLine(row));
103
var tab = doc.getTabString();
104
if (indent.slice(-tab.length) == tab)
105
doc.remove(new Range(row, indent.length-tab.length, row, indent.length));
108
}).call(Mode.prototype);
113
ace.define('ace/mode/sh_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
116
var oop = require("../lib/oop");
117
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
119
var reservedKeywords = exports.reservedKeywords = (
120
'!|{|}|case|do|done|elif|else|'+
121
'esac|fi|for|if|in|then|until|while|'+
122
'&|;|export|local|read|typeset|unset|'+
126
var languageConstructs = exports.languageConstructs = (
127
'[|]|alias|bg|bind|break|builtin|'+
128
'cd|command|compgen|complete|continue|'+
129
'dirs|disown|echo|enable|eval|exec|'+
130
'exit|fc|fg|getopts|hash|help|history|'+
131
'jobs|kill|let|logout|popd|printf|pushd|'+
132
'pwd|return|set|shift|shopt|source|'+
133
'suspend|test|times|trap|type|ulimit|'+
137
var ShHighlightRules = function() {
138
var keywordMapper = this.createKeywordMapper({
139
"keyword": reservedKeywords,
140
"support.function.builtin": languageConstructs,
141
"invalid.deprecated": "debugger"
144
var integer = "(?:(?:[1-9]\\d*)|(?:0))";
146
var fraction = "(?:\\.\\d+)";
147
var intPart = "(?:\\d+)";
148
var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))";
149
var exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + ")";
150
var floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")";
151
var fileDescriptor = "(?:&" + intPart + ")";
153
var variableName = "[a-zA-Z][a-zA-Z0-9_]*";
154
var variable = "(?:(?:\\$" + variableName + ")|(?:" + variableName + "=))";
156
var builtinVariable = "(?:\\$(?:SHLVL|\\$|\\!|\\?))";
158
var func = "(?:" + variableName + "\\s*\\(\\))";
165
token : ["text", "comment"],
166
regex : /(^|\s)(#.*)$/
171
token : "constant.language.escape",
172
regex : /\\(?:[$abeEfnrtv\\'"]|x[a-fA-F\d]{1,2}|u[a-fA-F\d]{4}([a-fA-F\d]{4})?|c.|\d{1,3})/
181
defaultToken: "string"
184
token : "variable.language",
185
regex : builtinVariable
190
token : "support.function",
193
token : "support.function",
194
regex : fileDescriptor
196
token : "string", // ' string
197
start : "'", end : "'"
199
token : "constant.numeric", // float
202
token : "constant.numeric", // integer
203
regex : integer + "\\b"
205
token : keywordMapper,
206
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
208
token : "keyword.operator",
209
regex : "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|~|<|>|<=|=>|=|!="
211
token : "paren.lparen",
212
regex : "[\\[\\(\\{]"
214
token : "paren.rparen",
215
regex : "[\\]\\)\\}]"
219
this.normalizeRules();
222
oop.inherits(ShHighlightRules, TextHighlightRules);
224
exports.ShHighlightRules = ShHighlightRules;