How to use readToken method in wpt

Best JavaScript code snippet using wpt

parsesb.js

Source:parsesb.js Github

copy

Full Screen

...85 break;case "CALL":86 current.type="CALL";87 //CALL SPRITE and CALL BG88 if(peekWord("SPRITE")||peekWord("BG")){89 readToken("word");90 current.mode=""//TODO: sprite or BG91 //regular CALL92 }else{93 current.inputs=readList(readExpression);94 if(readToken("OUT","keyword"))95 current.outputs=readList(readVariable);96 }97 //COMMON98 break;case "COMMON":99 assert(peekToken("DEF"),"COMMON without DEF");100 nextDefCommon=true;101 //DATA102 break;case "DATA":103 current.type="DATA";104 assert(current.inputs=readList(readExpression,true),"Missing list"); //should read constant expression105 //SWAP106 break;case "SWAP":107 current.type="SWAP";108 assert(current.variable=readVariable(),"Missing variable in SWAP");109 assert(readToken(","),"Missing comma in SWAP");110 assert(current.variable2=readVariable(),"Missing variable in SWAP");111 //READ112 break;case "READ":113 current.type="READ";114 assert(current.inputs=readList(readVariable,true),"Missing list");115 //DEC/INC116 break;case "DEC":117 current.type="DEC";118 assert(current.variable=readVariable(),"Missing DEC variable");119 if(readToken(","))120 assert(current.value=readExpression(),"Missing DEC amount");121 break;case "INC":122 current.type="INC";123 assert(current.variable=readVariable(),"Missing INC variable");124 if(readToken(","))125 assert(current.value=readExpression(),"Missing INC amount");126 //DEF127 break;case "DEF":128 assert(!defType,"Nested DEF");129 current.type="DEF";130 if(nextDefCommon)131 current.common=true;132 nextDefCommon=false;133 //read function name134 assert(readToken("word"),"Missing DEF name");135 current.name=word;136 //() form137 if(readToken("(")){138 defType=2;139 current.parenDef=true;140 //read argument list141 current.inputs=readList(readArgument,true);142 //read )143 assert(readToken(")"),"Missing \")\" after DEF arguments"144 );145 //subroutine/out form146 }else{147 defType=1;148 //read argument list149 current.inputs=readList(readArgument,true);150 //OUT151 //read output list152 if(readToken("OUT"))153 current.outputs=readList(readArgument,true);154 }155 startBlock();156 //VAR157 break;case "VAR":158 //assignment form159 if(peekToken("(")){160 current.type="assignment"161 readToken("(");162 assert(current.varName=readExpression(),"Missing var name");163 assert(readToken(")"),"missing )");164 //TODO - this165 while(readToken("[")){166 assert(readList(readExpression,true),"Missing array index");167 assert(readToken("]"),"Missing \"]\"");168 }169 assert(readToken("="),"missing =");170 current.value=readExpression();171 //normal form172 }else{173 current.type="DIM";174 assert(current.inputs=readList(readDeclaration),"Missing variable list");175 }176 //DIM177 break;case "DIM":178 current.type="DIM";179 assert(current.inputs=readList(readDeclaration),"Missing variable list");180 //IF, ELSEIF181 break;case "ELSEIF":182 assert(currentBlock().type=="IF"||currentBlock().type=="ELSEIF","ELSEIF without IF");183 endBlock();184 current.type="ELSEIF"185 current.condition=readExpression();186 startBlock();187 break;case "IF":188 current.type="IF"189 assert(current.condition=readExpression(),"Missing IF condition");190 assert(readToken("THEN")||readToken("GOTO"),"IF without THEN");191 //check goto vs then192 readToken("label");//optional193 startBlock();194 //END195 break;case "END":196 if(defType){197 defType=0;198 endDef();199 }else200 current.type="END";201 //EXEC/USE202 break;case "EXEC":203 current.type="EXEC";204 current.value=readExpression();205 break;case "USE":206 current.type="USE";207 current.value=readExpression();208 //FOR209 break;case "FOR":210 current.type="FOR";211 assert(current.variable=readVariable(),"Missing FOR variable");212 assert(readToken("="),"Missing = in FOR");213 current.start=readExpression();214 assert(readToken("word") && word==="TO","Missing TO in FOR");215 current.end=readExpression();216 if(readToken("word") && word==="STEP"){217 current.step=readExpression();218 }else219 readNext=0; //heck220 startBlock();221 //GOSUB GOTO RESTORE(?)222 break;case "GOSUB":223 current.type="GOSUB";224 if(readToken("label"))225 current.label=word;226 else227 assert(current.label=readExpression(),"Missing argument to GOSUB");228 break;case "GOTO":229 current.type="GOTO";230 if(readToken("label"))231 current.label=word;232 else233 assert(current.label=readExpression(),"Missing argument to GOTO");234 break;case "RESTORE":235 current.type="RESTORE";236 if(!(current.label=readToken("label")))237 assert(current.label=readExpression(),"Missing argument to RESTORE");238 //WHILE <condition>239 break;case "WHILE":240 current.type="WHILE"241 assert(current.condition=readExpression(),"Missing argument to keyword");242 startBlock();243 //UNTIL <condition>244 break;case "UNTIL":245 assert(currentBlock().type=="REPEAT","UNTIL without REPEAT");246 assert(currentBlock().condition=readExpression(),"Missing UNTIL condition");247 endBlock();248 //INPUT249 break;case "INPUT":250 current.type="INPUT";251 current.inputs=readPrintList(readExpression);252 //LINPUT253 break;case "LINPUT":254 current.type="LINPUT";255 current.inputs=readPrintList(readExpression);256 //NEXT257 break;case "NEXT":258 assert(currentBlock().type=="FOR","NEXT without FOR");259 readExpression();260 endBlock();261 //ON262 break;case "ON":263 current.type="ON"264 current.condition=readExpression();265 assert(readToken("GOTO")||readToken("GOSUB"),"ON without GOTO/GOSUB");266 current.onMode=""//GOTO or GOSUB267 assert(current.labels=readList(readExpression,true),"Missing label list after ON");268 //PRINT269 break;case "PRINT":270 current.type="PRINT"271 current.inputs=readPrintList(readExpression);272 //REM273 break;case "REM":274 do{275 next();276 }while(type!=="linebreak" && type!=="eof");;;277 //RETURN278 break;case "RETURN":279 current.type="RETURN";280 if(defType===2)281 current.value=readExpression();282 //OUT/THEN283 break;case "OUT":case "THEN":284 assert(false,"Illegal OUT/THEN");285 //other words286 break;case "word":case "(":287 //var name=text;288 readNext=readNext-1;289 var x=readVariable(true);290 if(readToken("=")){291 current.type="assignment";292 current.variable=x;293 current.value=readExpression();294 }else{295 //HORRIBLE STUPID FAKE KEYWORDS!!!296 //XON/XOFF/OPTION297 // I hate you! :(298 // not nice >:[299 switch(x){300 case "XON":301 current.type="xon";302 if(readToken("word")){303 assert(word==="MOTION"||word==="EXPAD"||word==="MIC"||word==="WIIU"||word=="COMPAT","invalid option");304 current.feature=word;305 }else{306 //what the [heck] were you THINKING!?!??!307 assert(readToken("integer"),"invalid option");308 assert(word==="3","invalid option");309 assert(readToken("word"),"invalid option");310 assert(word==="DS","invalid option");311 current.feature="3DS";312 }313 break;case "XOFF":314 current.type="xon";315 assert(readToken("word"));316 assert(word==="MOTION"||word==="EXPAD"||word==="MIC"||word=="COMPAT","invalid option");317 current.feature=word;318 break;case "OPTION":319 current.type="option";320 assert(readToken("word"),"invalid option");321 assert(word==="STRICT"||word==="DEFINT"||word==="TOOL","invalid option");322 current.option=word;323 //return to sanity, normal function call!324 break;default:325 current.type="function";326 current.name=x.name;327 current.inputs=readList(readExpression);328 if(readToken("OUT"))329 current.outputs=readList(readVariable);330 else331 current.outputs=[];332 }333 }334 //label335 break;case "label":336 current.type="label";337 current.label=word; //TODO: store label names338 //comment339 break;case "comment":340 //end341 break;case "eof":342 //line break, colon343 break;case ":":344 break;case "linebreak":345 break;default:346 assert(false,"Expected statement, got "+type);347 }348 if(current.type){349 currentBlocks[currentBlocks.length-1].code.push(current)//push to current block!350 current={}351 }352 }353 354 function currentBlock(){355 return currentBlocks[currentBlocks.length-1]356 }357 358 //check if next token is of a specific type359 function peekToken(wantedType){360 var prevType=type,prevWord=word;361 next();362 readNext=-1;363 newType=type;364 newWord=word;365 type=prevType;366 word=prevWord;367 return newType===wantedType;368 }369 //check if next token is of a specific type370 function peekWord(wantedWord){371 var prevType=type,prevWord=word;372 next();373 readNext=-1;374 newType=type;375 newWord=word;376 type=prevType;377 word=prevWord;378 return newType==="word" && newWord.trimLeft().toUpperCase()===wantedWord;379 }380 381 //Try to read a specific token382 function readToken(wantedType){383 next();384 if(type===wantedType){385 readNext=1;386 return true;387 }388 readNext=0;389 return false;390 }391 392 //Read list393 //reader: function to read item (readExpression etc.)394 //noNull: throw an error if a null value is found395 function readList(reader,noNull){396 var ret=[];397 var x=reader();398 if(x)399 ret.push(x);400 if(readToken(",","")){401 if(!x)402 ret.push(x);403 assert(x||!noNull,"Null value not allowed");404 do{405 assert(ret.push(reader())||!noNull,"Null value not allowed");406 }while(readToken(","));;;407 }408 return ret;409 }410 411 //read list of PRINT arguments412 function readPrintList(reader){413 var x=reader();414 if(!x)415 return [];416 var ret=[x];417 while(1){418 if(readToken(",")){419 ret.push(",");420 }else if(readToken(";")){421 ret.push(";");422 }else{423 return ret;424 }425 x=reader();426 if(!x)427 return ret;428 ret.push(x);429 }430 }431 432 //read normal expression433 //SHould return RPN list434 function readExpression(){435 expr=[];436 //var rpn=[],stack=[];437 //rpn parse tokens as they are read?438 if(readExpression2())439 return rpnFromExpr(expr);440 return false;441 }442 443 function prec(token){444 if(token.type==="unary"||token.type==="index")445 return Infinity446 else447 switch(token.name){448 case "*":case "/": case "DIV": case "MOD":449 return 10450 case "+":case "-":451 return 9452 case "<<":case ">>":453 return 8454 case "<":case "<=":case ">":case ">=":455 return 7456 case "==":case "!=":457 return 6458 case "AND":459 return 5460 case "XOR":461 return 4462 case "OR":463 return 3464 case "&&":465 return 2466 case "||":467 return 1468 }469 console.log(token);470 throw new Error("HECK")471 assert(false,"error prec "+token.name);472 }473 function left(token){474 return 0475 }476 477 function rpnFromExpr(expr){478 var rpn=[],stack=[];479 for(var i=0;i<expr.length;i++){480 var token=expr[i];481 switch(token.type){482 case "integer":case "float":case "string":case "variable":case "function":case "index":483 rpn.push(token);484 break;case "operator":case "unary":485 while(stack.length){486 var top=stack[stack.length-1]487 console.log(top)488 if(top.type!="("&&(prec(top)>=prec(token) || (prec(top)==prec(token) && left(token)))){489 rpn.push(stack.pop());490 }else{491 break;492 }493 }494 stack.push(token);495 break;case "(":496 stack.push(token);497 break;case ")":498 while(1){499 var top=stack[stack.length-1]500 if(top.type!="("){501 rpn.push(stack.pop());502 }else{503 break;504 }505 }506 stack.pop();507 break;default:508 assert(false,"error typ")509 }510 }511 while(stack.length){512 rpn.push(stack.pop());513 }514 return rpn;515 }516 517 function readExpression2(){518 var ret=false;519 next();520 switch(type){521 //VAR()522 case "VAR":523 readVar();524 //function or variable525 break;case "word":526 var name=word;527 if(readToken("(")){528 var x=readList(readExpression2);529 expr.push({type:"function",name:name,args:x.length});530 assert(readToken(")"),"Missing \")\" in function call");531 }else532 expr.push({type:"variable",name:name});533 //CALL()534 break;case "CALL":535 assert(readToken("("),"Bad CALL");536 //CALL537 var x=readList(readExpression2);538 expr.push({type:"call",args:x.length});539 assert(readToken(")"),"Missing \")\" in CALL()");540 ret=true;541 //number literals542 break;case "integer":case "float":543 expr.push({type:type,value:word});544 //string/label545 break;case "string":case "label":546 expr.push({type:"string",value:word});547 //operator (unary)548 break;case "unary":case "minus":549 //unary op550 expr.push({type:"unary",name:word,args:1});551 assert(readExpression2(),"Missing operator argument");552 //open parenthesis553 break;case "(":554 expr.push({type:"("});555 readExpression2();556 assert(readToken(")"),"Missing \")\"");557 expr.push({type:")"});558 //other crap559 break;default:560 readNext=0;561 return false;562 }563 //read []s564 while(readToken("[")){565 assert(x=readList(readExpression2,true),"Missing array index");566 expr.push({type:"index",args:x.length+1});567 assert(readToken("]"),"Missing \"]\"");568 }569 //read infix operators570 while(readToken("operator")||readToken("minus")){571 expr.push({type:"operator",name:word,args:2}); 572 assert(readExpression2(),"Operator missing second argument");573 }574 return true;575 }576 577 //read function definition argument578 function readArgument(){579 if(readToken("word")){580 var x=word;581 if(readToken("["))582 assert(readToken("]"),"Missing \"]\"");583 return x;584 }585 return false;586 }587 588 //read variable declaration589 function readDeclaration(){590 var ret={};591 if(readToken("word")){592 ret.name=word;593 if(readToken("[")){594 assert(ret.dims=readList(readExpression,true),"Missing array size");595 assert(readToken("]"),"Missing \"]\"");596 }else if(readToken("="))597 ret.value=readExpression();598 return ret;599 }600 return false;601 }602 603 //read function VAR()604 function readVar(){605 var ret;606 //"function" form of VAR607 if(readToken("(")){608 assert(ret=readExpression(),"Missing VAR argument");609 assert(readToken(")"),"Missing \")\" in VAR()");610 //bad VAR611 }else612 assert(false,"invalid VAR");613 return ret;614 }615 616 //keys:617 //name: [variable name expr token list]618 //indexes: [index list]619 function readVariable(noPrintVarName){620 var ret={name:"",indexes:[]};621 next();622 switch(type){623 case "VAR":624 ret.name=readVar();625 break;case "word":626 ret.name=word;627 break;default:628 readNext=0;629 return false;630 }631 while(readToken("[")){632 assert(ret.indexes.push(readList(readExpression)),"Missing index");633 assert(readToken("]"),"Missing \"]\"");634 }635 if(!ret.indexes)636 ret.indexes=undefined637 return ret;638 }639 640 //throw error with message if condition is false641 function assert(condition,message){642 if(!condition){643 console.log(message);644 var error=new Error(message);645 error.name="ParseError";646 throw error;647 } ...

Full Screen

Full Screen

module$node_modules$graphql$language$lexer.js

Source:module$node_modules$graphql$language$lexer.js Github

copy

Full Screen

1shadow$provide.module$node_modules$graphql$language$lexer = function($_blockStringValue_global$$, $process$$, $require$$, $module$$, $exports$$) {2 function $advanceLexer$$() {3 this.lastToken = this.token;4 return this.token = this.lookahead();5 }6 function $lookahead$$() {7 var $exports$$ = this.token;8 if ($exports$$.kind !== $TokenKind$$.EOF) {9 do {10 $exports$$ = $exports$$.next || ($exports$$.next = $readToken$$(this, $exports$$));11 } while ($exports$$.kind === $TokenKind$$.COMMENT);12 }13 return $exports$$;14 }15 function $Tok$$($exports$$, $require$$, $_error$$, $lookahead$$, $readToken$$, $readDigits$$, $Tok$$) {16 this.kind = $exports$$;17 this.start = $require$$;18 this.end = $_error$$;19 this.line = $lookahead$$;20 this.column = $readToken$$;21 this.value = $Tok$$;22 this.prev = $readDigits$$;23 this.next = null;24 }25 function $printCharCode$$($exports$$) {26 return isNaN($exports$$) ? $TokenKind$$.EOF : 127 > $exports$$ ? JSON.stringify(String.fromCharCode($exports$$)) : '"\\u' + ("00" + $exports$$.toString(16).toUpperCase()).slice(-4) + '"';27 }28 function $readToken$$($exports$$, $require$$) {29 var $lookahead$$ = $exports$$.source, $readToken$$ = $lookahead$$.body, $_blockStringValue_global$$ = $readToken$$.length;30 var $advanceLexer$$ = $readToken$$.length;31 for (var $col_lexer$$ = $require$$.end; $col_lexer$$ < $advanceLexer$$;) {32 var $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ = $charCodeAt$$.call($readToken$$, $col_lexer$$);33 if (9 === $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ || 32 === $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ || 44 === $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ || 65279 === $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$) {34 ++$col_lexer$$;35 } else {36 if (10 === $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$) {37 ++$col_lexer$$, ++$exports$$.line, $exports$$.lineStart = $col_lexer$$;38 } else {39 if (13 === $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$) {40 10 === $charCodeAt$$.call($readToken$$, $col_lexer$$ + 1) ? $col_lexer$$ += 2 : ++$col_lexer$$, ++$exports$$.line, $exports$$.lineStart = $col_lexer$$;41 } else {42 break;43 }44 }45 }46 }47 $advanceLexer$$ = $col_lexer$$;48 $col_lexer$$ = $exports$$.line;49 $exports$$ = 1 + $advanceLexer$$ - $exports$$.lineStart;50 if ($advanceLexer$$ >= $_blockStringValue_global$$) {51 return new $Tok$$($TokenKind$$.EOF, $_blockStringValue_global$$, $_blockStringValue_global$$, $col_lexer$$, $exports$$, $require$$);52 }53 $_blockStringValue_global$$ = $charCodeAt$$.call($readToken$$, $advanceLexer$$);54 if (32 > $_blockStringValue_global$$ && 9 !== $_blockStringValue_global$$ && 10 !== $_blockStringValue_global$$ && 13 !== $_blockStringValue_global$$) {55 throw (0, $_error$$.syntaxError)($lookahead$$, $advanceLexer$$, "Cannot contain the invalid character " + $printCharCode$$($_blockStringValue_global$$) + ".");56 }57 switch($_blockStringValue_global$$) {58 case 33:59 return new $Tok$$($TokenKind$$.BANG, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);60 case 35:61 $lookahead$$ = $lookahead$$.body;62 $_blockStringValue_global$$ = $advanceLexer$$;63 do {64 $readToken$$ = $charCodeAt$$.call($lookahead$$, ++$_blockStringValue_global$$);65 } while (null !== $readToken$$ && (31 < $readToken$$ || 9 === $readToken$$));66 return new $Tok$$($TokenKind$$.COMMENT, $advanceLexer$$, $_blockStringValue_global$$, $col_lexer$$, $exports$$, $require$$, $slice$$.call($lookahead$$, $advanceLexer$$ + 1, $_blockStringValue_global$$));67 case 36:68 return new $Tok$$($TokenKind$$.DOLLAR, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);69 case 38:70 return new $Tok$$($TokenKind$$.AMP, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);71 case 40:72 return new $Tok$$($TokenKind$$.PAREN_L, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);73 case 41:74 return new $Tok$$($TokenKind$$.PAREN_R, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);75 case 46:76 if (46 === $charCodeAt$$.call($readToken$$, $advanceLexer$$ + 1) && 46 === $charCodeAt$$.call($readToken$$, $advanceLexer$$ + 2)) {77 return new $Tok$$($TokenKind$$.SPREAD, $advanceLexer$$, $advanceLexer$$ + 3, $col_lexer$$, $exports$$, $require$$);78 }79 break;80 case 58:81 return new $Tok$$($TokenKind$$.COLON, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);82 case 61:83 return new $Tok$$($TokenKind$$.EQUALS, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);84 case 64:85 return new $Tok$$($TokenKind$$.AT, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);86 case 91:87 return new $Tok$$($TokenKind$$.BRACKET_L, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);88 case 93:89 return new $Tok$$($TokenKind$$.BRACKET_R, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);90 case 123:91 return new $Tok$$($TokenKind$$.BRACE_L, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);92 case 124:93 return new $Tok$$($TokenKind$$.PIPE, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);94 case 125:95 return new $Tok$$($TokenKind$$.BRACE_R, $advanceLexer$$, $advanceLexer$$ + 1, $col_lexer$$, $exports$$, $require$$);96 case 65:97 case 66:98 case 67:99 case 68:100 case 69:101 case 70:102 case 71:103 case 72:104 case 73:105 case 74:106 case 75:107 case 76:108 case 77:109 case 78:110 case 79:111 case 80:112 case 81:113 case 82:114 case 83:115 case 84:116 case 85:117 case 86:118 case 87:119 case 88:120 case 89:121 case 90:122 case 95:123 case 97:124 case 98:125 case 99:126 case 100:127 case 101:128 case 102:129 case 103:130 case 104:131 case 105:132 case 106:133 case 107:134 case 108:135 case 109:136 case 110:137 case 111:138 case 112:139 case 113:140 case 114:141 case 115:142 case 116:143 case 117:144 case 118:145 case 119:146 case 120:147 case 121:148 case 122:149 $lookahead$$ = $lookahead$$.body;150 $readToken$$ = $lookahead$$.length;151 $_blockStringValue_global$$ = $advanceLexer$$ + 1;152 for ($JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ = 0; $_blockStringValue_global$$ !== $readToken$$ && null !== ($JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ = $charCodeAt$$.call($lookahead$$, $_blockStringValue_global$$)) && (95 === $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ || 48 <= $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ && 153 57 >= $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ || 65 <= $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ && 90 >= $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ || 97 <= $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ && 122 >= $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$);) {154 ++$_blockStringValue_global$$;155 }156 return new $Tok$$($TokenKind$$.NAME, $advanceLexer$$, $_blockStringValue_global$$, $col_lexer$$, $exports$$, $require$$, $slice$$.call($lookahead$$, $advanceLexer$$, $_blockStringValue_global$$));157 case 45:158 case 48:159 case 49:160 case 50:161 case 51:162 case 52:163 case 53:164 case 54:165 case 55:166 case 56:167 case 57:168 $readToken$$ = $lookahead$$.body;169 $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ = $advanceLexer$$;170 var $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ = !1;171 45 === $_blockStringValue_global$$ && ($_blockStringValue_global$$ = $charCodeAt$$.call($readToken$$, ++$JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$));172 if (48 === $_blockStringValue_global$$) {173 if ($_blockStringValue_global$$ = $charCodeAt$$.call($readToken$$, ++$JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$), 48 <= $_blockStringValue_global$$ && 57 >= $_blockStringValue_global$$) {174 throw (0, $_error$$.syntaxError)($lookahead$$, $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$, "Invalid number, unexpected digit after 0: " + $printCharCode$$($_blockStringValue_global$$) + ".");175 }176 } else {177 $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ = $readDigits$$($lookahead$$, $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$, $_blockStringValue_global$$), $_blockStringValue_global$$ = $charCodeAt$$.call($readToken$$, $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$);178 }179 46 === $_blockStringValue_global$$ && ($code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ = !0, $_blockStringValue_global$$ = $charCodeAt$$.call($readToken$$, ++$JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$), $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ = $readDigits$$($lookahead$$, $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$, 180 $_blockStringValue_global$$), $_blockStringValue_global$$ = $charCodeAt$$.call($readToken$$, $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$));181 if (69 === $_blockStringValue_global$$ || 101 === $_blockStringValue_global$$) {182 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ = !0;183 $_blockStringValue_global$$ = $charCodeAt$$.call($readToken$$, ++$JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$);184 if (43 === $_blockStringValue_global$$ || 45 === $_blockStringValue_global$$) {185 $_blockStringValue_global$$ = $charCodeAt$$.call($readToken$$, ++$JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$);186 }187 $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ = $readDigits$$($lookahead$$, $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$, $_blockStringValue_global$$);188 }189 return new $Tok$$($code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ ? $TokenKind$$.FLOAT : $TokenKind$$.INT, $advanceLexer$$, $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$, $col_lexer$$, $exports$$, $require$$, $slice$$.call($readToken$$, $advanceLexer$$, $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$));190 case 34:191 if (34 === $charCodeAt$$.call($readToken$$, $advanceLexer$$ + 1) && 34 === $charCodeAt$$.call($readToken$$, $advanceLexer$$ + 2)) {192 a: {193 $readToken$$ = $lookahead$$.body;194 $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ = $_blockStringValue_global$$ = $advanceLexer$$ + 3;195 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ = 0;196 for (var $a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$ = ""; $_blockStringValue_global$$ < $readToken$$.length && null !== ($code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ = $charCodeAt$$.call($readToken$$, $_blockStringValue_global$$));) {197 if (34 === $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ && 34 === $charCodeAt$$.call($readToken$$, $_blockStringValue_global$$ + 1) && 34 === $charCodeAt$$.call($readToken$$, $_blockStringValue_global$$ + 2)) {198 $a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$ += $slice$$.call($readToken$$, $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$, $_blockStringValue_global$$);199 $require$$ = new $Tok$$($TokenKind$$.BLOCK_STRING, $advanceLexer$$, $_blockStringValue_global$$ + 3, $col_lexer$$, $exports$$, $require$$, (0, $_blockStringValue2$$.default)($a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$));200 break a;201 }202 if (32 > $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ && 9 !== $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ && 10 !== $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ && 13 !== $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$) {203 throw (0, $_error$$.syntaxError)($lookahead$$, $_blockStringValue_global$$, "Invalid character within String: " + $printCharCode$$($code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$) + ".");204 }205 92 === $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ && 34 === $charCodeAt$$.call($readToken$$, $_blockStringValue_global$$ + 1) && 34 === $charCodeAt$$.call($readToken$$, $_blockStringValue_global$$ + 2) && 34 === $charCodeAt$$.call($readToken$$, $_blockStringValue_global$$ + 3) ? ($a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$ += $slice$$.call($readToken$$, $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$, 206 $_blockStringValue_global$$) + '"""', $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ = $_blockStringValue_global$$ += 4) : ++$_blockStringValue_global$$;207 }208 throw (0, $_error$$.syntaxError)($lookahead$$, $_blockStringValue_global$$, "Unterminated string.");209 }210 return $require$$;211 }212 a: {213 $readToken$$ = $lookahead$$.body;214 $a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$ = $_blockStringValue_global$$ = $advanceLexer$$ + 1;215 $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ = 0;216 for ($code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ = ""; $_blockStringValue_global$$ < $readToken$$.length && null !== ($JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ = $charCodeAt$$.call($readToken$$, $_blockStringValue_global$$)) && 10 !== $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ && 13 !== $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$;) {217 if (34 === $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$) {218 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ += $slice$$.call($readToken$$, $a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$, $_blockStringValue_global$$);219 $require$$ = new $Tok$$($TokenKind$$.STRING, $advanceLexer$$, $_blockStringValue_global$$ + 1, $col_lexer$$, $exports$$, $require$$, $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$);220 break a;221 }222 if (32 > $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ && 9 !== $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$) {223 throw (0, $_error$$.syntaxError)($lookahead$$, $_blockStringValue_global$$, "Invalid character within String: " + $printCharCode$$($JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$) + ".");224 }225 ++$_blockStringValue_global$$;226 if (92 === $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$) {227 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ += $slice$$.call($readToken$$, $a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$, $_blockStringValue_global$$ - 1);228 $JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$ = $charCodeAt$$.call($readToken$$, $_blockStringValue_global$$);229 switch($JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$) {230 case 34:231 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ += '"';232 break;233 case 47:234 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ += "/";235 break;236 case 92:237 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ += "\\";238 break;239 case 98:240 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ += "\b";241 break;242 case 102:243 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ += "\f";244 break;245 case 110:246 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ += "\n";247 break;248 case 114:249 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ += "\r";250 break;251 case 116:252 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ += "\t";253 break;254 case 117:255 $a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$ = $charCodeAt$$.call($readToken$$, $_blockStringValue_global$$ + 1);256 var $b$$ = $charCodeAt$$.call($readToken$$, $_blockStringValue_global$$ + 2), $c$$ = $charCodeAt$$.call($readToken$$, $_blockStringValue_global$$ + 3), $d$$ = $charCodeAt$$.call($readToken$$, $_blockStringValue_global$$ + 4);257 $a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$ = $char2hex$$($a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$) << 12 | $char2hex$$($b$$) << 8 | $char2hex$$($c$$) << 4 | $char2hex$$($d$$);258 if (0 > $a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$) {259 throw (0, $_error$$.syntaxError)($lookahead$$, $_blockStringValue_global$$, "Invalid character escape sequence: " + ("\\u" + $readToken$$.slice($_blockStringValue_global$$ + 1, $_blockStringValue_global$$ + 5) + "."));260 }261 $code$jscomp$inline_121_isFloat$jscomp$inline_111_value$$ += String.fromCharCode($a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$);262 $_blockStringValue_global$$ += 4;263 break;264 default:265 throw (0, $_error$$.syntaxError)($lookahead$$, $_blockStringValue_global$$, "Invalid character escape sequence: \\" + String.fromCharCode($JSCompiler_inline_result$jscomp$10_JSCompiler_inline_result$jscomp$9_JSCompiler_temp_const$jscomp$5_prev$$) + ".");266 }267 ++$_blockStringValue_global$$;268 $a$jscomp$inline_362_charCode$jscomp$inline_134_chunkStart$jscomp$inline_131_rawValue$$ = $_blockStringValue_global$$;269 }270 }271 throw (0, $_error$$.syntaxError)($lookahead$$, $_blockStringValue_global$$, "Unterminated string.");272 }273 return $require$$;274 }275 $require$$ = (0, $_error$$.syntaxError);276 $col_lexer$$ = 39 === $_blockStringValue_global$$ ? "Unexpected single quote character ('), did you mean to use a double quote (\")?" : "Cannot parse the unexpected character " + $printCharCode$$($_blockStringValue_global$$) + ".";277 throw $require$$($lookahead$$, $advanceLexer$$, $col_lexer$$);278 }279 function $readDigits$$($exports$$, $require$$, $lookahead$$) {280 var $readToken$$ = $exports$$.body;281 if (48 <= $lookahead$$ && 57 >= $lookahead$$) {282 do {283 $lookahead$$ = $charCodeAt$$.call($readToken$$, ++$require$$);284 } while (48 <= $lookahead$$ && 57 >= $lookahead$$);285 return $require$$;286 }287 throw (0, $_error$$.syntaxError)($exports$$, $require$$, "Invalid number, expected digit but got: " + $printCharCode$$($lookahead$$) + ".");288 }289 function $char2hex$$($exports$$) {290 return 48 <= $exports$$ && 57 >= $exports$$ ? $exports$$ - 48 : 65 <= $exports$$ && 70 >= $exports$$ ? $exports$$ - 55 : 97 <= $exports$$ && 102 >= $exports$$ ? $exports$$ - 87 : -1;291 }292 Object.defineProperty($exports$$, "__esModule", {value:!0});293 $exports$$.TokenKind = void 0;294 $exports$$.createLexer = function($exports$$, $require$$) {295 var $_error$$ = new $Tok$$($TokenKind$$.SOF, 0, 0, 0, 0, null);296 return {source:$exports$$, options:$require$$, lastToken:$_error$$, token:$_error$$, line:1, lineStart:0, advance:$advanceLexer$$, lookahead:$lookahead$$};297 };298 $exports$$.getTokenDesc = function($exports$$) {299 var $require$$ = $exports$$.value;300 return $require$$ ? $exports$$.kind + ' "' + $require$$ + '"' : $exports$$.kind;301 };302 var $_error$$ = $require$$("module$node_modules$graphql$error$index"), $_blockStringValue2$$ = ($_blockStringValue_global$$ = $require$$("module$node_modules$graphql$language$blockStringValue")) && $_blockStringValue_global$$.__esModule ? $_blockStringValue_global$$ : {default:$_blockStringValue_global$$}, $TokenKind$$ = $exports$$.TokenKind = Object.freeze({SOF:"\x3cSOF\x3e", EOF:"\x3cEOF\x3e", BANG:"!", DOLLAR:"$", AMP:"\x26", PAREN_L:"(", PAREN_R:")", SPREAD:"...", COLON:":", EQUALS:"\x3d", 303 AT:"@", BRACKET_L:"[", BRACKET_R:"]", BRACE_L:"{", PIPE:"|", BRACE_R:"}", NAME:"Name", INT:"Int", FLOAT:"Float", STRING:"String", BLOCK_STRING:"BlockString", COMMENT:"Comment"}), $charCodeAt$$ = String.prototype.charCodeAt, $slice$$ = String.prototype.slice;304 $Tok$$.prototype.toJSON = $Tok$$.prototype.inspect = function() {305 return {kind:this.kind, value:this.value, line:this.line, column:this.column};306 };...

Full Screen

Full Screen

sbhighlight.js

Source:sbhighlight.js Github

copy

Full Screen

...31 break;case "CALL":32 output("keyword call");33 //CALL SPRITE and CALL BG34 if(peekWord("SPRITE")||peekWord("BG")){35 readToken("word","keyword");36 //regular CALL37 }else{38 readList(readExpression);39 if(readToken("OUT","keyword"))40 readList(readVariable);41 }42 //COMMON43 break;case "COMMON":44 output("keyword");45 assert(peekToken("DEF"),"COMMON without DEF");46 //DATA47 break;case "DATA":48 output("keyword");49 assert(readList(readExpression,true),"Missing list"); //should read constant expression50 //SWAP51 break;case "SWAP":52 output("keyword");53 assert(readVariable(),"Missing variable in SWAP");54 assert(readToken(","),"Missing comma in SWAP");55 assert(readVariable(),"Missing variable in SWAP");56 //READ57 break;case "READ":58 output("keyword");59 assert(readList(readVariable,true),"Missing list");60 //DEC/INC61 break;case "DEC":case "INC":62 output("keyword");63 assert(readVariable(),"Missing INC/DEC variable");64 if(readToken(",",""))65 assert(readExpression(),"Missing INC/DEC amount");66 //DEF67 break;case "DEF":68 output("keyword");69 //read function name70 assert(readToken("word","declaration function"),"Missing DEF name");71 //() form72 if(readToken("(","")){73 inDef=true;74 //read argument list75 readList(readArgument,true);76 //read )77 assert(readToken(")",""),"Missing \")\" after DEF arguments"78 );79 //subroutine/out form80 }else{81 //read argument list82 readList(readArgument,true);83 //OUT84 if(readToken("OUT","keyword"))85 //read output list86 readList(readArgument,true);87 }88 //VAR89 break;case "VAR":90 //assignment form91 if(peekToken("(")){92 output("var function");93 readToken("(","");94 assert(readExpression(),"Missing var name");95 assert(readToken(")",""),"missing )");96 while(readToken("[","")){97 assert(readList(readExpression,true),"Missing array index");98 assert(readToken("]",""),"Missing \"]\"");99 }100 assert(readToken("=",""),"missing =");101 readExpression();102 //normal form103 }else{104 output("keyword");105 assert(readList(readDeclaration,true),"Missing variable list");106 }107 //DIM108 break;case "DIM":109 output("keyword");110 assert(readList(readDeclaration,true),"Missing variable list");111 //IF, ELSEIF112 break;case "ELSEIF":case "IF":113 output("keyword");114 assert(readExpression(),"Missing IF condition");115 assert(readToken("THEN","keyword")||readToken("GOTO","keyword"),"IF without THEN");116 readToken("label","label");//optional117 //END118 break;case "END":119 output("keyword");120 if(inDef)121 inDef=false;122 //EXEC/USE123 break;case "EXEC":case "USE":124 output("keyword");125 readExpression();126 //FOR127 break;case "FOR":128 output("keyword");129 assert(readVariable(),"Missing FOR variable");130 assert(readToken("=",""),"Missing = in FOR");131 readExpression();132 assert(readToken("word","keyword") && word==="TO","Missing TO in FOR");133 readExpression();134 if(readToken("word") && word==="STEP"){135 output("keyword");136 readExpression();137 }else138 readNext=0; //heck139 //GOSUB GOTO RESTORE(?)140 break;case "GOSUB":case "GOTO":case "RESTORE":141 output("keyword");142 if(!readToken("label","label"))143 assert(readExpression(),"Missing argument to keyword");144 //WHILE, UNTIL145 break;case "UNTIL":case "WHILE": 146 output("keyword");147 assert(readExpression(),"Missing argument to keyword");148 //INPUT149 break;case "INPUT":150 output("keyword");151 readPrintList(readExpression);152 //LINPUT153 break;case "LINPUT":154 output("keyword");155 readPrintList(readExpression);156 //NEXT157 break;case "NEXT":158 output("keyword");159 readExpression();160 //ON161 break;case "ON":162 output("keyword");163 readExpression();164 assert(readToken("GOTO","keyword")||readToken("GOSUB","keyword"),"ON without GOTO/GOSUB");165 assert(readList(readLabel,true),"Missing label list after ON");166 //PRINT167 break;case "PRINT":168 output("keyword");169 readPrintList(readExpression);170 //REM171 break;case "REM":172 output("keyword");173 do{174 next();175 output("comment");176 }while(type!=="linebreak" && type!=="eof");;;177 //RETURN178 break;case "RETURN":179 output("keyword");180 if(inDef)181 readExpression();182 //OUT/THEN183 break;case "OUT":case "THEN":184 output("error");185 assert(false,"Illegal OUT/THEN");186 //other words187 break;case "word":case "(":188 //var name=text;189 readNext=readNext-1;190 var oldWord=word; //this is, the variable name! :D191 switch(readVariable(true)){192 case true:193 assert(readToken("=","equals"),"missing =");194 readExpression();195 break;case false:196 alert("what");197 break;default:198 if(peekToken("=")){199 output("variable");200 readToken("=","equals");201 readExpression();202 }else{203 //HORRIBLE STUPID FAKE KEYWORDS!!!204 //XON/XOFF/OPTION205 // I hate you! :(206 // not nice >:[207 switch(oldWord){208 case "XON":209 output("keyword");210 if(peekToken("word")){211 assert(newWord==="MOTION"||newWord==="EXPAD"||newWord==="MIC"||newWord==="WIIU"||newWord=="COMPAT","invalid option");212 readToken("word","keyword");213 }else{214 //what the [heck] were you THINKING!?!??!215 assert(peekToken("number"),"invalid option");216 assert(/^[ \t]*3$/.test(newText),"invalid option");217 var owo=newText;218 next();219 if(!(peekToken("word") && newWord==="DS")){220 callback(owo,"error");221 assert(false,"invalid option");222 }223 callback(owo,"keyword");224 readToken("word","keyword");225 }226 break;case "XOFF":227 output("keyword");228 assert(peekToken("word"),"invalid option");229 assert(newWord==="MOTION"||newWord==="EXPAD"||newWord==="MIC"||newWord=="COMPAT","invalid option");230 readToken("word","keyword");231 break;case "OPTION":232 output("keyword");233 assert(peekToken("word"),"invalid option");234 assert(newWord==="STRICT"||newWord==="DEFINT"||newWord==="TOOL","invalid option");235 readToken("word","keyword");236 //return to sanity, normal function call!237 break;default:238 output("function");239 readList(readExpression);240 if(readToken("OUT","keyword"))241 readList(readVariable); //------- (fence to stop people from falling off the indent cliff)242 }243 }244 }245 //label246 break;case "label":247 output("label");248 //comment249 break;case "comment":250 output("comment");251 //end252 break;case "eof":253 output("");254 return;255 //line break, colon256 break;case ":":257 output("");258 break;case "linebreak":259 output("linebreak");260 break;default:261 output("error");262 assert(false,"Expected statement, got "+type);263 }264 }catch(error){265 //normal parsing error266 if(error.name==="ParseError"){267 //read until the end of the line268 while(1){269 next();270 if(type==="linebreak"||type=="eof"){271 break;272 }273 output("error");274 }275 if(type==="linebreak")276 callback(text.slice(0,-1),"");277 else278 output("");279 //show error message280 if(showErrors)281 callback(error.message,"errormessage");282 else283 callback("","errormessage");284 if(type==="linebreak")285 output("linebreak");286 //bad error!!!287 }else{288 throw error;289 return;290 }291 }292 }293 294 //check if next token is of a specific type295 function peekToken(wantedType){296 var prevType=type,prevText=text,prevWord=word;297 next();298 readNext=-1;299 newType=type;300 newText=text;301 newWord=word;302 type=prevType;303 text=prevText;304 word=prevWord;305 return newType===wantedType;306 }307 //check if next token is of a specific type308 function peekWord(wantedWord){309 var prevType=type,prevText=text,prevWord=word;310 next();311 readNext=-1;312 newType=type;313 newText=text;314 newWord=word;315 type=prevType;316 text=prevText;317 word=prevWord;318 return newType==="word" && newWord.trimLeft().toUpperCase()===wantedWord;319 }320 321 //Try to read a specific token322 function readToken(wantedType,outputType){323 next();324 if(type===wantedType){325 readNext=1;326 if(outputType!==undefined)327 output(outputType);328 return true;329 }330 readNext=0;331 return false;332 }333 334 //Read list335 //reader: function to read item (readExpression etc.)336 //noNull: throw an error if a null value is found337 function readList(reader,noNull){338 var ret=reader();339 if(readToken(",","")){340 assert(ret||!noNull,"Null value not allowed");341 ret=1;342 do{343 assert(reader()||!noNull,"Null value not allowed");344 }while(readToken(",",""));;;345 }346 return ret;347 }348 349 //read list of PRINT arguments350 function readPrintList(reader){351 if(!reader())352 return;353 while((readToken(",","")||readToken(";",""))&&reader());354 }355 356 function readLabel(){357 return readToken("label","label");358 }359 360 //read normal expression361 function readExpression(){362 var ret=false;363 next();364 switch(type){365 //VAR()366 case "VAR":367 readVar();368 //function or variable369 break;case "word":370 if(peekToken("(")){371 output("function");372 readToken("(","");373 readList(readExpression);374 assert(readToken(")",""),"Missing \")\" in function call");375 }else376 output("variable");377 //CALL()378 break;case "CALL":379 if(peekToken("(")){380 output("function call");381 readToken("(","");382 readList(readExpression);383 assert(readToken(")",""),"Missing \")\" in CALL()");384 ret=true;385 //bad VAR386 }else{387 output("error");388 assert(false,"invalid CALL");389 }390 //literal value391 break;case "number":392 output("number");393 break;case "string":case "label":394 output("string");395 //operator (unary)396 break;case "unary":case "minus":397 output("operator");398 assert(readExpression(),"Missing operator argument");399 //open parenthesis400 break;case "(":401 output("");402 readExpression();403 assert(readToken(")",""),"Missing \")\"");404 //other crap405 break;default:406 readNext=0;407 return false;408 }409 //read []s410 while(readToken("[","")){411 assert(readList(readExpression,true),"Missing array index");412 assert(readToken("]",""),"Missing \"]\"");413 }414 //read infix operators415 while(readToken("operator","operator")||readToken("minus","operator"))416 assert(readExpression(),"Operator missing second argument");417 return true;418 }419 420 //read function definition argument421 function readArgument(){422 if(readToken("word","variable")){423 if(readToken("[",""))424 assert(readToken("]",""),"Missing \"]\"");425 return true;426 }427 return false;428 }429 430 //read variable declaration431 function readDeclaration(){432 if(readToken("word","variable")){433 if(readToken("[","")){434 assert(readList(readExpression,true),"Missing array size");435 assert(readToken("]",""),"Missing \"]\"");436 }else if(readToken("=",""))437 readExpression();438 return true;439 }440 return false;441 }442 443 //read function VAR()444 function readVar(){445 //"function" form of VAR446 if(peekToken("(")){447 output("var function");448 readToken("(","");449 assert(readExpression(),"Missing VAR argument");450 assert(readToken(")",""),"Missing \")\" in VAR()");451 //bad VAR452 }else{453 output("error");454 assert(false,"invalid VAR");455 }456 }457 458 //return values:459 // false - bad460 // true - definitely a variable461 // string - single word (could be function call or variable)462 // if true is passed to function, variable name will not be outputted when it might be a function call (for use in handling =)463 function readVariable(noPrintVarName){464 var ret=false;465 next();466 switch(type){467 case "VAR":468 readVar();469 break;case "word":470 if(!noPrintVarName){471 output("variable");472 ret=true;473 }else474 ret=text;475 break;case "(":476 output("");477 assert(readVariable(),"missing variable");478 assert(readToken(")",""),"missing )");479 ret=true;480 break;default:481 readNext=0;482 return false;483 }484 if(peekToken("[")){485 if(ret!==true && ret!==false)486 output("variable");487 while(readToken("[","")){488 assert(readList(readExpression,true),"Missing array index");489 assert(readToken("]",""),"Missing \"]\"");490 }491 ret=true;492 }493 return ret;494 }495 496 //throw error with message if condition is false497 function assert(condition,message){498 if(!condition){499 console.log(message);500 var error=new Error(message);501 error.name="ParseError";502 throw error;503 } ...

Full Screen

Full Screen

msgpack.js

Source:msgpack.js Github

copy

Full Screen

1const Buffer = require('./buffer').Buffer2module.exports = (function() {3 var __MODS__ = {};4 var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };5 var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };6 var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };7 var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };8 __DEFINE__(1578039707142, function(require, module, exports) {9 10 var BufferUtil = require('./lib/buffer-util');11 12 BufferUtil.toString = function (buffer, start, end) {13 return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength)14 .toString('utf8', start, end);15 };16 BufferUtil.fromString = function (string) {17 var buffer = Buffer.from(string);18 return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);19 };20 21 module.exports = require('./lib/msgpack');22 23 }, function(modId) {var map = {"./lib/buffer-util":1578039707143,"./lib/msgpack":1578039707144}; return __REQUIRE__(map[modId], modId); })24 __DEFINE__(1578039707143, function(require, module, exports) {25 26 27 // The given argument must be an array of Uint8Arrays.28 exports.concat = function (buffers) {29 var bufferCount = buffers.length;30 var totalLength = 0;31 for (var i=0; i<bufferCount; ++i) {32 totalLength += buffers[i].byteLength;33 }34 var output = new Uint8Array(totalLength);35 var offset = 0;36 for (var i=0; i<bufferCount; ++i) {37 var buffer = buffers[i];38 output.set(buffer, offset);39 offset += buffer.byteLength;40 }41 return output;42 };43 44 // The first argument must be a Uint8Array.45 // Start and end indices will be clamped to the range of the given Uint8Array.46 exports.subarray = function (buffer, start, end) {47 start = Math.min(Math.max(0, start), buffer.byteLength);48 return new Uint8Array(buffer.buffer,49 buffer.byteOffset + start,50 Math.min(Math.max(start, end), buffer.byteLength) - start51 );52 };53 54 }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })55 __DEFINE__(1578039707144, function(require, module, exports) {56 57 var Codec = require('./codec');58 var Paper = require('./paper');59 var encode = require('./encode');60 var decode = require('./decode');61 62 exports.encode = function (input, codec) {63 if (codec != null && !(codec instanceof Codec)) {64 throw new TypeError('Expected second argument to be a Codec, if provided.');65 }66 var encoder = new Paper(codec);67 encode(encoder, input);68 return encoder.read();69 };70 exports.decode = function (input, codec) {71 if (codec != null && !(codec instanceof Codec)) {72 throw new TypeError('Expected second argument to be a Codec, if provided.');73 }74 if (!(input instanceof Uint8Array)) {75 throw new TypeError('Expected first argument to be a Uint8Array.');76 }77 var decoder = new Paper(codec);78 decoder.setBuffer(input);79 return decode(decoder);80 };81 exports.Codec = Codec;82 83 }, function(modId) { var map = {"./codec":1578039707145,"./paper":1578039707146,"./encode":1578039707147,"./decode":1578039707149}; return __REQUIRE__(map[modId], modId); })84 __DEFINE__(1578039707145, function(require, module, exports) {85 86 function Codec() {87 if (!(this instanceof Codec)) {88 throw new TypeError('Codecs must be constructed with the "new" keyword.');89 }90 this._packers = [];91 this._packerClasses = [];92 this._unpackers = {};93 }94 Codec.prototype.register = function (etype, Class, packer, unpacker) {95 if (Array.isArray(packer)) {96 packer = join(packer);97 }98 if (Array.isArray(unpacker)) {99 unpacker = join(unpacker);100 }101 if (~~etype !== etype || !(etype >= 0 && etype < 128)) {102 throw new TypeError('Invalid extension type (must be between 0 and 127).');103 }104 if (typeof Class !== 'function') {105 throw new TypeError('Expected second argument to be a constructor function.');106 }107 this._packers.push(function (value) {108 var buffer = packer(value);109 if (!(buffer instanceof Uint8Array)) {110 throw new TypeError('Codec must return a Uint8Array (encoding "' + Class.name + '").');111 }112 return new ExtensionBuffer(buffer, etype);113 });114 this._packerClasses.push(Class);115 this._unpackers[etype] = unpacker;116 return this;117 };118 Codec.prototype._packerFor = function (value) {119 return getPacker(value.constructor, this._packerClasses, this._packers);120 };121 Codec.prototype._unpackerFor = function (etype) {122 return this._unpackers[etype];123 };124 module.exports = Codec;125 126 // This is isolated for optimization purposes.127 var getPacker = function (constructor, classes, packers) {128 for (var i=0, len=classes.length; i<len; ++i) {129 if (constructor === classes[i]) {130 return packers[i];131 }132 }133 };134 135 var join = function (filters) {136 filters = filters.slice();137 var iterator = function (value, filter) {138 return filter(value);139 };140 return function (value) {141 return filters.reduce(iterator, value);142 };143 };144 145 var ExtensionBuffer = function (buffer, etype) {146 this.buffer = buffer;147 this.etype = etype;148 };149 150 }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })151 __DEFINE__(1578039707146, function(require, module, exports) {152 153 var BufferUtil = require('./buffer-util');154 var MIN_BUFFER_SIZE = 2048;155 var MAX_BUFFER_SIZE = 65536;156 157 var Paper = function (codec) {158 this.codec = codec;159 };160 Paper.prototype.push = function (chunk) {161 var buffers = this.buffers || (this.buffers = []);162 buffers.push(chunk);163 };164 Paper.prototype.read = function () {165 this.flush();166 var buffers = this.buffers;167 if (buffers) {168 var chunk = buffers.length > 1 ? BufferUtil.concat(buffers) : buffers[0];169 buffers.length = 0;170 return chunk;171 }172 };173 Paper.prototype.flush = function () {174 if (this.start < this.offset) {175 this.push(BufferUtil.subarray(this.buffer, this.start, this.offset));176 this.start = this.offset;177 }178 };179 Paper.prototype.reserve = function (length) {180 if (!this.buffer) {181 return this.alloc(length);182 }183 var size = this.buffer.byteLength;184 // Does it need to be resized?185 if (this.offset + length > size) {186 // Flush current buffer.187 this.offset && this.flush();188 // Resize it to 2x current length.189 this.alloc(Math.max(length, Math.min(size * 2, MAX_BUFFER_SIZE)));190 }191 };192 Paper.prototype.alloc = function (length) {193 this.setBuffer(new Uint8Array(Math.max(length, MIN_BUFFER_SIZE)));194 };195 Paper.prototype.setBuffer = function (buffer) {196 this.buffer = buffer;197 this.offset = 0;198 this.start = 0;199 };200 Paper.prototype.send = function (buffer) {201 var end = this.offset + buffer.byteLength;202 if (this.buffer && end <= this.buffer.byteLength) {203 this.buffer.set(buffer, this.offset);204 this.offset = end;205 } else {206 this.flush();207 this.push(buffer);208 }209 };210 module.exports = Paper;211 212 }, function(modId) { var map = {"./buffer-util":1578039707143}; return __REQUIRE__(map[modId], modId); })213 __DEFINE__(1578039707147, function(require, module, exports) {214 215 var writeType = {};216 217 var encode = module.exports = function (encoder, value) {218 writeType[typeof value](encoder, value);219 };220 221 // Fills the writeType hash with functions that each encode values of their222 // respective types at the given Paper's offset.223 (function (write, fromString) {224 225 var float32Buffer = new Float32Array(1);226 var isFloat32 = function (num) {227 float32Buffer[0] = num;228 return float32Buffer[0] === num;229 };230 231 writeType.number = function (encoder, value) {232 var uivalue = value >>> 0;233 if (value === uivalue) {234 // positive fixint -- 0x00 - 0x7f235 // uint 8 -- 0xcc236 // uint 16 -- 0xcd237 // uint 32 -- 0xce238 uivalue <= 0x7f ? write.type(encoder, uivalue) :239 uivalue <= 0xff ? write.int8(encoder, 0xcc, uivalue) :240 uivalue <= 0xffff ? write.int16(encoder, 0xcd, uivalue) :241 write.int32(encoder, 0xce, uivalue);242 } else {243 var ivalue = value | 0;244 if (value === ivalue) {245 // negative fixint -- 0xe0 - 0xff246 // int 8 -- 0xd0247 // int 16 -- 0xd1248 // int 32 -- 0xd2249 ivalue >= -0x20 ? write.type(encoder, ivalue & 0xff) :250 ivalue >= -0x80 ? write.int8(encoder, 0xd0, ivalue) :251 ivalue >= -0x8000 ? write.int16(encoder, 0xd1, ivalue) :252 write.int32(encoder, 0xd2, ivalue);253 } else {254 isFloat32(value)255 ? write.float32(encoder, value) // float 32 -- 0xca256 : write.float64(encoder, value); // float 64 -- 0xcb257 }258 }259 };260 261 writeType.string = function (encoder, value) {262 var utf8 = fromString(value);263 var byteLength = utf8.byteLength;264 265 // fixstr -- 0xa0 - 0xbf266 // str 8 -- 0xd9267 // str 16 -- 0xda268 // str 32 -- 0xdb269 byteLength < 32 ? write.type(encoder, 0xa0 + byteLength) :270 byteLength <= 0xff ? write.int8(encoder, 0xd9, byteLength) :271 byteLength <= 0xffff ? write.int16(encoder, 0xda, byteLength) :272 write.int32(encoder, 0xdb, byteLength);273 274 encoder.send(utf8);275 };276 277 writeType.boolean = function (encoder, value) {278 // false -- 0xc2279 // true -- 0xc3280 write.type(encoder, value ? 0xc3 : 0xc2);281 };282 283 writeType.object = function (encoder, value) {284 var packer;285 if (value === null) return nil(encoder, value);286 if (Array.isArray(value)) return array(encoder, value);287 if (value instanceof Uint8Array) return bin(encoder, value);288 if (encoder.codec && (packer = encoder.codec._packerFor(value))) {289 return ext(encoder, packer(value));290 }291 map(encoder, value);292 };293 294 var nil = function (encoder) {295 // nil -- 0xc0296 write.type(encoder, 0xc0);297 };298 299 var array = function (encoder, value) {300 var length = value.length;301 302 // fixarray -- 0x90 - 0x9f303 // array 16 -- 0xdc304 // array 32 -- 0xdd305 length < 16 ? write.type(encoder, 0x90 + length) :306 length <= 0xffff ? write.int16(encoder, 0xdc, length) :307 write.int32(encoder, 0xdd, length);308 309 for (var i=0; i<length; ++i) {310 encode(encoder, value[i]);311 }312 };313 314 var bin = function (encoder, value) {315 var byteLength = value.byteLength;316 317 // bin 8 -- 0xc4318 // bin 16 -- 0xc5319 // bin 32 -- 0xc6320 byteLength <= 0xff ? write.int8(encoder, 0xc4, byteLength) :321 byteLength <= 0xffff ? write.int16(encoder, 0xc5, byteLength) :322 write.int32(encoder, 0xc6, byteLength);323 324 encoder.send(value);325 };326 327 var ext = function (encoder, value) {328 var byteLength = value.buffer.byteLength;329 330 // fixext 1 -- 0xd4331 // fixext 2 -- 0xd5332 // fixext 4 -- 0xd6333 // fixext 8 -- 0xd7334 // fixext 16 -- 0xd8335 // ext 8 -- 0xc7336 // ext 16 -- 0xc8337 // ext 32 -- 0xc9338 byteLength === 1 ? write.int8(encoder, 0xd4, value.etype) :339 byteLength === 2 ? write.int8(encoder, 0xd5, value.etype) :340 byteLength === 4 ? write.int8(encoder, 0xd6, value.etype) :341 byteLength === 8 ? write.int8(encoder, 0xd7, value.etype) :342 byteLength === 16 ? write.int8(encoder, 0xd8, value.etype) :343 byteLength <= 0xff ? (write.int8(encoder, 0xc7, byteLength), write.type(encoder, value.etype)) :344 byteLength <= 0xffff ? (write.int16(encoder, 0xc8, byteLength), write.type(encoder, value.etype)) :345 (write.int32(encoder, 0xc9, byteLength), write.type(encoder, value.etype));346 347 encoder.send(value.buffer);348 };349 350 var map = function (encoder, value) {351 var keys = Object.keys(value);352 var length = keys.length;353 354 // fixmap -- 0x80 - 0x8f355 // map 16 -- 0xde356 // map 32 -- 0xdf357 length < 16 ? write.type(encoder, 0x80 + length) :358 length <= 0xffff ? write.int16(encoder, 0xde, length) :359 write.int32(encoder, 0xdf, length);360 361 for (var i=0; i<length; ++i) {362 var key = keys[i];363 (key >>> 0) + '' === key ? encode(encoder, key >>> 0) : encode(encoder, key);364 encode(encoder, value[key]);365 }366 };367 368 writeType.undefined = nil;369 writeType.function = nil;370 writeType.symbol = nil;371 }(require('./write-header'), require('./buffer-util').fromString));372 373 }, function(modId) { var map = {"./write-header":1578039707148,"./buffer-util":1578039707143}; return __REQUIRE__(map[modId], modId); })374 __DEFINE__(1578039707148, function(require, module, exports) {375 376 377 exports.type = function (encoder, type) {378 encoder.reserve(1);379 encoder.buffer[encoder.offset++] = type;380 };381 exports.int8 = function (encoder, type, value) {382 encoder.reserve(2);383 var buffer = encoder.buffer;384 buffer[encoder.offset++] = type;385 buffer[encoder.offset++] = value;386 };387 exports.int16 = function (encoder, type, value) {388 encoder.reserve(3);389 var buffer = encoder.buffer;390 buffer[encoder.offset++] = type;391 buffer[encoder.offset++] = value >>> 8;392 buffer[encoder.offset++] = value;393 };394 exports.int32 = function (encoder, type, value) {395 encoder.reserve(5);396 var buffer = encoder.buffer;397 buffer[encoder.offset++] = type;398 buffer[encoder.offset++] = value >>> 24;399 buffer[encoder.offset++] = value >>> 16;400 buffer[encoder.offset++] = value >>> 8;401 buffer[encoder.offset++] = value;402 };403 exports.float32 = function (encoder, value) {404 encoder.reserve(5);405 var buffer = encoder.buffer;406 buffer[encoder.offset++] = 0xca;407 new DataView(buffer.buffer).setFloat32(buffer.byteOffset + encoder.offset, value);408 encoder.offset += 4;409 };410 exports.float64 = function (encoder, value) {411 encoder.reserve(9);412 var buffer = encoder.buffer;413 buffer[encoder.offset++] = 0xcb;414 new DataView(buffer.buffer).setFloat64(buffer.byteOffset + encoder.offset, value);415 encoder.offset += 8;416 };417 418 }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })419 __DEFINE__(1578039707149, function(require, module, exports) {420 421 module.exports = function (decoder) {422 var type = readUint8(decoder);423 var func = readToken[type];424 if (!func) {425 throw new Error('Invalid type: ' + (type ? ('0x' + type.toString(16)) : type));426 }427 return func(decoder);428 };429 430 // Dependencies are loaded after exporting, to satisfy the required load order.431 var readUint8 = require('./read-format').uint8;432 var readToken = new Array(256);433 434 // Fills the readToken array with functions that each return their decoded435 // interpretation of the bytes at the given Paper's offset.436 (function (read) {437 var i;438 439 // Creates a readToken function that returns a constant value.440 var constant = function (value) {441 return function () {442 return value;443 };444 };445 446 // Transforms the given method to always receive a second argument, which is447 // a number constant.448 var fix = function (len, method) {449 return function (decoder) {450 return method(decoder, len);451 };452 };453 454 // Transforms the given method to always receive a second argument, which is455 // a number returned by lenFunc when given a Paper.456 var flex = function (lenFunc, method) {457 return function (decoder) {458 return method(decoder, lenFunc(decoder));459 };460 };461 462 // positive fixint -- 0x00 - 0x7f463 for (i=0x00; i<=0x7f; ++i) {464 readToken[i] = constant(i);465 }466 467 // fixmap -- 0x80 - 0x8f468 for (i=0x80; i<=0x8f; ++i) {469 readToken[i] = fix(i - 0x80, read.map);470 }471 472 // fixarray -- 0x90 - 0x9f473 for (i=0x90; i<=0x9f; ++i) {474 readToken[i] = fix(i - 0x90, read.array);475 }476 477 // fixstr -- 0xa0 - 0xbf478 for (i=0xa0; i<=0xbf; ++i) {479 readToken[i] = fix(i - 0xa0, read.str);480 }481 482 // nil -- 0xc0483 readToken[0xc0] = constant(null);484 485 // (never used) -- 0xc1486 readToken[0xc1] = null;487 488 // false -- 0xc2489 // true -- 0xc3490 readToken[0xc2] = constant(false);491 readToken[0xc3] = constant(true);492 493 // bin 8 -- 0xc4494 // bin 16 -- 0xc5495 // bin 32 -- 0xc6496 readToken[0xc4] = flex(read.uint8, read.bin);497 readToken[0xc5] = flex(read.uint16, read.bin);498 readToken[0xc6] = flex(read.uint32, read.bin);499 500 // ext 8 -- 0xc7501 // ext 16 -- 0xc8502 // ext 32 -- 0xc9503 readToken[0xc7] = flex(read.uint8, read.ext);504 readToken[0xc8] = flex(read.uint16, read.ext);505 readToken[0xc9] = flex(read.uint32, read.ext);506 507 // float 32 -- 0xca508 // float 64 -- 0xcb509 readToken[0xca] = read.float32;510 readToken[0xcb] = read.float64;511 512 // uint 8 -- 0xcc513 // uint 16 -- 0xcd514 // uint 32 -- 0xce515 // uint 64 -- 0xcf516 readToken[0xcc] = read.uint8;517 readToken[0xcd] = read.uint16;518 readToken[0xce] = read.uint32;519 readToken[0xcf] = null;520 521 // int 8 -- 0xd0522 // int 16 -- 0xd1523 // int 32 -- 0xd2524 // int 64 -- 0xd3525 readToken[0xd0] = read.int8;526 readToken[0xd1] = read.int16;527 readToken[0xd2] = read.int32;528 readToken[0xd3] = null;529 530 // fixext 1 -- 0xd4531 // fixext 2 -- 0xd5532 // fixext 4 -- 0xd6533 // fixext 8 -- 0xd7534 // fixext 16 -- 0xd8535 readToken[0xd4] = fix(1, read.ext);536 readToken[0xd5] = fix(2, read.ext);537 readToken[0xd6] = fix(4, read.ext);538 readToken[0xd7] = fix(8, read.ext);539 readToken[0xd8] = fix(16, read.ext);540 541 // str 8 -- 0xd9542 // str 16 -- 0xda543 // str 32 -- 0xdb544 readToken[0xd9] = flex(read.uint8, read.str);545 readToken[0xda] = flex(read.uint16, read.str);546 readToken[0xdb] = flex(read.uint32, read.str);547 548 // array 16 -- 0xdc549 // array 32 -- 0xdd550 readToken[0xdc] = flex(read.uint16, read.array);551 readToken[0xdd] = flex(read.uint32, read.array);552 553 // map 16 -- 0xde554 // map 32 -- 0xdf555 readToken[0xde] = flex(read.uint16, read.map);556 readToken[0xdf] = flex(read.uint32, read.map);557 558 // negative fixint -- 0xe0 - 0xff559 for (i=0xe0; i<=0xff; ++i) {560 readToken[i] = constant(i - 0x100);561 }562 }(require('./read-format')));563 564 }, function(modId) { var map = {"./read-format":1578039707150}; return __REQUIRE__(map[modId], modId); })565 __DEFINE__(1578039707150, function(require, module, exports) {566 567 var BufferUtil = require('./buffer-util');568 var decode = require('./decode');569 570 var map = function (decoder, len) {571 var value = {};572 for (var i=0; i<len; ++i) {573 value[decode(decoder)] = decode(decoder);574 }575 return value;576 };577 578 var array = function (decoder, len) {579 var value = new Array(len);580 for (var i=0; i<len; ++i) {581 value[i] = decode(decoder);582 }583 return value;584 };585 586 var str = function (decoder, len) {587 var start = decoder.offset;588 var end = decoder.offset = start + len;589 if (end > decoder.buffer.byteLength) throw new RangeError('BUFFER_SHORTAGE');590 return BufferUtil.toString(decoder.buffer, start, end);591 };592 593 var bin = function (decoder, len) {594 var start = decoder.offset;595 var end = decoder.offset = start + len;596 if (end > decoder.buffer.byteLength) throw new RangeError('BUFFER_SHORTAGE');597 return BufferUtil.subarray(decoder.buffer, start, end);598 };599 600 var ext = function (decoder, len) {601 var start = decoder.offset;602 var end = decoder.offset = start + len + 1;603 if (end > decoder.buffer.byteLength) throw new RangeError('BUFFER_SHORTAGE');604 var etype = decoder.buffer[start];605 var unpacker;606 if (decoder.codec && (unpacker = decoder.codec._unpackerFor(etype))) {607 return unpacker(BufferUtil.subarray(decoder.buffer, start + 1, end));608 }609 throw new Error('Unrecognized extension type: ' + (etype ? ('0x' + etype.toString(16)) : etype));610 };611 612 var uint8 = function (decoder) {613 var buffer = decoder.buffer;614 if (decoder.offset >= buffer.byteLength) throw new RangeError('BUFFER_SHORTAGE');615 return buffer[decoder.offset++];616 };617 618 var uint16 = function (decoder) {619 var buffer = decoder.buffer;620 if (decoder.offset + 2 > buffer.byteLength) throw new RangeError('BUFFER_SHORTAGE');621 return (buffer[decoder.offset++] << 8) | buffer[decoder.offset++];622 };623 624 var uint32 = function (decoder) {625 var buffer = decoder.buffer;626 if (decoder.offset + 4 > buffer.byteLength) throw new RangeError('BUFFER_SHORTAGE');627 return (buffer[decoder.offset++] * 0x1000000) +628 ((buffer[decoder.offset++] << 16) |629 (buffer[decoder.offset++] << 8) |630 buffer[decoder.offset++]);631 };632 633 var int8 = function (decoder) {634 var val = uint8(decoder);635 return !(val & 0x80) ? val : (0xff - val + 1) * -1;636 };637 638 var int16 = function (decoder) {639 var val = uint16(decoder);640 return (val & 0x8000) ? val | 0xFFFF0000 : val;641 };642 643 var int32 = function (decoder) {644 var buffer = decoder.buffer;645 if (decoder.offset + 4 > buffer.byteLength) throw new RangeError('BUFFER_SHORTAGE');646 return (buffer[decoder.offset++] << 24) |647 (buffer[decoder.offset++] << 16) |648 (buffer[decoder.offset++] << 8) |649 buffer[decoder.offset++];650 };651 652 var float32 = function (decoder) {653 var buffer = decoder.buffer;654 var offset = decoder.offset;655 decoder.offset += 4;656 return new DataView(buffer.buffer).getFloat32(buffer.byteOffset + offset);657 };658 659 var float64 = function (decoder) {660 var buffer = decoder.buffer;661 var offset = decoder.offset;662 decoder.offset += 8;663 return new DataView(buffer.buffer).getFloat64(buffer.byteOffset + offset);664 };665 666 module.exports = {667 map: map,668 array: array,669 str: str,670 bin: bin,671 ext: ext,672 uint8: uint8,673 uint16: uint16,674 uint32: uint32,675 int8: int8,676 int16: int16,677 int32: int32,678 float32: float32,679 float64: float64680 };681 682 }, function(modId) { var map = {"./buffer-util":1578039707143,"./decode":1578039707149}; return __REQUIRE__(map[modId], modId); })683 return __REQUIRE__(1578039707142);684 })()...

Full Screen

Full Screen

sbhighlight3.js

Source:sbhighlight3.js Github

copy

Full Screen

...23 output("keyword");24 break;case "CALL":25 output("keyword");26 readList(readExpression);27 if(readToken("OUT","keyword"))28 readList(readVariable);29 //COMMON30 break;case "COMMON":31 output("keyword");32 assert(peekToken("DEF"),"COMMON without DEF");33 //DATA, DEC, INC, READ, SWAP34 break;case "DATA":case "READ":case "SWAP":35 output("keyword");36 assert(readList(readExpression,true),"Missing list");37 break;case "DEC":case "INC":38 output("keyword");39 assert(readVariable(),"Missing INC/DEC variable");40 if(readToken(",","separator"))41 assert(readExpression(),"Missing INC/DEC amount");42 //DEF43 break;case "DEF":44 output("keyword");45 assert(!isDef,"Nested DEF");46 isDef=true;47 //read function name48 assert(readToken("word","function"),"Missing DEF name");49 //() form50 if(readToken("(","separator")){51 //read argument list52 readList(readArgument,true);53 //read )54 assert(readToken(")","separator"),"Missing \")\" after DEF arguments"55 );56 //subroutine/out form57 }else{58 //read argument list59 readList(readArgument,true);60 //OUT61 if(readToken("OUT","keyword"))62 //read output list63 readList(readArgument,true);64 }65 //VAR66 break;case "VAR":67 output("keyword");68 //assignment form69 if(readToken("(","separator")){70 assert(readExpression(),"Missing var name");71 assert(readToken(")","separator"),"missing )")72 while(readToken("[","separator")){73 assert(readList(readExpression,true),"Missing array index");74 assert(readToken("]","separator"),"Missing \"]\"");75 }76 assert(readToken("=","separator"),"missing =")77 readExpression();78 //normal form79 }else80 assert(readList(readDeclaration,true),"Missing variable list");81 //DIM82 break;case "DIM":83 output("keyword");84 assert(readList(readDeclaration,true),"Missing variable list");85 //IF, ELSEIF86 break;case "ELSEIF":case "IF":87 output("keyword");88 assert(readExpression(),"Missing IF condition");89 assert(readToken("THEN","keyword")||readToken("GOTO","keyword"),"IF without THEN");90 readToken("label","label");//optional91 //END92 break;case "END":93 output("keyword");94 if(isDef)95 isDef=false;96 //EXEC/USE97 break;case "EXEC":case "USE":98 output("keyword");99 readExpression();100 //FOR101 break;case "FOR":102 output("keyword");103 assert(readVariable(),"Missing FOR variable");104 assert(readToken("=","separator"),"Missing = in FOR");105 readExpression();106 assert(readToken("word") && text.toUpperCase().trimLeft()==="TO","Missing TO in FOR");107 output("keyword");108 readExpression();109 if(readToken("word") && text.toUpperCase().trimLeft()==="STEP"){110 output("keyword");111 readExpression();112 }else113 readNext=0;114 //GOSUB GOTO RESTORE(?)115 break;case "GOSUB":case "GOTO":case "RESTORE":116 output("keyword");117 if(!readToken("label","label"))118 assert(readExpression(),"Missing argument to keyword");119 //WHILE, UNTIL120 break;case "UNTIL":case "WHILE": 121 output("keyword");122 assert(readExpression(),"Missing argument to keyword");123 //INPUT124 break;case "INPUT":125 output("keyword");126 readPrintList(readExpression);127 //LINPUT128 break;case "LINPUT":129 output("keyword");130 readPrintList(readExpression);131 //NEXT132 break;case "NEXT":133 output("keyword");134 readExpression();135 //ON136 break;case "ON":137 output("keyword");138 readExpression();139 assert(readToken("GOTO","keyword")||readToken("GOSUB","keyword"),"ON without GOTO/GOSUB");140 assert(readList(readExpression,true),"Missing label list after ON");141 //PRINT142 break;case "PRINT":143 output("keyword");144 readPrintList(readExpression,true);145 //REM146 break;case "REM":147 output("keyword");148 do{149 next();150 output("comment");151 }while(type!=="linebreak" && type!=="eof");;;152 //RETURN153 break;case "RETURN":154 output("keyword");155 if(isDef)156 readExpression();157 //OUT/THEN158 break;case "OUT":case "THEN":159 output("error");160 assert(false,"Illegal OUT/THEN");161 //other words162 break;case "word":case "(":163 //var name=text;164 readNext=readNext-1;165 switch(readVariable(true)){166 case true:167 assert(readToken("=","equals"),"missing =");168 readExpression();169 break;case false:170 alert("what");171 break;default:172 if(peekToken("=")){173 output("variable");174 readToken("=","equals");175 readExpression();176 }else{177 output("function");178 readList(readExpression);179 if(readToken("OUT","keyword"))180 readList(readVariable);181 }182 }183 //label184 break;case "label":185 output("label");186 //comment187 break;case "comment":188 output("comment");189 //end190 break;case "eof":191 return;192 //line break, colon193 break;case "linebreak":case ":":194 output("separator");195 //other196 break;default:197 output("error");198 assert(false,"Expected statement, got "+type);199 }200 }catch(error){201 if(error.name==="ParseError"){202 while(1){203 next();204 if(type==="linebreak"||type=="eof"){205 break;206 }207 output("error");208 }209 callback("errormessage",error.message);210 output("text"); //line break211 }else{212 alert("real actual error!!! "+error);213 return;214 }215 }216 }217 218 function peekToken(wantedType){219 var prevType=type,prevText=text;220 next();221 readNext=-1;222 newType=type;223 newText=text;224 type=prevType;225 text=prevText;226 return newType===wantedType;227 }228 229 function readToken(wantedType,outputType){ //add "output type" too!230 next();231 if(type===wantedType){232 readNext=1;233 if(outputType)234 output(outputType);235 return true;236 }237 readNext=0;238 return false;239 }240 241 function readList(reader,noNull){242 var ret=reader();243 if(readToken(",","separator")){244 assert(ret||!noNull,"Null value not allowed");245 ret=1;246 do{247 assert(reader()||!noNull,"Null value not allowed");248 }while(readToken(",","separator"));;;249 }250 return ret;251 }252 253 function readPrintList(reader){254 var ret=false;255 if(!reader())256 return;257 while((readToken(",","separator")||readToken(";","separator"))&&reader());258 }259 260 function readExpression(){261 next();262 switch(type){263 //VAR264 case "VAR":265 readVar();266 //function or variable267 break;case "word":268 if(peekToken("(")){269 output("function");270 readToken("(","separator");271 readList(readExpression);272 assert(readToken(")","separator"),"Missing \")\" in function call");273 }else{274 output("variable");275 }276 //literal value277 break;case "number":case "string":case "label":278 output(type);279 //operator (unary)280 break;case "unary":case "minus":281 output("operator");282 assert(readExpression(),"Missing operator argument");283 //open parenthesis284 break;case "(":285 output("separator");286 readExpression();287 assert(readToken(")","separator"),"Missing \")\"");288 //other crap289 break;default:290 readNext=0;291 return false;292 }293 //read []s294 while(readToken("[","separator")){295 assert(readList(readExpression,true),"Missing array index");296 assert(readToken("]","separator"),"Missing \"]\"");297 }298 //read infix operators299 while(readToken("operator","operator")||readToken("minus","operator"))300 assert(readExpression(),"Operator missing second argument");301 return true;302 }303 304 function readArgument(){305 if(readToken("word","variable")){306 if(readToken("[","separator"))307 assert(readToken("]","separator"),"Missing \"]\"");308 return true;309 }310 return false;311 }312 313 function readDeclaration(){314 if(readToken("word","variable")){315 if(readToken("[","separator")){316 assert(readList(readExpression,true),"Missing array size");317 assert(readToken("]","separator"),"Missing \"]\"");318 }else if(readToken("=","separator"))319 readExpression();320 return true;321 }322 return false;323 }324 325 function readVar(){326 //"function" form of VAR327 if(peekToken("(")){328 output("keyword");329 readToken("(","separator");330 assert(readExpression(),"Missing VAR argument");331 assert(readToken(")","separator"),"Missing \")\" in VAR()");332 ret=true;333 //bad VAR334 }else{335 output("error");336 assert(false,"invalid VAR");337 }338 }339 340 //return values:341 // false - bad342 // true - definitely a variable343 // string - single word (could be function call or variable)344 // if true is passed to function, variable name will not be outputted when it might be a function call (for use in handling =)345 function readVariable(noPrintVarName){346 var ret=false;347 next();348 switch(type){349 case "VAR":350 readVar();351 break;case "word":352 if(!noPrintVarName){353 output("variable");354 ret=true;355 }else356 ret=text;357 break;case "(":358 output("separator");359 assert(readVariable(),"missing variable");360 assert(readToken(")","separator"),"missing )");361 ret=true;362 break;default:363 readNext=0;364 return false;365 }366 if(peekToken("[")){367 if(ret!==true && ret!==false)368 output("variable");369 while(readToken("[","separator")){370 assert(readList(readExpression,true),"Missing array index");371 assert(readToken("]","separator"),"Missing \"]\"");372 }373 ret=true;374 }375 return ret;376 }377 378 function assert(value,message){379 if(!value){380 console.log(message);381 var error=new Error(message);382 error.name="ParseError";383 throw error;384 }385 } ...

Full Screen

Full Screen

parser.js

Source:parser.js Github

copy

Full Screen

...116 //SWAP117 break;case "SWAP":118 current.type="SWAP";119 assert(current.variable=readVariable(),"Missing variable in SWAP");120 assert(readToken(","),"Missing comma in SWAP");121 assert(current.variable2=readVariable(),"Missing variable in SWAP");122 //IF, ELSEIF123 break;case "ELSEIF":124 assert(currentBlock().type=="IF"||currentBlock().type=="ELSEIF","ELSEIF without IF");125 endBlock();126 current.type="ELSEIF"127 current.condition=readExpression();128 assert(readToken("THEN"),"ELSEIF without THEN");129 startBlock();130 break;case "IF":131 current.type="IF"132 assert(current.condition=readExpression(),"Missing IF condition");133 assert(readToken("THEN"),"IF without THEN");134 startBlock();135 ifThisLine=true;136 codeAfterThen=false;137 //FOR138 break;case "FOR":139 current.type="FOR";140 assert(current.variable=readVariable(),"Missing FOR variable");141 assert(readToken("="),"Missing = in FOR");142 current.start=readExpression();143 assert(readToken("word") && word==="TO","Missing TO in FOR");144 current.end=readExpression();145 if(readToken("word") && word==="STEP")146 current.step=readExpression();147 else148 readNext=0; //heck149 startBlock();150 //WHILE <condition>151 break;case "WHILE":152 current.type="WHILE"153 assert(current.condition=readExpression(),"Missing argument to keyword");154 startBlock();155 break;case "WEND":156 assert(currentBlock().type=="WHILE","WEND without WHILE");157 endBlock();158 //do/LOOP159 break;case "DO":160 current.type="DO"161 startBlock();162 break;case "LOOP":163 assert(currentBlock().type=="DO","LOOP without DO");164 endBlock();165 //UNTIL <condition>166 break;case "UNTIL":167 assert(currentBlock().type=="REPEAT","UNTIL without REPEAT");168 assert(currentBlock().condition=readExpression(),"Missing UNTIL condition");169 endBlock();170 //NEXT171 break;case "NEXT":172 assert(currentBlock().type=="FOR","NEXT without FOR");173 readExpression();174 endBlock();175 //OUT/THEN176 break;case "OUT":case "THEN":177 assert(false,"Illegal OUT/THEN");178 //other words179 break;case "word":180 //var name=text;181 readNext=readNext-1;182 var x=readVariable(true);183 if(readToken("=")){184 current.type="assignment";185 current.variable=x;186 assert(current.value=readExpression(),"Missing value in assignment");187 }else{188 current.type="function";189 current.name=x.name;190 current.inputs=readList(readExpression);191 if(readToken("OUT"))192 current.outputs=readList(readVariable);193 else194 current.outputs=[];195 }196 //comment197 break;case "comment":198 //colon NOP199 break;case ":":200 //line break, end201 break;case "eof":202 case "linebreak":203 if(ifThisLine){204 ifThisLine=false;205 if(codeAfterThen){206 endBlock();207 console.log("ended single line IF");208 }209 }210 break;default:211 assert(false,"Expected statement, got "+type+" '"+word+"'");212 }213 if(current.type){214 current.line=lineNumber;215 currentBlocks[currentBlocks.length-1].code.push(current)//push to current block!216 current={}217 }218 }219 220 function currentBlock(){221 return currentBlocks[currentBlocks.length-1]222 }223 224 //check if next token is of a specific type225 function peekToken(wantedType){226 var prevType=type,prevWord=word;227 next();228 readNext=-1;229 newType=type;230 newWord=word;231 type=prevType;232 word=prevWord;233 return newType===wantedType;234 }235 //check if next token is of a specific type236 function peekWord(wantedWord){237 var prevType=type,prevWord=word;238 next();239 readNext=-1;240 newType=type;241 newWord=word;242 type=prevType;243 word=prevWord;244 return newType==="word" && newWord.trimLeft().toUpperCase()===wantedWord;245 }246 247 //Try to read a specific token248 function readToken(wantedType){249 next();250 if(type===wantedType){251 readNext=1;252 return true;253 }254 readNext=0;255 return false;256 }257 258 //Read list259 //reader: function to read item (readExpression etc.)260 //noNull: throw an error if a null value is found261 function readList(reader){262 var ret=[];263 var x=reader();264 if(x)265 ret.push(x);266 if(readToken(",","")){267 assert(x,"Null value not allowed");268 do269 assert(ret.push(reader()),"Null value not allowed");270 while(readToken(","));;;271 }272 return ret;273 }274 275 function readList2(reader){276 var ret=[];277 var x=reader();278 if(x)279 ret.push(x);280 if(readToken(",","")&&expr.push({type:"comma"})){281 assert(x,"Null value not allowed");282 do283 assert(ret.push(reader()),"Null value not allowed");284 while(readToken(",")&&expr.push({type:"comma"}));;;285 }286 return ret;287 }288 289 //read normal expression290 //SHould return RPN list291 function readExpression(){292 expr=[];293 //var rpn=[],stack=[];294 //rpn parse tokens as they are read?295 if(readExpression2())296 return rpnFromExpr(expr);297 return false;298 }299 300 function prec(token){301 if(token.type==="unary" || token.type==="comma")302 return Infinity;303 else304 switch(token.name){305 case "^":306 return 11;307 case "*":case "/": case "\\": case "%":308 return 10;309 case "+":case "-":310 return 9;311 case "<<":case ">>":312 return 8;313 case "<":case "<=":case ">":case ">=":314 return 7;315 case "==":case "!=":316 return 6;317 case "&":318 return 5;319 case "~":320 return 4;321 case "|":322 return 3;323 case "AND":324 return 2;325 case "OR":326 return 1;327 }328 console.log(token);329 assert(false,"error prec "+token.name);330 }331 function left(token){332 return 0333 }334 335 function rpnFromExpr(expr){336 console.log({...expr},"expr");337 var rpn=[],stack=[];338 for(var i=0;i<expr.length;i++){339 var token=expr[i];340 switch(token.type){341 case "number":case "string":case "variable":case "function":case "array": //see, functions are actually pushed AFTER their arguments, so we can just send them directly to the output! :D342 rpn.push(token);343 break;case "operator":case "unary":344 while(stack.length){345 var top=stack[stack.length-1]346 //console.log(top)347 if(top.type!="("&&(prec(top)>=prec(token) || (prec(top)==prec(token) && left(token)))){348 rpn.push(stack.pop());349 }else{350 break;351 }352 }353 stack.push(token);354 break;case "comma":355 while(stack.length){356 var top=stack[stack.length-1]357 //console.log(top)358 if(top.type!="("){359 rpn.push(stack.pop());360 }else{361 break;362 }363 }364 break;case "(":365 stack.push(token);366 break;case ")":367 while(1){368 var top=stack[stack.length-1]369 if(top.type!="(")370 rpn.push(stack.pop());371 else372 break;373 }374 stack.pop();375 break;default:376 assert(false,"error typ "+token.type)377 }378 }379 while(stack.length)380 rpn.push(stack.pop());381 return rpn;382 }383 384 function readExpression2(){385 var ret=false;386 next();387 switch(type){388 //function or variable389 case "word":390 var name=word;391 if(readToken("(")){392 expr.push({type:"("}); //all we needed!393 var x=readList2(readExpression2);394 assert(readToken(")"),"Missing \")\" in function call");395 expr.push({type:")"});396 expr.push({type:"function",name:name,args:x.length});397 }else398 expr.push({type:"variable",name:name});399 //number literals400 break;case "number":401 expr.push({type:"number",value:word});402 //string/label403 break;case "string":404 expr.push({type:"string",value:word});405 //operator (unary)406 break;case "unary":case "minus":case "xor":407 //unary op408 expr.push({type:"unary",name:word,args:1});409 //expr.push({type:"("}); //actual fear410 assert(readExpression2(),"Missing operator argument");411 //expr.push({type:")"});412 413 //open parenthesis414 break;case "(":415 expr.push({type:"("});416 readExpression2();417 assert(readToken(")"),"Missing \")\"");418 expr.push({type:")"});419 break;case "[":420 expr.push({type:"("});421 var x=readList2(readExpression2);422 expr.push({type:"array",args:x.length});423 assert(readToken("]"),"Missing \"]\"");424 expr.push({type:")"});425 426 //other crap427 break;default:428 readNext=0;429 return false;430 }431 while(readToken("dot")){432 assert(readToken("word"),"Dot missing function");433 var name=word;434 assert(readToken("("),"Dot missing function");435 expr.push({type:"("}); //all we needed!436 var x=readList2(readExpression2);437 assert(readToken(")"),"Missing \")\" in function call");438 expr.push({type:")"});439 expr.push({type:"function",name:name,args:x.length+1});440 }441 //read infix operators442 //this might have to be WHILE not IF443 if(readToken("operator")||readToken("minus")||readToken("xor")){444 expr.push({type:"operator",name:word,args:2});445 assert(readExpression2(),"Operator missing second argument");446 }447 return true;448 }449 450 //read function definition argument451 function readArgument(){452 if(readToken("word"))453 return word;454 else455 return false;456 }457 458 //read variable declaration459 function readDeclaration(){460 var ret={};461 if(readToken("word")){462 ret.name=word;463 if(readToken("="))464 ret.value=readExpression();465 return ret;466 }467 return false;468 }469 470 //keys:471 //name: [variable name expr token list]472 //indexes: [index list]473 function readVariable(){474 var ret={name:""};475 next();476 return {name:word}477 switch(type){ ...

Full Screen

Full Screen

DsdiffParser.js

Source:DsdiffParser.js Github

copy

Full Screen

...16 * http://www.sonicstudio.com/pdf/dsd/DSDIFF_1.5_Spec.pdf17 */18class DsdiffParser extends BasicParser_1.BasicParser {19 async parse() {20 const header = await this.tokenizer.readToken(DsdiffToken_1.ChunkHeader64);21 if (header.chunkID !== 'FRM8')22 throw new Error('Unexpected chunk-ID');23 const type = (await this.tokenizer.readToken(FourCC_1.FourCcToken)).trim();24 switch (type) {25 case 'DSD':26 this.metadata.setFormat('container', `DSDIFF/${type}`);27 this.metadata.setFormat('lossless', true);28 return this.readFmt8Chunks(header.chunkSize - BigInt(FourCC_1.FourCcToken.len));29 default:30 throw Error(`Unsupported DSDIFF type: ${type}`);31 }32 }33 async readFmt8Chunks(remainingSize) {34 while (remainingSize >= DsdiffToken_1.ChunkHeader64.len) {35 const chunkHeader = await this.tokenizer.readToken(DsdiffToken_1.ChunkHeader64);36 // If the data is an odd number of bytes in length, a pad byte must be added at the end37 debug(`Chunk id=${chunkHeader.chunkID}`);38 await this.readData(chunkHeader);39 remainingSize -= (BigInt(DsdiffToken_1.ChunkHeader64.len) + chunkHeader.chunkSize);40 }41 }42 async readData(header) {43 debug(`Reading data of chunk[ID=${header.chunkID}, size=${header.chunkSize}]`);44 const p0 = this.tokenizer.position;45 switch (header.chunkID.trim()) {46 case 'FVER': // 3.1 FORMAT VERSION CHUNK47 const version = await this.tokenizer.readToken(Token.UINT32_LE);48 debug(`DSDIFF version=${version}`);49 break;50 case 'PROP': // 3.2 PROPERTY CHUNK51 const propType = await this.tokenizer.readToken(FourCC_1.FourCcToken);52 if (propType !== 'SND ')53 throw new Error('Unexpected PROP-chunk ID');54 await this.handleSoundPropertyChunks(header.chunkSize - BigInt(FourCC_1.FourCcToken.len));55 break;56 case 'ID3': // Unofficial ID3 tag support57 const id3_data = await this.tokenizer.readToken(new Token.Uint8ArrayType(Number(header.chunkSize)));58 const rst = strtok3.fromBuffer(id3_data);59 await new ID3v2Parser_1.ID3v2Parser().parse(this.metadata, rst, this.options);60 break;61 default:62 debug(`Ignore chunk[ID=${header.chunkID}, size=${header.chunkSize}]`);63 break;64 case 'DSD':65 this.metadata.setFormat('numberOfSamples', Number(header.chunkSize * BigInt(8) / BigInt(this.metadata.format.numberOfChannels)));66 this.metadata.setFormat('duration', this.metadata.format.numberOfSamples / this.metadata.format.sampleRate);67 break;68 }69 const remaining = header.chunkSize - BigInt(this.tokenizer.position - p0);70 if (remaining > 0) {71 debug(`After Parsing chunk, remaining ${remaining} bytes`);72 await this.tokenizer.ignore(Number(remaining));73 }74 }75 async handleSoundPropertyChunks(remainingSize) {76 debug(`Parsing sound-property-chunks, remainingSize=${remainingSize}`);77 while (remainingSize > 0) {78 const sndPropHeader = await this.tokenizer.readToken(DsdiffToken_1.ChunkHeader64);79 debug(`Sound-property-chunk[ID=${sndPropHeader.chunkID}, size=${sndPropHeader.chunkSize}]`);80 const p0 = this.tokenizer.position;81 switch (sndPropHeader.chunkID.trim()) {82 case 'FS': // 3.2.1 Sample Rate Chunk83 const sampleRate = await this.tokenizer.readToken(Token.UINT32_BE);84 this.metadata.setFormat('sampleRate', sampleRate);85 break;86 case 'CHNL': // 3.2.2 Channels Chunk87 const numChannels = await this.tokenizer.readToken(Token.UINT16_BE);88 this.metadata.setFormat('numberOfChannels', numChannels);89 await this.handleChannelChunks(sndPropHeader.chunkSize - BigInt(Token.UINT16_BE.len));90 break;91 case 'CMPR': // 3.2.3 Compression Type Chunk92 const compressionIdCode = (await this.tokenizer.readToken(FourCC_1.FourCcToken)).trim();93 const count = await this.tokenizer.readToken(Token.UINT8);94 const compressionName = await this.tokenizer.readToken(new Token.StringType(count, 'ascii'));95 if (compressionIdCode === 'DSD') {96 this.metadata.setFormat('lossless', true);97 this.metadata.setFormat('bitsPerSample', 1);98 }99 this.metadata.setFormat('codec', `${compressionIdCode} (${compressionName})`);100 break;101 case 'ABSS': // 3.2.4 Absolute Start Time Chunk102 const hours = await this.tokenizer.readToken(Token.UINT16_BE);103 const minutes = await this.tokenizer.readToken(Token.UINT8);104 const seconds = await this.tokenizer.readToken(Token.UINT8);105 const samples = await this.tokenizer.readToken(Token.UINT32_BE);106 debug(`ABSS ${hours}:${minutes}:${seconds}.${samples}`);107 break;108 case 'LSCO': // 3.2.5 Loudspeaker Configuration Chunk109 const lsConfig = await this.tokenizer.readToken(Token.UINT16_BE);110 debug(`LSCO lsConfig=${lsConfig}`);111 break;112 case 'COMT':113 default:114 debug(`Unknown sound-property-chunk[ID=${sndPropHeader.chunkID}, size=${sndPropHeader.chunkSize}]`);115 await this.tokenizer.ignore(Number(sndPropHeader.chunkSize));116 }117 const remaining = sndPropHeader.chunkSize - BigInt(this.tokenizer.position - p0);118 if (remaining > 0) {119 debug(`After Parsing sound-property-chunk ${sndPropHeader.chunkSize}, remaining ${remaining} bytes`);120 await this.tokenizer.ignore(Number(remaining));121 }122 remainingSize -= BigInt(DsdiffToken_1.ChunkHeader64.len) + sndPropHeader.chunkSize;123 debug(`Parsing sound-property-chunks, remainingSize=${remainingSize}`);124 }125 if (this.metadata.format.lossless && this.metadata.format.sampleRate && this.metadata.format.numberOfChannels && this.metadata.format.bitsPerSample) {126 const bitrate = this.metadata.format.sampleRate * this.metadata.format.numberOfChannels * this.metadata.format.bitsPerSample;127 this.metadata.setFormat('bitrate', bitrate);128 }129 }130 async handleChannelChunks(remainingSize) {131 debug(`Parsing channel-chunks, remainingSize=${remainingSize}`);132 const channels = [];133 while (remainingSize >= FourCC_1.FourCcToken.len) {134 const channelId = await this.tokenizer.readToken(FourCC_1.FourCcToken);135 debug(`Channel[ID=${channelId}]`);136 channels.push(channelId);137 remainingSize -= BigInt(FourCC_1.FourCcToken.len);138 }139 debug(`Channels: ${channels.join(', ')}`);140 return channels;141 }142} ...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1"use strict";2function type(e, t) {3 e.reserve(1), e.buffer[e.offset++] = t;4}5function int8(e, t, n) {6 e.reserve(2), e.buffer[e.offset++] = t, e.buffer[e.offset++] = n;7}8function int16(e, t, n) {9 e.reserve(3), e.buffer[e.offset++] = t, e.buffer[e.offset++] = n >>> 8, e.buffer[e.offset++] = n;10}11function int32(e, t, n) {12 e.reserve(5), e.buffer[e.offset++] = t, e.buffer[e.offset++] = n >>> 24, e.buffer[e.offset++] = n >>> 16, 13 e.buffer[e.offset++] = n >>> 8, e.buffer[e.offset++] = n;14}15function float32(e, t) {16 e.reserve(5), e.buffer[e.offset++] = 202, new DataView(e.buffer.buffer).setFloat32(e.buffer.byteOffset + e.offset, t), 17 e.offset += 4;18}19function float64(e, t) {20 e.reserve(9), e.buffer[e.offset++] = 203, new DataView(e.buffer.buffer).setFloat64(e.buffer.byteOffset + e.offset, t), 21 e.offset += 8;22}23function concat(e) {24 let t = 0;25 const n = e.length;26 for (let f = 0; f < n; ++f) t += e[f].byteLength;27 let f = 0;28 const r = new Uint8Array(t);29 for (let t = 0; t < n; ++t) {30 const n = e[t];31 r.set(n, f), f += n.byteLength;32 }33 return r;34}35function subarray(e, t, n) {36 return t = Math.min(Math.max(0, t), e.byteLength), new Uint8Array(e.buffer, e.byteOffset + t, Math.min(Math.max(t, n), e.byteLength) - t);37}38function toString(e, t, n) {39 return Buffer.from(e.buffer, e.byteOffset, e.byteLength).toString("utf8", t, n);40}41function fromString(e) {42 const t = Buffer.from(e);43 return new Uint8Array(t.buffer, t.byteOffset, t.length);44}45Object.defineProperty(exports, "__esModule", {46 value: !047});48const float32Buffer = new Float32Array(1);49function nil(e) {50 type(e, 192);51}52function isFloat32(e) {53 return float32Buffer[0] = e, float32Buffer[0] === e;54}55function bin(e, t) {56 const n = t.byteLength;57 n <= 255 ? int8(e, 196, n) : n <= 65535 ? int16(e, 197, n) : int32(e, 198, n), e.send(t);58}59function array(e, t) {60 const n = t.length;61 n < 16 ? type(e, 144 + n) : n <= 65535 ? int16(e, 220, n) : int32(e, 221, n);62 for (let f = 0; f < n; ++f) encodeFn(e, t[f]);63}64function map(e, t) {65 const n = Object.keys(t), f = n.length;66 f < 16 ? type(e, 128 + f) : f <= 65535 ? int16(e, 222, f) : int32(e, 223, f);67 for (let r = 0; r < f; ++r) {68 const f = n[r], o = f >>> 0;69 encodeFn(e, o + "" === f ? o : f), encodeFn(e, t[f]);70 }71}72function number(e, t) {73 const n = t >>> 0;74 if (t === n) n <= 127 ? type(e, n) : n <= 255 ? int8(e, 204, n) : n <= 65535 ? int16(e, 205, n) : int32(e, 206, n); else {75 const n = 0 | t;76 t === n ? n >= -32 ? type(e, 255 & n) : n >= -128 ? int8(e, 208, n) : n >= -32768 ? int16(e, 209, n) : int32(e, 210, n) : isFloat32(t) ? float32(e, t) : float64(e, t);77 }78}79function string(e, t) {80 const n = fromString(t), f = n.byteLength;81 f < 32 ? type(e, 160 + f) : f <= 255 ? int8(e, 217, f) : f <= 65535 ? int16(e, 218, f) : int32(e, 219, f), 82 e.send(n);83}84function object(e, t) {85 return null === t ? nil(e) : Array.isArray(t) ? array(e, t) : t instanceof Uint8Array ? bin(e, t) : void map(e, t);86}87function boolean(e, t) {88 type(e, t ? 195 : 194);89}90const encodingFunctions = {91 number: number,92 object: object,93 string: string,94 boolean: boolean,95 symbol: nil,96 function: nil,97 undefined: nil98};99function encodeFn(e, t) {100 encodingFunctions[typeof t](e, t);101}102function map$1(e, t) {103 const n = {};104 for (let f = 0; f < t; ++f) n[decodeFn(e)] = decodeFn(e);105 return n;106}107function array$1(e, t) {108 const n = new Array(t);109 for (let f = 0; f < t; ++f) n[f] = decodeFn(e);110 return n;111}112function str(e, t) {113 const n = e.offset, f = e.offset = n + t;114 return toString(e.buffer, n, f);115}116function bin$1(e, t) {117 const n = e.offset, f = e.offset = n + t;118 return subarray(e.buffer, n, f);119}120function uint8(e) {121 return e.buffer[e.offset++];122}123function uint16(e) {124 const t = e.buffer;125 return t[e.offset++] << 8 | t[e.offset++];126}127function uint32(e) {128 const t = e.buffer;129 return 16777216 * t[e.offset++] + (t[e.offset++] << 16 | t[e.offset++] << 8 | t[e.offset++]);130}131function int8$1(e) {132 const t = uint8(e);133 return 128 & t ? -1 * (255 - t + 1) : t;134}135function int16$1(e) {136 const t = uint16(e);137 return 32768 & t ? 4294901760 | t : t;138}139function int32$1(e) {140 const t = e.buffer;141 return t[e.offset++] << 24 | t[e.offset++] << 16 | t[e.offset++] << 8 | t[e.offset++];142}143function float32$1(e) {144 const t = e.buffer, n = e.offset;145 return e.offset += 4, new DataView(t.buffer).getFloat32(t.byteOffset + n);146}147function float64$1(e) {148 const t = e.buffer, n = e.offset;149 return e.offset += 8, new DataView(t.buffer).getFloat64(t.byteOffset + n);150}151const readToken = new Array(256);152function fix(e, t) {153 return n => t(n, e);154}155function flex(e, t) {156 return n => t(n, e(n));157}158function constant(e) {159 return () => e;160}161let i;162for (i = 0; i <= 127; ++i) readToken[i] = constant(i);163for (i = 128; i <= 143; ++i) readToken[i] = fix(i - 128, map$1);164for (i = 144; i <= 159; ++i) readToken[i] = fix(i - 144, array$1);165for (i = 160; i <= 191; ++i) readToken[i] = fix(i - 160, str);166for (readToken[192] = constant(null), readToken[193] = null, readToken[194] = constant(!1), 167readToken[195] = constant(!0), readToken[196] = flex(uint8, bin$1), readToken[197] = flex(uint16, bin$1), 168readToken[198] = flex(uint32, bin$1), readToken[202] = float32$1, readToken[203] = float64$1, 169readToken[204] = uint8, readToken[205] = uint16, readToken[206] = uint32, readToken[207] = null, 170readToken[208] = int8$1, readToken[209] = int16$1, readToken[210] = int32$1, readToken[211] = null, 171readToken[217] = flex(uint8, str), readToken[218] = flex(uint16, str), readToken[219] = flex(uint32, str), 172readToken[220] = flex(uint16, array$1), readToken[221] = flex(uint32, array$1), 173readToken[222] = flex(uint16, map$1), readToken[223] = flex(uint32, map$1), i = 224; i <= 255; ++i) readToken[i] = constant(i - 256);174function decodeFn(e) {175 return readToken[uint8(e)](e);176}177const MIN_BUFFER_SIZE = 2048, MAX_BUFFER_SIZE = 65536;178class BufferHolder {179 constructor() {180 this.start = 0, this.offset = 0, this.buffers = [];181 }182 setBuffer(e) {183 this.start = 0, this.offset = 0, this.buffer = e;184 }185 alloc(e) {186 this.setBuffer(new Uint8Array(Math.max(e, MIN_BUFFER_SIZE)));187 }188 push(e) {189 this.buffers.push(e);190 }191 reserve(e) {192 if (!this.buffer) return this.alloc(e);193 const t = this.buffer.byteLength;194 this.offset + e > t && (this.offset && this.flush(), this.alloc(Math.max(e, Math.min(2 * t, MAX_BUFFER_SIZE))));195 }196 read() {197 this.flush();198 const e = this.buffers.length;199 if (e) {200 const t = e > 1 ? concat(this.buffers) : this.buffers[0];201 return this.buffers.length = 0, t;202 }203 }204 flush() {205 this.start < this.offset && (this.push(subarray(this.buffer, this.start, this.offset)), 206 this.start = this.offset);207 }208 send(e) {209 const t = this.offset + e.byteLength;210 this.buffer && t <= this.buffer.byteLength ? (this.buffer.set(e, this.offset), this.offset = t) : (this.flush(), 211 this.push(e));212 }213}214const encoder = new BufferHolder(), decoder = new BufferHolder();215function encode(e) {216 return encodeFn(encoder, e), encoder.read();217}218function decode(e) {219 return decoder.setBuffer(e), decodeFn(decoder);220}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoken = require('wptoken');2var token = wptoken.readToken('test.txt');3console.log(token);4var wptoken = require('wptoken');5wptoken.writeToken('test.txt', 'token');6var wptoken = require('wptoken');7var token = wptoken.readToken('test.txt');8console.log(token);9var wptoken = require('wptoken');10var token = wptoken.readToken('test.txt');11console.log(token);12var wptoken = require('wptoken');13var token = wptoken.readToken('test.txt');14console.log(token);15var wptoken = require('wptoken');16var token = wptoken.readToken('test.txt');17console.log(token);18var wptoken = require('wptoken');19var token = wptoken.readToken('test.txt');20console.log(token);21var wptoken = require('wptoken');22var token = wptoken.readToken('test.txt');23console.log(token);24var wptoken = require('wptoken');25var token = wptoken.readToken('test.txt');26console.log(token);27var wptoken = require('wptoken');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');3wpt.readToken(function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log('Token: ' + data.token);8 }9});10var wpt = require('wpt');11var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');12 if (err) {13 console.log('Error: ' + err);14 } else {15 console.log('Test ID: ' + data.data.testId);16 }17});18var wpt = require('wpt');19var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');20wpt.getTestResults('140605_6E_1C1', function(err, data) {21 if (err) {22 console.log('Error: ' + err);23 } else {24 console.log('First View: ' + data.data.average.firstView.loadTime);25 }26});27var wpt = require('wpt');28var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');29wpt.getLocations(function(err, data) {30 if (err) {31 console.log('Error: ' + err);32 } else {33 console.log('Locations: ' + data.data.locations);34 }35});36var wpt = require('wpt');37var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');38wpt.getTesters(function(err, data) {39 if (err) {40 console.log('Error: ' + err);41 } else {42 console.log('Testers: ' + data.data.testers);43 }44});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoken = require('./wptoken');2wptoken.readToken();3module.exports = {4 readToken: function() {5 }6}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var token = wpt.readToken();3console.log('token is: ' + token);4exports.readToken = function() {5 var token = fs.readFileSync('token.txt', 'utf8');6 return token;7};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful