LaravelTest
275 строк · 9.6 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("vb", function(conf, parserConf) {15var ERRORCLASS = 'error';16
17function wordRegexp(words) {18return new RegExp("^((" + words.join(")|(") + "))\\b", "i");19}20
21var singleOperators = new RegExp("^[\\+\\-\\*/%&\\\\|\\^~<>!]");22var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');23var doubleOperators = new RegExp("^((==)|(<>)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");24var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");25var tripleDelimiters = new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))");26var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");27
28var openingKeywords = ['class','module', 'sub','enum','select','while','if','function', 'get','set','property', 'try', 'structure', 'synclock', 'using', 'with'];29var middleKeywords = ['else','elseif','case', 'catch', 'finally'];30var endKeywords = ['next','loop'];31
32var operatorKeywords = ['and', "andalso", 'or', 'orelse', 'xor', 'in', 'not', 'is', 'isnot', 'like'];33var wordOperators = wordRegexp(operatorKeywords);34
35var 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"];36
37var 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'];38
39var keywords = wordRegexp(commonKeywords);40var types = wordRegexp(commontypes);41var stringPrefixes = '"';42
43var opening = wordRegexp(openingKeywords);44var middle = wordRegexp(middleKeywords);45var closing = wordRegexp(endKeywords);46var doubleClosing = wordRegexp(['end']);47var doOpening = wordRegexp(['do']);48
49var indentInfo = null;50
51CodeMirror.registerHelper("hintWords", "vb", openingKeywords.concat(middleKeywords).concat(endKeywords)52.concat(operatorKeywords).concat(commonKeywords).concat(commontypes));53
54function indent(_stream, state) {55state.currentIndent++;56}57
58function dedent(_stream, state) {59state.currentIndent--;60}61// tokenizers62function tokenBase(stream, state) {63if (stream.eatSpace()) {64return null;65}66
67var ch = stream.peek();68
69// Handle Comments70if (ch === "'") {71stream.skipToEnd();72return 'comment';73}74
75
76// Handle Number Literals77if (stream.match(/^((&H)|(&O))?[0-9\.a-f]/i, false)) {78var floatLiteral = false;79// Floats80if (stream.match(/^\d*\.\d+F?/i)) { floatLiteral = true; }81else if (stream.match(/^\d+\.\d*F?/)) { floatLiteral = true; }82else if (stream.match(/^\.\d+F?/)) { floatLiteral = true; }83
84if (floatLiteral) {85// Float literals may be "imaginary"86stream.eat(/J/i);87return 'number';88}89// Integers90var intLiteral = false;91// Hex92if (stream.match(/^&H[0-9a-f]+/i)) { intLiteral = true; }93// Octal94else if (stream.match(/^&O[0-7]+/i)) { intLiteral = true; }95// Decimal96else if (stream.match(/^[1-9]\d*F?/)) {97// Decimal literals may be "imaginary"98stream.eat(/J/i);99// TODO - Can you have imaginary longs?100intLiteral = true;101}102// Zero by itself with no other piece of number.103else if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }104if (intLiteral) {105// Integer literals may be "long"106stream.eat(/L/i);107return 'number';108}109}110
111// Handle Strings112if (stream.match(stringPrefixes)) {113state.tokenize = tokenStringFactory(stream.current());114return state.tokenize(stream, state);115}116
117// Handle operators and Delimiters118if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {119return null;120}121if (stream.match(doubleOperators)122|| stream.match(singleOperators)123|| stream.match(wordOperators)) {124return 'operator';125}126if (stream.match(singleDelimiters)) {127return null;128}129if (stream.match(doOpening)) {130indent(stream,state);131state.doInCurrentLine = true;132return 'keyword';133}134if (stream.match(opening)) {135if (! state.doInCurrentLine)136indent(stream,state);137else138state.doInCurrentLine = false;139return 'keyword';140}141if (stream.match(middle)) {142return 'keyword';143}144
145if (stream.match(doubleClosing)) {146dedent(stream,state);147dedent(stream,state);148return 'keyword';149}150if (stream.match(closing)) {151dedent(stream,state);152return 'keyword';153}154
155if (stream.match(types)) {156return 'keyword';157}158
159if (stream.match(keywords)) {160return 'keyword';161}162
163if (stream.match(identifiers)) {164return 'variable';165}166
167// Handle non-detected items168stream.next();169return ERRORCLASS;170}171
172function tokenStringFactory(delimiter) {173var singleline = delimiter.length == 1;174var OUTCLASS = 'string';175
176return function(stream, state) {177while (!stream.eol()) {178stream.eatWhile(/[^'"]/);179if (stream.match(delimiter)) {180state.tokenize = tokenBase;181return OUTCLASS;182} else {183stream.eat(/['"]/);184}185}186if (singleline) {187if (parserConf.singleLineStringErrors) {188return ERRORCLASS;189} else {190state.tokenize = tokenBase;191}192}193return OUTCLASS;194};195}196
197
198function tokenLexer(stream, state) {199var style = state.tokenize(stream, state);200var current = stream.current();201
202// Handle '.' connected identifiers203if (current === '.') {204style = state.tokenize(stream, state);205if (style === 'variable') {206return 'variable';207} else {208return ERRORCLASS;209}210}211
212
213var delimiter_index = '[({'.indexOf(current);214if (delimiter_index !== -1) {215indent(stream, state );216}217if (indentInfo === 'dedent') {218if (dedent(stream, state)) {219return ERRORCLASS;220}221}222delimiter_index = '])}'.indexOf(current);223if (delimiter_index !== -1) {224if (dedent(stream, state)) {225return ERRORCLASS;226}227}228
229return style;230}231
232var external = {233electricChars:"dDpPtTfFeE ",234startState: function() {235return {236tokenize: tokenBase,237lastToken: null,238currentIndent: 0,239nextLineIndent: 0,240doInCurrentLine: false241
242
243};244},245
246token: function(stream, state) {247if (stream.sol()) {248state.currentIndent += state.nextLineIndent;249state.nextLineIndent = 0;250state.doInCurrentLine = 0;251}252var style = tokenLexer(stream, state);253
254state.lastToken = {style:style, content: stream.current()};255
256
257
258return style;259},260
261indent: function(state, textAfter) {262var trueText = textAfter.replace(/^\s+|\s+$/g, '') ;263if (trueText.match(closing) || trueText.match(doubleClosing) || trueText.match(middle)) return conf.indentUnit*(state.currentIndent-1);264if(state.currentIndent < 0) return 0;265return state.currentIndent * conf.indentUnit;266},267
268lineComment: "'"269};270return external;271});272
273CodeMirror.defineMIME("text/x-vb", "vb");274
275});276