var words={};function define(style,dict){for(var i=0;i<dict.length;i++)words[dict[i]]=style}var commonAtoms=["true","false"],commonKeywords=["if","then","do","else","elif","while","until","for","in","esac","fi","fin","fil","done","exit","set","unset","export","function"],commonCommands=["ab","awk","bash","beep","cat","cc","cd","chown","chmod","chroot","clear","cp","curl","cut","diff","echo","find","gawk","gcc","get","git","grep","hg","kill","killall","ln","ls","make","mkdir","openssl","mv","nc","nl","node","npm","ping","ps","restart","rm","rmdir","sed","service","sh","shopt","shred","source","sort","sleep","ssh","start","stop","su","sudo","svn","tee","telnet","top","touch","vi","vim","wall","wc","wget","who","write","yes","zsh"];function tokenBase(stream,state){if(stream.eatSpace())return null;var delim,sol=stream.sol(),ch=stream.next();if("\\"===ch)return stream.next(),null;if("'"===ch||'"'===ch||"`"===ch)return state.tokens.unshift(tokenString(ch,"`"===ch?"quote":"string")),tokenize(stream,state);if("#"===ch)return sol&&stream.eat("!")?(stream.skipToEnd(),"meta"):(stream.skipToEnd(),"comment");if("$"===ch)return state.tokens.unshift(tokenDollar),tokenize(stream,state);if("+"===ch||"="===ch)return"operator";if("-"===ch)return stream.eat("-"),stream.eatWhile(/\w/),"attribute";if("<"==ch){if(stream.match("<<"))return"operator";var heredoc=stream.match(/^<-?\s*(?:['"]([^'"]*)['"]|([^'"\s]*))/);if(heredoc)return state.tokens.unshift((delim=heredoc[1]||heredoc[2],function(stream,state){return stream.sol()&&stream.string==delim&&state.tokens.shift(),stream.skipToEnd(),"string.special"})),"string.special"}if(/\d/.test(ch)&&(stream.eatWhile(/\d/),stream.eol()||!/\w/.test(stream.peek())))return"number";stream.eatWhile(/[\w-]/);var cur=stream.current();return"="===stream.peek()&&/\w+/.test(cur)?"def":words.hasOwnProperty(cur)?words[cur]:null}function tokenString(quote,style){var close="("==quote?")":"{"==quote?"}":quote;return function(stream,state){for(var next,escaped=!1;null!=(next=stream.next());){if(next===close&&!escaped){state.tokens.shift();break}if("$"===next&&!escaped&&"'"!==quote&&stream.peek()!=close){escaped=!0,stream.backUp(1),state.tokens.unshift(tokenDollar);break}if(!escaped&&quote!==close&&next===quote)return state.tokens.unshift(tokenString(quote,style)),tokenize(stream,state);if(!escaped&&/['"]/.test(next)&&!/['"]/.test(quote)){state.tokens.unshift(tokenStringStart(next,"string")),stream.backUp(1);break}escaped=!escaped&&"\\"===next}return style}}function tokenStringStart(quote,style){return function(stream,state){return state.tokens[0]=tokenString(quote,style),stream.next(),tokenize(stream,state)}}define("atom",commonAtoms),define("keyword",commonKeywords),define("builtin",commonCommands);var tokenDollar=function(stream,state){state.tokens.length>1&&stream.eat("$");var ch=stream.next();return/['"({]/.test(ch)?(state.tokens[0]=tokenString(ch,"("==ch?"quote":"{"==ch?"def":"string"),tokenize(stream,state)):(/\d/.test(ch)||stream.eatWhile(/\w/),state.tokens.shift(),"def")};function tokenize(stream,state){return(state.tokens[0]||tokenBase)(stream,state)}const shell={name:"shell",startState:function(){return{tokens:[]}},token:function(stream,state){return tokenize(stream,state)},languageData:{autocomplete:commonAtoms.concat(commonKeywords,commonCommands),closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"#"}}};export{shell};
