16
if (typeof exports == "object" && typeof module == "object")
17
mod(require("../../lib/codemirror"));
18
else if (typeof define == "function" && define.amd)
19
define(["../../lib/codemirror"], mod);
22
})(function(CodeMirror) {
25
CodeMirror.defineMode("vbscript", function(conf, parserConf) {
26
var ERRORCLASS = 'error';
28
function wordRegexp(words) {
29
return new RegExp("^((" + words.join(")|(") + "))\\b", "i");
32
var singleOperators = new RegExp("^[\\+\\-\\*/&\\\\\\^<>=]");
33
var doubleOperators = new RegExp("^((<>)|(<=)|(>=))");
34
var singleDelimiters = new RegExp('^[\\.,]');
35
var brackets = new RegExp('^[\\(\\)]');
36
var identifiers = new RegExp("^[A-Za-z][_A-Za-z0-9]*");
38
var openingKeywords = ['class','sub','select','while','if','function', 'property', 'with', 'for'];
39
var middleKeywords = ['else','elseif','case'];
40
var endKeywords = ['next','loop','wend'];
42
var wordOperators = wordRegexp(['and', 'or', 'not', 'xor', 'is', 'mod', 'eqv', 'imp']);
43
var commonkeywords = ['dim', 'redim', 'then', 'until', 'randomize',
44
'byval','byref','new','property', 'exit', 'in',
45
'const','private', 'public',
46
'get','set','let', 'stop', 'on error resume next', 'on error goto 0', 'option explicit', 'call', 'me'];
49
var atomWords = ['true', 'false', 'nothing', 'empty', 'null'];
51
var builtinFuncsWords = ['abs', 'array', 'asc', 'atn', 'cbool', 'cbyte', 'ccur', 'cdate', 'cdbl', 'chr', 'cint', 'clng', 'cos', 'csng', 'cstr', 'date', 'dateadd', 'datediff', 'datepart',
52
'dateserial', 'datevalue', 'day', 'escape', 'eval', 'execute', 'exp', 'filter', 'formatcurrency', 'formatdatetime', 'formatnumber', 'formatpercent', 'getlocale', 'getobject',
53
'getref', 'hex', 'hour', 'inputbox', 'instr', 'instrrev', 'int', 'fix', 'isarray', 'isdate', 'isempty', 'isnull', 'isnumeric', 'isobject', 'join', 'lbound', 'lcase', 'left',
54
'len', 'loadpicture', 'log', 'ltrim', 'rtrim', 'trim', 'maths', 'mid', 'minute', 'month', 'monthname', 'msgbox', 'now', 'oct', 'replace', 'rgb', 'right', 'rnd', 'round',
55
'scriptengine', 'scriptenginebuildversion', 'scriptenginemajorversion', 'scriptengineminorversion', 'second', 'setlocale', 'sgn', 'sin', 'space', 'split', 'sqr', 'strcomp',
56
'string', 'strreverse', 'tan', 'time', 'timer', 'timeserial', 'timevalue', 'typename', 'ubound', 'ucase', 'unescape', 'vartype', 'weekday', 'weekdayname', 'year'];
59
var builtinConsts = ['vbBlack', 'vbRed', 'vbGreen', 'vbYellow', 'vbBlue', 'vbMagenta', 'vbCyan', 'vbWhite', 'vbBinaryCompare', 'vbTextCompare',
60
'vbSunday', 'vbMonday', 'vbTuesday', 'vbWednesday', 'vbThursday', 'vbFriday', 'vbSaturday', 'vbUseSystemDayOfWeek', 'vbFirstJan1', 'vbFirstFourDays', 'vbFirstFullWeek',
61
'vbGeneralDate', 'vbLongDate', 'vbShortDate', 'vbLongTime', 'vbShortTime', 'vbObjectError',
62
'vbOKOnly', 'vbOKCancel', 'vbAbortRetryIgnore', 'vbYesNoCancel', 'vbYesNo', 'vbRetryCancel', 'vbCritical', 'vbQuestion', 'vbExclamation', 'vbInformation', 'vbDefaultButton1', 'vbDefaultButton2',
63
'vbDefaultButton3', 'vbDefaultButton4', 'vbApplicationModal', 'vbSystemModal', 'vbOK', 'vbCancel', 'vbAbort', 'vbRetry', 'vbIgnore', 'vbYes', 'vbNo',
64
'vbCr', 'VbCrLf', 'vbFormFeed', 'vbLf', 'vbNewLine', 'vbNullChar', 'vbNullString', 'vbTab', 'vbVerticalTab', 'vbUseDefault', 'vbTrue', 'vbFalse',
65
'vbEmpty', 'vbNull', 'vbInteger', 'vbLong', 'vbSingle', 'vbDouble', 'vbCurrency', 'vbDate', 'vbString', 'vbObject', 'vbError', 'vbBoolean', 'vbVariant', 'vbDataObject', 'vbDecimal', 'vbByte', 'vbArray'];
67
var builtinObjsWords = ['WScript', 'err', 'debug', 'RegExp'];
68
var knownProperties = ['description', 'firstindex', 'global', 'helpcontext', 'helpfile', 'ignorecase', 'length', 'number', 'pattern', 'source', 'value', 'count'];
69
var knownMethods = ['clear', 'execute', 'raise', 'replace', 'test', 'write', 'writeline', 'close', 'open', 'state', 'eof', 'update', 'addnew', 'end', 'createobject', 'quit'];
71
var aspBuiltinObjsWords = ['server', 'response', 'request', 'session', 'application'];
72
var aspKnownProperties = ['buffer', 'cachecontrol', 'charset', 'contenttype', 'expires', 'expiresabsolute', 'isclientconnected', 'pics', 'status',
73
'clientcertificate', 'cookies', 'form', 'querystring', 'servervariables', 'totalbytes',
74
'contents', 'staticobjects',
75
'codepage', 'lcid', 'sessionid', 'timeout',
77
var aspKnownMethods = ['addheader', 'appendtolog', 'binarywrite', 'end', 'flush', 'redirect',
79
'remove', 'removeall', 'lock', 'unlock',
81
'getlasterror', 'htmlencode', 'mappath', 'transfer', 'urlencode'];
83
var knownWords = knownMethods.concat(knownProperties);
85
builtinObjsWords = builtinObjsWords.concat(builtinConsts);
88
builtinObjsWords = builtinObjsWords.concat(aspBuiltinObjsWords);
89
knownWords = knownWords.concat(aspKnownMethods, aspKnownProperties);
92
var keywords = wordRegexp(commonkeywords);
93
var atoms = wordRegexp(atomWords);
94
var builtinFuncs = wordRegexp(builtinFuncsWords);
95
var builtinObjs = wordRegexp(builtinObjsWords);
96
var known = wordRegexp(knownWords);
97
var stringPrefixes = '"';
99
var opening = wordRegexp(openingKeywords);
100
var middle = wordRegexp(middleKeywords);
101
var closing = wordRegexp(endKeywords);
102
var doubleClosing = wordRegexp(['end']);
103
var doOpening = wordRegexp(['do']);
104
var noIndentWords = wordRegexp(['on error resume next', 'exit']);
105
var comment = wordRegexp(['rem']);
108
function indent(_stream, state) {
109
state.currentIndent++;
112
function dedent(_stream, state) {
113
state.currentIndent--;
116
function tokenBase(stream, state) {
117
if (stream.eatSpace()) {
122
var ch = stream.peek();
129
if (stream.match(comment)){
136
if (stream.match(/^((&H)|(&O))?[0-9\.]/i, false) && !stream.match(/^((&H)|(&O))?[0-9\.]+[a-z_]/i, false)) {
137
var floatLiteral = false;
139
if (stream.match(/^\d*\.\d+/i)) { floatLiteral = true; }
140
else if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }
141
else if (stream.match(/^\.\d+/)) { floatLiteral = true; }
149
var intLiteral = false;
151
if (stream.match(/^&H[0-9a-f]+/i)) { intLiteral = true; }
153
else if (stream.match(/^&O[0-7]+/i)) { intLiteral = true; }
155
else if (stream.match(/^[1-9]\d*F?/)) {
162
else if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }
171
if (stream.match(stringPrefixes)) {
172
state.tokenize = tokenStringFactory(stream.current());
173
return state.tokenize(stream, state);
177
if (stream.match(doubleOperators)
178
|| stream.match(singleOperators)
179
|| stream.match(wordOperators)) {
182
if (stream.match(singleDelimiters)) {
186
if (stream.match(brackets)) {
190
if (stream.match(noIndentWords)) {
191
state.doInCurrentLine = true;
196
if (stream.match(doOpening)) {
197
indent(stream,state);
198
state.doInCurrentLine = true;
202
if (stream.match(opening)) {
203
if (! state.doInCurrentLine)
204
indent(stream,state);
206
state.doInCurrentLine = false;
210
if (stream.match(middle)) {
215
if (stream.match(doubleClosing)) {
216
dedent(stream,state);
217
dedent(stream,state);
221
if (stream.match(closing)) {
222
if (! state.doInCurrentLine)
223
dedent(stream,state);
225
state.doInCurrentLine = false;
230
if (stream.match(keywords)) {
234
if (stream.match(atoms)) {
238
if (stream.match(known)) {
242
if (stream.match(builtinFuncs)) {
246
if (stream.match(builtinObjs)){
250
if (stream.match(identifiers)) {
259
function tokenStringFactory(delimiter) {
260
var singleline = delimiter.length == 1;
261
var OUTCLASS = 'string';
263
return function(stream, state) {
264
while (!stream.eol()) {
265
stream.eatWhile(/[^'"]/);
266
if (stream.match(delimiter)) {
267
state.tokenize = tokenBase;
274
if (parserConf.singleLineStringErrors) {
277
state.tokenize = tokenBase;
285
function tokenLexer(stream, state) {
286
var style = state.tokenize(stream, state);
287
var current = stream.current();
290
if (current === '.') {
291
style = state.tokenize(stream, state);
293
current = stream.current();
294
if (style && (style.substr(0, 8) === 'variable' || style==='builtin' || style==='keyword')){
295
if (style === 'builtin' || style === 'keyword') style='variable';
296
if (knownWords.indexOf(current.substr(1)) > -1) style='variable-2';
308
electricChars:"dDpPtTfFeE ",
309
startState: function() {
315
doInCurrentLine: false,
322
token: function(stream, state) {
324
state.currentIndent += state.nextLineIndent;
325
state.nextLineIndent = 0;
326
state.doInCurrentLine = 0;
328
var style = tokenLexer(stream, state);
330
state.lastToken = {style:style, content: stream.current()};
332
if (style==='space') style=null;
337
indent: function(state, textAfter) {
338
var trueText = textAfter.replace(/^\s+|\s+$/g, '') ;
339
if (trueText.match(closing) || trueText.match(doubleClosing) || trueText.match(middle)) return conf.indentUnit*(state.currentIndent-1);
340
if(state.currentIndent < 0) return 0;
341
return state.currentIndent * conf.indentUnit;
348
CodeMirror.defineMIME("text/vbscript", "vbscript");