LaravelTest
350 строк · 13.5 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4/*
5For extra ASP classic objects, initialize CodeMirror instance with this option:
6isASP: true
7
8E.G.:
9var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
10lineNumbers: true,
11isASP: true
12});
13*/
14
15(function(mod) {16if (typeof exports == "object" && typeof module == "object") // CommonJS17mod(require("../../lib/codemirror"));18else if (typeof define == "function" && define.amd) // AMD19define(["../../lib/codemirror"], mod);20else // Plain browser env21mod(CodeMirror);22})(function(CodeMirror) {23"use strict";24
25CodeMirror.defineMode("vbscript", function(conf, parserConf) {26var ERRORCLASS = 'error';27
28function wordRegexp(words) {29return new RegExp("^((" + words.join(")|(") + "))\\b", "i");30}31
32var singleOperators = new RegExp("^[\\+\\-\\*/&\\\\\\^<>=]");33var doubleOperators = new RegExp("^((<>)|(<=)|(>=))");34var singleDelimiters = new RegExp('^[\\.,]');35var brackets = new RegExp('^[\\(\\)]');36var identifiers = new RegExp("^[A-Za-z][_A-Za-z0-9]*");37
38var openingKeywords = ['class','sub','select','while','if','function', 'property', 'with', 'for'];39var middleKeywords = ['else','elseif','case'];40var endKeywords = ['next','loop','wend'];41
42var wordOperators = wordRegexp(['and', 'or', 'not', 'xor', 'is', 'mod', 'eqv', 'imp']);43var 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'];47
48//This list was from: http://msdn.microsoft.com/en-us/library/f8tbc79x(v=vs.84).aspx49var atomWords = ['true', 'false', 'nothing', 'empty', 'null'];50//This list was from: http://msdn.microsoft.com/en-us/library/3ca8tfek(v=vs.84).aspx51var 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'];57
58//This list was from: http://msdn.microsoft.com/en-us/library/ydz4cfk3(v=vs.84).aspx59var 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'];66//This list was from: http://msdn.microsoft.com/en-us/library/hkc375ea(v=vs.84).aspx67var builtinObjsWords = ['WScript', 'err', 'debug', 'RegExp'];68var knownProperties = ['description', 'firstindex', 'global', 'helpcontext', 'helpfile', 'ignorecase', 'length', 'number', 'pattern', 'source', 'value', 'count'];69var knownMethods = ['clear', 'execute', 'raise', 'replace', 'test', 'write', 'writeline', 'close', 'open', 'state', 'eof', 'update', 'addnew', 'end', 'createobject', 'quit'];70
71var aspBuiltinObjsWords = ['server', 'response', 'request', 'session', 'application'];72var aspKnownProperties = ['buffer', 'cachecontrol', 'charset', 'contenttype', 'expires', 'expiresabsolute', 'isclientconnected', 'pics', 'status', //response73'clientcertificate', 'cookies', 'form', 'querystring', 'servervariables', 'totalbytes', //request74'contents', 'staticobjects', //application75'codepage', 'lcid', 'sessionid', 'timeout', //session76'scripttimeout']; //server77var aspKnownMethods = ['addheader', 'appendtolog', 'binarywrite', 'end', 'flush', 'redirect', //response78'binaryread', //request79'remove', 'removeall', 'lock', 'unlock', //application80'abandon', //session81'getlasterror', 'htmlencode', 'mappath', 'transfer', 'urlencode']; //server82
83var knownWords = knownMethods.concat(knownProperties);84
85builtinObjsWords = builtinObjsWords.concat(builtinConsts);86
87if (conf.isASP){88builtinObjsWords = builtinObjsWords.concat(aspBuiltinObjsWords);89knownWords = knownWords.concat(aspKnownMethods, aspKnownProperties);90};91
92var keywords = wordRegexp(commonkeywords);93var atoms = wordRegexp(atomWords);94var builtinFuncs = wordRegexp(builtinFuncsWords);95var builtinObjs = wordRegexp(builtinObjsWords);96var known = wordRegexp(knownWords);97var stringPrefixes = '"';98
99var opening = wordRegexp(openingKeywords);100var middle = wordRegexp(middleKeywords);101var closing = wordRegexp(endKeywords);102var doubleClosing = wordRegexp(['end']);103var doOpening = wordRegexp(['do']);104var noIndentWords = wordRegexp(['on error resume next', 'exit']);105var comment = wordRegexp(['rem']);106
107
108function indent(_stream, state) {109state.currentIndent++;110}111
112function dedent(_stream, state) {113state.currentIndent--;114}115// tokenizers116function tokenBase(stream, state) {117if (stream.eatSpace()) {118return 'space';119//return null;120}121
122var ch = stream.peek();123
124// Handle Comments125if (ch === "'") {126stream.skipToEnd();127return 'comment';128}129if (stream.match(comment)){130stream.skipToEnd();131return 'comment';132}133
134
135// Handle Number Literals136if (stream.match(/^((&H)|(&O))?[0-9\.]/i, false) && !stream.match(/^((&H)|(&O))?[0-9\.]+[a-z_]/i, false)) {137var floatLiteral = false;138// Floats139if (stream.match(/^\d*\.\d+/i)) { floatLiteral = true; }140else if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }141else if (stream.match(/^\.\d+/)) { floatLiteral = true; }142
143if (floatLiteral) {144// Float literals may be "imaginary"145stream.eat(/J/i);146return 'number';147}148// Integers149var intLiteral = false;150// Hex151if (stream.match(/^&H[0-9a-f]+/i)) { intLiteral = true; }152// Octal153else if (stream.match(/^&O[0-7]+/i)) { intLiteral = true; }154// Decimal155else if (stream.match(/^[1-9]\d*F?/)) {156// Decimal literals may be "imaginary"157stream.eat(/J/i);158// TODO - Can you have imaginary longs?159intLiteral = true;160}161// Zero by itself with no other piece of number.162else if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }163if (intLiteral) {164// Integer literals may be "long"165stream.eat(/L/i);166return 'number';167}168}169
170// Handle Strings171if (stream.match(stringPrefixes)) {172state.tokenize = tokenStringFactory(stream.current());173return state.tokenize(stream, state);174}175
176// Handle operators and Delimiters177if (stream.match(doubleOperators)178|| stream.match(singleOperators)179|| stream.match(wordOperators)) {180return 'operator';181}182if (stream.match(singleDelimiters)) {183return null;184}185
186if (stream.match(brackets)) {187return "bracket";188}189
190if (stream.match(noIndentWords)) {191state.doInCurrentLine = true;192
193return 'keyword';194}195
196if (stream.match(doOpening)) {197indent(stream,state);198state.doInCurrentLine = true;199
200return 'keyword';201}202if (stream.match(opening)) {203if (! state.doInCurrentLine)204indent(stream,state);205else206state.doInCurrentLine = false;207
208return 'keyword';209}210if (stream.match(middle)) {211return 'keyword';212}213
214
215if (stream.match(doubleClosing)) {216dedent(stream,state);217dedent(stream,state);218
219return 'keyword';220}221if (stream.match(closing)) {222if (! state.doInCurrentLine)223dedent(stream,state);224else225state.doInCurrentLine = false;226
227return 'keyword';228}229
230if (stream.match(keywords)) {231return 'keyword';232}233
234if (stream.match(atoms)) {235return 'atom';236}237
238if (stream.match(known)) {239return 'variable-2';240}241
242if (stream.match(builtinFuncs)) {243return 'builtin';244}245
246if (stream.match(builtinObjs)){247return 'variable-2';248}249
250if (stream.match(identifiers)) {251return 'variable';252}253
254// Handle non-detected items255stream.next();256return ERRORCLASS;257}258
259function tokenStringFactory(delimiter) {260var singleline = delimiter.length == 1;261var OUTCLASS = 'string';262
263return function(stream, state) {264while (!stream.eol()) {265stream.eatWhile(/[^'"]/);266if (stream.match(delimiter)) {267state.tokenize = tokenBase;268return OUTCLASS;269} else {270stream.eat(/['"]/);271}272}273if (singleline) {274if (parserConf.singleLineStringErrors) {275return ERRORCLASS;276} else {277state.tokenize = tokenBase;278}279}280return OUTCLASS;281};282}283
284
285function tokenLexer(stream, state) {286var style = state.tokenize(stream, state);287var current = stream.current();288
289// Handle '.' connected identifiers290if (current === '.') {291style = state.tokenize(stream, state);292
293current = stream.current();294if (style && (style.substr(0, 8) === 'variable' || style==='builtin' || style==='keyword')){//|| knownWords.indexOf(current.substring(1)) > -1) {295if (style === 'builtin' || style === 'keyword') style='variable';296if (knownWords.indexOf(current.substr(1)) > -1) style='variable-2';297
298return style;299} else {300return ERRORCLASS;301}302}303
304return style;305}306
307var external = {308electricChars:"dDpPtTfFeE ",309startState: function() {310return {311tokenize: tokenBase,312lastToken: null,313currentIndent: 0,314nextLineIndent: 0,315doInCurrentLine: false,316ignoreKeyword: false317
318
319};320},321
322token: function(stream, state) {323if (stream.sol()) {324state.currentIndent += state.nextLineIndent;325state.nextLineIndent = 0;326state.doInCurrentLine = 0;327}328var style = tokenLexer(stream, state);329
330state.lastToken = {style:style, content: stream.current()};331
332if (style==='space') style=null;333
334return style;335},336
337indent: function(state, textAfter) {338var trueText = textAfter.replace(/^\s+|\s+$/g, '') ;339if (trueText.match(closing) || trueText.match(doubleClosing) || trueText.match(middle)) return conf.indentUnit*(state.currentIndent-1);340if(state.currentIndent < 0) return 0;341return state.currentIndent * conf.indentUnit;342}343
344};345return external;346});347
348CodeMirror.defineMIME("text/vbscript", "vbscript");349
350});351