~pvigo/+junk/owncloud-14.04

« back to all changes in this revision

Viewing changes to usr/share/owncloud/apps/files_texteditor/js/vendor/ace/src-noconflict/mode-sh.js

  • Committer: Pablo Vigo
  • Date: 2014-12-15 13:36:46 UTC
  • Revision ID: pvigo@xtec.cat-20141215133646-7d6it90e1dbsijc2
2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ***** BEGIN LICENSE BLOCK *****
2
 
 * Distributed under the BSD license:
3
 
 *
4
 
 * Copyright (c) 2010, Ajax.org B.V.
5
 
 * All rights reserved.
6
 
 * 
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.
17
 
 * 
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.
28
 
 *
29
 
 * ***** END LICENSE BLOCK ***** */
30
 
 
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) {
32
 
 
33
 
 
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;
39
 
 
40
 
var Mode = function() {
41
 
    var highlighter = new ShHighlightRules();
42
 
    
43
 
    this.$tokenizer = new Tokenizer(highlighter.getRules());
44
 
    this.$keywordList = highlighter.$keywordList;
45
 
};
46
 
oop.inherits(Mode, TextMode);
47
 
 
48
 
(function() {
49
 
 
50
 
   
51
 
    this.lineCommentStart = "#";
52
 
 
53
 
    this.getNextLineIndent = function(state, line, tab) {
54
 
        var indent = this.$getIndent(line);
55
 
 
56
 
        var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
57
 
        var tokens = tokenizedLine.tokens;
58
 
 
59
 
        if (tokens.length && tokens[tokens.length-1].type == "comment") {
60
 
            return indent;
61
 
        }
62
 
 
63
 
        if (state == "start") {
64
 
            var match = line.match(/^.*[\{\(\[\:]\s*$/);
65
 
            if (match) {
66
 
                indent += tab;
67
 
            }
68
 
        }
69
 
 
70
 
        return indent;
71
 
    };
72
 
 
73
 
    var outdents = {
74
 
        "pass": 1,
75
 
        "return": 1,
76
 
        "raise": 1,
77
 
        "break": 1,
78
 
        "continue": 1
79
 
    };
80
 
 
81
 
    this.checkOutdent = function(state, line, input) {
82
 
        if (input !== "\r\n" && input !== "\r" && input !== "\n")
83
 
            return false;
84
 
 
85
 
        var tokens = this.$tokenizer.getLineTokens(line.trim(), state).tokens;
86
 
 
87
 
        if (!tokens)
88
 
            return false;
89
 
        do {
90
 
            var last = tokens.pop();
91
 
        } while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/))));
92
 
 
93
 
        if (!last)
94
 
            return false;
95
 
 
96
 
        return (last.type == "keyword" && outdents[last.value]);
97
 
    };
98
 
 
99
 
    this.autoOutdent = function(state, doc, row) {
100
 
 
101
 
        row += 1;
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));
106
 
    };
107
 
 
108
 
}).call(Mode.prototype);
109
 
 
110
 
exports.Mode = Mode;
111
 
});
112
 
 
113
 
ace.define('ace/mode/sh_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
114
 
 
115
 
 
116
 
var oop = require("../lib/oop");
117
 
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
118
 
 
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|'+
123
 
        'elif|select|set'
124
 
    );
125
 
 
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|'+
134
 
     'umask|unalias|wait'
135
 
);
136
 
 
137
 
var ShHighlightRules = function() {
138
 
    var keywordMapper = this.createKeywordMapper({
139
 
        "keyword": reservedKeywords,
140
 
        "support.function.builtin": languageConstructs,
141
 
        "invalid.deprecated": "debugger"
142
 
    }, "identifier");
143
 
 
144
 
    var integer = "(?:(?:[1-9]\\d*)|(?:0))";
145
 
 
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 + ")";
152
 
 
153
 
    var variableName = "[a-zA-Z][a-zA-Z0-9_]*";
154
 
    var variable = "(?:(?:\\$" + variableName + ")|(?:" + variableName + "=))";
155
 
 
156
 
    var builtinVariable = "(?:\\$(?:SHLVL|\\$|\\!|\\?))";
157
 
 
158
 
    var func = "(?:" + variableName + "\\s*\\(\\))";
159
 
 
160
 
    this.$rules = {
161
 
        "start" : [{
162
 
            token : "constant",
163
 
            regex : /\\./
164
 
        }, {
165
 
            token : ["text", "comment"],
166
 
            regex : /(^|\s)(#.*)$/
167
 
        }, {
168
 
            token : "string",
169
 
            regex : '"',
170
 
            push : [{
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})/
173
 
            }, {
174
 
                token : "constant",
175
 
                regex : /\$\w+/
176
 
            }, {
177
 
                token : "string",
178
 
                regex : '"',
179
 
                next: "pop"
180
 
            }, {
181
 
                defaultToken: "string"
182
 
            }]
183
 
        }, {
184
 
            token : "variable.language",
185
 
            regex : builtinVariable
186
 
        }, {
187
 
            token : "variable",
188
 
            regex : variable
189
 
        }, {
190
 
            token : "support.function",
191
 
            regex : func
192
 
        }, {
193
 
            token : "support.function",
194
 
            regex : fileDescriptor
195
 
        }, {
196
 
            token : "string",           // ' string
197
 
            start : "'", end : "'"
198
 
        }, {
199
 
            token : "constant.numeric", // float
200
 
            regex : floatNumber
201
 
        }, {
202
 
            token : "constant.numeric", // integer
203
 
            regex : integer + "\\b"
204
 
        }, {
205
 
            token : keywordMapper,
206
 
            regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
207
 
        }, {
208
 
            token : "keyword.operator",
209
 
            regex : "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|~|<|>|<=|=>|=|!="
210
 
        }, {
211
 
            token : "paren.lparen",
212
 
            regex : "[\\[\\(\\{]"
213
 
        }, {
214
 
            token : "paren.rparen",
215
 
            regex : "[\\]\\)\\}]"
216
 
        } ]
217
 
    };
218
 
    
219
 
    this.normalizeRules();
220
 
};
221
 
 
222
 
oop.inherits(ShHighlightRules, TextHighlightRules);
223
 
 
224
 
exports.ShHighlightRules = ShHighlightRules;
225
 
});