How to use AtKeywordToken method in Playwright Internal

Best JavaScript code snippet using playwright-internal

vimtokenizer.js

Source:vimtokenizer.js Github

copy

Full Screen

...346 break;347 case "at-keyword":348 if (code == 0x2d) {349 if (namestartchar(next()))350 create(new AtKeywordToken(0x2d)) && switchto('at-keyword-rest');351 else if (next(1) == 0x5c && !badescape(next(2)))352 create(new AtKeywordtoken(0x2d)) && switchto('at-keyword-rest');353 else354 parseerror() && emit(new DelimToken(0x40)) && switchto('data') && reconsume();355 } else if (namestartchar(code))356 create(new AtKeywordToken(code)) && switchto('at-keyword-rest');357 else if (code == 0x5c) {358 if (badescape(next()))359 parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();360 else361 create(new AtKeywordToken(consumeEscape())) && switchto('at-keyword-rest');362 } else363 emit(new DelimToken(0x40)) && switchto('data') && reconsume();364 break;365 case "at-keyword-rest":366 if (namechar(code))367 currtoken.append(code);368 else if (code == 0x5c) {369 if (badescape(next()))370 parseerror() && emit() && switchto("data") && reconsume();371 else372 currtoken.append(consumeEscape());373 } else374 emit() && switchto('data') && reconsume();375 break;376 case "ident":377 if (code == 0x2d) {378 if (namestartchar(next()))379 create(new IdentifierToken(code)) && switchto('ident-rest');380 else if (next(1) == 0x5c && !badescape(next(2)))381 create(new IdentifierToken(code)) && switchto('ident-rest');382 else383 emit(new DelimToken(0x2d)) && switchto('data');384 } else if (namestartchar(code))385 create(new IdentifierToken(code)) && switchto('ident-rest');386 else if (code == 0x5c) {387 if (badescape(next()))388 parseerror() && switchto("data") && reconsume();389 else390 create(new IdentifierToken(consumeEscape())) && switchto('ident-rest');391 } else392 catchfire("Hit the generic 'else' clause in ident state.") && switchto('data') && reconsume();393 break;394 case "ident-rest":395 if (namechar(code))396 currtoken.append(code);397 else if (code == 0x5c) {398 if (badescape(next()))399 parseerror() && emit() && switchto("data") && reconsume();400 else401 currtoken.append(consumeEscape());402 } else if (code == 0x28) {403 if (currtoken.ASCIImatch('url'))404 switchto('url');405 else406 emit(new FunctionToken(currtoken)) && switchto('data');407 } else if (whitespace(code) && options.transformFunctionWhitespace)408 switchto('transform-function-whitespace') && reconsume();409 else410 emit() && switchto('data') && reconsume();411 break;412 case "transform-function-whitespace":413 if (whitespace(next()))414 donothing();415 else if (code == 0x28)416 emit(new FunctionToken(currtoken)) && switchto('data');417 else418 emit() && switchto('data') && reconsume();419 break;420 case "number":421 create(new NumberToken());422 if (code == 0x2d) {423 if (digit(next()))424 consume() && currtoken.append([0x2d, code]) && switchto('number-rest');425 else if (next(1) == 0x2e && digit(next(2)))426 consume(2) && currtoken.append([0x2d, 0x2e, code]) && switchto('number-fraction');427 else428 switchto('data') && reconsume();429 } else if (code == 0x2b) {430 if (digit(next()))431 consume() && currtoken.append([0x2b, code]) && switchto('number-rest');432 else if (next(1) == 0x2e && digit(next(2)))433 consume(2) && currtoken.append([0x2b, 0x2e, code]) && switchto('number-fraction');434 else435 switchto('data') && reconsume();436 } else if (digit(code))437 currtoken.append(code) && switchto('number-rest');438 else if (code == 0x2e) {439 if (digit(next()))440 consume() && currtoken.append([0x2e, code]) && switchto('number-fraction');441 else442 switchto('data') && reconsume();443 } else444 switchto('data') && reconsume();445 break;446 case "number-rest":447 if (digit(code))448 currtoken.append(code);449 else if (code == 0x2e) {450 if (digit(next()))451 consume() && currtoken.append([0x2e, code]) && switchto('number-fraction');452 else453 emit() && switchto('data') && reconsume();454 } else if (code == 0x25)455 emit(new PercentageToken(currtoken)) && switchto('data');456 else if (code == 0x45 || code == 0x65) {457 if (digit(next()))458 consume() && currtoken.append([0x25, code]) && switchto('sci-notation');459 else if ((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2)))460 currtoken.append([0x25, next(1), next(2)]) && consume(2) && switchto('sci-notation');461 else462 create(new DimensionToken(currtoken, code)) && switchto('dimension');463 } else if (code == 0x2d) {464 if (namestartchar(next()))465 consume() && create(new DimensionToken(currtoken, [0x2d, code])) && switchto('dimension');466 else if (next(1) == 0x5c && badescape(next(2)))467 parseerror() && emit() && switchto('data') && reconsume();468 else if (next(1) == 0x5c)469 consume() && create(new DimensionToken(currtoken, [0x2d, consumeEscape()])) && switchto('dimension');470 else471 emit() && switchto('data') && reconsume();472 } else if (namestartchar(code))473 create(new DimensionToken(currtoken, code)) && switchto('dimension');474 else if (code == 0x5c) {475 if (badescape(next))476 parseerror() && emit() && switchto('data') && reconsume();477 else478 create(new DimensionToken(currtoken, consumeEscape)) && switchto('dimension');479 } else480 emit() && switchto('data') && reconsume();481 break;482 case "number-fraction":483 currtoken.type = "number";484 if (digit(code))485 currtoken.append(code);486 else if (code == 0x25)487 emit(new PercentageToken(currtoken)) && switchto('data');488 else if (code == 0x45 || code == 0x65) {489 if (digit(next()))490 consume() && currtoken.append([0x65, code]) && switchto('sci-notation');491 else if ((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2)))492 currtoken.append([0x65, next(1), next(2)]) && consume(2) && switchto('sci-notation');493 else494 create(new DimensionToken(currtoken, code)) && switchto('dimension');495 } else if (code == 0x2d) {496 if (namestartchar(next()))497 consume() && create(new DimensionToken(currtoken, [0x2d, code])) && switchto('dimension');498 else if (next(1) == 0x5c && badescape(next(2)))499 parseerror() && emit() && switchto('data') && reconsume();500 else if (next(1) == 0x5c)501 consume() && create(new DimensionToken(currtoken, [0x2d, consumeEscape()])) && switchto('dimension');502 else503 emit() && switchto('data') && reconsume();504 } else if (namestartchar(code))505 create(new DimensionToken(currtoken, code)) && switchto('dimension');506 else if (code == 0x5c) {507 if (badescape(next))508 parseerror() && emit() && switchto('data') && reconsume();509 else510 create(new DimensionToken(currtoken, consumeEscape())) && switchto('dimension');511 } else512 emit() && switchto('data') && reconsume();513 break;514 case "dimension":515 if (namechar(code))516 currtoken.append(code);517 else if (code == 0x5c) {518 if (badescape(next()))519 parseerror() && emit() && switchto('data') && reconsume();520 else521 currtoken.append(consumeEscape());522 } else523 emit() && switchto('data') && reconsume();524 break;525 case "sci-notation":526 currtoken.type = "number";527 if (digit(code))528 currtoken.append(code);529 else530 emit() && switchto('data') && reconsume();531 break;532 case "url":533 if (eof())534 parseerror() && emit(new BadURLToken) && switchto('data');535 else if (code == 0x22)536 switchto('url-double-quote');537 else if (code == 0x27)538 switchto('url-single-quote');539 else if (code == 0x29)540 emit(new URLToken) && switchto('data');541 else if (whitespace(code))542 donothing();543 else544 switchto('url-unquoted') && reconsume();545 break;546 case "url-double-quote":547 if (!( currtoken instanceof URLToken))548 create(new URLToken);549 if (eof())550 parseerror() && emit(new BadURLToken) && switchto('data');551 else if (code == 0x22)552 switchto('url-end');553 else if (newline(code))554 parseerror() && switchto('bad-url');555 else if (code == 0x5c) {556 if (newline(next()))557 consume();558 else if (badescape(next()))559 parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();560 else561 currtoken.append(consumeEscape());562 } else563 currtoken.append(code);564 break;565 case "url-single-quote":566 if (!( currtoken instanceof URLToken))567 create(new URLToken);568 if (eof())569 parseerror() && emit(new BadURLToken) && switchto('data');570 else if (code == 0x27)571 switchto('url-end');572 else if (newline(code))573 parseerror() && switchto('bad-url');574 else if (code == 0x5c) {575 if (newline(next()))576 consume();577 else if (badescape(next()))578 parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();579 else580 currtoken.append(consumeEscape());581 } else582 currtoken.append(code);583 break;584 case "url-end":585 if (eof())586 parseerror() && emit(new BadURLToken) && switchto('data');587 else if (whitespace(code))588 donothing();589 else if (code == 0x29)590 emit() && switchto('data');591 else592 parseerror() && switchto('bad-url') && reconsume();593 break;594 case "url-unquoted":595 if (!( currtoken instanceof URLToken))596 create(new URLToken);597 if (eof())598 parseerror() && emit(new BadURLToken) && switchto('data');599 else if (whitespace(code))600 switchto('url-end');601 else if (code == 0x29)602 emit() && switchto('data');603 else if (code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code))604 parseerror() && switchto('bad-url');605 else if (code == 0x5c) {606 if (badescape(next()))607 parseerror() && switchto('bad-url');608 else609 currtoken.append(consumeEscape());610 } else611 currtoken.append(code);612 break;613 case "bad-url":614 if (eof())615 parseerror() && emit(new BadURLToken) && switchto('data');616 else if (code == 0x29)617 emit(new BadURLToken) && switchto('data');618 else if (code == 0x5c) {619 if (badescape(next()))620 donothing();621 else622 consumeEscape();623 } else624 donothing();625 break;626 case "unicode-range":627 // We already know that the current code is a hexdigit.628 var start = [code], end = [code];629 for (var total = 1; total < 6; total++) {630 if (hexdigit(next())) {631 consume();632 start.push(code);633 end.push(code);634 } else635 break;636 }637 if (next() == 0x3f) {638 for (; total < 6; total++) {639 if (next() == 0x3f) {640 consume();641 start.push("0".charCodeAt(0));642 end.push("f".charCodeAt(0));643 } else644 break;645 }646 emit(new UnicodeRangeToken(start, end)) && switchto('data');647 } else if (next(1) == 0x2d && hexdigit(next(2))) {648 consume();649 consume();650 end = [code];651 for (var total = 1; total < 6; total++) {652 if (hexdigit(next())) {653 consume();654 end.push(code);655 } else656 break;657 }658 emit(new UnicodeRangeToken(start, end)) && switchto('data');659 } else660 emit(new UnicodeRangeToken(start)) && switchto('data');661 break;662 default:663 catchfire("Unknown state '" + state + "'");664 }665 }666 }667 function stringFromCodeArray(arr) {668 return String.fromCharCode.apply(null, arr.filter(function(e) {669 return e;670 }));671 }672 function CSSParserToken(options) {673 return this;674 }675 CSSParserToken.prototype.finish = function() {676 return this;677 }678 CSSParserToken.prototype.toString = function() {679 return this.tokenType;680 }681 CSSParserToken.prototype.toSourceString = CSSParserToken.prototype.toString;682 CSSParserToken.prototype.toJSON = function() {683 return this.toString();684 }685 function BadStringToken() {686 return this;687 }688 BadStringToken.prototype = new CSSParserToken;689 BadStringToken.prototype.tokenType = "BADSTRING";690 function BadURLToken() {691 return this;692 }693 BadURLToken.prototype = new CSSParserToken;694 BadURLToken.prototype.tokenType = "BADURL";695 function WhitespaceToken() {696 return this;697 }698 WhitespaceToken.prototype = new CSSParserToken;699 WhitespaceToken.prototype.tokenType = "WHITESPACE";700 WhitespaceToken.prototype.toString = function() {701 return "WS";702 }703 WhitespaceToken.prototype.toSourceString = function() {704 return " ";705 }706 function CDOToken() {707 return this;708 }709 CDOToken.prototype = new CSSParserToken;710 CDOToken.prototype.tokenType = "CDO";711 function CDCToken() {712 return this;713 }714 CDCToken.prototype = new CSSParserToken;715 CDCToken.prototype.tokenType = "CDC";716 function ColonToken() {717 return this;718 }719 ColonToken.prototype = new CSSParserToken;720 ColonToken.prototype.tokenType = ":";721 function SemicolonToken() {722 return this;723 }724 SemicolonToken.prototype = new CSSParserToken;725 SemicolonToken.prototype.tokenType = ";";726 function OpenCurlyToken() {727 return this;728 }729 OpenCurlyToken.prototype = new CSSParserToken;730 OpenCurlyToken.prototype.tokenType = "{";731 function CloseCurlyToken() {732 return this;733 }734 CloseCurlyToken.prototype = new CSSParserToken;735 CloseCurlyToken.prototype.tokenType = "}";736 function OpenSquareToken() {737 return this;738 }739 OpenSquareToken.prototype = new CSSParserToken;740 OpenSquareToken.prototype.tokenType = "[";741 function CloseSquareToken() {742 return this;743 }744 CloseSquareToken.prototype = new CSSParserToken;745 CloseSquareToken.prototype.tokenType = "]";746 function OpenParenToken() {747 return this;748 }749 OpenParenToken.prototype = new CSSParserToken;750 OpenParenToken.prototype.tokenType = "(";751 function CloseParenToken() {752 return this;753 }754 CloseParenToken.prototype = new CSSParserToken;755 CloseParenToken.prototype.tokenType = ")";756 function EOFToken() {757 return this;758 }759 EOFToken.prototype = new CSSParserToken;760 EOFToken.prototype.tokenType = "EOF";761 function DelimToken(code) {762 this.value = String.fromCharCode(code);763 return this;764 }765 DelimToken.prototype = new CSSParserToken;766 DelimToken.prototype.tokenType = "DELIM";767 DelimToken.prototype.toString = function() {768 return "DELIM(" + this.value + ")";769 }770 DelimToken.prototype.toSourceString = function() {771 return this.value;772 }773 function StringValuedToken() {774 return this;775 }776 StringValuedToken.prototype = new CSSParserToken;777 StringValuedToken.prototype.append = function(val) {778 if ( val instanceof Array) {779 for (var i = 0; i < val.length; i++) {780 this.value.push(val[i]);781 }782 } else {783 this.value.push(val);784 }785 return true;786 }787 StringValuedToken.prototype.finish = function() {788 this.value = this.valueAsString();789 return this;790 }791 StringValuedToken.prototype.ASCIImatch = function(str) {792 return this.valueAsString().toLowerCase() == str.toLowerCase();793 }794 StringValuedToken.prototype.valueAsString = function() {795 if ( typeof this.value == 'string')796 return this.value;797 return stringFromCodeArray(this.value);798 }799 StringValuedToken.prototype.valueAsCodes = function() {800 if ( typeof this.value == 'string') {801 var ret = [];802 for (var i = 0; i < this.value.length; i++)803 ret.push(this.value.charCodeAt(i));804 return ret;805 }806 return this.value.filter(function(e) {807 return e;808 });809 }810 function IdentifierToken(val) {811 this.value = [];812 this.append(val);813 }814 IdentifierToken.prototype = new StringValuedToken;815 IdentifierToken.prototype.tokenType = "IDENT";816 IdentifierToken.prototype.toString = function() {817 return "IDENT(" + this.value + ")";818 }819 IdentifierToken.prototype.toSourceString = function() {820 return this.value;821 }822 function FunctionToken(val) {823 // These are always constructed by passing an IdentifierToken824 this.value = val.finish().value;825 }826 FunctionToken.prototype = new StringValuedToken;827 FunctionToken.prototype.tokenType = "FUNCTION";828 FunctionToken.prototype.toString = function() {829 return "FUNCTION(" + this.value + ")";830 }831 FunctionToken.prototype.toSourceString = function() {832 return this.value;833 }834 function AtKeywordToken(val) {835 this.value = [];836 this.append(val);837 }838 AtKeywordToken.prototype = new StringValuedToken;839 AtKeywordToken.prototype.tokenType = "AT-KEYWORD";840 AtKeywordToken.prototype.toString = function() {841 return "AT(" + this.value + ")";842 }843 AtKeywordToken.prototype.toSourceString = function() {844 return "@" + this.value;845 }846 function HashToken(val) {847 this.value = [];848 this.append(val);...

Full Screen

Full Screen

parse-css.js

Source:parse-css.js Github

copy

Full Screen

...218 }219 }220 else if(code == 0x40) {221 if(wouldStartAnIdentifier(next(1), next(2), next(3))) {222 return new AtKeywordToken(consumeAName());223 } else {224 return new DelimToken(code);225 }226 }227 else if(code == 0x5b) return new OpenSquareToken();228 else if(code == 0x5c) {229 if(startsWithAValidEscape()) {230 reconsume();231 return consumeAnIdentlikeToken();232 } else {233 parseerror();234 return new DelimToken(code);235 }236 }237 else if(code == 0x5d) return new CloseSquareToken();238 else if(code == 0x5e) {239 if(next() == 0x3d) {240 consume();241 return new PrefixMatchToken();242 } else {243 return new DelimToken(code);244 }245 }246 else if(code == 0x7b) return new OpenCurlyToken();247 else if(code == 0x7c) {248 if(next() == 0x3d) {249 consume();250 return new DashMatchToken();251 // } else if(next() == 0x7c) {252 // consume();253 // return new ColumnToken();254 } else {255 return new DelimToken(code);256 }257 }258 else if(code == 0x7d) return new CloseCurlyToken();259 else if(code == 0x7e) {260 if(next() == 0x3d) {261 consume();262 return new IncludeMatchToken();263 } else {264 return new DelimToken(code);265 }266 }267 else if(digit(code)) {268 reconsume();269 return consumeANumericToken();270 }271 else if(namestartchar(code)) {272 reconsume();273 return consumeAnIdentlikeToken();274 }275 else if(eof()) return new EOFToken();276 else return new DelimToken(code);277 };278 var consumeAComment = function() {279 consume();280 var comment = "";281 while(true) {282 consume();283 if(code == 0x2a && next() == 0x2f) {284 consume();285 break;286 } else if(eof()) {287 break;288 }289 comment += stringFromCode(code);290 }291 return new CommentToken(comment);292 };293 var consumeANumericToken = function() {294 var num = consumeANumber();295 var token;296 if(wouldStartAnIdentifier(next(1), next(2), next(3))) {297 token = new DimensionToken();298 token.value = num.value;299 token.repr = num.repr;300 token.type = num.type;301 token.unit = consumeAName();302 token.text = token.unit;303 } else if(next() == 0x25) {304 consume();305 token = new PercentageToken();306 token.value = num.value;307 token.repr = num.repr;308 } else {309 var token = new NumberToken();310 token.value = num.value;311 token.repr = num.repr;312 token.type = num.type;313 }314 token.number = token.value;315 token.isInteger = token.type === "integer";316 // FIXME hasSign317 return token;318 };319 var consumeAnIdentlikeToken = function() {320 var str = consumeAName();321 if(str.toLowerCase() == "url" && next() == 0x28) {322 consume();323 while(whitespace(next(1)) && whitespace(next(2)))324 consume();325 if((next() == 0x22 || next() == 0x27) ||326 (whitespace(next()) && (next(2) == 0x22 || next(2) == 0x27))) {327 while(whitespace(next()))328 consume();329 consume();330 let str = consumeAStringToken();331 while(whitespace(next()))332 consume();333 // The closing paren.334 consume();335 return new URLToken(str.text);336 } else {337 return consumeAURLToken();338 }339 } else if(next() == 0x28) {340 consume();341 return new FunctionToken(str);342 } else {343 return new IdentToken(str);344 }345 };346 var consumeAStringToken = function(endingCodePoint) {347 if(endingCodePoint === undefined) endingCodePoint = code;348 var string = "";349 while(consume()) {350 if(code == endingCodePoint || eof()) {351 return new StringToken(string);352 } else if(newline(code)) {353 reconsume();354 return new BadStringToken(string);355 } else if(code == 0x5c) {356 if(eof(next())) {357 donothing();358 } else if(newline(next())) {359 consume();360 } else {361 string += stringFromCode(consumeEscape());362 }363 } else {364 string += stringFromCode(code);365 }366 }367 };368 var consumeAURLToken = function() {369 var token = new URLToken("");370 while(whitespace(next())) consume();371 if(eof(next())) return token;372 while(consume()) {373 if(code == 0x29 || eof()) {374 break;375 } else if(whitespace(code)) {376 while(whitespace(next()))377 consume();378 if(next() == 0x29 || eof(next())) {379 consume();380 break;381 } else {382 consumeTheRemnantsOfABadURL();383 return new BadURLToken();384 }385 } else if(code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code)) {386 parseerror();387 consumeTheRemnantsOfABadURL();388 return new BadURLToken();389 } else if(code == 0x5c) {390 if(startsWithAValidEscape()) {391 token.value += stringFromCode(consumeEscape());392 } else {393 parseerror();394 consumeTheRemnantsOfABadURL();395 return new BadURLToken();396 }397 } else {398 token.value += stringFromCode(code);399 }400 }401 token.text = token.value;402 return token;403 };404 var consumeEscape = function() {405 // Assume the the current character is the \406 // and the next code point is not a newline.407 consume();408 if(hexdigit(code)) {409 // Consume 1-6 hex digits410 var digits = [code];411 for(var total = 0; total < 5; total++) {412 if(hexdigit(next())) {413 consume();414 digits.push(code);415 } else {416 break;417 }418 }419 if(whitespace(next())) consume();420 var value = parseInt(digits.map(function(x){return String.fromCharCode(x);}).join(''), 16);421 if( value > maximumallowedcodepoint ) value = 0xfffd;422 return value;423 } else if(eof()) {424 return 0xfffd;425 } else {426 return code;427 }428 };429 var areAValidEscape = function(c1, c2) {430 if(c1 != 0x5c) return false;431 if(newline(c2)) return false;432 return true;433 };434 var startsWithAValidEscape = function() {435 return areAValidEscape(code, next());436 };437 var wouldStartAnIdentifier = function(c1, c2, c3) {438 if(c1 == 0x2d) {439 return namestartchar(c2) || c2 == 0x2d || areAValidEscape(c2, c3);440 } else if(namestartchar(c1)) {441 return true;442 } else if(c1 == 0x5c) {443 return areAValidEscape(c1, c2);444 } else {445 return false;446 }447 };448 var startsWithAnIdentifier = function() {449 return wouldStartAnIdentifier(code, next(1), next(2));450 };451 var wouldStartANumber = function(c1, c2, c3) {452 if(c1 == 0x2b || c1 == 0x2d) {453 if(digit(c2)) return true;454 if(c2 == 0x2e && digit(c3)) return true;455 return false;456 } else if(c1 == 0x2e) {457 if(digit(c2)) return true;458 return false;459 } else if(digit(c1)) {460 return true;461 } else {462 return false;463 }464 };465 var startsWithANumber = function() {466 return wouldStartANumber(code, next(1), next(2));467 };468 var consumeAName = function() {469 var result = "";470 while(consume()) {471 if(namechar(code)) {472 result += stringFromCode(code);473 } else if(startsWithAValidEscape()) {474 result += stringFromCode(consumeEscape());475 } else {476 reconsume();477 return result;478 }479 }480 };481 var consumeANumber = function() {482 var repr = [];483 var type = "integer";484 if(next() == 0x2b || next() == 0x2d) {485 consume();486 repr += stringFromCode(code);487 }488 while(digit(next())) {489 consume();490 repr += stringFromCode(code);491 }492 if(next(1) == 0x2e && digit(next(2))) {493 consume();494 repr += stringFromCode(code);495 consume();496 repr += stringFromCode(code);497 type = "number";498 while(digit(next())) {499 consume();500 repr += stringFromCode(code);501 }502 }503 var c1 = next(1), c2 = next(2), c3 = next(3);504 if((c1 == 0x45 || c1 == 0x65) && digit(c2)) {505 consume();506 repr += stringFromCode(code);507 consume();508 repr += stringFromCode(code);509 type = "number";510 while(digit(next())) {511 consume();512 repr += stringFromCode(code);513 }514 } else if((c1 == 0x45 || c1 == 0x65) && (c2 == 0x2b || c2 == 0x2d) && digit(c3)) {515 consume();516 repr += stringFromCode(code);517 consume();518 repr += stringFromCode(code);519 consume();520 repr += stringFromCode(code);521 type = "number";522 while(digit(next())) {523 consume();524 repr += stringFromCode(code);525 }526 }527 var value = convertAStringToANumber(repr);528 return {type:type, value:value, repr:repr};529 };530 var convertAStringToANumber = function(string) {531 // CSS's number rules are identical to JS, afaik.532 return +string;533 };534 var consumeTheRemnantsOfABadURL = function() {535 while(consume()) {536 if(code == 0x2d || eof()) {537 return;538 } else if(startsWithAValidEscape()) {539 consumeEscape();540 donothing();541 } else {542 donothing();543 }544 }545 };546 var iterationCount = 0;547 while(!eof(next())) {548 var token = consumeAToken();549 if (options.loc) {550 token.loc = {};551 token.loc.start = {line:locStart.line, column:locStart.column};552 token.loc.end = {line:line, column:column};553 }554 if (options.offsets) {555 token.startOffset = offsetStart;556 token.endOffset = i + 1;557 }558 yield token;559 iterationCount++;560 if(iterationCount > str.length*2) return "I'm infinite-looping!";561 }562}563function CSSParserToken() { throw "Abstract Base Class"; }564CSSParserToken.prototype.toJSON = function() {565 return {token: this.tokenType};566};567CSSParserToken.prototype.toString = function() { return this.tokenType; };568CSSParserToken.prototype.toSource = function() { return ''+this; };569function BadStringToken(text) {570 this.text = text;571 return this;572}573BadStringToken.prototype = Object.create(CSSParserToken.prototype);574BadStringToken.prototype.tokenType = "bad_string";575function BadURLToken() { return this; }576BadURLToken.prototype = Object.create(CSSParserToken.prototype);577BadURLToken.prototype.tokenType = "bad_url";578function WhitespaceToken() { return this; }579WhitespaceToken.prototype = Object.create(CSSParserToken.prototype);580WhitespaceToken.prototype.tokenType = "whitespace";581WhitespaceToken.prototype.toString = function() { return "WS"; };582WhitespaceToken.prototype.toSource = function() { return " "; };583function CDOToken() { return this; }584CDOToken.prototype = Object.create(CSSParserToken.prototype);585CDOToken.prototype.tokenType = "htmlcomment";586CDOToken.prototype.toSource = function() { return "<!--"; };587function CDCToken() { return this; }588CDCToken.prototype = Object.create(CSSParserToken.prototype);589CDCToken.prototype.tokenType = "htmlcomment";590CDCToken.prototype.toSource = function() { return "-->"; };591function ColonToken() { return this; }592ColonToken.prototype = Object.create(CSSParserToken.prototype);593ColonToken.prototype.tokenType = "symbol";594ColonToken.prototype.text = ":";595function SemicolonToken() { return this; }596SemicolonToken.prototype = Object.create(CSSParserToken.prototype);597SemicolonToken.prototype.tokenType = "symbol";598SemicolonToken.prototype.text = ";";599function CommaToken() { return this; }600CommaToken.prototype = Object.create(CSSParserToken.prototype);601CommaToken.prototype.tokenType = "symbol";602CommaToken.prototype.text = ",";603function GroupingToken() { throw "Abstract Base Class"; }604GroupingToken.prototype = Object.create(CSSParserToken.prototype);605function OpenCurlyToken() { this.value = "{"; this.mirror = "}"; return this; }606OpenCurlyToken.prototype = Object.create(GroupingToken.prototype);607OpenCurlyToken.prototype.tokenType = "symbol";608OpenCurlyToken.prototype.text = "{";609function CloseCurlyToken() { this.value = "}"; this.mirror = "{"; return this; }610CloseCurlyToken.prototype = Object.create(GroupingToken.prototype);611CloseCurlyToken.prototype.tokenType = "symbol";612CloseCurlyToken.prototype.text = "}";613function OpenSquareToken() { this.value = "["; this.mirror = "]"; return this; }614OpenSquareToken.prototype = Object.create(GroupingToken.prototype);615OpenSquareToken.prototype.tokenType = "symbol";616OpenSquareToken.prototype.text = "[";617function CloseSquareToken() { this.value = "]"; this.mirror = "["; return this; }618CloseSquareToken.prototype = Object.create(GroupingToken.prototype);619CloseSquareToken.prototype.tokenType = "symbol";620CloseSquareToken.prototype.text = "]";621function OpenParenToken() { this.value = "("; this.mirror = ")"; return this; }622OpenParenToken.prototype = Object.create(GroupingToken.prototype);623OpenParenToken.prototype.tokenType = "symbol";624OpenParenToken.prototype.text = "(";625function CloseParenToken() { this.value = ")"; this.mirror = "("; return this; }626CloseParenToken.prototype = Object.create(GroupingToken.prototype);627CloseParenToken.prototype.tokenType = "symbol";628CloseParenToken.prototype.text = ")";629function IncludeMatchToken() { return this; }630IncludeMatchToken.prototype = Object.create(CSSParserToken.prototype);631IncludeMatchToken.prototype.tokenType = "includes";632function DashMatchToken() { return this; }633DashMatchToken.prototype = Object.create(CSSParserToken.prototype);634DashMatchToken.prototype.tokenType = "dashmatch";635function PrefixMatchToken() { return this; }636PrefixMatchToken.prototype = Object.create(CSSParserToken.prototype);637PrefixMatchToken.prototype.tokenType = "beginsmatch";638function SuffixMatchToken() { return this; }639SuffixMatchToken.prototype = Object.create(CSSParserToken.prototype);640SuffixMatchToken.prototype.tokenType = "endsmatch";641function SubstringMatchToken() { return this; }642SubstringMatchToken.prototype = Object.create(CSSParserToken.prototype);643SubstringMatchToken.prototype.tokenType = "containsmatch";644function ColumnToken() { return this; }645ColumnToken.prototype = Object.create(CSSParserToken.prototype);646ColumnToken.prototype.tokenType = "||";647function EOFToken() { return this; }648EOFToken.prototype = Object.create(CSSParserToken.prototype);649EOFToken.prototype.tokenType = "EOF";650EOFToken.prototype.toSource = function() { return ""; };651function DelimToken(code) {652 this.value = stringFromCode(code);653 this.text = this.value;654 return this;655}656DelimToken.prototype = Object.create(CSSParserToken.prototype);657DelimToken.prototype.tokenType = "symbol";658DelimToken.prototype.toString = function() { return "DELIM("+this.value+")"; };659DelimToken.prototype.toJSON = function() {660 var json = this.constructor.prototype.constructor.prototype.toJSON.call(this);661 json.value = this.value;662 return json;663};664DelimToken.prototype.toSource = function() {665 if(this.value == "\\")666 return "\\\n";667 else668 return this.value;669};670function StringValuedToken() { throw "Abstract Base Class"; }671StringValuedToken.prototype = Object.create(CSSParserToken.prototype);672StringValuedToken.prototype.ASCIIMatch = function(str) {673 return this.value.toLowerCase() == str.toLowerCase();674};675StringValuedToken.prototype.toJSON = function() {676 var json = this.constructor.prototype.constructor.prototype.toJSON.call(this);677 json.value = this.value;678 return json;679};680function IdentToken(val) {681 this.value = val;682 this.text = val;683}684IdentToken.prototype = Object.create(StringValuedToken.prototype);685IdentToken.prototype.tokenType = "ident";686IdentToken.prototype.toString = function() { return "IDENT("+this.value+")"; };687IdentToken.prototype.toSource = function() {688 return escapeIdent(this.value);689};690function FunctionToken(val) {691 this.value = val;692 this.text = val;693 this.mirror = ")";694}695FunctionToken.prototype = Object.create(StringValuedToken.prototype);696FunctionToken.prototype.tokenType = "function";697FunctionToken.prototype.toString = function() { return "FUNCTION("+this.value+")"; };698FunctionToken.prototype.toSource = function() {699 return escapeIdent(this.value) + "(";700};701function AtKeywordToken(val) {702 this.value = val;703 this.text = val;704}705AtKeywordToken.prototype = Object.create(StringValuedToken.prototype);706AtKeywordToken.prototype.tokenType = "at";707AtKeywordToken.prototype.toString = function() { return "AT("+this.value+")"; };708AtKeywordToken.prototype.toSource = function() {709 return "@" + escapeIdent(this.value);710};711function HashToken(val) {712 this.value = val;713 this.text = val;714 this.type = "unrestricted";715}...

Full Screen

Full Screen

css-syntax.js

Source:css-syntax.js Github

copy

Full Screen

...216 }217 }218 else if(code == 0x40) {219 if(wouldStartAnIdentifier(next(1), next(2), next(3))) {220 return new AtKeywordToken(consumeAName());221 } else {222 return new DelimToken(code);223 }224 }225 else if(code == 0x5b) return new OpenSquareToken();226 else if(code == 0x5c) {227 if(startsWithAValidEscape()) {228 reconsume();229 return consumeAnIdentlikeToken();230 } else {231 tokenizeerror();232 return new DelimToken(code);233 }234 }235 else if(code == 0x5d) return new CloseSquareToken();236 else if(code == 0x5e) {237 if(next() == 0x3d) {238 consume();239 return new PrefixMatchToken();240 } else {241 return new DelimToken(code);242 }243 }244 else if(code == 0x7b) return new OpenCurlyToken();245 else if(code == 0x7c) {246 if(next() == 0x3d) {247 consume();248 return new DashMatchToken();249 } else if(next() == 0x7c) {250 consume();251 return new ColumnToken();252 } else {253 return new DelimToken(code);254 }255 }256 else if(code == 0x7d) return new CloseCurlyToken();257 else if(code == 0x7e) {258 if(next() == 0x3d) {259 consume();260 return new IncludeMatchToken();261 } else {262 return new DelimToken(code);263 }264 }265 else if(digit(code)) {266 reconsume();267 return consumeANumericToken();268 }269 else if(namestartchar(code)) {270 reconsume();271 return consumeAnIdentlikeToken();272 }273 else if(eof()) return new EOFToken();274 else return new DelimToken(code);275 };276 var consumeComments = function() {277 while(next(1) == 0x2f && next(2) == 0x2a) {278 consume(2);279 while(true) {280 consume();281 if(code == 0x2a && next() == 0x2f) {282 consume();283 break;284 } else if(eof()) {285 tokenizeerror();286 return;287 }288 }289 }290 };291 var consumeANumericToken = function() {292 var num = consumeANumber();293 if(wouldStartAnIdentifier(next(1), next(2), next(3))) {294 var token = new DimensionToken();295 token.value = num.value;296 token.repr = num.repr;297 token.type = num.type;298 token.unit = consumeAName();299 return token;300 } else if(next() == 0x25) {301 consume();302 var token = new PercentageToken();303 token.value = num.value;304 token.repr = num.repr;305 return token;306 } else {307 var token = new NumberToken();308 token.value = num.value;309 token.repr = num.repr;310 token.type = num.type;311 return token;312 }313 };314 var consumeAnIdentlikeToken = function() {315 var str = consumeAName();316 if(str.toLowerCase() == "url" && next() == 0x28) {317 consume();318 while(whitespace(next(1)) && whitespace(next(2))) consume();319 if(next() == 0x22 || next() == 0x27) {320 return new FunctionToken(str);321 } else if(whitespace(next()) && (next(2) == 0x22 || next(2) == 0x27)) {322 return new FunctionToken(str);323 } else {324 return consumeAURLToken();325 }326 } else if(next() == 0x28) {327 consume();328 return new FunctionToken(str);329 } else {330 return new IdentifierToken(str);331 }332 };333 var consumeAStringToken = function(endingCodePoint) {334 if(endingCodePoint === undefined) endingCodePoint = code;335 var string = "";336 while(consume()) {337 if(code == endingCodePoint || eof()) {338 return new StringToken(string);339 } else if(newline(code)) {340 tokenizeerror();341 reconsume();342 return new BadStringToken();343 } else if(code == 0x5c) {344 if(eof(next())) {345 donothing();346 } else if(newline(next())) {347 consume();348 } else {349 string += stringFromCode(consumeEscape())350 }351 } else {352 string += stringFromCode(code);353 }354 }355 };356 var consumeAURLToken = function() {357 var token = new URLToken("");358 while(whitespace(next())) consume();359 if(eof(next())) return token;360 while(consume()) {361 if(code == 0x29 || eof()) {362 return token;363 } else if(whitespace(code)) {364 while(whitespace(next())) consume();365 if(next() == 0x29 || eof(next())) {366 consume();367 return token;368 } else {369 consumeTheRemnantsOfABadURL();370 return new BadURLToken();371 }372 } else if(code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code)) {373 tokenizeerror();374 consumeTheRemnantsOfABadURL();375 return new BadURLToken();376 } else if(code == 0x5c) {377 if(startsWithAValidEscape()) {378 token.value += stringFromCode(consumeEscape());379 } else {380 tokenizeerror();381 consumeTheRemnantsOfABadURL();382 return new BadURLToken();383 }384 } else {385 token.value += stringFromCode(code);386 }387 }388 };389 var consumeEscape = function() {390 // Assume the the current character is the \391 // and the next code point is not a newline.392 consume();393 if(hexdigit(code)) {394 // Consume 1-6 hex digits395 var digits = [code];396 for(var total = 0; total < 5; total++) {397 if(hexdigit(next())) {398 consume();399 digits.push(code);400 } else {401 break;402 }403 }404 if(whitespace(next())) consume();405 var value = parseInt(digits.map(function(x){return String.fromCharCode(x);}).join(''), 16);406 if( value > maximumallowedcodepoint ) value = 0xfffd;407 return value;408 } else if(eof()) {409 return 0xfffd;410 } else {411 return code;412 }413 };414 var areAValidEscape = function(c1, c2) {415 if(c1 != 0x5c) return false;416 if(newline(c2)) return false;417 return true;418 };419 var startsWithAValidEscape = function() {420 return areAValidEscape(code, next());421 };422 var wouldStartAnIdentifier = function(c1, c2, c3) {423 if(c1 == 0x2d) {424 return namestartchar(c2) || c2 == 0x2d || areAValidEscape(c2, c3);425 } else if(namestartchar(c1)) {426 return true;427 } else if(c1 == 0x5c) {428 return areAValidEscape(c1, c2);429 } else {430 return false;431 }432 };433 var startsWithAnIdentifier = function() {434 return wouldStartAnIdentifier(code, next(1), next(2));435 };436 var wouldStartANumber = function(c1, c2, c3) {437 if(c1 == 0x2b || c1 == 0x2d) {438 if(digit(c2)) return true;439 if(c2 == 0x2e && digit(c3)) return true;440 return false;441 } else if(c1 == 0x2e) {442 if(digit(c2)) return true;443 return false;444 } else if(digit(c1)) {445 return true;446 } else {447 return false;448 }449 };450 var startsWithANumber = function() {451 return wouldStartANumber(code, next(1), next(2));452 };453 var consumeAName = function() {454 var result = "";455 while(consume()) {456 if(namechar(code)) {457 result += stringFromCode(code);458 } else if(startsWithAValidEscape()) {459 result += stringFromCode(consumeEscape());460 } else {461 reconsume();462 return result;463 }464 }465 };466 var consumeANumber = function() {467 var repr = '';468 var type = "integer";469 if(next() == 0x2b || next() == 0x2d) {470 consume();471 repr += stringFromCode(code);472 }473 while(digit(next())) {474 consume();475 repr += stringFromCode(code);476 }477 if(next(1) == 0x2e && digit(next(2))) {478 consume();479 repr += stringFromCode(code);480 consume();481 repr += stringFromCode(code);482 type = "number";483 while(digit(next())) {484 consume();485 repr += stringFromCode(code);486 }487 }488 var c1 = next(1), c2 = next(2), c3 = next(3);489 if((c1 == 0x45 || c1 == 0x65) && digit(c2)) {490 consume();491 repr += stringFromCode(code);492 consume();493 repr += stringFromCode(code);494 type = "number";495 while(digit(next())) {496 consume();497 repr += stringFromCode(code);498 }499 } else if((c1 == 0x45 || c1 == 0x65) && (c2 == 0x2b || c2 == 0x2d) && digit(c3)) {500 consume();501 repr += stringFromCode(code);502 consume();503 repr += stringFromCode(code);504 consume();505 repr += stringFromCode(code);506 type = "number";507 while(digit(next())) {508 consume();509 repr += stringFromCode(code);510 }511 }512 var value = convertAStringToANumber(repr);513 return {type:type, value:value, repr:repr};514 };515 var convertAStringToANumber = function(string) {516 // CSS's number rules are identical to JS, afaik.517 return +string;518 };519 var consumeTheRemnantsOfABadURL = function() {520 while(consume()) {521 if(code == 0x2d || eof()) {522 return;523 } else if(startsWithAValidEscape()) {524 consumeEscape();525 donothing();526 } else {527 donothing();528 }529 }530 };531 var iterationCount = 0;532 while(!eof(next())) {533 tokens.push(consumeAToken());534 if(iterationCount++ > str.length*2) throw new Error("The CSS Tokenizer is infinite-looping");535 }536 return tokens;537}538function CSSParserToken() { return this; }539CSSParserToken.prototype.toJSON = function() {540 return {token: this.tokenType};541}542CSSParserToken.prototype.toString = function() { return this.tokenType; }543CSSParserToken.prototype.toCSSString = function() { return ''+this; }544function BadStringToken() { return this; }545BadStringToken.prototype = new CSSParserToken;546BadStringToken.prototype.tokenType = "BADSTRING";547BadStringToken.prototype.toCSSString = function() { return "'"; }548function BadURLToken() { return this; }549BadURLToken.prototype = new CSSParserToken;550BadURLToken.prototype.tokenType = "BADURL";551BadURLToken.prototype.toCSSString = function() { return "url("; }552function WhitespaceToken() { return this; }553WhitespaceToken.prototype = new CSSParserToken;554WhitespaceToken.prototype.tokenType = "WHITESPACE";555WhitespaceToken.prototype.toString = function() { return "WS"; }556WhitespaceToken.prototype.toCSSString = function() { return " "; }557function CDOToken() { return this; }558CDOToken.prototype = new CSSParserToken;559CDOToken.prototype.tokenType = "CDO";560CDOToken.prototype.toCSSString = function() { return "<!--"; }561function CDCToken() { return this; }562CDCToken.prototype = new CSSParserToken;563CDCToken.prototype.tokenType = "CDC";564CDCToken.prototype.toCSSString = function() { return "-->"; }565function ColonToken() { return this; }566ColonToken.prototype = new CSSParserToken;567ColonToken.prototype.tokenType = ":";568function SemicolonToken() { return this; }569SemicolonToken.prototype = new CSSParserToken;570SemicolonToken.prototype.tokenType = ";";571function CommaToken() { return this; }572CommaToken.prototype = new CSSParserToken;573CommaToken.prototype.tokenType = ",";574CommaToken.prototype.value = ";"; // backwards-compat with DELIM token575function GroupingToken() { return this; }576GroupingToken.prototype = new CSSParserToken;577function OpenCurlyToken() { this.value = "{"; this.mirror = "}"; return this; }578OpenCurlyToken.prototype = new GroupingToken;579OpenCurlyToken.prototype.tokenType = "{";580function CloseCurlyToken() { this.value = "}"; this.mirror = "{"; return this; }581CloseCurlyToken.prototype = new GroupingToken;582CloseCurlyToken.prototype.tokenType = "}";583function OpenSquareToken() { this.value = "["; this.mirror = "]"; return this; }584OpenSquareToken.prototype = new GroupingToken;585OpenSquareToken.prototype.tokenType = "[";586function CloseSquareToken() { this.value = "]"; this.mirror = "["; return this; }587CloseSquareToken.prototype = new GroupingToken;588CloseSquareToken.prototype.tokenType = "]";589function OpenParenToken() { this.value = "("; this.mirror = ")"; return this; }590OpenParenToken.prototype = new GroupingToken;591OpenParenToken.prototype.tokenType = "(";592function CloseParenToken() { this.value = ")"; this.mirror = "("; return this; }593CloseParenToken.prototype = new GroupingToken;594CloseParenToken.prototype.tokenType = ")";595function IncludeMatchToken() { return this; }596IncludeMatchToken.prototype = new CSSParserToken;597IncludeMatchToken.prototype.tokenType = "~=";598function DashMatchToken() { return this; }599DashMatchToken.prototype = new CSSParserToken;600DashMatchToken.prototype.tokenType = "|=";601function PrefixMatchToken() { return this; }602PrefixMatchToken.prototype = new CSSParserToken;603PrefixMatchToken.prototype.tokenType = "^=";604function SuffixMatchToken() { return this; }605SuffixMatchToken.prototype = new CSSParserToken;606SuffixMatchToken.prototype.tokenType = "$=";607function SubstringMatchToken() { return this; }608SubstringMatchToken.prototype = new CSSParserToken;609SubstringMatchToken.prototype.tokenType = "*=";610function ColumnToken() { return this; }611ColumnToken.prototype = new CSSParserToken;612ColumnToken.prototype.tokenType = "||";613function EOFToken() { return this; }614EOFToken.prototype = new CSSParserToken;615EOFToken.prototype.tokenType = "EOF";616EOFToken.prototype.toCSSString = function() { return ""; }617function DelimToken(code) {618 this.value = stringFromCode(code);619 return this;620}621DelimToken.prototype = new CSSParserToken;622DelimToken.prototype.tokenType = "DELIM";623DelimToken.prototype.toString = function() { return "DELIM("+this.value+")"; }624DelimToken.prototype.toCSSString = function() {625 return (this.value == "\\") ? "\\\n" : this.value;626}627function StringValuedToken() { return this; }628StringValuedToken.prototype = new CSSParserToken;629StringValuedToken.prototype.ASCIIMatch = function(str) {630 return this.value.toLowerCase() == str.toLowerCase();631}632function IdentifierToken(val) {633 this.value = val;634}635IdentifierToken.prototype = new StringValuedToken;636IdentifierToken.prototype.tokenType = "IDENT";637IdentifierToken.prototype.toString = function() { return "IDENT("+this.value+")"; }638IdentifierToken.prototype.toCSSString = function() {639 return escapeIdent(this.value);640}641function FunctionToken(val) {642 this.value = val;643 this.mirror = ")";644}645FunctionToken.prototype = new StringValuedToken;646FunctionToken.prototype.tokenType = "FUNCTION";647FunctionToken.prototype.toString = function() { return "FUNCTION("+this.value+")"; }648FunctionToken.prototype.toCSSString = function() {649 return escapeIdent(this.value) + "(";650}651 652function AtKeywordToken(val) {653 this.value = val;654}655AtKeywordToken.prototype = new StringValuedToken;656AtKeywordToken.prototype.tokenType = "AT-KEYWORD";657AtKeywordToken.prototype.toString = function() { return "AT("+this.value+")"; }658AtKeywordToken.prototype.toCSSString = function() {659 return "@" + escapeIdent(this.value);660}661function HashToken(val) {662 this.value = val;663 this.type = "unrestricted";664}665HashToken.prototype = new StringValuedToken;666HashToken.prototype.tokenType = "HASH";...

Full Screen

Full Screen

tokenizer.js

Source:tokenizer.js Github

copy

Full Screen

...225 else donothing();226 break;227 case "at-keyword":228 if(code == 0x2d) {229 if(namestartchar(next())) create(new AtKeywordToken(0x2d)) && switchto('at-keyword-rest');230 else if(next(1) == 0x5c && !badescape(next(2))) create(new AtKeywordtoken(0x2d)) && switchto('at-keyword-rest');231 else parseerror() && emit(new DelimToken(0x40)) && switchto('data') && reconsume();232 }233 else if(namestartchar(code)) create(new AtKeywordToken(code)) && switchto('at-keyword-rest');234 else if(code == 0x5c) {235 if(badescape(next())) parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();236 else create(new AtKeywordToken(consumeEscape())) && switchto('at-keyword-rest');237 }238 else emit(new DelimToken(0x40)) && switchto('data') && reconsume();239 break;240 case "at-keyword-rest":241 if(namechar(code)) currtoken.append(code);242 else if(code == 0x5c) {243 if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();244 else currtoken.append(consumeEscape());245 }246 else emit() && switchto('data') && reconsume();247 break;248 case "ident":249 if(code == 0x2d) {250 if(namestartchar(next())) create(new IdentifierToken(code)) && switchto('ident-rest');251 else if(next(1) == 0x5c && !badescape(next(2))) create(new IdentifierToken(code)) && switchto('ident-rest');252 else emit(new DelimToken(0x2d)) && switchto('data');253 }254 else if(namestartchar(code)) create(new IdentifierToken(code)) && switchto('ident-rest');255 else if(code == 0x5c) {256 if(badescape(next())) parseerror() && switchto("data") && reconsume();257 else create(new IdentifierToken(consumeEscape())) && switchto('ident-rest');258 }259 else catchfire("Hit the generic 'else' clause in ident state.") && switchto('data') && reconsume();260 break;261 case "ident-rest":262 if(namechar(code)) currtoken.append(code);263 else if(code == 0x5c) {264 if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();265 else currtoken.append(consumeEscape());266 }267 else if(code == 0x28) {268 if(currtoken.ASCIImatch('url')) switchto('url');269 else emit(new FunctionToken(currtoken)) && switchto('data');270 } 271 else if(whitespace(code) && options.transformFunctionWhitespace) switchto('transform-function-whitespace') && reconsume();272 else emit() && switchto('data') && reconsume();273 break;274 case "transform-function-whitespace":275 if(whitespace(next())) donothing();276 else if(code == 0x28) emit(new FunctionToken(currtoken)) && switchto('data');277 else emit() && switchto('data') && reconsume();278 break;279 case "number":280 create(new NumberToken());281 if(code == 0x2d) {282 if(digit(next())) consume() && currtoken.append([0x2d,code]) && switchto('number-rest');283 else if(next(1) == 0x2e && digit(next(2))) consume(2) && currtoken.append([0x2d,0x2e,code]) && switchto('number-fraction');284 else switchto('data') && reconsume();285 }286 else if(code == 0x2b) {287 if(digit(next())) consume() && currtoken.append([0x2b,code]) && switchto('number-rest');288 else if(next(1) == 0x2e && digit(next(2))) consume(2) && currtoken.append([0x2b,0x2e,code]) && switchto('number-fraction');289 else switchto('data') && reconsume();290 }291 else if(digit(code)) currtoken.append(code) && switchto('number-rest');292 else if(code == 0x2e) {293 if(digit(next())) consume() && currtoken.append([0x2e,code]) && switchto('number-fraction');294 else switchto('data') && reconsume();295 }296 else switchto('data') && reconsume();297 break;298 case "number-rest":299 if(digit(code)) currtoken.append(code);300 else if(code == 0x2e) {301 if(digit(next())) consume() && currtoken.append([0x2e,code]) && switchto('number-fraction');302 else emit() && switchto('data') && reconsume();303 }304 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data');305 else if(code == 0x45 || code == 0x65) {306 if(digit(next())) consume() && currtoken.append([0x25,code]) && switchto('sci-notation');307 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x25,next(1),next(2)]) && consume(2) && switchto('sci-notation');308 else create(new DimensionToken(currtoken,code)) && switchto('dimension');309 }310 else if(code == 0x2d) {311 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');312 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();313 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');314 else emit() && switchto('data') && reconsume();315 }316 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');317 else if(code == 0x5c) {318 if(badescape(next)) parseerror() && emit() && switchto('data') && reconsume();319 else create(new DimensionToken(currtoken,consumeEscape)) && switchto('dimension');320 }321 else emit() && switchto('data') && reconsume();322 break;323 case "number-fraction":324 currtoken.type = "number";325 if(digit(code)) currtoken.append(code);326 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data');327 else if(code == 0x45 || code == 0x65) {328 if(digit(next())) consume() && currtoken.append([0x65,code]) && switchto('sci-notation');329 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x65,next(1),next(2)]) && consume(2) && switchto('sci-notation');330 else create(new DimensionToken(currtoken,code)) && switchto('dimension');331 }332 else if(code == 0x2d) {333 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');334 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();335 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');336 else emit() && switchto('data') && reconsume();337 }338 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');339 else if(code == 0x5c) {340 if(badescape(next)) parseerror() && emit() && switchto('data') && reconsume();341 else create(new DimensionToken(currtoken,consumeEscape())) && switchto('dimension');342 }343 else emit() && switchto('data') && reconsume();344 break;345 case "dimension":346 if(namechar(code)) currtoken.append(code);347 else if(code == 0x5c) {348 if(badescape(next())) parseerror() && emit() && switchto('data') && reconsume();349 else currtoken.append(consumeEscape());350 }351 else emit() && switchto('data') && reconsume();352 break;353 case "sci-notation":354 currtoken.type = "number";355 if(digit(code)) currtoken.append(code);356 else emit() && switchto('data') && reconsume();357 break;358 case "url":359 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');360 else if(code == 0x22) switchto('url-double-quote');361 else if(code == 0x27) switchto('url-single-quote');362 else if(code == 0x29) emit(new URLToken) && switchto('data');363 else if(whitespace(code)) donothing();364 else switchto('url-unquoted') && reconsume();365 break;366 case "url-double-quote":367 if(! (currtoken instanceof URLToken)) create(new URLToken);368 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');369 else if(code == 0x22) switchto('url-end');370 else if(newline(code)) parseerror() && switchto('bad-url');371 else if(code == 0x5c) {372 if(newline(next())) consume();373 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();374 else currtoken.append(consumeEscape());375 }376 else currtoken.append(code);377 break;378 case "url-single-quote":379 if(! (currtoken instanceof URLToken)) create(new URLToken);380 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');381 else if(code == 0x27) switchto('url-end');382 else if(newline(code)) parseerror() && switchto('bad-url');383 else if(code == 0x5c) {384 if(newline(next())) consume();385 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();386 else currtoken.append(consumeEscape());387 }388 else currtoken.append(code);389 break;390 case "url-end":391 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');392 else if(whitespace(code)) donothing();393 else if(code == 0x29) emit() && switchto('data');394 else parseerror() && switchto('bad-url') && reconsume();395 break;396 case "url-unquoted":397 if(! (currtoken instanceof URLToken)) create(new URLToken);398 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');399 else if(whitespace(code)) switchto('url-end');400 else if(code == 0x29) emit() && switchto('data');401 else if(code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code)) parseerror() && switchto('bad-url');402 else if(code == 0x5c) {403 if(badescape(next())) parseerror() && switchto('bad-url');404 else currtoken.append(consumeEscape());405 }406 else currtoken.append(code);407 break;408 case "bad-url":409 if(eof()) parseerror() && emit(new BadURLToken) && switchto('data');410 else if(code == 0x29) emit(new BadURLToken) && switchto('data');411 else if(code == 0x5c) {412 if(badescape(next())) donothing();413 else consumeEscape();414 }415 else donothing();416 break;417 case "unicode-range":418 // We already know that the current code is a hexdigit.419 var start = [code], end = [code];420 for(var total = 1; total < 6; total++) {421 if(hexdigit(next())) {422 consume();423 start.push(code);424 end.push(code);425 }426 else break;427 }428 if(next() == 0x3f) {429 for(;total < 6; total++) {430 if(next() == 0x3f) {431 consume();432 start.push("0".charCodeAt(0));433 end.push("f".charCodeAt(0));434 }435 else break;436 }437 emit(new UnicodeRangeToken(start,end)) && switchto('data');438 }439 else if(next(1) == 0x2d && hexdigit(next(2))) {440 consume();441 consume();442 end = [code];443 for(var total = 1; total < 6; total++) {444 if(hexdigit(next())) {445 consume();446 end.push(code);447 }448 else break;449 }450 emit(new UnicodeRangeToken(start,end)) && switchto('data');451 }452 else emit(new UnicodeRangeToken(start)) && switchto('data');453 break;454 default:455 catchfire("Unknown state '" + state + "'");456 }457 }458}459function stringFromCodeArray(arr) {460 return String.fromCharCode.apply(null,arr.filter(function(e){return e;}));461}462function CSSParserToken(options) { return this; }463CSSParserToken.prototype.finish = function() { return this; }464CSSParserToken.prototype.toString = function() { return this.tokenType; }465CSSParserToken.prototype.toSourceString = CSSParserToken.prototype.toString;466CSSParserToken.prototype.toJSON = function() { return this.toString(); }467function BadStringToken() { return this; }468BadStringToken.prototype = new CSSParserToken;469BadStringToken.prototype.tokenType = "BADSTRING";470function BadURLToken() { return this; }471BadURLToken.prototype = new CSSParserToken;472BadURLToken.prototype.tokenType = "BADURL";473function WhitespaceToken() { return this; }474WhitespaceToken.prototype = new CSSParserToken;475WhitespaceToken.prototype.tokenType = "WHITESPACE";476WhitespaceToken.prototype.toString = function() { return "WS"; }477WhitespaceToken.prototype.toSourceString = function() { return " "; }478function CDOToken() { return this; }479CDOToken.prototype = new CSSParserToken;480CDOToken.prototype.tokenType = "CDO";481function CDCToken() { return this; }482CDCToken.prototype = new CSSParserToken;483CDCToken.prototype.tokenType = "CDC";484function ColonToken() { return this; }485ColonToken.prototype = new CSSParserToken;486ColonToken.prototype.tokenType = ":";487function SemicolonToken() { return this; }488SemicolonToken.prototype = new CSSParserToken;489SemicolonToken.prototype.tokenType = ";";490function OpenCurlyToken() { return this; }491OpenCurlyToken.prototype = new CSSParserToken;492OpenCurlyToken.prototype.tokenType = "{";493function CloseCurlyToken() { return this; }494CloseCurlyToken.prototype = new CSSParserToken;495CloseCurlyToken.prototype.tokenType = "}";496function OpenSquareToken() { return this; }497OpenSquareToken.prototype = new CSSParserToken;498OpenSquareToken.prototype.tokenType = "[";499function CloseSquareToken() { return this; }500CloseSquareToken.prototype = new CSSParserToken;501CloseSquareToken.prototype.tokenType = "]";502function OpenParenToken() { return this; }503OpenParenToken.prototype = new CSSParserToken;504OpenParenToken.prototype.tokenType = "(";505function CloseParenToken() { return this; }506CloseParenToken.prototype = new CSSParserToken;507CloseParenToken.prototype.tokenType = ")";508function EOFToken() { return this; }509EOFToken.prototype = new CSSParserToken;510EOFToken.prototype.tokenType = "EOF";511function DelimToken(code) {512 this.value = String.fromCharCode(code);513 return this;514}515DelimToken.prototype = new CSSParserToken;516DelimToken.prototype.tokenType = "DELIM";517DelimToken.prototype.toString = function() { return "DELIM("+this.value+")"; }518DelimToken.prototype.toSourceString = function() { return this.value; }519function StringValuedToken() { return this; }520StringValuedToken.prototype = new CSSParserToken;521StringValuedToken.prototype.append = function(val) {522 if(val instanceof Array) {523 for(var i = 0; i < val.length; i++) {524 this.value.push(val[i]);525 }526 } else {527 this.value.push(val);528 }529 return true;530}531StringValuedToken.prototype.finish = function() {532 this.value = this.valueAsString();533 return this;534}535StringValuedToken.prototype.ASCIImatch = function(str) {536 return this.valueAsString().toLowerCase() == str.toLowerCase();537}538StringValuedToken.prototype.valueAsString = function() {539 if(typeof this.value == 'string') return this.value;540 return stringFromCodeArray(this.value);541}542StringValuedToken.prototype.valueAsCodes = function() {543 if(typeof this.value == 'string') {544 var ret = [];545 for(var i = 0; i < this.value.length; i++)546 ret.push(this.value.charCodeAt(i));547 return ret;548 }549 return this.value.filter(function(e){return e;});550}551function IdentifierToken(val) {552 this.value = [];553 this.append(val);554}555IdentifierToken.prototype = new StringValuedToken;556IdentifierToken.prototype.tokenType = "IDENT";557IdentifierToken.prototype.toString = function() { return "IDENT("+this.value+")"; }558IdentifierToken.prototype.toSourceString = function() { return this.value; }559function FunctionToken(val) {560 // These are always constructed by passing an IdentifierToken561 this.value = val.finish().value;562}563FunctionToken.prototype = new StringValuedToken;564FunctionToken.prototype.tokenType = "FUNCTION";565FunctionToken.prototype.toString = function() { return "FUNCTION("+this.value+")"; }566FunctionToken.prototype.toSourceString = function() { return this.value; }567function AtKeywordToken(val) {568 this.value = [];569 this.append(val);570}571AtKeywordToken.prototype = new StringValuedToken;572AtKeywordToken.prototype.tokenType = "AT-KEYWORD";573AtKeywordToken.prototype.toString = function() { return "AT("+this.value+")"; }574AtKeywordToken.prototype.toSourceString = function() { return "@"+this.value; }575function HashToken(val) {576 this.value = [];577 this.append(val);578}579HashToken.prototype = new StringValuedToken;580HashToken.prototype.tokenType = "HASH";581HashToken.prototype.toString = function() { return "HASH("+this.value+")"; }...

Full Screen

Full Screen

css-tokenizer.js

Source:css-tokenizer.js Github

copy

Full Screen

...224 else donothing();225 break;226 case "at-keyword":227 if(code == 0x2d) {228 if(namestartchar(next())) consume() && create(new AtKeywordToken([0x40,code])) && switchto('at-keyword-rest');229 else emit(new DelimToken(0x40)) && switchto('data') && reconsume();230 }231 else if(namestartchar(code)) create(new AtKeywordToken(code)) && switchto('at-keyword-rest');232 else if(code == 0x5c) {233 if(badescape(next())) parseerror() && emit(new DelimToken(0x23)) && switchto("data") && reconsume();234 else create(new AtKeywordToken(consumeEscape())) && switchto('at-keyword-rest');235 }236 else emit(new DelimToken(0x40)) && switchto('data') && reconsume();237 break;238 case "at-keyword-rest":239 if(namechar(code)) currtoken.append(code);240 else if(code == 0x5c) {241 if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();242 else currtoken.append(consumeEscape());243 }244 else emit() && switchto('data') && reconsume();245 break;246 case "identifier":247 if(code == 0x2d) {248 if(namestartchar(next())) create(new IdentifierToken(code)) && switchto('identifier-rest');249 else switchto('data') && reconsume();250 }251 else if(namestartchar(code)) create(new IdentifierToken(code)) && switchto('identifier-rest');252 else if(code == 0x5c) {253 if(badescape(next())) parseerror() && switchto("data") && reconsume();254 else create(new IdentifierToken(consumeEscape())) && switchto('identifier-rest');255 }256 else switchto('data') && reconsume();257 break;258 case "identifier-rest":259 if(namechar(code)) currtoken.append(code);260 else if(code == 0x5c) {261 if(badescape(next())) parseerror() && emit() && switchto("data") && reconsume();262 else currtoken.append(consumeEscape());263 }264 else if(code == 0x28) emit(new FunctionToken(currtoken)) && switchto('data');265 else if(whitespace(code) && options.transformFunctionWhitespace) switchto('transform-function-whitespace');266 else emit() && switchto('data') && reconsume();267 break;268 case "transform-function-whitespace":269 if(whitespace(code)) donothing();270 else if(code == 0x28) emit(new FunctionToken(currtoken)) && switchto('data');271 else emit() && switchto('data') && reconsume();272 break;273 case "number":274 create(new NumberToken());275 if(code == 0x2d) {276 if(digit(next())) consume() && currtoken.append([0x2d,code]) && switchto('number-rest');277 else if(next(1) == 0x2e && digit(next(2))) consume(2) && currtoken.append([0x2d,0x2e,code]) && switchto('number-fraction');278 else switchto('data') && reconsume();279 }280 else if(code == 0x2b) {281 if(digit(next())) consume() && currtoken.append([0x2b,code]) && switchto('number-rest');282 else if(next(1) == 0x2e && digit(next(2))) consume(2) && currtoken.append([0x2b,0x2e,code]) && switchto('number-fraction');283 else switchto('data') && reconsume();284 }285 else if(digit(code)) currtoken.append(code) && switchto('number-rest');286 else if(code == 0x2e) {287 if(digit(next())) consume() && currtoken.append([0x2e,code]) && switchto('number-fraction');288 else switchto('data') && reconsume();289 }290 else switchto('data') && reconsume();291 break;292 case "number-rest":293 if(digit(code)) currtoken.append(code);294 else if(code == 0x2e) {295 if(digit(next())) consume() && currtoken.append([0x2e,code]) && switchto('number-fraction');296 else emit() && switchto('data') && reconsume();297 }298 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data') && reconsume();299 else if(code == 0x45 || code == 0x65) {300 if(!options.scientificNotation) create(new DimensionToken(currtoken,code)) && switchto('dimension');301 else if(digit(next())) consume() && currtoken.append([0x25,code]) && switchto('sci-notation');302 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x25,next(1),next(2)]) && consume(2) && switchto('sci-notation');303 else create(new DimensionToken(currtoken,code)) && switchto('dimension');304 }305 else if(code == 0x2d) {306 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');307 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();308 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');309 else emit() && switchto('data') && reconsume();310 }311 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');312 else if(code == 0x5c) {313 if(badescape(next)) emit() && switchto('data') && reconsume();314 else create(new DimensionToken(currtoken,consumeEscape)) && switchto('dimension');315 }316 else emit() && switchto('data') && reconsume();317 break;318 case "number-fraction":319 currtoken.type = "number";320 if(digit(code)) currtoken.append(code);321 else if(code == 0x2e) emit() && switchto('data') && reconsume();322 else if(code == 0x25) emit(new PercentageToken(currtoken)) && switchto('data') && reconsume();323 else if(code == 0x45 || code == 0x65) {324 if(!options.scientificNotation) create(new DimensionToken(currtoken,code)) && switchto('dimension');325 else if(digit(next())) consume() && currtoken.append([0x25,code]) && switchto('sci-notation');326 else if((next(1) == 0x2b || next(1) == 0x2d) && digit(next(2))) currtoken.append([0x25,next(1),next(2)]) && consume(2) && switchto('sci-notation');327 else create(new DimensionToken(currtoken,code)) && switchto('dimension');328 }329 else if(code == 0x2d) {330 if(namestartchar(next())) consume() && create(new DimensionToken(currtoken,[0x2d,code])) && switchto('dimension');331 else if(next(1) == 0x5c && badescape(next(2))) parseerror() && emit() && switchto('data') && reconsume();332 else if(next(1) == 0x5c) consume() && create(new DimensionToken(currtoken, [0x2d,consumeEscape()])) && switchto('dimension');333 else emit() && switchto('data') && reconsume();334 }335 else if(namestartchar(code)) create(new DimensionToken(currtoken, code)) && switchto('dimension');336 else if(code == 0x5c) {337 if(badescape(next)) emit() && switchto('data') && reconsume();338 else create(new DimensionToken(currtoken,consumeEscape)) && switchto('dimension');339 }340 else emit() && switchto('data') && reconsume();341 break;342 case "dimension":343 if(namechar(code)) currtoken.append(code);344 else if(code == 0x5c) {345 if(badescape(next())) parseerror() && emit() && switchto('data') && reconsume();346 else currtoken.append(consumeEscape());347 }348 else emit() && switchto('data') && reconsume();349 break;350 case "sci-notation":351 if(digit(code)) currtoken.append(code);352 else emit() && switchto('data') && reconsume();353 break;354 case "url":355 if(code == 0x22) switchto('url-double-quote');356 else if(code == 0x27) switchto('url-single-quote');357 else if(code == 0x29) emit(new URLToken) && switchto('data');358 else if(whitespace(code)) donothing();359 else switchto('url-unquoted') && reconsume();360 break;361 case "url-double-quote":362 if(currtoken == undefined) create(new URLToken);363 if(code == 0x22) switchto('url-end');364 else if(newline(code)) parseerror() && switchto('bad-url');365 else if(code == 0x5c) {366 if(newline(next())) consume();367 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();368 else currtoken.append(consumeEscape());369 }370 else currtoken.append(code);371 break;372 case "url-single-quote":373 if(currtoken == undefined) create(new URLToken);374 if(code == 0x27) switchto('url-end');375 else if(newline(code)) parseerror() && switchto('bad-url');376 else if(code == 0x5c) {377 if(newline(next())) consume();378 else if(badescape(next())) parseerror() && emit(new BadURLToken) && switchto('data') && reconsume();379 else currtoken.append(consumeEscape());380 }381 else currtoken.append(code);382 break;383 case "url-end":384 if(whitespace(code)) donothing();385 else if(code == 0x29) emit() && switchto('data');386 else parseerror() && switchto('bad-url') && reconsume();387 break;388 case "url-unquoted":389 if(currtoken == undefined) create(new URLToken);390 if(whitespace(code)) switchto('url-end');391 else if(code == 0x29) emit() && switchto('data');392 else if(code == 0x22 || code == 0x27 || code == 0x28 || nonprintable(code)) parseerror() && switchto('bad-url');393 else if(code == 0x5c) {394 if(badescape(next())) parseerror() && switchto('bad-url');395 else currtoken.append(consumeEscape());396 }397 else currtoken.append(code);398 break;399 case "bad-url":400 if(code == 0x29) emit(new BadURLToken) && switchto('data');401 else if(code == 0x5c) {402 if(badescape(next())) donothing();403 else consumeEscape()404 }405 else donothing();406 break;407 case "unicode-range":408 // We already know that the current code is a hexdigit.409 var start = [code], end = [code];410 for(var total = 1; total < 6; total++) {411 if(hexdigit(next())) {412 consume();413 start.push(code);414 end.push(code);415 }416 else break;417 }418 if(next() == 0x3f) {419 for(;total < 6; total++) {420 if(next() == 0x3f) {421 consume();422 start.push("0".charCodeAt(0));423 end.push("f".charCodeAt(0));424 }425 else break;426 }427 emit(new UnicodeRangeToken(start,end)) && switchto('data');428 }429 else if(next(1) == 0x2d && hexdigit(next(2))) {430 consume();431 consume();432 end = [code];433 for(var total = 1; total < 6; total++) {434 if(hexdigit(next())) {435 consume();436 end.push(code);437 }438 else break;439 }440 emit(new UnicodeRangeToken(start,end)) && switchto('data');441 }442 else emit(new UnicodeRangeToken(start)) && switchto('data');443 break;444 default:445 console.log("Unknown state '" + state + "'");446 }447 }448}449function stringFromCodeArray(arr) {450 return String.fromCharCode.apply(null,arr.filter(function(e){return e;}));451}452function CSSParserToken(options) { return this; }453CSSParserToken.prototype.finish = function() { return this; }454CSSParserToken.prototype.toString = function() { return this.tokenType; }455CSSParserToken.prototype.toJSON = function() { return this.toString(); }456function BadStringToken() { return this; }457BadStringToken.prototype = new CSSParserToken;458BadStringToken.prototype.tokenType = "BADSTRING";459function BadURLToken() { return this; }460BadURLToken.prototype = new CSSParserToken;461BadURLToken.prototype.tokenType = "BADURL";462function WhitespaceToken() { return this; }463WhitespaceToken.prototype = new CSSParserToken;464WhitespaceToken.prototype.tokenType = "WHITESPACE";465WhitespaceToken.prototype.toString = function() { return "WS"; }466function CDOToken() { return this; }467CDOToken.prototype = new CSSParserToken;468CDOToken.prototype.tokenType = "CDO";469function CDCToken() { return this; }470CDCToken.prototype = new CSSParserToken;471CDCToken.prototype.tokenType = "CDC";472function ColonToken() { return this; }473ColonToken.prototype = new CSSParserToken;474ColonToken.prototype.tokenType = ":";475function SemicolonToken() { return this; }476SemicolonToken.prototype = new CSSParserToken;477SemicolonToken.prototype.tokenType = ";";478function OpenCurlyToken() { return this; }479OpenCurlyToken.prototype = new CSSParserToken;480OpenCurlyToken.prototype.tokenType = "{";481function CloseCurlyToken() { return this; }482CloseCurlyToken.prototype = new CSSParserToken;483CloseCurlyToken.prototype.tokenType = "}";484function OpenSquareToken() { return this; }485OpenSquareToken.prototype = new CSSParserToken;486OpenSquareToken.prototype.tokenType = "[";487function CloseSquareToken() { return this; }488CloseSquareToken.prototype = new CSSParserToken;489CloseSquareToken.prototype.tokenType = "]";490function OpenParenToken() { return this; }491OpenParenToken.prototype = new CSSParserToken;492OpenParenToken.prototype.tokenType = "(";493function CloseParenToken() { return this; }494CloseParenToken.prototype = new CSSParserToken;495CloseParenToken.prototype.tokenType = ")";496function EOFToken() { return this; }497EOFToken.prototype = new CSSParserToken;498EOFToken.prototype.tokenType = "EOF";499function DelimToken(code) {500 this.value = String.fromCharCode(code);501 return this;502}503DelimToken.prototype = new CSSParserToken;504DelimToken.prototype.tokenType = "DELIM";505DelimToken.prototype.toString = function() { return "DELIM("+this.value+")"; }506function StringValuedToken() { return this; }507StringValuedToken.prototype = new CSSParserToken;508StringValuedToken.prototype.append = function(val) {509 if(val instanceof Array) {510 for(var i = 0; i < val.length; i++) {511 this.value.push(val[i]);512 }513 } else {514 this.value.push(val);515 }516 return true;517}518StringValuedToken.prototype.finish = function() {519 this.value = stringFromCodeArray(this.value);520 return this;521}522function IdentifierToken(val) {523 this.value = [];524 this.append(val);525}526IdentifierToken.prototype = new StringValuedToken;527IdentifierToken.prototype.tokenType = "IDENT";528IdentifierToken.prototype.toString = function() { return "IDENT("+this.value+")"; }529function FunctionToken(val) {530 // These are always constructed by passing an IdentifierToken531 this.value = val.finish().value;532}533FunctionToken.prototype = new CSSParserToken;534FunctionToken.prototype.tokenType = "FUNCTION";535FunctionToken.prototype.toString = function() { return "FUNCTION("+this.value+")"; }536function AtKeywordToken(val) {537 this.value = [];538 this.append(val);539}540AtKeywordToken.prototype = new StringValuedToken;541AtKeywordToken.prototype.tokenType = "AT-KEYWORD";542AtKeywordToken.prototype.toString = function() { return "AT("+this.value+")"; }543function HashToken(val) {544 this.value = [];545 this.append(val);546}547HashToken.prototype = new StringValuedToken;548HashToken.prototype.tokenType = "HASH";549HashToken.prototype.toString = function() { return "HASH("+this.value+")"; }550function StringToken(val) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { test, expect } = require('@playwright/test');2test('test', async ({ page }) => {3 await page.click('text=Get Started');4 await page.click('text=Docs');5 await page.click('text=API');6 await page.click('text=class: AtKeywordToken');7 console.log(await page.evaluate(() => {8 return new AtKeywordToken('test').value;9 }));10});11 10 | await page.click('text=class: AtKeywordToken');12 11 | console.log(await page.evaluate(() => {13 > 12 | return new AtKeywordToken('test').value;14 13 | }));15 14 | });16 at Object.toBe (test.js:12:12)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AtKeywordToken } = require('playwright/lib/server/supplements/recorder/recorderTypes');2const token = new AtKeywordToken('foo');3console.log(token);4const { AtKeywordToken } = require('playwright/lib/server/supplements/recorder/recorderTypes');5const token = new AtKeywordToken('foo');6console.log(token);7const { AtKeywordToken } = require('playwright/lib/server/supplements/recorder/recorderTypes');8const token = new AtKeywordToken('foo');9console.log(token);10const { AtKeywordToken } = require('playwright/lib/server/supplements/recorder/recorderTypes');11const token = new AtKeywordToken('foo');12console.log(token);13const { AtKeywordToken } = require('playwright/lib/server/supplements/recorder/recorderTypes');14const token = new AtKeywordToken('foo');15console.log(token);16const { AtKeywordToken } = require('playwright/lib/server/supplements/recorder/recorderTypes');17const token = new AtKeywordToken('foo');18console.log(token);19const { AtKeywordToken } = require('playwright/lib/server/supplements/recorder/recorderTypes');20const token = new AtKeywordToken('foo');21console.log(token);22const { AtKeywordToken } = require('playwright/lib/server/supplements/recorder/recorderTypes');23const token = new AtKeywordToken('foo');24console.log(token);25const { AtKeywordToken } = require('playwright/lib/server/supplements/recorder/recorderTypes');26const token = new AtKeywordToken('foo');27console.log(token);28const { AtKeywordToken } = require('playwright/lib/server/supplements/recorder/recorderTypes');29const token = new AtKeywordToken('foo');30console.log(token);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AtKeywordToken } = require('playwright-core/lib/server/supplements/recorder/recorderTypes');2const token = new AtKeywordToken('name', 'value');3console.log(token);4const { AtKeywordToken } = require('playwright-core/lib/server/supplements/recorder/recorderTypes');5const token = new AtKeywordToken('name', 'value');6console.log(token);7AtKeywordToken {8}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AtKeywordToken } = require('playwright-core/lib/server/supplements/cssTokenizer');2const { getStylesheetText } = require('playwright-core/lib/server/supplements/cssParser');3const { parseStylesheet } = require('playwright-core/lib/server/supplements/cssParser');4const { parseStyleAttribute } = require('playwright-core/lib/server/supplements/cssParser');5const { parseInlineStylesheet } = require('playwright-core/lib/server/supplements/cssParser');6const { AtKeywordToken } = require('playwright-core/lib/server/supplements/cssTokenizer');7const { getStylesheetText } = require('playwright-core/lib/server/supplements/cssParser');8const { parseStylesheet } = require('playwright-core/lib/server/supplements/cssParser');9const { parseStyleAttribute } = require('playwright-core/lib/server/supplements/cssParser');10const { parseInlineStylesheet } = require('playwright-core/lib/server/supplements/cssParser');11const { AtKeywordToken } = require('playwright-core/lib/server/supplements/cssTokenizer');12const { getStylesheetText } = require('playwright-core/lib/server/supplements/cssParser');13const { parseStylesheet } = require('playwright-core/lib/server/supplements/cssParser');14const { parseStyleAttribute } = require('playwright-core/lib/server/supplements/cssParser');15const { parseInlineStylesheet } = require('playwright-core/lib/server/supplements/cssParser');16const { AtKeywordToken } = require('playwright-core/lib/server/supplements/cssTokenizer');17const { getStylesheetText } = require('playwright-core/lib/server/supplements/cssParser');18const { parseStylesheet } = require('playwright-core/lib/server/supplements/cssParser');19const { parseStyleAttribute } = require('playwright-core/lib/server/supplements/cssParser');20const { parseInlineStylesheet } = require('playwright-core/lib/server/supplements/cssParser');21const { AtKeywordToken } = require('playwright-core/lib/server/supplements/cssTokenizer');22const { getStylesheetText } = require('playwright-core

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AtKeywordToken } = require('playwright/lib/web/lexer');2const { Page } = require('playwright/lib/server/page');3Page.prototype.atKeywordToken = function (selector) {4 return new AtKeywordToken(selector);5};6const { AtKeywordToken } = require('playwright/lib/web/lexer');7const { Page } = require('playwright/lib/server/page');8Page.prototype.atKeywordToken = function (selector) {9 return new AtKeywordToken(selector);10};11const { AtKeywordToken } = require('playwright/lib/web/lexer');12const { Page } = require('playwright/lib/server/page');13Page.prototype.atKeywordToken = function (selector) {14 return new AtKeywordToken(selector);15};16const { AtKeywordToken } = require('playwright/lib/web/lexer');17const { Page } = require('playwright/lib/server/page');18Page.prototype.atKeywordToken = function (selector) {19 return new AtKeywordToken(selector);20};21const { AtKeywordToken } = require('playwright/lib/web/lexer');22const { Page } = require('playwright/lib/server/page');23Page.prototype.atKeywordToken = function (selector) {24 return new AtKeywordToken(selector);25};26const { AtKeywordToken } = require('playwright/lib/web/lexer');27const { Page } = require('playwright/lib/server/page');28Page.prototype.atKeywordToken = function (selector) {29 return new AtKeywordToken(selector);30};31const { AtKeywordToken } = require('playwright/lib/web/lexer');32const { Page } = require('playwright/lib/server/page');33Page.prototype.atKeywordToken = function (selector) {34 return new AtKeywordToken(selector);35};36const { AtKeywordToken } = require('playwright/lib/web/lexer');37const { Page } = require('playwright/lib/server/page');38Page.prototype.atKeywordToken = function (selector) {39 return new AtKeywordToken(selector);40};

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AtKeywordToken } = require('playwright/lib/web.technology/protocol');2const { WebTechnology } = require('playwright/lib/web.technology');3const { WebTechnologyTokenizer } = require('playwright/lib/web.technology/tokenizer');4const webTechnology = new WebTechnology();5webTechnology.addTokenizer(new WebTechnologyTokenizer());6const token = new AtKeywordToken(webTechnology, '@', 'import');7console.log(token.value);8console.log(token.type);9console.log(token.name);10console.log(token.toString());

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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