bzr branch
http://gegoxaren.bato24.eu/bzr/lenasys/trunk
15.1.1
by galaxyAbstractor
Started implementation of a new codeviewer using Ace |
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 |
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 |
this.$tokenizer = new Tokenizer(new ShHighlightRules().getRules()); |
|
42 |
};
|
|
43 |
oop.inherits(Mode, TextMode); |
|
44 |
||
45 |
(function() { |
|
46 |
||
47 |
|
|
48 |
this.lineCommentStart = "#"; |
|
49 |
||
50 |
this.getNextLineIndent = function(state, line, tab) { |
|
51 |
var indent = this.$getIndent(line); |
|
52 |
||
53 |
var tokenizedLine = this.$tokenizer.getLineTokens(line, state); |
|
54 |
var tokens = tokenizedLine.tokens; |
|
55 |
||
56 |
if (tokens.length && tokens[tokens.length-1].type == "comment") { |
|
57 |
return indent; |
|
58 |
} |
|
59 |
||
60 |
if (state == "start") { |
|
61 |
var match = line.match(/^.*[\{\(\[\:]\s*$/); |
|
62 |
if (match) { |
|
63 |
indent += tab; |
|
64 |
} |
|
65 |
} |
|
66 |
||
67 |
return indent; |
|
68 |
}; |
|
69 |
||
70 |
var outdents = { |
|
71 |
"pass": 1, |
|
72 |
"return": 1, |
|
73 |
"raise": 1, |
|
74 |
"break": 1, |
|
75 |
"continue": 1 |
|
76 |
}; |
|
77 |
||
78 |
this.checkOutdent = function(state, line, input) { |
|
79 |
if (input !== "\r\n" && input !== "\r" && input !== "\n") |
|
80 |
return false; |
|
81 |
||
82 |
var tokens = this.$tokenizer.getLineTokens(line.trim(), state).tokens; |
|
83 |
||
84 |
if (!tokens) |
|
85 |
return false; |
|
86 |
do { |
|
87 |
var last = tokens.pop(); |
|
88 |
} while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/)))); |
|
89 |
||
90 |
if (!last) |
|
91 |
return false; |
|
92 |
||
93 |
return (last.type == "keyword" && outdents[last.value]); |
|
94 |
}; |
|
95 |
||
96 |
this.autoOutdent = function(state, doc, row) { |
|
97 |
||
98 |
row += 1; |
|
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)); |
|
103 |
}; |
|
104 |
||
105 |
}).call(Mode.prototype); |
|
106 |
||
107 |
exports.Mode = Mode; |
|
108 |
});
|
|
109 |
||
110 |
define('ace/mode/sh_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) { |
|
111 |
||
112 |
||
113 |
var oop = require("../lib/oop"); |
|
114 |
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; |
|
115 |
||
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|'+ |
|
120 |
'elif|select|set' |
|
121 |
); |
|
122 |
||
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|'+ |
|
131 |
'umask|unalias|wait' |
|
132 |
);
|
|
133 |
||
134 |
var ShHighlightRules = function() { |
|
135 |
var keywordMapper = this.createKeywordMapper({ |
|
136 |
"keyword": reservedKeywords, |
|
137 |
"support.function.builtin": languageConstructs, |
|
138 |
"invalid.deprecated": "debugger" |
|
139 |
}, "identifier"); |
|
140 |
||
141 |
var integer = "(?:(?:[1-9]\\d*)|(?:0))"; |
|
142 |
||
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 + ")"; |
|
149 |
||
150 |
var variableName = "[a-zA-Z][a-zA-Z0-9_]*"; |
|
151 |
var variable = "(?:(?:\\$" + variableName + ")|(?:" + variableName + "=))"; |
|
152 |
||
153 |
var builtinVariable = "(?:\\$(?:SHLVL|\\$|\\!|\\?))"; |
|
154 |
||
155 |
var func = "(?:" + variableName + "\\s*\\(\\))"; |
|
156 |
||
157 |
this.$rules = { |
|
158 |
"start" : [ { |
|
159 |
token : ["text", "comment"], |
|
160 |
regex : /(^|\s)(#.*)$/ |
|
161 |
}, { |
|
162 |
token : "string", // " string |
|
163 |
regex : '"(?:[^\\\\]|\\\\.)*?"' |
|
164 |
}, { |
|
165 |
token : "variable.language", |
|
166 |
regex : builtinVariable |
|
167 |
}, { |
|
168 |
token : "variable", |
|
169 |
regex : variable |
|
170 |
}, { |
|
171 |
token : "support.function", |
|
172 |
regex : func |
|
173 |
}, { |
|
174 |
token : "support.function", |
|
175 |
regex : fileDescriptor |
|
176 |
}, { |
|
177 |
token : "string", // ' string |
|
178 |
regex : "'(?:[^\\\\]|\\\\.)*?'" |
|
179 |
}, { |
|
180 |
token : "constant.numeric", // float |
|
181 |
regex : floatNumber |
|
182 |
}, { |
|
183 |
token : "constant.numeric", // integer |
|
184 |
regex : integer + "\\b" |
|
185 |
}, { |
|
186 |
token : keywordMapper, |
|
187 |
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" |
|
188 |
}, { |
|
189 |
token : "keyword.operator", |
|
190 |
regex : "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|~|<|>|<=|=>|=|!=" |
|
191 |
}, { |
|
192 |
token : "paren.lparen", |
|
193 |
regex : "[\\[\\(\\{]" |
|
194 |
}, { |
|
195 |
token : "paren.rparen", |
|
196 |
regex : "[\\]\\)\\}]" |
|
197 |
} ] |
|
198 |
}; |
|
199 |
};
|
|
200 |
||
201 |
oop.inherits(ShHighlightRules, TextHighlightRules); |
|
202 |
||
203 |
exports.ShHighlightRules = ShHighlightRules; |
|
204 |
});
|