5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineMode("vb", function(conf, parserConf) {
15
var ERRORCLASS = 'error';
17
function wordRegexp(words) {
18
return new RegExp("^((" + words.join(")|(") + "))\\b", "i");
21
var singleOperators = new RegExp("^[\\+\\-\\*/%&\\\\|\\^~<>!]");
22
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
23
var doubleOperators = new RegExp("^((==)|(<>)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
24
var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
25
var tripleDelimiters = new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))");
26
var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
28
var openingKeywords = ['class','module', 'sub','enum','select','while','if','function', 'get','set','property', 'try', 'structure', 'synclock', 'using', 'with'];
29
var middleKeywords = ['else','elseif','case', 'catch', 'finally'];
30
var endKeywords = ['next','loop'];
32
var operatorKeywords = ['and', "andalso", 'or', 'orelse', 'xor', 'in', 'not', 'is', 'isnot', 'like'];
33
var wordOperators = wordRegexp(operatorKeywords);
35
var commonKeywords = ["#const", "#else", "#elseif", "#end", "#if", "#region", "addhandler", "addressof", "alias", "as", "byref", "byval", "cbool", "cbyte", "cchar", "cdate", "cdbl", "cdec", "cint", "clng", "cobj", "compare", "const", "continue", "csbyte", "cshort", "csng", "cstr", "cuint", "culng", "cushort", "declare", "default", "delegate", "dim", "directcast", "each", "erase", "error", "event", "exit", "explicit", "false", "for", "friend", "gettype", "goto", "handles", "implements", "imports", "infer", "inherits", "interface", "isfalse", "istrue", "lib", "me", "mod", "mustinherit", "mustoverride", "my", "mybase", "myclass", "namespace", "narrowing", "new", "nothing", "notinheritable", "notoverridable", "of", "off", "on", "operator", "option", "optional", "out", "overloads", "overridable", "overrides", "paramarray", "partial", "private", "protected", "public", "raiseevent", "readonly", "redim", "removehandler", "resume", "return", "shadows", "shared", "static", "step", "stop", "strict", "then", "throw", "to", "true", "trycast", "typeof", "until", "until", "when", "widening", "withevents", "writeonly"];
37
var commontypes = ['object', 'boolean', 'char', 'string', 'byte', 'sbyte', 'short', 'ushort', 'int16', 'uint16', 'integer', 'uinteger', 'int32', 'uint32', 'long', 'ulong', 'int64', 'uint64', 'decimal', 'single', 'double', 'float', 'date', 'datetime', 'intptr', 'uintptr'];
39
var keywords = wordRegexp(commonKeywords);
40
var types = wordRegexp(commontypes);
41
var stringPrefixes = '"';
43
var opening = wordRegexp(openingKeywords);
44
var middle = wordRegexp(middleKeywords);
45
var closing = wordRegexp(endKeywords);
46
var doubleClosing = wordRegexp(['end']);
47
var doOpening = wordRegexp(['do']);
49
var indentInfo = null;
51
CodeMirror.registerHelper("hintWords", "vb", openingKeywords.concat(middleKeywords).concat(endKeywords)
52
.concat(operatorKeywords).concat(commonKeywords).concat(commontypes));
54
function indent(_stream, state) {
55
state.currentIndent++;
58
function dedent(_stream, state) {
59
state.currentIndent--;
62
function tokenBase(stream, state) {
63
if (stream.eatSpace()) {
67
var ch = stream.peek();
77
if (stream.match(/^((&H)|(&O))?[0-9\.a-f]/i, false)) {
78
var floatLiteral = false;
80
if (stream.match(/^\d*\.\d+F?/i)) { floatLiteral = true; }
81
else if (stream.match(/^\d+\.\d*F?/)) { floatLiteral = true; }
82
else if (stream.match(/^\.\d+F?/)) { floatLiteral = true; }
90
var intLiteral = false;
92
if (stream.match(/^&H[0-9a-f]+/i)) { intLiteral = true; }
94
else if (stream.match(/^&O[0-7]+/i)) { intLiteral = true; }
96
else if (stream.match(/^[1-9]\d*F?/)) {
103
else if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }
112
if (stream.match(stringPrefixes)) {
113
state.tokenize = tokenStringFactory(stream.current());
114
return state.tokenize(stream, state);
118
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
121
if (stream.match(doubleOperators)
122
|| stream.match(singleOperators)
123
|| stream.match(wordOperators)) {
126
if (stream.match(singleDelimiters)) {
129
if (stream.match(doOpening)) {
130
indent(stream,state);
131
state.doInCurrentLine = true;
134
if (stream.match(opening)) {
135
if (! state.doInCurrentLine)
136
indent(stream,state);
138
state.doInCurrentLine = false;
141
if (stream.match(middle)) {
145
if (stream.match(doubleClosing)) {
146
dedent(stream,state);
147
dedent(stream,state);
150
if (stream.match(closing)) {
151
dedent(stream,state);
155
if (stream.match(types)) {
159
if (stream.match(keywords)) {
163
if (stream.match(identifiers)) {
172
function tokenStringFactory(delimiter) {
173
var singleline = delimiter.length == 1;
174
var OUTCLASS = 'string';
176
return function(stream, state) {
177
while (!stream.eol()) {
178
stream.eatWhile(/[^'"]/);
179
if (stream.match(delimiter)) {
180
state.tokenize = tokenBase;
187
if (parserConf.singleLineStringErrors) {
190
state.tokenize = tokenBase;
198
function tokenLexer(stream, state) {
199
var style = state.tokenize(stream, state);
200
var current = stream.current();
203
if (current === '.') {
204
style = state.tokenize(stream, state);
205
if (style === 'variable') {
213
var delimiter_index = '[({'.indexOf(current);
214
if (delimiter_index !== -1) {
215
indent(stream, state );
217
if (indentInfo === 'dedent') {
218
if (dedent(stream, state)) {
222
delimiter_index = '])}'.indexOf(current);
223
if (delimiter_index !== -1) {
224
if (dedent(stream, state)) {
233
electricChars:"dDpPtTfFeE ",
234
startState: function() {
240
doInCurrentLine: false
246
token: function(stream, state) {
248
state.currentIndent += state.nextLineIndent;
249
state.nextLineIndent = 0;
250
state.doInCurrentLine = 0;
252
var style = tokenLexer(stream, state);
254
state.lastToken = {style:style, content: stream.current()};
261
indent: function(state, textAfter) {
262
var trueText = textAfter.replace(/^\s+|\s+$/g, '') ;
263
if (trueText.match(closing) || trueText.match(doubleClosing) || trueText.match(middle)) return conf.indentUnit*(state.currentIndent-1);
264
if(state.currentIndent < 0) return 0;
265
return state.currentIndent * conf.indentUnit;
273
CodeMirror.defineMIME("text/x-vb", "vb");