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
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
this.$tokenizer = new Tokenizer(new ShHighlightRules().getRules());
43
oop.inherits(Mode, TextMode);
48
this.lineCommentStart = "#";
50
this.getNextLineIndent = function(state, line, tab) {
51
var indent = this.$getIndent(line);
53
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
54
var tokens = tokenizedLine.tokens;
56
if (tokens.length && tokens[tokens.length-1].type == "comment") {
60
if (state == "start") {
61
var match = line.match(/^.*[\{\(\[\:]\s*$/);
78
this.checkOutdent = function(state, line, input) {
79
if (input !== "\r\n" && input !== "\r" && input !== "\n")
82
var tokens = this.$tokenizer.getLineTokens(line.trim(), state).tokens;
87
var last = tokens.pop();
88
} while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/))));
93
return (last.type == "keyword" && outdents[last.value]);
96
this.autoOutdent = function(state, doc, row) {
99
var indent = this.$getIndent(doc.getLine(row));
100
var tab = doc.getTabString();
101
if (indent.slice(-tab.length) == tab)
102
doc.remove(new Range(row, indent.length-tab.length, row, indent.length));
105
}).call(Mode.prototype);
110
define('ace/mode/sh_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
113
var oop = require("../lib/oop");
114
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
116
var reservedKeywords = exports.reservedKeywords = (
117
'!|{|}|case|do|done|elif|else|'+
118
'esac|fi|for|if|in|then|until|while|'+
119
'&|;|export|local|read|typeset|unset|'+
123
var languageConstructs = exports.languageConstructs = (
124
'[|]|alias|bg|bind|break|builtin|'+
125
'cd|command|compgen|complete|continue|'+
126
'dirs|disown|echo|enable|eval|exec|'+
127
'exit|fc|fg|getopts|hash|help|history|'+
128
'jobs|kill|let|logout|popd|printf|pushd|'+
129
'pwd|return|set|shift|shopt|source|'+
130
'suspend|test|times|trap|type|ulimit|'+
134
var ShHighlightRules = function() {
135
var keywordMapper = this.createKeywordMapper({
136
"keyword": reservedKeywords,
137
"support.function.builtin": languageConstructs,
138
"invalid.deprecated": "debugger"
141
var integer = "(?:(?:[1-9]\\d*)|(?:0))";
143
var fraction = "(?:\\.\\d+)";
144
var intPart = "(?:\\d+)";
145
var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))";
146
var exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + ")";
147
var floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")";
148
var fileDescriptor = "(?:&" + intPart + ")";
150
var variableName = "[a-zA-Z][a-zA-Z0-9_]*";
151
var variable = "(?:(?:\\$" + variableName + ")|(?:" + variableName + "=))";
153
var builtinVariable = "(?:\\$(?:SHLVL|\\$|\\!|\\?))";
155
var func = "(?:" + variableName + "\\s*\\(\\))";
159
token : ["text", "comment"],
160
regex : /(^|\s)(#.*)$/
162
token : "string", // " string
163
regex : '"(?:[^\\\\]|\\\\.)*?"'
165
token : "variable.language",
166
regex : builtinVariable
171
token : "support.function",
174
token : "support.function",
175
regex : fileDescriptor
177
token : "string", // ' string
178
regex : "'(?:[^\\\\]|\\\\.)*?'"
180
token : "constant.numeric", // float
183
token : "constant.numeric", // integer
184
regex : integer + "\\b"
186
token : keywordMapper,
187
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
189
token : "keyword.operator",
190
regex : "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|~|<|>|<=|=>|=|!="
192
token : "paren.lparen",
193
regex : "[\\[\\(\\{]"
195
token : "paren.rparen",
196
regex : "[\\]\\)\\}]"
201
oop.inherits(ShHighlightRules, TextHighlightRules);
203
exports.ShHighlightRules = ShHighlightRules;