LaravelTest
398 строк · 12.6 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5'use strict';6if (typeof exports == 'object' && typeof module == 'object') // CommonJS7mod(require('../../lib/codemirror'));8else if (typeof define == 'function' && define.amd) // AMD9define(['../../lib/codemirror'], mod);10else // Plain browser env11mod(window.CodeMirror);12})(function(CodeMirror) {13'use strict';14
15CodeMirror.defineMode('powershell', function() {16function buildRegexp(patterns, options) {17options = options || {};18var prefix = options.prefix !== undefined ? options.prefix : '^';19var suffix = options.suffix !== undefined ? options.suffix : '\\b';20
21for (var i = 0; i < patterns.length; i++) {22if (patterns[i] instanceof RegExp) {23patterns[i] = patterns[i].source;24}25else {26patterns[i] = patterns[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');27}28}29
30return new RegExp(prefix + '(' + patterns.join('|') + ')' + suffix, 'i');31}32
33var notCharacterOrDash = '(?=[^A-Za-z\\d\\-_]|$)';34var varNames = /[\w\-:]/35var keywords = buildRegexp([36/begin|break|catch|continue|data|default|do|dynamicparam/,37/else|elseif|end|exit|filter|finally|for|foreach|from|function|if|in/,38/param|process|return|switch|throw|trap|try|until|where|while/39], { suffix: notCharacterOrDash });40
41var punctuation = /[\[\]{},;`\\\.]|@[({]/;42var wordOperators = buildRegexp([43'f',44/b?not/,45/[ic]?split/, 'join',46/is(not)?/, 'as',47/[ic]?(eq|ne|[gl][te])/,48/[ic]?(not)?(like|match|contains)/,49/[ic]?replace/,50/b?(and|or|xor)/51], { prefix: '-' });52var symbolOperators = /[+\-*\/%]=|\+\+|--|\.\.|[+\-*&^%:=!|\/]|<(?!#)|(?!#)>/;53var operators = buildRegexp([wordOperators, symbolOperators], { suffix: '' });54
55var numbers = /^((0x[\da-f]+)|((\d+\.\d+|\d\.|\.\d+|\d+)(e[\+\-]?\d+)?))[ld]?([kmgtp]b)?/i;56
57var identifiers = /^[A-Za-z\_][A-Za-z\-\_\d]*\b/;58
59var symbolBuiltins = /[A-Z]:|%|\?/i;60var namedBuiltins = buildRegexp([61/Add-(Computer|Content|History|Member|PSSnapin|Type)/,62/Checkpoint-Computer/,63/Clear-(Content|EventLog|History|Host|Item(Property)?|Variable)/,64/Compare-Object/,65/Complete-Transaction/,66/Connect-PSSession/,67/ConvertFrom-(Csv|Json|SecureString|StringData)/,68/Convert-Path/,69/ConvertTo-(Csv|Html|Json|SecureString|Xml)/,70/Copy-Item(Property)?/,71/Debug-Process/,72/Disable-(ComputerRestore|PSBreakpoint|PSRemoting|PSSessionConfiguration)/,73/Disconnect-PSSession/,74/Enable-(ComputerRestore|PSBreakpoint|PSRemoting|PSSessionConfiguration)/,75/(Enter|Exit)-PSSession/,76/Export-(Alias|Clixml|Console|Counter|Csv|FormatData|ModuleMember|PSSession)/,77/ForEach-Object/,78/Format-(Custom|List|Table|Wide)/,79new RegExp('Get-(Acl|Alias|AuthenticodeSignature|ChildItem|Command|ComputerRestorePoint|Content|ControlPanelItem|Counter|Credential'80+ '|Culture|Date|Event|EventLog|EventSubscriber|ExecutionPolicy|FormatData|Help|History|Host|HotFix|Item|ItemProperty|Job'81+ '|Location|Member|Module|PfxCertificate|Process|PSBreakpoint|PSCallStack|PSDrive|PSProvider|PSSession|PSSessionConfiguration'82+ '|PSSnapin|Random|Service|TraceSource|Transaction|TypeData|UICulture|Unique|Variable|Verb|WinEvent|WmiObject)'),83/Group-Object/,84/Import-(Alias|Clixml|Counter|Csv|LocalizedData|Module|PSSession)/,85/ImportSystemModules/,86/Invoke-(Command|Expression|History|Item|RestMethod|WebRequest|WmiMethod)/,87/Join-Path/,88/Limit-EventLog/,89/Measure-(Command|Object)/,90/Move-Item(Property)?/,91new RegExp('New-(Alias|Event|EventLog|Item(Property)?|Module|ModuleManifest|Object|PSDrive|PSSession|PSSessionConfigurationFile'92+ '|PSSessionOption|PSTransportOption|Service|TimeSpan|Variable|WebServiceProxy|WinEvent)'),93/Out-(Default|File|GridView|Host|Null|Printer|String)/,94/Pause/,95/(Pop|Push)-Location/,96/Read-Host/,97/Receive-(Job|PSSession)/,98/Register-(EngineEvent|ObjectEvent|PSSessionConfiguration|WmiEvent)/,99/Remove-(Computer|Event|EventLog|Item(Property)?|Job|Module|PSBreakpoint|PSDrive|PSSession|PSSnapin|TypeData|Variable|WmiObject)/,100/Rename-(Computer|Item(Property)?)/,101/Reset-ComputerMachinePassword/,102/Resolve-Path/,103/Restart-(Computer|Service)/,104/Restore-Computer/,105/Resume-(Job|Service)/,106/Save-Help/,107/Select-(Object|String|Xml)/,108/Send-MailMessage/,109new RegExp('Set-(Acl|Alias|AuthenticodeSignature|Content|Date|ExecutionPolicy|Item(Property)?|Location|PSBreakpoint|PSDebug' +110'|PSSessionConfiguration|Service|StrictMode|TraceSource|Variable|WmiInstance)'),111/Show-(Command|ControlPanelItem|EventLog)/,112/Sort-Object/,113/Split-Path/,114/Start-(Job|Process|Service|Sleep|Transaction|Transcript)/,115/Stop-(Computer|Job|Process|Service|Transcript)/,116/Suspend-(Job|Service)/,117/TabExpansion2/,118/Tee-Object/,119/Test-(ComputerSecureChannel|Connection|ModuleManifest|Path|PSSessionConfigurationFile)/,120/Trace-Command/,121/Unblock-File/,122/Undo-Transaction/,123/Unregister-(Event|PSSessionConfiguration)/,124/Update-(FormatData|Help|List|TypeData)/,125/Use-Transaction/,126/Wait-(Event|Job|Process)/,127/Where-Object/,128/Write-(Debug|Error|EventLog|Host|Output|Progress|Verbose|Warning)/,129/cd|help|mkdir|more|oss|prompt/,130/ac|asnp|cat|cd|chdir|clc|clear|clhy|cli|clp|cls|clv|cnsn|compare|copy|cp|cpi|cpp|cvpa|dbp|del|diff|dir|dnsn|ebp/,131/echo|epal|epcsv|epsn|erase|etsn|exsn|fc|fl|foreach|ft|fw|gal|gbp|gc|gci|gcm|gcs|gdr|ghy|gi|gjb|gl|gm|gmo|gp|gps/,132/group|gsn|gsnp|gsv|gu|gv|gwmi|h|history|icm|iex|ihy|ii|ipal|ipcsv|ipmo|ipsn|irm|ise|iwmi|iwr|kill|lp|ls|man|md/,133/measure|mi|mount|move|mp|mv|nal|ndr|ni|nmo|npssc|nsn|nv|ogv|oh|popd|ps|pushd|pwd|r|rbp|rcjb|rcsn|rd|rdr|ren|ri/,134/rjb|rm|rmdir|rmo|rni|rnp|rp|rsn|rsnp|rujb|rv|rvpa|rwmi|sajb|sal|saps|sasv|sbp|sc|select|set|shcm|si|sl|sleep|sls/,135/sort|sp|spjb|spps|spsv|start|sujb|sv|swmi|tee|trcm|type|where|wjb|write/136], { prefix: '', suffix: '' });137var variableBuiltins = buildRegexp([138/[$?^_]|Args|ConfirmPreference|ConsoleFileName|DebugPreference|Error|ErrorActionPreference|ErrorView|ExecutionContext/,139/FormatEnumerationLimit|Home|Host|Input|MaximumAliasCount|MaximumDriveCount|MaximumErrorCount|MaximumFunctionCount/,140/MaximumHistoryCount|MaximumVariableCount|MyInvocation|NestedPromptLevel|OutputEncoding|Pid|Profile|ProgressPreference/,141/PSBoundParameters|PSCommandPath|PSCulture|PSDefaultParameterValues|PSEmailServer|PSHome|PSScriptRoot|PSSessionApplicationName/,142/PSSessionConfigurationName|PSSessionOption|PSUICulture|PSVersionTable|Pwd|ShellId|StackTrace|VerbosePreference/,143/WarningPreference|WhatIfPreference/,144
145/Event|EventArgs|EventSubscriber|Sender/,146/Matches|Ofs|ForEach|LastExitCode|PSCmdlet|PSItem|PSSenderInfo|This/,147/true|false|null/148], { prefix: '\\$', suffix: '' });149
150var builtins = buildRegexp([symbolBuiltins, namedBuiltins, variableBuiltins], { suffix: notCharacterOrDash });151
152var grammar = {153keyword: keywords,154number: numbers,155operator: operators,156builtin: builtins,157punctuation: punctuation,158identifier: identifiers159};160
161// tokenizers162function tokenBase(stream, state) {163// Handle Comments164//var ch = stream.peek();165
166var parent = state.returnStack[state.returnStack.length - 1];167if (parent && parent.shouldReturnFrom(state)) {168state.tokenize = parent.tokenize;169state.returnStack.pop();170return state.tokenize(stream, state);171}172
173if (stream.eatSpace()) {174return null;175}176
177if (stream.eat('(')) {178state.bracketNesting += 1;179return 'punctuation';180}181
182if (stream.eat(')')) {183state.bracketNesting -= 1;184return 'punctuation';185}186
187for (var key in grammar) {188if (stream.match(grammar[key])) {189return key;190}191}192
193var ch = stream.next();194
195// single-quote string196if (ch === "'") {197return tokenSingleQuoteString(stream, state);198}199
200if (ch === '$') {201return tokenVariable(stream, state);202}203
204// double-quote string205if (ch === '"') {206return tokenDoubleQuoteString(stream, state);207}208
209if (ch === '<' && stream.eat('#')) {210state.tokenize = tokenComment;211return tokenComment(stream, state);212}213
214if (ch === '#') {215stream.skipToEnd();216return 'comment';217}218
219if (ch === '@') {220var quoteMatch = stream.eat(/["']/);221if (quoteMatch && stream.eol()) {222state.tokenize = tokenMultiString;223state.startQuote = quoteMatch[0];224return tokenMultiString(stream, state);225} else if (stream.eol()) {226return 'error';227} else if (stream.peek().match(/[({]/)) {228return 'punctuation';229} else if (stream.peek().match(varNames)) {230// splatted variable231return tokenVariable(stream, state);232}233}234return 'error';235}236
237function tokenSingleQuoteString(stream, state) {238var ch;239while ((ch = stream.peek()) != null) {240stream.next();241
242if (ch === "'" && !stream.eat("'")) {243state.tokenize = tokenBase;244return 'string';245}246}247
248return 'error';249}250
251function tokenDoubleQuoteString(stream, state) {252var ch;253while ((ch = stream.peek()) != null) {254if (ch === '$') {255state.tokenize = tokenStringInterpolation;256return 'string';257}258
259stream.next();260if (ch === '`') {261stream.next();262continue;263}264
265if (ch === '"' && !stream.eat('"')) {266state.tokenize = tokenBase;267return 'string';268}269}270
271return 'error';272}273
274function tokenStringInterpolation(stream, state) {275return tokenInterpolation(stream, state, tokenDoubleQuoteString);276}277
278function tokenMultiStringReturn(stream, state) {279state.tokenize = tokenMultiString;280state.startQuote = '"'281return tokenMultiString(stream, state);282}283
284function tokenHereStringInterpolation(stream, state) {285return tokenInterpolation(stream, state, tokenMultiStringReturn);286}287
288function tokenInterpolation(stream, state, parentTokenize) {289if (stream.match('$(')) {290var savedBracketNesting = state.bracketNesting;291state.returnStack.push({292/*jshint loopfunc:true */293shouldReturnFrom: function(state) {294return state.bracketNesting === savedBracketNesting;295},296tokenize: parentTokenize297});298state.tokenize = tokenBase;299state.bracketNesting += 1;300return 'punctuation';301} else {302stream.next();303state.returnStack.push({304shouldReturnFrom: function() { return true; },305tokenize: parentTokenize306});307state.tokenize = tokenVariable;308return state.tokenize(stream, state);309}310}311
312function tokenComment(stream, state) {313var maybeEnd = false, ch;314while ((ch = stream.next()) != null) {315if (maybeEnd && ch == '>') {316state.tokenize = tokenBase;317break;318}319maybeEnd = (ch === '#');320}321return 'comment';322}323
324function tokenVariable(stream, state) {325var ch = stream.peek();326if (stream.eat('{')) {327state.tokenize = tokenVariableWithBraces;328return tokenVariableWithBraces(stream, state);329} else if (ch != undefined && ch.match(varNames)) {330stream.eatWhile(varNames);331state.tokenize = tokenBase;332return 'variable-2';333} else {334state.tokenize = tokenBase;335return 'error';336}337}338
339function tokenVariableWithBraces(stream, state) {340var ch;341while ((ch = stream.next()) != null) {342if (ch === '}') {343state.tokenize = tokenBase;344break;345}346}347return 'variable-2';348}349
350function tokenMultiString(stream, state) {351var quote = state.startQuote;352if (stream.sol() && stream.match(new RegExp(quote + '@'))) {353state.tokenize = tokenBase;354}355else if (quote === '"') {356while (!stream.eol()) {357var ch = stream.peek();358if (ch === '$') {359state.tokenize = tokenHereStringInterpolation;360return 'string';361}362
363stream.next();364if (ch === '`') {365stream.next();366}367}368}369else {370stream.skipToEnd();371}372
373return 'string';374}375
376var external = {377startState: function() {378return {379returnStack: [],380bracketNesting: 0,381tokenize: tokenBase382};383},384
385token: function(stream, state) {386return state.tokenize(stream, state);387},388
389blockCommentStart: '<#',390blockCommentEnd: '#>',391lineComment: '#',392fold: 'brace'393};394return external;395});396
397CodeMirror.defineMIME('application/x-powershell', 'powershell');398});399