How to use EOFToken method in Playwright Internal

Best JavaScript code snippet using playwright-internal

index.js

Source:index.js Github

copy

Full Screen

...335 type: type,336 chars: ch337 };338 }339 _createEOFToken() {340 this.currentToken = { type: Tokenizer.EOF_TOKEN };341 }342 //Tag attributes343 _createAttr(attrNameFirstCh) {344 this.currentAttr = {345 name: attrNameFirstCh,346 value: ''347 };348 }349 _leaveAttrName(toState) {350 if (Tokenizer.getTokenAttr(this.currentToken, this.currentAttr.name) === null) {351 this.currentToken.attrs.push(this.currentAttr);352 } else {353 this._err(ERR.duplicateAttribute);354 }355 this.state = toState;356 }357 _leaveAttrValue(toState) {358 this.state = toState;359 }360 //Token emission361 _emitCurrentToken() {362 this._emitCurrentCharacterToken();363 const ct = this.currentToken;364 this.currentToken = null;365 //NOTE: store emited start tag's tagName to determine is the following end tag token is appropriate.366 if (ct.type === Tokenizer.START_TAG_TOKEN) {367 this.lastStartTagName = ct.tagName;368 } else if (ct.type === Tokenizer.END_TAG_TOKEN) {369 if (ct.attrs.length > 0) {370 this._err(ERR.endTagWithAttributes);371 }372 if (ct.selfClosing) {373 this._err(ERR.endTagWithTrailingSolidus);374 }375 }376 this.tokenQueue.push(ct);377 }378 _emitCurrentCharacterToken() {379 if (this.currentCharacterToken) {380 this.tokenQueue.push(this.currentCharacterToken);381 this.currentCharacterToken = null;382 }383 }384 _emitEOFToken() {385 this._createEOFToken();386 this._emitCurrentToken();387 }388 //Characters emission389 //OPTIMIZATION: specification uses only one type of character tokens (one token per character).390 //This causes a huge memory overhead and a lot of unnecessary parser loops. parse5 uses 3 groups of characters.391 //If we have a sequence of characters that belong to the same group, parser can process it392 //as a single solid character token.393 //So, there are 3 types of character tokens in parse5:394 //1)NULL_CHARACTER_TOKEN - \u0000-character sequences (e.g. '\u0000\u0000\u0000')395 //2)WHITESPACE_CHARACTER_TOKEN - any whitespace/new-line character sequences (e.g. '\n \r\t \f')396 //3)CHARACTER_TOKEN - any character sequence which don't belong to groups 1 and 2 (e.g. 'abcdef1234@@#$%^')397 _appendCharToCurrentCharacterToken(type, ch) {398 if (this.currentCharacterToken && this.currentCharacterToken.type !== type) {399 this._emitCurrentCharacterToken();400 }401 if (this.currentCharacterToken) {402 this.currentCharacterToken.chars += ch;403 } else {404 this._createCharacterToken(type, ch);405 }406 }407 _emitCodePoint(cp) {408 let type = Tokenizer.CHARACTER_TOKEN;409 if (isWhitespace(cp)) {410 type = Tokenizer.WHITESPACE_CHARACTER_TOKEN;411 } else if (cp === $.NULL) {412 type = Tokenizer.NULL_CHARACTER_TOKEN;413 }414 this._appendCharToCurrentCharacterToken(type, toChar(cp));415 }416 _emitSeveralCodePoints(codePoints) {417 for (let i = 0; i < codePoints.length; i++) {418 this._emitCodePoint(codePoints[i]);419 }420 }421 //NOTE: used then we emit character explicitly. This is always a non-whitespace and a non-null character.422 //So we can avoid additional checks here.423 _emitChars(ch) {424 this._appendCharToCurrentCharacterToken(Tokenizer.CHARACTER_TOKEN, ch);425 }426 // Character reference helpers427 _matchNamedCharacterReference(startCp) {428 let result = null;429 let excess = 1;430 let i = findNamedEntityTreeBranch(0, startCp);431 this.tempBuff.push(startCp);432 while (i > -1) {433 const current = neTree[i];434 const inNode = current < MAX_BRANCH_MARKER_VALUE;435 const nodeWithData = inNode && current & HAS_DATA_FLAG;436 if (nodeWithData) {437 //NOTE: we use greedy search, so we continue lookup at this point438 result = current & DATA_DUPLET_FLAG ? [neTree[++i], neTree[++i]] : [neTree[++i]];439 excess = 0;440 }441 const cp = this._consume();442 this.tempBuff.push(cp);443 excess++;444 if (cp === $.EOF) {445 break;446 }447 if (inNode) {448 i = current & HAS_BRANCHES_FLAG ? findNamedEntityTreeBranch(i, cp) : -1;449 } else {450 i = cp === current ? ++i : -1;451 }452 }453 while (excess--) {454 this.tempBuff.pop();455 this._unconsume();456 }457 return result;458 }459 _isCharacterReferenceInAttribute() {460 return (461 this.returnState === ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE ||462 this.returnState === ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE ||463 this.returnState === ATTRIBUTE_VALUE_UNQUOTED_STATE464 );465 }466 _isCharacterReferenceAttributeQuirk(withSemicolon) {467 if (!withSemicolon && this._isCharacterReferenceInAttribute()) {468 const nextCp = this._consume();469 this._unconsume();470 return nextCp === $.EQUALS_SIGN || isAsciiAlphaNumeric(nextCp);471 }472 return false;473 }474 _flushCodePointsConsumedAsCharacterReference() {475 if (this._isCharacterReferenceInAttribute()) {476 for (let i = 0; i < this.tempBuff.length; i++) {477 this.currentAttr.value += toChar(this.tempBuff[i]);478 }479 } else {480 this._emitSeveralCodePoints(this.tempBuff);481 }482 this.tempBuff = [];483 }484 // State machine485 // Data state486 //------------------------------------------------------------------487 [DATA_STATE](cp) {488 this.preprocessor.dropParsedChunk();489 if (cp === $.LESS_THAN_SIGN) {490 this.state = TAG_OPEN_STATE;491 } else if (cp === $.AMPERSAND) {492 this.returnState = DATA_STATE;493 this.state = CHARACTER_REFERENCE_STATE;494 } else if (cp === $.NULL) {495 this._err(ERR.unexpectedNullCharacter);496 this._emitCodePoint(cp);497 } else if (cp === $.EOF) {498 this._emitEOFToken();499 } else {500 this._emitCodePoint(cp);501 }502 }503 // RCDATA state504 //------------------------------------------------------------------505 [RCDATA_STATE](cp) {506 this.preprocessor.dropParsedChunk();507 if (cp === $.AMPERSAND) {508 this.returnState = RCDATA_STATE;509 this.state = CHARACTER_REFERENCE_STATE;510 } else if (cp === $.LESS_THAN_SIGN) {511 this.state = RCDATA_LESS_THAN_SIGN_STATE;512 } else if (cp === $.NULL) {513 this._err(ERR.unexpectedNullCharacter);514 this._emitChars(unicode.REPLACEMENT_CHARACTER);515 } else if (cp === $.EOF) {516 this._emitEOFToken();517 } else {518 this._emitCodePoint(cp);519 }520 }521 // RAWTEXT state522 //------------------------------------------------------------------523 [RAWTEXT_STATE](cp) {524 this.preprocessor.dropParsedChunk();525 if (cp === $.LESS_THAN_SIGN) {526 this.state = RAWTEXT_LESS_THAN_SIGN_STATE;527 } else if (cp === $.NULL) {528 this._err(ERR.unexpectedNullCharacter);529 this._emitChars(unicode.REPLACEMENT_CHARACTER);530 } else if (cp === $.EOF) {531 this._emitEOFToken();532 } else {533 this._emitCodePoint(cp);534 }535 }536 // Script data state537 //------------------------------------------------------------------538 [SCRIPT_DATA_STATE](cp) {539 this.preprocessor.dropParsedChunk();540 if (cp === $.LESS_THAN_SIGN) {541 this.state = SCRIPT_DATA_LESS_THAN_SIGN_STATE;542 } else if (cp === $.NULL) {543 this._err(ERR.unexpectedNullCharacter);544 this._emitChars(unicode.REPLACEMENT_CHARACTER);545 } else if (cp === $.EOF) {546 this._emitEOFToken();547 } else {548 this._emitCodePoint(cp);549 }550 }551 // PLAINTEXT state552 //------------------------------------------------------------------553 [PLAINTEXT_STATE](cp) {554 this.preprocessor.dropParsedChunk();555 if (cp === $.NULL) {556 this._err(ERR.unexpectedNullCharacter);557 this._emitChars(unicode.REPLACEMENT_CHARACTER);558 } else if (cp === $.EOF) {559 this._emitEOFToken();560 } else {561 this._emitCodePoint(cp);562 }563 }564 // Tag open state565 //------------------------------------------------------------------566 [TAG_OPEN_STATE](cp) {567 if (cp === $.EXCLAMATION_MARK) {568 this.state = MARKUP_DECLARATION_OPEN_STATE;569 } else if (cp === $.SOLIDUS) {570 this.state = END_TAG_OPEN_STATE;571 } else if (isAsciiLetter(cp)) {572 this._createStartTagToken();573 this._reconsumeInState(TAG_NAME_STATE);574 } else if (cp === $.QUESTION_MARK) {575 this._err(ERR.unexpectedQuestionMarkInsteadOfTagName);576 this._createCommentToken();577 this._reconsumeInState(BOGUS_COMMENT_STATE);578 } else if (cp === $.EOF) {579 this._err(ERR.eofBeforeTagName);580 this._emitChars('<');581 this._emitEOFToken();582 } else {583 this._err(ERR.invalidFirstCharacterOfTagName);584 this._emitChars('<');585 this._reconsumeInState(DATA_STATE);586 }587 }588 // End tag open state589 //------------------------------------------------------------------590 [END_TAG_OPEN_STATE](cp) {591 if (isAsciiLetter(cp)) {592 this._createEndTagToken();593 this._reconsumeInState(TAG_NAME_STATE);594 } else if (cp === $.GREATER_THAN_SIGN) {595 this._err(ERR.missingEndTagName);596 this.state = DATA_STATE;597 } else if (cp === $.EOF) {598 this._err(ERR.eofBeforeTagName);599 this._emitChars('</');600 this._emitEOFToken();601 } else {602 this._err(ERR.invalidFirstCharacterOfTagName);603 this._createCommentToken();604 this._reconsumeInState(BOGUS_COMMENT_STATE);605 }606 }607 // Tag name state608 //------------------------------------------------------------------609 [TAG_NAME_STATE](cp) {610 if (isWhitespace(cp)) {611 this.state = BEFORE_ATTRIBUTE_NAME_STATE;612 } else if (cp === $.SOLIDUS) {613 this.state = SELF_CLOSING_START_TAG_STATE;614 } else if (cp === $.GREATER_THAN_SIGN) {615 this.state = DATA_STATE;616 this._emitCurrentToken();617 } else if (isAsciiUpper(cp)) {618 this.currentToken.tagName += toAsciiLowerChar(cp);619 } else if (cp === $.NULL) {620 this._err(ERR.unexpectedNullCharacter);621 this.currentToken.tagName += unicode.REPLACEMENT_CHARACTER;622 } else if (cp === $.EOF) {623 this._err(ERR.eofInTag);624 this._emitEOFToken();625 } else {626 this.currentToken.tagName += toChar(cp);627 }628 }629 // RCDATA less-than sign state630 //------------------------------------------------------------------631 [RCDATA_LESS_THAN_SIGN_STATE](cp) {632 if (cp === $.SOLIDUS) {633 this.tempBuff = [];634 this.state = RCDATA_END_TAG_OPEN_STATE;635 } else {636 this._emitChars('<');637 this._reconsumeInState(RCDATA_STATE);638 }639 }640 // RCDATA end tag open state641 //------------------------------------------------------------------642 [RCDATA_END_TAG_OPEN_STATE](cp) {643 if (isAsciiLetter(cp)) {644 this._createEndTagToken();645 this._reconsumeInState(RCDATA_END_TAG_NAME_STATE);646 } else {647 this._emitChars('</');648 this._reconsumeInState(RCDATA_STATE);649 }650 }651 // RCDATA end tag name state652 //------------------------------------------------------------------653 [RCDATA_END_TAG_NAME_STATE](cp) {654 if (isAsciiUpper(cp)) {655 this.currentToken.tagName += toAsciiLowerChar(cp);656 this.tempBuff.push(cp);657 } else if (isAsciiLower(cp)) {658 this.currentToken.tagName += toChar(cp);659 this.tempBuff.push(cp);660 } else {661 if (this.lastStartTagName === this.currentToken.tagName) {662 if (isWhitespace(cp)) {663 this.state = BEFORE_ATTRIBUTE_NAME_STATE;664 return;665 }666 if (cp === $.SOLIDUS) {667 this.state = SELF_CLOSING_START_TAG_STATE;668 return;669 }670 if (cp === $.GREATER_THAN_SIGN) {671 this.state = DATA_STATE;672 this._emitCurrentToken();673 return;674 }675 }676 this._emitChars('</');677 this._emitSeveralCodePoints(this.tempBuff);678 this._reconsumeInState(RCDATA_STATE);679 }680 }681 // RAWTEXT less-than sign state682 //------------------------------------------------------------------683 [RAWTEXT_LESS_THAN_SIGN_STATE](cp) {684 if (cp === $.SOLIDUS) {685 this.tempBuff = [];686 this.state = RAWTEXT_END_TAG_OPEN_STATE;687 } else {688 this._emitChars('<');689 this._reconsumeInState(RAWTEXT_STATE);690 }691 }692 // RAWTEXT end tag open state693 //------------------------------------------------------------------694 [RAWTEXT_END_TAG_OPEN_STATE](cp) {695 if (isAsciiLetter(cp)) {696 this._createEndTagToken();697 this._reconsumeInState(RAWTEXT_END_TAG_NAME_STATE);698 } else {699 this._emitChars('</');700 this._reconsumeInState(RAWTEXT_STATE);701 }702 }703 // RAWTEXT end tag name state704 //------------------------------------------------------------------705 [RAWTEXT_END_TAG_NAME_STATE](cp) {706 if (isAsciiUpper(cp)) {707 this.currentToken.tagName += toAsciiLowerChar(cp);708 this.tempBuff.push(cp);709 } else if (isAsciiLower(cp)) {710 this.currentToken.tagName += toChar(cp);711 this.tempBuff.push(cp);712 } else {713 if (this.lastStartTagName === this.currentToken.tagName) {714 if (isWhitespace(cp)) {715 this.state = BEFORE_ATTRIBUTE_NAME_STATE;716 return;717 }718 if (cp === $.SOLIDUS) {719 this.state = SELF_CLOSING_START_TAG_STATE;720 return;721 }722 if (cp === $.GREATER_THAN_SIGN) {723 this._emitCurrentToken();724 this.state = DATA_STATE;725 return;726 }727 }728 this._emitChars('</');729 this._emitSeveralCodePoints(this.tempBuff);730 this._reconsumeInState(RAWTEXT_STATE);731 }732 }733 // Script data less-than sign state734 //------------------------------------------------------------------735 [SCRIPT_DATA_LESS_THAN_SIGN_STATE](cp) {736 if (cp === $.SOLIDUS) {737 this.tempBuff = [];738 this.state = SCRIPT_DATA_END_TAG_OPEN_STATE;739 } else if (cp === $.EXCLAMATION_MARK) {740 this.state = SCRIPT_DATA_ESCAPE_START_STATE;741 this._emitChars('<!');742 } else {743 this._emitChars('<');744 this._reconsumeInState(SCRIPT_DATA_STATE);745 }746 }747 // Script data end tag open state748 //------------------------------------------------------------------749 [SCRIPT_DATA_END_TAG_OPEN_STATE](cp) {750 if (isAsciiLetter(cp)) {751 this._createEndTagToken();752 this._reconsumeInState(SCRIPT_DATA_END_TAG_NAME_STATE);753 } else {754 this._emitChars('</');755 this._reconsumeInState(SCRIPT_DATA_STATE);756 }757 }758 // Script data end tag name state759 //------------------------------------------------------------------760 [SCRIPT_DATA_END_TAG_NAME_STATE](cp) {761 if (isAsciiUpper(cp)) {762 this.currentToken.tagName += toAsciiLowerChar(cp);763 this.tempBuff.push(cp);764 } else if (isAsciiLower(cp)) {765 this.currentToken.tagName += toChar(cp);766 this.tempBuff.push(cp);767 } else {768 if (this.lastStartTagName === this.currentToken.tagName) {769 if (isWhitespace(cp)) {770 this.state = BEFORE_ATTRIBUTE_NAME_STATE;771 return;772 } else if (cp === $.SOLIDUS) {773 this.state = SELF_CLOSING_START_TAG_STATE;774 return;775 } else if (cp === $.GREATER_THAN_SIGN) {776 this._emitCurrentToken();777 this.state = DATA_STATE;778 return;779 }780 }781 this._emitChars('</');782 this._emitSeveralCodePoints(this.tempBuff);783 this._reconsumeInState(SCRIPT_DATA_STATE);784 }785 }786 // Script data escape start state787 //------------------------------------------------------------------788 [SCRIPT_DATA_ESCAPE_START_STATE](cp) {789 if (cp === $.HYPHEN_MINUS) {790 this.state = SCRIPT_DATA_ESCAPE_START_DASH_STATE;791 this._emitChars('-');792 } else {793 this._reconsumeInState(SCRIPT_DATA_STATE);794 }795 }796 // Script data escape start dash state797 //------------------------------------------------------------------798 [SCRIPT_DATA_ESCAPE_START_DASH_STATE](cp) {799 if (cp === $.HYPHEN_MINUS) {800 this.state = SCRIPT_DATA_ESCAPED_DASH_DASH_STATE;801 this._emitChars('-');802 } else {803 this._reconsumeInState(SCRIPT_DATA_STATE);804 }805 }806 // Script data escaped state807 //------------------------------------------------------------------808 [SCRIPT_DATA_ESCAPED_STATE](cp) {809 if (cp === $.HYPHEN_MINUS) {810 this.state = SCRIPT_DATA_ESCAPED_DASH_STATE;811 this._emitChars('-');812 } else if (cp === $.LESS_THAN_SIGN) {813 this.state = SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN_STATE;814 } else if (cp === $.NULL) {815 this._err(ERR.unexpectedNullCharacter);816 this._emitChars(unicode.REPLACEMENT_CHARACTER);817 } else if (cp === $.EOF) {818 this._err(ERR.eofInScriptHtmlCommentLikeText);819 this._emitEOFToken();820 } else {821 this._emitCodePoint(cp);822 }823 }824 // Script data escaped dash state825 //------------------------------------------------------------------826 [SCRIPT_DATA_ESCAPED_DASH_STATE](cp) {827 if (cp === $.HYPHEN_MINUS) {828 this.state = SCRIPT_DATA_ESCAPED_DASH_DASH_STATE;829 this._emitChars('-');830 } else if (cp === $.LESS_THAN_SIGN) {831 this.state = SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN_STATE;832 } else if (cp === $.NULL) {833 this._err(ERR.unexpectedNullCharacter);834 this.state = SCRIPT_DATA_ESCAPED_STATE;835 this._emitChars(unicode.REPLACEMENT_CHARACTER);836 } else if (cp === $.EOF) {837 this._err(ERR.eofInScriptHtmlCommentLikeText);838 this._emitEOFToken();839 } else {840 this.state = SCRIPT_DATA_ESCAPED_STATE;841 this._emitCodePoint(cp);842 }843 }844 // Script data escaped dash dash state845 //------------------------------------------------------------------846 [SCRIPT_DATA_ESCAPED_DASH_DASH_STATE](cp) {847 if (cp === $.HYPHEN_MINUS) {848 this._emitChars('-');849 } else if (cp === $.LESS_THAN_SIGN) {850 this.state = SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN_STATE;851 } else if (cp === $.GREATER_THAN_SIGN) {852 this.state = SCRIPT_DATA_STATE;853 this._emitChars('>');854 } else if (cp === $.NULL) {855 this._err(ERR.unexpectedNullCharacter);856 this.state = SCRIPT_DATA_ESCAPED_STATE;857 this._emitChars(unicode.REPLACEMENT_CHARACTER);858 } else if (cp === $.EOF) {859 this._err(ERR.eofInScriptHtmlCommentLikeText);860 this._emitEOFToken();861 } else {862 this.state = SCRIPT_DATA_ESCAPED_STATE;863 this._emitCodePoint(cp);864 }865 }866 // Script data escaped less-than sign state867 //------------------------------------------------------------------868 [SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN_STATE](cp) {869 if (cp === $.SOLIDUS) {870 this.tempBuff = [];871 this.state = SCRIPT_DATA_ESCAPED_END_TAG_OPEN_STATE;872 } else if (isAsciiLetter(cp)) {873 this.tempBuff = [];874 this._emitChars('<');875 this._reconsumeInState(SCRIPT_DATA_DOUBLE_ESCAPE_START_STATE);876 } else {877 this._emitChars('<');878 this._reconsumeInState(SCRIPT_DATA_ESCAPED_STATE);879 }880 }881 // Script data escaped end tag open state882 //------------------------------------------------------------------883 [SCRIPT_DATA_ESCAPED_END_TAG_OPEN_STATE](cp) {884 if (isAsciiLetter(cp)) {885 this._createEndTagToken();886 this._reconsumeInState(SCRIPT_DATA_ESCAPED_END_TAG_NAME_STATE);887 } else {888 this._emitChars('</');889 this._reconsumeInState(SCRIPT_DATA_ESCAPED_STATE);890 }891 }892 // Script data escaped end tag name state893 //------------------------------------------------------------------894 [SCRIPT_DATA_ESCAPED_END_TAG_NAME_STATE](cp) {895 if (isAsciiUpper(cp)) {896 this.currentToken.tagName += toAsciiLowerChar(cp);897 this.tempBuff.push(cp);898 } else if (isAsciiLower(cp)) {899 this.currentToken.tagName += toChar(cp);900 this.tempBuff.push(cp);901 } else {902 if (this.lastStartTagName === this.currentToken.tagName) {903 if (isWhitespace(cp)) {904 this.state = BEFORE_ATTRIBUTE_NAME_STATE;905 return;906 }907 if (cp === $.SOLIDUS) {908 this.state = SELF_CLOSING_START_TAG_STATE;909 return;910 }911 if (cp === $.GREATER_THAN_SIGN) {912 this._emitCurrentToken();913 this.state = DATA_STATE;914 return;915 }916 }917 this._emitChars('</');918 this._emitSeveralCodePoints(this.tempBuff);919 this._reconsumeInState(SCRIPT_DATA_ESCAPED_STATE);920 }921 }922 // Script data double escape start state923 //------------------------------------------------------------------924 [SCRIPT_DATA_DOUBLE_ESCAPE_START_STATE](cp) {925 if (isWhitespace(cp) || cp === $.SOLIDUS || cp === $.GREATER_THAN_SIGN) {926 this.state = this._isTempBufferEqualToScriptString()927 ? SCRIPT_DATA_DOUBLE_ESCAPED_STATE928 : SCRIPT_DATA_ESCAPED_STATE;929 this._emitCodePoint(cp);930 } else if (isAsciiUpper(cp)) {931 this.tempBuff.push(toAsciiLowerCodePoint(cp));932 this._emitCodePoint(cp);933 } else if (isAsciiLower(cp)) {934 this.tempBuff.push(cp);935 this._emitCodePoint(cp);936 } else {937 this._reconsumeInState(SCRIPT_DATA_ESCAPED_STATE);938 }939 }940 // Script data double escaped state941 //------------------------------------------------------------------942 [SCRIPT_DATA_DOUBLE_ESCAPED_STATE](cp) {943 if (cp === $.HYPHEN_MINUS) {944 this.state = SCRIPT_DATA_DOUBLE_ESCAPED_DASH_STATE;945 this._emitChars('-');946 } else if (cp === $.LESS_THAN_SIGN) {947 this.state = SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN_STATE;948 this._emitChars('<');949 } else if (cp === $.NULL) {950 this._err(ERR.unexpectedNullCharacter);951 this._emitChars(unicode.REPLACEMENT_CHARACTER);952 } else if (cp === $.EOF) {953 this._err(ERR.eofInScriptHtmlCommentLikeText);954 this._emitEOFToken();955 } else {956 this._emitCodePoint(cp);957 }958 }959 // Script data double escaped dash state960 //------------------------------------------------------------------961 [SCRIPT_DATA_DOUBLE_ESCAPED_DASH_STATE](cp) {962 if (cp === $.HYPHEN_MINUS) {963 this.state = SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH_STATE;964 this._emitChars('-');965 } else if (cp === $.LESS_THAN_SIGN) {966 this.state = SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN_STATE;967 this._emitChars('<');968 } else if (cp === $.NULL) {969 this._err(ERR.unexpectedNullCharacter);970 this.state = SCRIPT_DATA_DOUBLE_ESCAPED_STATE;971 this._emitChars(unicode.REPLACEMENT_CHARACTER);972 } else if (cp === $.EOF) {973 this._err(ERR.eofInScriptHtmlCommentLikeText);974 this._emitEOFToken();975 } else {976 this.state = SCRIPT_DATA_DOUBLE_ESCAPED_STATE;977 this._emitCodePoint(cp);978 }979 }980 // Script data double escaped dash dash state981 //------------------------------------------------------------------982 [SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH_STATE](cp) {983 if (cp === $.HYPHEN_MINUS) {984 this._emitChars('-');985 } else if (cp === $.LESS_THAN_SIGN) {986 this.state = SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN_STATE;987 this._emitChars('<');988 } else if (cp === $.GREATER_THAN_SIGN) {989 this.state = SCRIPT_DATA_STATE;990 this._emitChars('>');991 } else if (cp === $.NULL) {992 this._err(ERR.unexpectedNullCharacter);993 this.state = SCRIPT_DATA_DOUBLE_ESCAPED_STATE;994 this._emitChars(unicode.REPLACEMENT_CHARACTER);995 } else if (cp === $.EOF) {996 this._err(ERR.eofInScriptHtmlCommentLikeText);997 this._emitEOFToken();998 } else {999 this.state = SCRIPT_DATA_DOUBLE_ESCAPED_STATE;1000 this._emitCodePoint(cp);1001 }1002 }1003 // Script data double escaped less-than sign state1004 //------------------------------------------------------------------1005 [SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN_STATE](cp) {1006 if (cp === $.SOLIDUS) {1007 this.tempBuff = [];1008 this.state = SCRIPT_DATA_DOUBLE_ESCAPE_END_STATE;1009 this._emitChars('/');1010 } else {1011 this._reconsumeInState(SCRIPT_DATA_DOUBLE_ESCAPED_STATE);1012 }1013 }1014 // Script data double escape end state1015 //------------------------------------------------------------------1016 [SCRIPT_DATA_DOUBLE_ESCAPE_END_STATE](cp) {1017 if (isWhitespace(cp) || cp === $.SOLIDUS || cp === $.GREATER_THAN_SIGN) {1018 this.state = this._isTempBufferEqualToScriptString()1019 ? SCRIPT_DATA_ESCAPED_STATE1020 : SCRIPT_DATA_DOUBLE_ESCAPED_STATE;1021 this._emitCodePoint(cp);1022 } else if (isAsciiUpper(cp)) {1023 this.tempBuff.push(toAsciiLowerCodePoint(cp));1024 this._emitCodePoint(cp);1025 } else if (isAsciiLower(cp)) {1026 this.tempBuff.push(cp);1027 this._emitCodePoint(cp);1028 } else {1029 this._reconsumeInState(SCRIPT_DATA_DOUBLE_ESCAPED_STATE);1030 }1031 }1032 // Before attribute name state1033 //------------------------------------------------------------------1034 [BEFORE_ATTRIBUTE_NAME_STATE](cp) {1035 if (isWhitespace(cp)) {1036 return;1037 }1038 if (cp === $.SOLIDUS || cp === $.GREATER_THAN_SIGN || cp === $.EOF) {1039 this._reconsumeInState(AFTER_ATTRIBUTE_NAME_STATE);1040 } else if (cp === $.EQUALS_SIGN) {1041 this._err(ERR.unexpectedEqualsSignBeforeAttributeName);1042 this._createAttr('=');1043 this.state = ATTRIBUTE_NAME_STATE;1044 } else {1045 this._createAttr('');1046 this._reconsumeInState(ATTRIBUTE_NAME_STATE);1047 }1048 }1049 // Attribute name state1050 //------------------------------------------------------------------1051 [ATTRIBUTE_NAME_STATE](cp) {1052 if (isWhitespace(cp) || cp === $.SOLIDUS || cp === $.GREATER_THAN_SIGN || cp === $.EOF) {1053 this._leaveAttrName(AFTER_ATTRIBUTE_NAME_STATE);1054 this._unconsume();1055 } else if (cp === $.EQUALS_SIGN) {1056 this._leaveAttrName(BEFORE_ATTRIBUTE_VALUE_STATE);1057 } else if (isAsciiUpper(cp)) {1058 this.currentAttr.name += toAsciiLowerChar(cp);1059 } else if (cp === $.QUOTATION_MARK || cp === $.APOSTROPHE || cp === $.LESS_THAN_SIGN) {1060 this._err(ERR.unexpectedCharacterInAttributeName);1061 this.currentAttr.name += toChar(cp);1062 } else if (cp === $.NULL) {1063 this._err(ERR.unexpectedNullCharacter);1064 this.currentAttr.name += unicode.REPLACEMENT_CHARACTER;1065 } else {1066 this.currentAttr.name += toChar(cp);1067 }1068 }1069 // After attribute name state1070 //------------------------------------------------------------------1071 [AFTER_ATTRIBUTE_NAME_STATE](cp) {1072 if (isWhitespace(cp)) {1073 return;1074 }1075 if (cp === $.SOLIDUS) {1076 this.state = SELF_CLOSING_START_TAG_STATE;1077 } else if (cp === $.EQUALS_SIGN) {1078 this.state = BEFORE_ATTRIBUTE_VALUE_STATE;1079 } else if (cp === $.GREATER_THAN_SIGN) {1080 this.state = DATA_STATE;1081 this._emitCurrentToken();1082 } else if (cp === $.EOF) {1083 this._err(ERR.eofInTag);1084 this._emitEOFToken();1085 } else {1086 this._createAttr('');1087 this._reconsumeInState(ATTRIBUTE_NAME_STATE);1088 }1089 }1090 // Before attribute value state1091 //------------------------------------------------------------------1092 [BEFORE_ATTRIBUTE_VALUE_STATE](cp) {1093 if (isWhitespace(cp)) {1094 return;1095 }1096 if (cp === $.QUOTATION_MARK) {1097 this.state = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;1098 } else if (cp === $.APOSTROPHE) {1099 this.state = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;1100 } else if (cp === $.GREATER_THAN_SIGN) {1101 this._err(ERR.missingAttributeValue);1102 this.state = DATA_STATE;1103 this._emitCurrentToken();1104 } else {1105 this._reconsumeInState(ATTRIBUTE_VALUE_UNQUOTED_STATE);1106 }1107 }1108 // Attribute value (double-quoted) state1109 //------------------------------------------------------------------1110 [ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE](cp) {1111 if (cp === $.QUOTATION_MARK) {1112 this.state = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;1113 } else if (cp === $.AMPERSAND) {1114 this.returnState = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;1115 this.state = CHARACTER_REFERENCE_STATE;1116 } else if (cp === $.NULL) {1117 this._err(ERR.unexpectedNullCharacter);1118 this.currentAttr.value += unicode.REPLACEMENT_CHARACTER;1119 } else if (cp === $.EOF) {1120 this._err(ERR.eofInTag);1121 this._emitEOFToken();1122 } else {1123 this.currentAttr.value += toChar(cp);1124 }1125 }1126 // Attribute value (single-quoted) state1127 //------------------------------------------------------------------1128 [ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE](cp) {1129 if (cp === $.APOSTROPHE) {1130 this.state = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;1131 } else if (cp === $.AMPERSAND) {1132 this.returnState = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;1133 this.state = CHARACTER_REFERENCE_STATE;1134 } else if (cp === $.NULL) {1135 this._err(ERR.unexpectedNullCharacter);1136 this.currentAttr.value += unicode.REPLACEMENT_CHARACTER;1137 } else if (cp === $.EOF) {1138 this._err(ERR.eofInTag);1139 this._emitEOFToken();1140 } else {1141 this.currentAttr.value += toChar(cp);1142 }1143 }1144 // Attribute value (unquoted) state1145 //------------------------------------------------------------------1146 [ATTRIBUTE_VALUE_UNQUOTED_STATE](cp) {1147 if (isWhitespace(cp)) {1148 this._leaveAttrValue(BEFORE_ATTRIBUTE_NAME_STATE);1149 } else if (cp === $.AMPERSAND) {1150 this.returnState = ATTRIBUTE_VALUE_UNQUOTED_STATE;1151 this.state = CHARACTER_REFERENCE_STATE;1152 } else if (cp === $.GREATER_THAN_SIGN) {1153 this._leaveAttrValue(DATA_STATE);1154 this._emitCurrentToken();1155 } else if (cp === $.NULL) {1156 this._err(ERR.unexpectedNullCharacter);1157 this.currentAttr.value += unicode.REPLACEMENT_CHARACTER;1158 } else if (1159 cp === $.QUOTATION_MARK ||1160 cp === $.APOSTROPHE ||1161 cp === $.LESS_THAN_SIGN ||1162 cp === $.EQUALS_SIGN ||1163 cp === $.GRAVE_ACCENT1164 ) {1165 this._err(ERR.unexpectedCharacterInUnquotedAttributeValue);1166 this.currentAttr.value += toChar(cp);1167 } else if (cp === $.EOF) {1168 this._err(ERR.eofInTag);1169 this._emitEOFToken();1170 } else {1171 this.currentAttr.value += toChar(cp);1172 }1173 }1174 // After attribute value (quoted) state1175 //------------------------------------------------------------------1176 [AFTER_ATTRIBUTE_VALUE_QUOTED_STATE](cp) {1177 if (isWhitespace(cp)) {1178 this._leaveAttrValue(BEFORE_ATTRIBUTE_NAME_STATE);1179 } else if (cp === $.SOLIDUS) {1180 this._leaveAttrValue(SELF_CLOSING_START_TAG_STATE);1181 } else if (cp === $.GREATER_THAN_SIGN) {1182 this._leaveAttrValue(DATA_STATE);1183 this._emitCurrentToken();1184 } else if (cp === $.EOF) {1185 this._err(ERR.eofInTag);1186 this._emitEOFToken();1187 } else {1188 this._err(ERR.missingWhitespaceBetweenAttributes);1189 this._reconsumeInState(BEFORE_ATTRIBUTE_NAME_STATE);1190 }1191 }1192 // Self-closing start tag state1193 //------------------------------------------------------------------1194 [SELF_CLOSING_START_TAG_STATE](cp) {1195 if (cp === $.GREATER_THAN_SIGN) {1196 this.currentToken.selfClosing = true;1197 this.state = DATA_STATE;1198 this._emitCurrentToken();1199 } else if (cp === $.EOF) {1200 this._err(ERR.eofInTag);1201 this._emitEOFToken();1202 } else {1203 this._err(ERR.unexpectedSolidusInTag);1204 this._reconsumeInState(BEFORE_ATTRIBUTE_NAME_STATE);1205 }1206 }1207 // Bogus comment state1208 //------------------------------------------------------------------1209 [BOGUS_COMMENT_STATE](cp) {1210 if (cp === $.GREATER_THAN_SIGN) {1211 this.state = DATA_STATE;1212 this._emitCurrentToken();1213 } else if (cp === $.EOF) {1214 this._emitCurrentToken();1215 this._emitEOFToken();1216 } else if (cp === $.NULL) {1217 this._err(ERR.unexpectedNullCharacter);1218 this.currentToken.data += unicode.REPLACEMENT_CHARACTER;1219 } else {1220 this.currentToken.data += toChar(cp);1221 }1222 }1223 // Markup declaration open state1224 //------------------------------------------------------------------1225 [MARKUP_DECLARATION_OPEN_STATE](cp) {1226 if (this._consumeSequenceIfMatch($$.DASH_DASH_STRING, cp, true)) {1227 this._createCommentToken();1228 this.state = COMMENT_START_STATE;1229 } else if (this._consumeSequenceIfMatch($$.DOCTYPE_STRING, cp, false)) {1230 this.state = DOCTYPE_STATE;1231 } else if (this._consumeSequenceIfMatch($$.CDATA_START_STRING, cp, true)) {1232 if (this.allowCDATA) {1233 this.state = CDATA_SECTION_STATE;1234 } else {1235 this._err(ERR.cdataInHtmlContent);1236 this._createCommentToken();1237 this.currentToken.data = '[CDATA[';1238 this.state = BOGUS_COMMENT_STATE;1239 }1240 }1241 //NOTE: sequence lookup can be abrupted by hibernation. In that case lookup1242 //results are no longer valid and we will need to start over.1243 else if (!this._ensureHibernation()) {1244 this._err(ERR.incorrectlyOpenedComment);1245 this._createCommentToken();1246 this._reconsumeInState(BOGUS_COMMENT_STATE);1247 }1248 }1249 // Comment start state1250 //------------------------------------------------------------------1251 [COMMENT_START_STATE](cp) {1252 if (cp === $.HYPHEN_MINUS) {1253 this.state = COMMENT_START_DASH_STATE;1254 } else if (cp === $.GREATER_THAN_SIGN) {1255 this._err(ERR.abruptClosingOfEmptyComment);1256 this.state = DATA_STATE;1257 this._emitCurrentToken();1258 } else {1259 this._reconsumeInState(COMMENT_STATE);1260 }1261 }1262 // Comment start dash state1263 //------------------------------------------------------------------1264 [COMMENT_START_DASH_STATE](cp) {1265 if (cp === $.HYPHEN_MINUS) {1266 this.state = COMMENT_END_STATE;1267 } else if (cp === $.GREATER_THAN_SIGN) {1268 this._err(ERR.abruptClosingOfEmptyComment);1269 this.state = DATA_STATE;1270 this._emitCurrentToken();1271 } else if (cp === $.EOF) {1272 this._err(ERR.eofInComment);1273 this._emitCurrentToken();1274 this._emitEOFToken();1275 } else {1276 this.currentToken.data += '-';1277 this._reconsumeInState(COMMENT_STATE);1278 }1279 }1280 // Comment state1281 //------------------------------------------------------------------1282 [COMMENT_STATE](cp) {1283 if (cp === $.HYPHEN_MINUS) {1284 this.state = COMMENT_END_DASH_STATE;1285 } else if (cp === $.LESS_THAN_SIGN) {1286 this.currentToken.data += '<';1287 this.state = COMMENT_LESS_THAN_SIGN_STATE;1288 } else if (cp === $.NULL) {1289 this._err(ERR.unexpectedNullCharacter);1290 this.currentToken.data += unicode.REPLACEMENT_CHARACTER;1291 } else if (cp === $.EOF) {1292 this._err(ERR.eofInComment);1293 this._emitCurrentToken();1294 this._emitEOFToken();1295 } else {1296 this.currentToken.data += toChar(cp);1297 }1298 }1299 // Comment less-than sign state1300 //------------------------------------------------------------------1301 [COMMENT_LESS_THAN_SIGN_STATE](cp) {1302 if (cp === $.EXCLAMATION_MARK) {1303 this.currentToken.data += '!';1304 this.state = COMMENT_LESS_THAN_SIGN_BANG_STATE;1305 } else if (cp === $.LESS_THAN_SIGN) {1306 this.currentToken.data += '!';1307 } else {1308 this._reconsumeInState(COMMENT_STATE);1309 }1310 }1311 // Comment less-than sign bang state1312 //------------------------------------------------------------------1313 [COMMENT_LESS_THAN_SIGN_BANG_STATE](cp) {1314 if (cp === $.HYPHEN_MINUS) {1315 this.state = COMMENT_LESS_THAN_SIGN_BANG_DASH_STATE;1316 } else {1317 this._reconsumeInState(COMMENT_STATE);1318 }1319 }1320 // Comment less-than sign bang dash state1321 //------------------------------------------------------------------1322 [COMMENT_LESS_THAN_SIGN_BANG_DASH_STATE](cp) {1323 if (cp === $.HYPHEN_MINUS) {1324 this.state = COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH_STATE;1325 } else {1326 this._reconsumeInState(COMMENT_END_DASH_STATE);1327 }1328 }1329 // Comment less-than sign bang dash dash state1330 //------------------------------------------------------------------1331 [COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH_STATE](cp) {1332 if (cp !== $.GREATER_THAN_SIGN && cp !== $.EOF) {1333 this._err(ERR.nestedComment);1334 }1335 this._reconsumeInState(COMMENT_END_STATE);1336 }1337 // Comment end dash state1338 //------------------------------------------------------------------1339 [COMMENT_END_DASH_STATE](cp) {1340 if (cp === $.HYPHEN_MINUS) {1341 this.state = COMMENT_END_STATE;1342 } else if (cp === $.EOF) {1343 this._err(ERR.eofInComment);1344 this._emitCurrentToken();1345 this._emitEOFToken();1346 } else {1347 this.currentToken.data += '-';1348 this._reconsumeInState(COMMENT_STATE);1349 }1350 }1351 // Comment end state1352 //------------------------------------------------------------------1353 [COMMENT_END_STATE](cp) {1354 if (cp === $.GREATER_THAN_SIGN) {1355 this.state = DATA_STATE;1356 this._emitCurrentToken();1357 } else if (cp === $.EXCLAMATION_MARK) {1358 this.state = COMMENT_END_BANG_STATE;1359 } else if (cp === $.HYPHEN_MINUS) {1360 this.currentToken.data += '-';1361 } else if (cp === $.EOF) {1362 this._err(ERR.eofInComment);1363 this._emitCurrentToken();1364 this._emitEOFToken();1365 } else {1366 this.currentToken.data += '--';1367 this._reconsumeInState(COMMENT_STATE);1368 }1369 }1370 // Comment end bang state1371 //------------------------------------------------------------------1372 [COMMENT_END_BANG_STATE](cp) {1373 if (cp === $.HYPHEN_MINUS) {1374 this.currentToken.data += '--!';1375 this.state = COMMENT_END_DASH_STATE;1376 } else if (cp === $.GREATER_THAN_SIGN) {1377 this._err(ERR.incorrectlyClosedComment);1378 this.state = DATA_STATE;1379 this._emitCurrentToken();1380 } else if (cp === $.EOF) {1381 this._err(ERR.eofInComment);1382 this._emitCurrentToken();1383 this._emitEOFToken();1384 } else {1385 this.currentToken.data += '--!';1386 this._reconsumeInState(COMMENT_STATE);1387 }1388 }1389 // DOCTYPE state1390 //------------------------------------------------------------------1391 [DOCTYPE_STATE](cp) {1392 if (isWhitespace(cp)) {1393 this.state = BEFORE_DOCTYPE_NAME_STATE;1394 } else if (cp === $.GREATER_THAN_SIGN) {1395 this._reconsumeInState(BEFORE_DOCTYPE_NAME_STATE);1396 } else if (cp === $.EOF) {1397 this._err(ERR.eofInDoctype);1398 this._createDoctypeToken(null);1399 this.currentToken.forceQuirks = true;1400 this._emitCurrentToken();1401 this._emitEOFToken();1402 } else {1403 this._err(ERR.missingWhitespaceBeforeDoctypeName);1404 this._reconsumeInState(BEFORE_DOCTYPE_NAME_STATE);1405 }1406 }1407 // Before DOCTYPE name state1408 //------------------------------------------------------------------1409 [BEFORE_DOCTYPE_NAME_STATE](cp) {1410 if (isWhitespace(cp)) {1411 return;1412 }1413 if (isAsciiUpper(cp)) {1414 this._createDoctypeToken(toAsciiLowerChar(cp));1415 this.state = DOCTYPE_NAME_STATE;1416 } else if (cp === $.NULL) {1417 this._err(ERR.unexpectedNullCharacter);1418 this._createDoctypeToken(unicode.REPLACEMENT_CHARACTER);1419 this.state = DOCTYPE_NAME_STATE;1420 } else if (cp === $.GREATER_THAN_SIGN) {1421 this._err(ERR.missingDoctypeName);1422 this._createDoctypeToken(null);1423 this.currentToken.forceQuirks = true;1424 this._emitCurrentToken();1425 this.state = DATA_STATE;1426 } else if (cp === $.EOF) {1427 this._err(ERR.eofInDoctype);1428 this._createDoctypeToken(null);1429 this.currentToken.forceQuirks = true;1430 this._emitCurrentToken();1431 this._emitEOFToken();1432 } else {1433 this._createDoctypeToken(toChar(cp));1434 this.state = DOCTYPE_NAME_STATE;1435 }1436 }1437 // DOCTYPE name state1438 //------------------------------------------------------------------1439 [DOCTYPE_NAME_STATE](cp) {1440 if (isWhitespace(cp)) {1441 this.state = AFTER_DOCTYPE_NAME_STATE;1442 } else if (cp === $.GREATER_THAN_SIGN) {1443 this.state = DATA_STATE;1444 this._emitCurrentToken();1445 } else if (isAsciiUpper(cp)) {1446 this.currentToken.name += toAsciiLowerChar(cp);1447 } else if (cp === $.NULL) {1448 this._err(ERR.unexpectedNullCharacter);1449 this.currentToken.name += unicode.REPLACEMENT_CHARACTER;1450 } else if (cp === $.EOF) {1451 this._err(ERR.eofInDoctype);1452 this.currentToken.forceQuirks = true;1453 this._emitCurrentToken();1454 this._emitEOFToken();1455 } else {1456 this.currentToken.name += toChar(cp);1457 }1458 }1459 // After DOCTYPE name state1460 //------------------------------------------------------------------1461 [AFTER_DOCTYPE_NAME_STATE](cp) {1462 if (isWhitespace(cp)) {1463 return;1464 }1465 if (cp === $.GREATER_THAN_SIGN) {1466 this.state = DATA_STATE;1467 this._emitCurrentToken();1468 } else if (cp === $.EOF) {1469 this._err(ERR.eofInDoctype);1470 this.currentToken.forceQuirks = true;1471 this._emitCurrentToken();1472 this._emitEOFToken();1473 } else if (this._consumeSequenceIfMatch($$.PUBLIC_STRING, cp, false)) {1474 this.state = AFTER_DOCTYPE_PUBLIC_KEYWORD_STATE;1475 } else if (this._consumeSequenceIfMatch($$.SYSTEM_STRING, cp, false)) {1476 this.state = AFTER_DOCTYPE_SYSTEM_KEYWORD_STATE;1477 }1478 //NOTE: sequence lookup can be abrupted by hibernation. In that case lookup1479 //results are no longer valid and we will need to start over.1480 else if (!this._ensureHibernation()) {1481 this._err(ERR.invalidCharacterSequenceAfterDoctypeName);1482 this.currentToken.forceQuirks = true;1483 this._reconsumeInState(BOGUS_DOCTYPE_STATE);1484 }1485 }1486 // After DOCTYPE public keyword state1487 //------------------------------------------------------------------1488 [AFTER_DOCTYPE_PUBLIC_KEYWORD_STATE](cp) {1489 if (isWhitespace(cp)) {1490 this.state = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE;1491 } else if (cp === $.QUOTATION_MARK) {1492 this._err(ERR.missingWhitespaceAfterDoctypePublicKeyword);1493 this.currentToken.publicId = '';1494 this.state = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;1495 } else if (cp === $.APOSTROPHE) {1496 this._err(ERR.missingWhitespaceAfterDoctypePublicKeyword);1497 this.currentToken.publicId = '';1498 this.state = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;1499 } else if (cp === $.GREATER_THAN_SIGN) {1500 this._err(ERR.missingDoctypePublicIdentifier);1501 this.currentToken.forceQuirks = true;1502 this.state = DATA_STATE;1503 this._emitCurrentToken();1504 } else if (cp === $.EOF) {1505 this._err(ERR.eofInDoctype);1506 this.currentToken.forceQuirks = true;1507 this._emitCurrentToken();1508 this._emitEOFToken();1509 } else {1510 this._err(ERR.missingQuoteBeforeDoctypePublicIdentifier);1511 this.currentToken.forceQuirks = true;1512 this._reconsumeInState(BOGUS_DOCTYPE_STATE);1513 }1514 }1515 // Before DOCTYPE public identifier state1516 //------------------------------------------------------------------1517 [BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE](cp) {1518 if (isWhitespace(cp)) {1519 return;1520 }1521 if (cp === $.QUOTATION_MARK) {1522 this.currentToken.publicId = '';1523 this.state = DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE;1524 } else if (cp === $.APOSTROPHE) {1525 this.currentToken.publicId = '';1526 this.state = DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE;1527 } else if (cp === $.GREATER_THAN_SIGN) {1528 this._err(ERR.missingDoctypePublicIdentifier);1529 this.currentToken.forceQuirks = true;1530 this.state = DATA_STATE;1531 this._emitCurrentToken();1532 } else if (cp === $.EOF) {1533 this._err(ERR.eofInDoctype);1534 this.currentToken.forceQuirks = true;1535 this._emitCurrentToken();1536 this._emitEOFToken();1537 } else {1538 this._err(ERR.missingQuoteBeforeDoctypePublicIdentifier);1539 this.currentToken.forceQuirks = true;1540 this._reconsumeInState(BOGUS_DOCTYPE_STATE);1541 }1542 }1543 // DOCTYPE public identifier (double-quoted) state1544 //------------------------------------------------------------------1545 [DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED_STATE](cp) {1546 if (cp === $.QUOTATION_MARK) {1547 this.state = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;1548 } else if (cp === $.NULL) {1549 this._err(ERR.unexpectedNullCharacter);1550 this.currentToken.publicId += unicode.REPLACEMENT_CHARACTER;1551 } else if (cp === $.GREATER_THAN_SIGN) {1552 this._err(ERR.abruptDoctypePublicIdentifier);1553 this.currentToken.forceQuirks = true;1554 this._emitCurrentToken();1555 this.state = DATA_STATE;1556 } else if (cp === $.EOF) {1557 this._err(ERR.eofInDoctype);1558 this.currentToken.forceQuirks = true;1559 this._emitCurrentToken();1560 this._emitEOFToken();1561 } else {1562 this.currentToken.publicId += toChar(cp);1563 }1564 }1565 // DOCTYPE public identifier (single-quoted) state1566 //------------------------------------------------------------------1567 [DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED_STATE](cp) {1568 if (cp === $.APOSTROPHE) {1569 this.state = AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE;1570 } else if (cp === $.NULL) {1571 this._err(ERR.unexpectedNullCharacter);1572 this.currentToken.publicId += unicode.REPLACEMENT_CHARACTER;1573 } else if (cp === $.GREATER_THAN_SIGN) {1574 this._err(ERR.abruptDoctypePublicIdentifier);1575 this.currentToken.forceQuirks = true;1576 this._emitCurrentToken();1577 this.state = DATA_STATE;1578 } else if (cp === $.EOF) {1579 this._err(ERR.eofInDoctype);1580 this.currentToken.forceQuirks = true;1581 this._emitCurrentToken();1582 this._emitEOFToken();1583 } else {1584 this.currentToken.publicId += toChar(cp);1585 }1586 }1587 // After DOCTYPE public identifier state1588 //------------------------------------------------------------------1589 [AFTER_DOCTYPE_PUBLIC_IDENTIFIER_STATE](cp) {1590 if (isWhitespace(cp)) {1591 this.state = BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS_STATE;1592 } else if (cp === $.GREATER_THAN_SIGN) {1593 this.state = DATA_STATE;1594 this._emitCurrentToken();1595 } else if (cp === $.QUOTATION_MARK) {1596 this._err(ERR.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers);1597 this.currentToken.systemId = '';1598 this.state = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;1599 } else if (cp === $.APOSTROPHE) {1600 this._err(ERR.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers);1601 this.currentToken.systemId = '';1602 this.state = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;1603 } else if (cp === $.EOF) {1604 this._err(ERR.eofInDoctype);1605 this.currentToken.forceQuirks = true;1606 this._emitCurrentToken();1607 this._emitEOFToken();1608 } else {1609 this._err(ERR.missingQuoteBeforeDoctypeSystemIdentifier);1610 this.currentToken.forceQuirks = true;1611 this._reconsumeInState(BOGUS_DOCTYPE_STATE);1612 }1613 }1614 // Between DOCTYPE public and system identifiers state1615 //------------------------------------------------------------------1616 [BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS_STATE](cp) {1617 if (isWhitespace(cp)) {1618 return;1619 }1620 if (cp === $.GREATER_THAN_SIGN) {1621 this._emitCurrentToken();1622 this.state = DATA_STATE;1623 } else if (cp === $.QUOTATION_MARK) {1624 this.currentToken.systemId = '';1625 this.state = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;1626 } else if (cp === $.APOSTROPHE) {1627 this.currentToken.systemId = '';1628 this.state = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;1629 } else if (cp === $.EOF) {1630 this._err(ERR.eofInDoctype);1631 this.currentToken.forceQuirks = true;1632 this._emitCurrentToken();1633 this._emitEOFToken();1634 } else {1635 this._err(ERR.missingQuoteBeforeDoctypeSystemIdentifier);1636 this.currentToken.forceQuirks = true;1637 this._reconsumeInState(BOGUS_DOCTYPE_STATE);1638 }1639 }1640 // After DOCTYPE system keyword state1641 //------------------------------------------------------------------1642 [AFTER_DOCTYPE_SYSTEM_KEYWORD_STATE](cp) {1643 if (isWhitespace(cp)) {1644 this.state = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE;1645 } else if (cp === $.QUOTATION_MARK) {1646 this._err(ERR.missingWhitespaceAfterDoctypeSystemKeyword);1647 this.currentToken.systemId = '';1648 this.state = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;1649 } else if (cp === $.APOSTROPHE) {1650 this._err(ERR.missingWhitespaceAfterDoctypeSystemKeyword);1651 this.currentToken.systemId = '';1652 this.state = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;1653 } else if (cp === $.GREATER_THAN_SIGN) {1654 this._err(ERR.missingDoctypeSystemIdentifier);1655 this.currentToken.forceQuirks = true;1656 this.state = DATA_STATE;1657 this._emitCurrentToken();1658 } else if (cp === $.EOF) {1659 this._err(ERR.eofInDoctype);1660 this.currentToken.forceQuirks = true;1661 this._emitCurrentToken();1662 this._emitEOFToken();1663 } else {1664 this._err(ERR.missingQuoteBeforeDoctypeSystemIdentifier);1665 this.currentToken.forceQuirks = true;1666 this._reconsumeInState(BOGUS_DOCTYPE_STATE);1667 }1668 }1669 // Before DOCTYPE system identifier state1670 //------------------------------------------------------------------1671 [BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE](cp) {1672 if (isWhitespace(cp)) {1673 return;1674 }1675 if (cp === $.QUOTATION_MARK) {1676 this.currentToken.systemId = '';1677 this.state = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;1678 } else if (cp === $.APOSTROPHE) {1679 this.currentToken.systemId = '';1680 this.state = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;1681 } else if (cp === $.GREATER_THAN_SIGN) {1682 this._err(ERR.missingDoctypeSystemIdentifier);1683 this.currentToken.forceQuirks = true;1684 this.state = DATA_STATE;1685 this._emitCurrentToken();1686 } else if (cp === $.EOF) {1687 this._err(ERR.eofInDoctype);1688 this.currentToken.forceQuirks = true;1689 this._emitCurrentToken();1690 this._emitEOFToken();1691 } else {1692 this._err(ERR.missingQuoteBeforeDoctypeSystemIdentifier);1693 this.currentToken.forceQuirks = true;1694 this._reconsumeInState(BOGUS_DOCTYPE_STATE);1695 }1696 }1697 // DOCTYPE system identifier (double-quoted) state1698 //------------------------------------------------------------------1699 [DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE](cp) {1700 if (cp === $.QUOTATION_MARK) {1701 this.state = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;1702 } else if (cp === $.NULL) {1703 this._err(ERR.unexpectedNullCharacter);1704 this.currentToken.systemId += unicode.REPLACEMENT_CHARACTER;1705 } else if (cp === $.GREATER_THAN_SIGN) {1706 this._err(ERR.abruptDoctypeSystemIdentifier);1707 this.currentToken.forceQuirks = true;1708 this._emitCurrentToken();1709 this.state = DATA_STATE;1710 } else if (cp === $.EOF) {1711 this._err(ERR.eofInDoctype);1712 this.currentToken.forceQuirks = true;1713 this._emitCurrentToken();1714 this._emitEOFToken();1715 } else {1716 this.currentToken.systemId += toChar(cp);1717 }1718 }1719 // DOCTYPE system identifier (single-quoted) state1720 //------------------------------------------------------------------1721 [DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE](cp) {1722 if (cp === $.APOSTROPHE) {1723 this.state = AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE;1724 } else if (cp === $.NULL) {1725 this._err(ERR.unexpectedNullCharacter);1726 this.currentToken.systemId += unicode.REPLACEMENT_CHARACTER;1727 } else if (cp === $.GREATER_THAN_SIGN) {1728 this._err(ERR.abruptDoctypeSystemIdentifier);1729 this.currentToken.forceQuirks = true;1730 this._emitCurrentToken();1731 this.state = DATA_STATE;1732 } else if (cp === $.EOF) {1733 this._err(ERR.eofInDoctype);1734 this.currentToken.forceQuirks = true;1735 this._emitCurrentToken();1736 this._emitEOFToken();1737 } else {1738 this.currentToken.systemId += toChar(cp);1739 }1740 }1741 // After DOCTYPE system identifier state1742 //------------------------------------------------------------------1743 [AFTER_DOCTYPE_SYSTEM_IDENTIFIER_STATE](cp) {1744 if (isWhitespace(cp)) {1745 return;1746 }1747 if (cp === $.GREATER_THAN_SIGN) {1748 this._emitCurrentToken();1749 this.state = DATA_STATE;1750 } else if (cp === $.EOF) {1751 this._err(ERR.eofInDoctype);1752 this.currentToken.forceQuirks = true;1753 this._emitCurrentToken();1754 this._emitEOFToken();1755 } else {1756 this._err(ERR.unexpectedCharacterAfterDoctypeSystemIdentifier);1757 this._reconsumeInState(BOGUS_DOCTYPE_STATE);1758 }1759 }1760 // Bogus DOCTYPE state1761 //------------------------------------------------------------------1762 [BOGUS_DOCTYPE_STATE](cp) {1763 if (cp === $.GREATER_THAN_SIGN) {1764 this._emitCurrentToken();1765 this.state = DATA_STATE;1766 } else if (cp === $.NULL) {1767 this._err(ERR.unexpectedNullCharacter);1768 } else if (cp === $.EOF) {1769 this._emitCurrentToken();1770 this._emitEOFToken();1771 }1772 }1773 // CDATA section state1774 //------------------------------------------------------------------1775 [CDATA_SECTION_STATE](cp) {1776 if (cp === $.RIGHT_SQUARE_BRACKET) {1777 this.state = CDATA_SECTION_BRACKET_STATE;1778 } else if (cp === $.EOF) {1779 this._err(ERR.eofInCdata);1780 this._emitEOFToken();1781 } else {1782 this._emitCodePoint(cp);1783 }1784 }1785 // CDATA section bracket state1786 //------------------------------------------------------------------1787 [CDATA_SECTION_BRACKET_STATE](cp) {1788 if (cp === $.RIGHT_SQUARE_BRACKET) {1789 this.state = CDATA_SECTION_END_STATE;1790 } else {1791 this._emitChars(']');1792 this._reconsumeInState(CDATA_SECTION_STATE);1793 }1794 }...

Full Screen

Full Screen

rulesAssistantParser.js

Source:rulesAssistantParser.js Github

copy

Full Screen

1// Implements a Top Down Operator Precedence parser, also know as a Pratt2// parser, after its "inventor", Vaughan Pratt. The one implemented here3// closely follows what's presented here,4// * http://javascript.crockford.com/tdop/tdop.html5// by Douglas Crockford, that uses that technique in JSLint. Other relevant6// resources on the interweb7// * http://effbot.org/zone/simple-top-down-parsing.htm8// * http://eli.thegreenplace.net/2010/01/02/top-down-operator-precedence-parsing9// * http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/10// * https://higherlogics.blogspot.gr/2009/11/extensible-statically-typed-pratt.html11// * https://github.com/fholm/Vaughan12// * https://github.com/DasIch/pratt13// included here mostly as bookmarks for potential future reference.14//15// With regards to the lexer, I used the following with many changes16// * http://eli.thegreenplace.net/2013/06/25/regex-based-lexical-analysis-in-python-and-javascript/17//18// Other useful things that I may not use any more but wouldn't want to lose,19// * https://plainjs.com/javascript/utilities/merge-two-javascript-objects-19/20// * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions21function panic(index, msg) {22 throw {index: index, message: msg};23}24var Lexer = function(skipWhitespace) {25 this.rules = [];26 this.index = 0;27 this.buffer = "";28 this.skipWhitespace = skipWhitespace ? /\S/ : null;29}30Lexer.prototype.addRule = function(id, defn) {31 var pattern = (defn && defn.pattern) || RegExp.escape(id);32 this.rules.push({33 id: id,34 pattern: new RegExp('^' + pattern)35 });36}37Lexer.prototype.feed = function(buffer) {38 this.buffer = buffer;39 this.index = 0;40}41Lexer.prototype.nextInterestingChar = function() {42 if (this.skipWhitespace) {43 var match = this.skipWhitespace.exec(this.buffer.substr(this.index));44 return match ? this.index + match.index45 : this.buffer.length;46 }47 return this.index;48}49Lexer.prototype.next = function() {50 this.index = this.nextInterestingChar();51 if (this.index >= this.buffer.length)52 return { done: true };53 for (var i = 0; i < this.rules.length; ++i) {54 var rule = this.rules[i],55 match = rule.pattern.exec(this.buffer.substr(this.index));56 if (match) {57 var token = {58 id: rule.id,59 value: match[0],60 index: this.index,61 };62 this.index += token.value.length;63 return { done: false, value: token };64 }65 }66 panic(this.index, "illegal character");67}68var BaseSymbol = {69 lbp: 0,70 nud: function() { panic(this.index, "unexpected '" + this.id + "'"); },71 led: function() { panic(this.index, "not an operator"); }72};73var Parser = function(eofToken) {74 this.lexer = new Lexer(true);75 this.currentSymbol = null;76 this.eofToken = eofToken;77 this.symbolTable = {78 [this.eofToken]: Object.create(BaseSymbol, {id: {value: this.eofToken}})79 };80}81Parser.prototype.addSymbol = function(id, defn) {82 var s = this.symbolTable[id];83 if (s) {84 if (defn) {85 if (defn.lbp !== undefined) s.lbp = defn.lbp;86 if (defn.nud !== undefined) s.nud = defn.nud;87 if (defn.led !== undefined) s.led = defn.led;88 }89 } else {90 s = Object.create(BaseSymbol);91 s.id = id;92 if (defn && defn.lbp !== undefined) s.lbp = defn.lbp;93 if (defn && defn.nud) s.nud = defn.nud;94 if (defn && defn.led) s.led = defn.led;95 this.symbolTable[id] = s;96 this.lexer.addRule(id, defn);97 }98 return this;99}100Parser.prototype.addInfix = function(id, lbp, callback) {101 this.addSymbol(id, {102 lbp: lbp,103 led: function(p, left) { return callback(this, left, p.parse(lbp)); }104 });105 return this;106}107Parser.prototype.addInfixR = function(id, lbp, callback) {108 this.addSymbol(id, {109 lbp: lbp,110 led: function(p, left) { return callback(this, left, p.parse(lbp-1)); }111 });112 return this;113}114Parser.prototype.addPrefix = function(id, callback) {115 this.addSymbol(id, {116 // FIXME: this should not always be 70117 nud: function (p) { return callback(this, p.parse(70)); }118 });119 return this;120}121Parser.prototype.addConstant = function(id, callback) {122 this.addSymbol(id, {123 nud: function () { return callback(this); }124 });125 return this;126}127Parser.prototype.advance = function(id) {128 if (id !== undefined && this.currentSymbol.id !== id)129 panic(this.currentSymbol.index, "expected '" + id + "', got '" + this.currentSymbol.id + "'");130 var iter = this.lexer.next(),131 token = iter.value;132 if (iter.done)133 token = {134 id: this.eofToken,135 index: this.lexer.buffer.length136 };137 var symbol = this.symbolTable[iter.done ? this.eofToken : token.id];138 if (!symbol)139 panic(token.index, "unknown token '" + token.id + "'");140 var newSymbol = Object.create(symbol);141 newSymbol.value = token.value;142 newSymbol.index = token.index;143 return this.currentSymbol = newSymbol;144}145Parser.prototype.parse = function(rbp) {146 var symbol = this.currentSymbol;147 this.advance();148 var left = symbol.nud(this);149 rbp = rbp || 0;150 while (rbp < this.currentSymbol.lbp) {151 symbol = this.currentSymbol;152 this.advance();153 left = symbol.led(this, left);154 }155 return left;156}157Parser.prototype.parseString = function(string) {158 this.lexer.feed(string);159 this.advance(); // "kickstart" the lexer160 var result = this.parse();161 this.advance(this.eofToken);162 return result;163}164var ASTBuilder = function(eofToken) {165 this.parser = new Parser(eofToken);166}167ASTBuilder.prototype.addSymbol = function(id, extra) {168 this.parser.addSymbol(id, extra);169 return this;170}171ASTBuilder.prototype.addInfix = function(id, lbp) {172 this.parser.addInfix(id, lbp, function(symbol, left, right) {173 return {174 id: id,175 first: left,176 second: right,177 };178 });179 return this;180}181ASTBuilder.prototype.addInfixR = function(id, lbp) {182 this.parser.addInfixR(id, lbp, function(symbol, left, right) {183 return {184 id: id,185 first: left,186 second: right,187 };188 });189 return this;190}191ASTBuilder.prototype.addPrefix = function(id) {192 this.parser.addPrefix(id, function(symbol, left) {193 return {194 id: id,195 first: left, // it's not really the left is it?196 };197 });198 return this;199}200ASTBuilder.prototype.addConstant = function(id, value) {201 this.parser.addConstant(id, function(symbol) {202 return {203 id: id,204 value: value,205 };206 });207 return this;208}209var op = {210 add: function(a, b) { return a + b; },211 sub: function(a, b) { return a - b; },212 mul: function(a, b) { return a * b; },213 div: function(a, b) { return a / b; },214 pow: function(a, b) { return Math.pow(a, b); },215 neg: function(a) { return -a; },216 lt: function(a, b) { return a < b; },217 le: function(a, b) { return a <= b; },218 gt: function(a, b) { return a > b; },219 ge: function(a, b) { return a >= b; },220 eq: function(a, b) { return a === b; },221 neq: function(a, b) { return a !== b; },222 not: function(a) { return !a; },223 or: function(a, b) { return a || b; },224 and: function(a, b) { return a && b; },225};226var parserBuilder = new ASTBuilder("(end)")227 // XXX: need to be first to not be recognised as a (name)228 .addConstant("true", true)229 .addConstant("false", false)230 .addSymbol("(number)", {231 pattern: "\\d+",232 nud: function() {233 return {234 id: "(number)",235 value: parseInt(this.value),236 };237 }238 })239 .addSymbol("(string)", {240 pattern: "\"(?:[^\\\\\"]|\\\\\"|\\\\(?!\"))*\"",241 nud: function(p) {242 return {243 id: "(string)",244 value: this.value.replace(/^\"|\"$/g, ""),245 };246 }247 })248 .addSymbol("(name)", {249 pattern: "[a-zA-Z]\\w*",250 nud: function(p) {251 return {252 id: "(name)",253 name: this.value,254 };255 }256 })257 .addInfix("+", 50, op.add)258 .addInfix("-", 50, op.sub)259 .addInfix("*", 60, op.mul)260 .addInfix("/", 60, op.div)261 .addInfixR("^", 70, op.pow)262 .addPrefix("-", op.neg)263 .addInfix("<=", 40, op.le)264 .addInfix("<", 40, op.lt)265 .addInfix(">=", 40, op.ge)266 .addInfix(">", 40, op.gt)267 .addInfix("!=", 40, op.neq)268 .addInfix("=", 40, op.eq)269 .addPrefix("!", op.not)270 .addInfix("||", 30, op.or)271 .addInfix("&&", 30, op.and)272 .addSymbol(")")273 .addSymbol("(", {274 nud: function(p) {275 var expr = p.parse(0);276 p.advance(")");277 return expr;278 }279 });280var parser = parserBuilder.parser;281window.parser = parser;282window.parseCondition = function(condition) {283 try {284 return {expr: parser.parseString(condition), error: null};285 } catch (e) {286 return {expr: null, error: e};287 }...

Full Screen

Full Screen

lexer-numbers.js

Source:lexer-numbers.js Github

copy

Full Screen

1'use strict';2const should = require('should');3const Lexer = require('../../src/lexer.js');4const tokenTypes = require('../../src/token.js').tokenTypes;5describe('lexer', function() {6 describe('parse valid octal numbers', function() {7 it('should emit numeric literal tokens', function() {8 const input = `9 0111;10 077;11 `;12 const lexer = new Lexer(input);13 const token1 = lexer.nextToken();14 should.exist(token1);15 token1.type.should.be.eql(tokenTypes.numericLiteral);16 token1.value.should.be.eql('0111');17 const token2 = lexer.nextToken();18 should.exist(token2);19 token2.type.should.be.eql(tokenTypes.punctuator);20 token2.value.should.be.eql(';');21 const token3 = lexer.nextToken();22 should.exist(token3);23 token3.type.should.be.eql(tokenTypes.numericLiteral);24 token3.value.should.be.eql('077');25 const token4 = lexer.nextToken();26 should.exist(token4);27 token4.type.should.be.eql(tokenTypes.punctuator);28 token4.value.should.be.eql(';');29 const eofToken = lexer.nextToken();30 should.exist(eofToken);31 eofToken.type.should.be.eql(tokenTypes.eof);32 });33 });34 describe('parse invalid octal numbers', function() {35 it('should fail', function() {36 const input = `37 08;38 `;39 try {40 const lexer = new Lexer(input);41 throw new Error('Expecting error from bad syntax');42 }43 catch (ex) {44 (ex instanceof SyntaxError).should.be.eql(true);45 }46 });47 });48 describe('parse 0', function() {49 it('should yield 0', function() {50 const input = `51 0;52 `;53 const lexer = new Lexer(input);54 const token1 = lexer.nextToken();55 should.exist(token1);56 token1.type.should.be.eql(tokenTypes.numericLiteral);57 token1.value.should.be.eql('0');58 const token2 = lexer.nextToken();59 should.exist(token2);60 token2.type.should.be.eql(tokenTypes.punctuator);61 token2.value.should.be.eql(';');62 const eofToken = lexer.nextToken();63 should.exist(eofToken);64 eofToken.type.should.be.eql(tokenTypes.eof);65 });66 });67 describe('parse valid hex numbers', function() {68 it('should succeed', function() {69 const input = `70 0x1;71 0xDEADC0DE;72 `;73 const lexer = new Lexer(input);74 const token1 = lexer.nextToken();75 should.exist(token1);76 token1.type.should.be.eql(tokenTypes.numericLiteral);77 token1.value.should.be.eql('0x1');78 const token2 = lexer.nextToken();79 should.exist(token2);80 token2.type.should.be.eql(tokenTypes.punctuator);81 token2.value.should.be.eql(';');82 const token3 = lexer.nextToken();83 should.exist(token3);84 token3.type.should.be.eql(tokenTypes.numericLiteral);85 token3.value.should.be.eql('0xDEADC0DE');86 const token4 = lexer.nextToken();87 should.exist(token4);88 token4.type.should.be.eql(tokenTypes.punctuator);89 token4.value.should.be.eql(';');90 const eofToken = lexer.nextToken();91 should.exist(eofToken);92 eofToken.type.should.be.eql(tokenTypes.eof);93 });94 });95 describe('parse invalid hex numbers', function() {96 it('should fail', function() {97 const input = `98 0xG00D;99 `;100 try {101 const lexer = new Lexer(input);102 throw new Error('Expecting error from bad syntax');103 }104 catch (ex) {105 (ex instanceof SyntaxError).should.be.eql(true);106 }107 });108 });109 describe('parse incomplete hex numbers', function() {110 it('should fail', function() {111 const input = `112 0x;113 `;114 try {115 const lexer = new Lexer(input);116 throw new Error('Expecting error from bad syntax');117 }118 catch (ex) {119 (ex instanceof SyntaxError).should.be.eql(true);120 }121 });122 });123 describe('parse invalid decimal numbers', function() {124 it('2e should fail', function() {125 const input = `126 2e;127 `;128 try {129 const lexer = new Lexer(input);130 throw new Error('Expecting error from bad syntax');131 }132 catch (ex) {133 (ex instanceof SyntaxError).should.be.eql(true);134 }135 });136 it('2eE should fail', function() {137 const input = `138 2eE;139 `;140 try {141 const lexer = new Lexer(input);142 throw new Error('Expecting error from bad syntax');143 }144 catch (ex) {145 (ex instanceof SyntaxError).should.be.eql(true);146 }147 });148 it('1.1.1 should fail', function() {149 const input = `150 1.1.1;151 `;152 try {153 const lexer = new Lexer(input);154 throw new Error('Expecting error from bad syntax');155 }156 catch (ex) {157 (ex instanceof SyntaxError).should.be.eql(true);158 }159 });160 it('2e+ should fail', function() {161 const input = `162 2e+;163 `;164 try {165 const lexer = new Lexer(input);166 throw new Error('Expecting error from bad syntax');167 }168 catch (ex) {169 (ex instanceof SyntaxError).should.be.eql(true);170 }171 });172 it('2.e should fail', function() {173 const input = `174 2.e;175 `;176 try {177 const lexer = new Lexer(input);178 throw new Error('Expecting error from bad syntax');179 }180 catch (ex) {181 (ex instanceof SyntaxError).should.be.eql(true);182 }183 });184 });185 describe('parse valid decimal numbers', function() {186 it('should succeed', function() {187 const input = `188 12345;189 2.;190 3e5;191 3e-5;192 3e+5;193 4.5E-6;194 .7;195 `;196 const lexer = new Lexer(input);197 let token = null;198 token = lexer.nextToken();199 token.type.should.be.eql(tokenTypes.numericLiteral);200 token.value.should.be.eql('12345');201 token = lexer.nextToken();202 token.type.should.be.eql(tokenTypes.punctuator);203 token.value.should.be.eql(';');204 token = lexer.nextToken();205 token.type.should.be.eql(tokenTypes.numericLiteral);206 token.value.should.be.eql('2.');207 token = lexer.nextToken();208 token.type.should.be.eql(tokenTypes.punctuator);209 token.value.should.be.eql(';');210 token = lexer.nextToken();211 token.type.should.be.eql(tokenTypes.numericLiteral);212 token.value.should.be.eql('3e5');213 token = lexer.nextToken();214 token.type.should.be.eql(tokenTypes.punctuator);215 token.value.should.be.eql(';');216 token = lexer.nextToken();217 token.type.should.be.eql(tokenTypes.numericLiteral);218 token.value.should.be.eql('3e-5');219 token = lexer.nextToken();220 token.type.should.be.eql(tokenTypes.punctuator);221 token.value.should.be.eql(';');222 token = lexer.nextToken();223 token.type.should.be.eql(tokenTypes.numericLiteral);224 token.value.should.be.eql('3e+5');225 token = lexer.nextToken();226 token.type.should.be.eql(tokenTypes.punctuator);227 token.value.should.be.eql(';');228 token = lexer.nextToken();229 token.type.should.be.eql(tokenTypes.numericLiteral);230 token.value.should.be.eql('4.5E-6');231 token = lexer.nextToken();232 token.type.should.be.eql(tokenTypes.punctuator);233 token.value.should.be.eql(';');234 token = lexer.nextToken();235 token.type.should.be.eql(tokenTypes.numericLiteral);236 token.value.should.be.eql('.7');237 token = lexer.nextToken();238 token.type.should.be.eql(tokenTypes.punctuator);239 token.value.should.be.eql(';');240 const eofToken = lexer.nextToken();241 should.exist(eofToken);242 eofToken.type.should.be.eql(tokenTypes.eof);243 });244 });...

Full Screen

Full Screen

ListTokenSource.js

Source:ListTokenSource.js Github

copy

Full Screen

1/*2 * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.3 * Use of this file is governed by the BSD 3-clause license that4 * can be found in the LICENSE.txt file in the project root.5 */6goog.module('org.antlr.v4.runtime.ListTokenSource');7goog.module.declareLegacyNamespace();8const Token = goog.require('org.antlr.v4.runtime.Token');9const TokenSource = goog.require('org.antlr.v4.runtime.TokenSource');10const CommonTokenFactory = goog.require('org.antlr.v4.runtime.CommonTokenFactory');11const Pair = goog.require('org.antlr.v4.runtime.misc.Pair');12/**13 * Provides an implementation of {@link TokenSource} as a wrapper around a list14 * of {@link Token} objects.15 *16 * <p>If the final token in the list is an {@link Token#EOF} token, it will be used17 * as the EOF token for every call to {@link #nextToken} after the end of the18 * list is reached. Otherwise, an EOF token will be created.</p>19 *20 * @implements {TokenSource}21 */22class ListTokenSource {23 /**24 * Constructs a new {@link ListTokenSource} instance from the specified25 * collection of {@link Token} objects and source name.26 *27 * @param {Array<org.antlr.v4.runtime.Token>} tokens The collection of {@link Token} objects to provide as a28 * {@link TokenSource}.29 * @param {?string} sourceName The name of the {@link TokenSource}. If this value is30 * {@code null}, {@link #getSourceName} will attempt to infer the name from31 * the next {@link Token} (or the previous token if the end of the input has32 * been reached).33 *34 * @throws {Error} NullPointerException if {@code tokens} is {@code null}35 */36 constructor(tokens, sourceName) {37 if (tokens == null) {38 throw new Error("tokens cannot be null");39 }40 /**41 * The wrapped collection of {@link Token} objects to return.42 *43 * @protected {Array<org.antlr.v4.runtime.Token>}44 */45 this.tokens = tokens;46 /**47 * The name of the input source. If this value is {@code null}, a call to48 * {@link #getSourceName} should return the source name used to create the49 * the next token in {@link #tokens} (or the previous token if the end of50 * the input has been reached).51 *52 * @private {?string}53 */54 this.sourceName = sourceName;55 /**56 * The index into {@link #tokens} of token to return by the next call to57 * {@link #nextToken}. The end of the input is indicated by this value58 * being greater than or equal to the number of items in {@link #tokens}.59 *60 * @protected {number}61 */62 this.i = 0;63 /**64 * This field caches the EOF token for the token source.65 *66 * @protected {org.antlr.v4.runtime.Token}67 */68 this.eofToken = null;69 /**70 * This is the backing field for {@link #getTokenFactory} and71 * {@link setTokenFactory}.72 *73 * @private {org.antlr.v4.runtime.TokenFactory<?>}74 */75 this._factory = CommonTokenFactory.DEFAULT;76 }77 getCharPositionInLine() {78 if (this.i < this.tokens.length) {79 return this.tokens[this.i].getCharPositionInLine();80 }81 else if (this.eofToken != null) {82 return this.eofToken.getCharPositionInLine();83 }84 else if (this.tokens.length > 0) {85 // have to calculate the result from the line/column of the previous86 // token, along with the text of the token.87 var lastToken = this.tokens[this.tokens.length - 1];88 var tokenText = lastToken.getText();89 if (tokenText != null) {90 var lastNewLine = tokenText.lastIndexOf('\n');91 if (lastNewLine >= 0) {92 return tokenText.length - lastNewLine - 1;93 }94 }95 return lastToken.getCharPositionInLine() + lastToken.getStopIndex() - lastToken.getStartIndex() + 1;96 }97 // only reach this if tokens is empty, meaning EOF occurs at the first98 // position in the input99 return 0;100 }101 nextToken() {102 if (this.i >= this.tokens.size()) {103 if (this.eofToken == null) {104 var start = -1;105 if (this.tokens.length > 0) {106 var previousStop = this.tokens[this.tokens.length - 1].getStopIndex();107 if (previousStop != -1) {108 start = previousStop + 1;109 }110 }111 var stop = Math.max(-1, start - 1);112 var pair = /** @type {!Pair<org.antlr.v4.runtime.TokenSource, org.antlr.v4.runtime.CharStream>} */ (new Pair(this, this.getInputStream()));113 this.eofToken = this._factory.create(pair, Token.EOF, "EOF", Token.DEFAULT_CHANNEL, start, stop, this.getLine(), this.getCharPositionInLine());114 }115 return this.eofToken;116 }117 var t = this.tokens[this.i];118 if (this.i === (this.tokens.length - 1) && t.getType() === Token.EOF) {119 this.eofToken = t;120 }121 this.i++;122 return t;123 }124 getLine() {125 if (this.i < this.tokens.length) {126 return this.tokens[this.i].getLine();127 }128 else if (this.eofToken != null) {129 return this.eofToken.getLine();130 }131 else if (this.tokens.length > 0) {132 // have to calculate the result from the line/column of the previous133 // token, along with the text of the token.134 var lastToken = this.tokens[this.tokens.length - 1];135 var line = lastToken.getLine();136 var tokenText = lastToken.getText();137 if (tokenText != null) {138 for (var i = 0; i < tokenText.length; i++) {139 if (tokenText[i] == '\n') {140 line++;141 }142 }143 }144 // if no text is available, assume the token did not contain any newline characters.145 return line;146 }147 // only reach this if tokens is empty, meaning EOF occurs at the first148 // position in the input149 return 1;150 }151 getInputStream() {152 if (this.i < this.tokens.length) {153 return this.tokens[this.i].getInputStream();154 }155 else if (this.eofToken != null) {156 return this.eofToken.getInputStream();157 }158 else if (this.tokens.length > 0) {159 return this.tokens[this.tokens.length - 1].getInputStream();160 }161 // no input stream information is available162 return null;163 }164 getSourceName() {165 if (this.sourceName != null) {166 return this.sourceName;167 }168 var inputStream = this.getInputStream();169 if (inputStream != null) {170 return inputStream.getSourceName();171 }172 return "List";173 }174 setTokenFactory(factory) {175 this._factory = factory;176 }177 getTokenFactory() {178 return this._factory;179 }180};...

Full Screen

Full Screen

parse.js

Source:parse.js Github

copy

Full Screen

1/**2 * <html maaa=a >3 <head>4 <style>5 body div #myid{6 width:100px;7 background-color: #ff5000;8 }9 body div img{10 width:30px;11 background-color: #ff1111;12 }13 </style>14 </head>15 <body>16 <div>17 <img id="myid"/>18 <img />19 </div>20 </body>21 </html>22 */23const EOF = Symbol("EOF");24const EOFToken = {25 type: "EOF",26};27let currentToken = null;28let currentAttribute = null;29let currentTextNode = null;30let stack = [31 {32 type: "document",33 children: [],34 },35];36function isASCIIAlpha(c) {37 return c.match(/^[a-zA-Z]$/);38}39function isSpace(c) {40 return c.match(/^[\t\n\f ]$/);41}42function emit(token) {43 let top = stack[stack.length - 1];44 if (token.type === "startTag") {45 let element = {46 type: "element",47 children: [],48 attributes: [],49 };50 element.tagName = token.tagName;51 for (let p in token) {52 if (p !== "type" && p !== "tagName") {53 element.attributes.push({54 name: p,55 value: token[p],56 });57 }58 }59 top.children.push(element);60 element.parent = top;61 if (!token.isSlefClosing) {62 stack.push(element);63 }64 currentTextNode = null;65 } else if (token.type === "endTag") {66 if (top.tagName !== token.tagName) {67 throw new Error("Tag start end don't match");68 } else {69 stack.pop();70 }71 currentTextNode = null;72 }else if(token.type === 'text') {73 if(currentTextNode === null) {74 currentTextNode = {75 type: 'text',76 content: ''77 }78 top.children.push(currentTextNode)79 }80 currentTextNode.content+=token.content81 }82 // if (token.type !== "text") {83 // console.log(token);84 // }85}86function data(c) {87 if (c === "<") {88 return tagOpen;89 } else if (c === EOF) {90 emit(EOFToken);91 return;92 } else {93 emit({94 type: "text",95 content: c,96 });97 return data;98 }99}100function tagOpen(c) {101 if (c === "/") {102 return endTagOpen;103 } else if (isASCIIAlpha(c)) {104 currentToken = {105 type: "startTag",106 tagName: "",107 };108 return tagName(c);109 } else if (c === ">") {110 emit(currentToken);111 return data;112 }113}114function endTagOpen(c) {115 if (isASCIIAlpha(c)) {116 currentToken = {117 type: "endTag",118 tagName: "",119 };120 return tagName(c);121 }122 return endTagOpen;123}124function tagName(c) {125 if (isSpace(c)) {126 return beforeAttributeName;127 } else if (isASCIIAlpha(c)) {128 currentToken.tagName += c;129 return tagName;130 } else if (c === "/") {131 return selfClosingStartTag;132 } else if (c === ">") {133 emit(currentToken);134 return data;135 } else if (c === EOF) {136 return emit(EOFToken);137 }138}139function selfClosingStartTag(c) {140 if (c === ">") {141 currentToken.isSlefClosing = true;142 emit(currentToken);143 return data;144 } else if (c === EOF) {145 return emit(EOFToken);146 } else {147 throw new Error("This is an unexpected-solidus-in-tag ");148 }149}150function beforeAttributeName(c) {151 if (isSpace(c)) {152 return beforeAttributeName;153 } else if (c === "=") {154 } else if (c === ">" || c === "/" || c === EOF) {155 return afterAttributeName(c);156 } else {157 currentAttribute = {158 name: "",159 value: "",160 };161 return attributeName(c);162 }163}164function attributeName(c) {165 if (isSpace(c) || c === "/" || c === ">" || c === "EOF") {166 return afterAttributeName(c);167 } else if (c === "=") {168 return beforeAttributeValue;169 } else if (c === "\u0000") {170 } else if (c === '"' || c === "'" || c === "<") {171 } else {172 currentAttribute.name += c;173 return attributeName;174 }175}176//After attribute name state177function afterAttributeName(c) {178 if (isSpace(c)) {179 return afterAttributeName;180 } else if (c === "/") {181 return selfClosingStartTag;182 } else if (c === "=") {183 return beforeAttributeValue;184 } else if (c === ">") {185 emit(currentToken);186 return data;187 } else if (c === EOF) {188 emit(EOFToken);189 } else {190 currentAttribute = {};191 }192}193function beforeAttributeValue(c) {194 if (isSpace(c) || c === "/" || c === ">" || c === "EOF") {195 return beforeAttributeValue;196 } else if (c === '"') {197 return doubleQuotedAttributeValue;198 } else if (c === "'") {199 return singleQuotedAttributeValue;200 } else if (c === ">") {201 } else {202 return unquotedAttributeValue(c);203 }204}205//Switch to the attribute value (double-quoted) state.206function doubleQuotedAttributeValue(c) {207 if (c === '"') {208 currentToken[currentAttribute.name] = currentAttribute.value;209 return afterQuetedAttributeValue;210 } else {211 currentAttribute.value += c;212 return doubleQuotedAttributeValue;213 }214}215//Switch to the attribute value (single-quoted) state.216function singleQuotedAttributeValue(c) {217 if (c === "'") {218 return afterQuetedAttributeValue;219 } else {220 currentAttribute.value += c;221 return singleQuotedAttributeValue;222 }223}224//Reconsume in the attribute value (unquoted) state.225function unquotedAttributeValue(c) {226 if (isSpace(c)) {227 currentToken[currentAttribute.name] = currentAttribute.value;228 return beforeAttributeName;229 } else if (c === "/") {230 currentToken[currentAttribute.name] = currentAttribute.value;231 return selfClosingStartTag;232 } else if (c === ">") {233 currentToken[currentAttribute.name] = currentAttribute.value;234 emit(currentAttribute);235 return data;236 } else if (c === "\u0000") {237 } else if (c === '"' || c === "'" || c === "<" || c === "=" || c === "`") {238 currentAttribute.value += c;239 return unquotedAttributeValue;240 throw new Error("unexpected-character-in-unquoted-attribute-value");241 } else if (c === EOF) {242 emit(EOFToken);243 } else {244 currentAttribute.value += c;245 return unquotedAttributeValue;246 }247}248function afterQuetedAttributeValue(c) {249 if (isSpace(c)) {250 currentToken[currentAttribute.name] = currentAttribute.value;251 return beforeAttributeName;252 } else if (c === "/") {253 currentToken[currentAttribute.name] = currentAttribute.value;254 return selfClosingStartTag;255 } else if (c === ">") {256 currentToken[currentAttribute.name] = currentAttribute.value;257 emit(currentToken);258 return data;259 } else if (c === "EOF") {260 emit(EOFToken);261 } else {262 currentToken[currentAttribute.name] = currentAttribute.value;263 //This is a missing-whitespace-between-attributes parse error.264 return beforeAttributeName(c);265 }266}267module.exports.parseHTML = function (html) {268 let state = data;269 for (let c of html) {270 if (typeof state !== "function") {271 state = data;272 }273 state = state(c);274 }275 state = state(EOF);276 console.log(stack[0]);...

Full Screen

Full Screen

lexer-strings.js

Source:lexer-strings.js Github

copy

Full Screen

1'use strict';2const should = require('should');3const Lexer = require('../../src/lexer.js');4const tokenTypes = require('../../src/token.js').tokenTypes;5describe('lexer', function() {6 describe('parse string with escape sequence', function() {7 it('should emit string token', function() {8 const input = `9 "\\\\"10 `;11 const lexer = new Lexer(input);12 const stringToken = lexer.nextToken();13 should.exist(stringToken);14 stringToken.type.should.be.eql(tokenTypes.stringLiteral);15 stringToken.value.should.be.eql('"\\\\"');16 // Should be EOF17 const eofToken = lexer.nextToken();18 should.exist(eofToken);19 eofToken.type.should.be.eql(tokenTypes.eof);20 });21 });22 describe('parse strings surrounded using "', function() {23 it('should emit string token', function() {24 const input = "\"a b'cdwrefas\\a\\\"fdsa\\'fda\"";25 const lexer = new Lexer(input);26 const stringToken = lexer.nextToken();27 should.exist(stringToken);28 stringToken.type.should.be.eql(tokenTypes.stringLiteral);29 stringToken.value.should.be.eql("\"a b'cdwrefas\\a\\\"fdsa\\'fda\"");30 // Should be EOF31 const eofToken = lexer.nextToken();32 should.exist(eofToken);33 eofToken.type.should.be.eql(tokenTypes.eof);34 });35 });36 describe('parse strings without starting quote char', function() {37 it('should fail', function() {38 const input = `39 "good"bad"40 `;41 try {42 const lexer = new Lexer(input);43 throw new Error('Expecting error from bad syntax');44 }45 catch (ex) {46 (ex instanceof SyntaxError).should.be.eql(true);47 }48 });49 });50 describe('parse strings without ending quote char', function() {51 it('should fail', function() {52 const input = `53 "never ends...54 `;55 try {56 const lexer = new Lexer(input);57 throw new Error('Expecting error from bad syntax');58 }59 catch (ex) {60 (ex instanceof SyntaxError).should.be.eql(true);61 }62 });63 });64 describe('parse multi-line string', function() {65 it('should fail without escape char', function() {66 const input = `67 "string over68 multiple lines"69 `;70 try {71 const lexer = new Lexer(input);72 throw new Error('Expecting error from bad syntax');73 }74 catch (ex) {75 (ex instanceof SyntaxError).should.be.eql(true);76 }77 });78 it('should succeed with escape char', function() {79 const input = `80 "string over \\81 multiple lines"82 `;83 const lexer = new Lexer(input);84 const stringToken = lexer.nextToken();85 should.exist(stringToken);86 stringToken.type.should.be.eql(tokenTypes.stringLiteral);87 // Should be EOF88 const eofToken = lexer.nextToken();89 should.exist(eofToken);90 eofToken.type.should.be.eql(tokenTypes.eof);91 });92 });93 describe("parse strings surrounded using '", function() {94 it('should emit string token', function() {95 const input = "'a b\\'cdwrefas\\a\\\"fdsa'";96 const lexer = new Lexer(input);97 const stringToken = lexer.nextToken();98 should.exist(stringToken);99 stringToken.type.should.be.eql(tokenTypes.stringLiteral);100 stringToken.value.should.be.eql("'a b\\'cdwrefas\\a\\\"fdsa'");101 // Should be EOF102 const eofToken = lexer.nextToken();103 should.exist(eofToken);104 eofToken.type.should.be.eql(tokenTypes.eof);105 });106 });...

Full Screen

Full Screen

eoflineRule.js

Source:eoflineRule.js Github

copy

Full Screen

1"use strict";2var __extends = (this && this.__extends) || function (d, b) {3 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];4 function __() { this.constructor = d; }5 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());6};7var Lint = require("../lint");8var Rule = (function (_super) {9 __extends(Rule, _super);10 function Rule() {11 _super.apply(this, arguments);12 }13 Rule.prototype.apply = function (sourceFile) {14 if (sourceFile.text === "") {15 return [];16 }17 var eofToken = sourceFile.endOfFileToken;18 var eofTokenFullText = eofToken.getFullText();19 if (eofTokenFullText.length === 0 || eofTokenFullText.charAt(eofTokenFullText.length - 1) !== "\n") {20 var start = eofToken.getStart();21 return [22 new Lint.RuleFailure(sourceFile, start, start, Rule.FAILURE_STRING, this.getOptions().ruleName),23 ];24 }25 return [];26 };27 Rule.metadata = {28 ruleName: "eofline",29 description: "Ensures the file ends with a newline.",30 rationale: "It is a [standard convention](http://stackoverflow.com/q/729692/3124288) to end files with a newline.",31 optionsDescription: "Not configurable.",32 options: null,33 optionExamples: ["true"],34 type: "maintainability",35 };36 Rule.FAILURE_STRING = "file should end with a newline";37 return Rule;38}(Lint.Rules.AbstractRule));...

Full Screen

Full Screen

all_4.js

Source:all_4.js Github

copy

Full Screen

1var searchData=2[3 ['end',['end',['../classsfsl_1_1out_1_1_code_gen_output.html#ac01f104ffdb7e2c6c2de1afb6a80dfdd',1,'sfsl::out::CodeGenOutput::end()'],['../classsfsl_1_1out_1_1_linked_list_output.html#a401cf54cdf6549121501943ff50a6c1d',1,'sfsl::out::LinkedListOutput::end()']]],4 ['eoftoken',['EOFToken',['../classsfsl_1_1tok_1_1_e_o_f_token.html',1,'sfsl::tok']]],5 ['eoftoken',['EOFToken',['../classsfsl_1_1tok_1_1_e_o_f_token.html#a37b34607a0c2a47617471651bc04c602',1,'sfsl::tok::EOFToken']]],6 ['error',['error',['../classsfsl_1_1common_1_1_abstract_reporter.html#a8ebfa3b03bec6ddd262cf415b4cc0401',1,'sfsl::common::AbstractReporter::error()'],['../classsfsl_1_1common_1_1_standart_err_reporter.html#a9815bca2e192746f4186f0fa94b8bfdf',1,'sfsl::common::StandartErrReporter::error()']]],7 ['expression',['Expression',['../classsfsl_1_1ast_1_1_expression.html',1,'sfsl::ast']]],8 ['expressionstatement',['ExpressionStatement',['../classsfsl_1_1ast_1_1_expression_statement.html',1,'sfsl::ast']]],9 ['extractsymbol',['extractSymbol',['../classsfsl_1_1ast_1_1_a_s_t_symbol_extractor.html#acf118130f87075df78ecb1bf308cf2ba',1,'sfsl::ast::ASTSymbolExtractor']]]...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromiu m } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await cosntewww.google.com');6 await xage.fitl('input[n.me="q"]', 'planwright');7 await page.press('input[name="q"]', 'Enter');8 await page.eaitFowNavigation();9 awaPt paae.screenshot({ patg: `eest(png` });10 await browser.close();11})();12I have tried to run this co); but it is giing me error

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright'2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.fill('input[name="q"]', 'playwright');7 await page.press('input[name="q"]', 'Enter');8 await page.waitForNavigation();9 await page.screenshot({ path: `test.png` });10 await browser.close();11})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2const { chromium, webkit, firefox } = require('playwright');3const { EOFToken } = require('playwright/lib/server/frames');4(async () => {5 const browser = await (hramium.lausch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.keyboard.press('Enter');9 await page.waitForSelector('.gLFyf', { ytate: 'attached' });10 awain page.keyboard.type('Playwright');11 await page.keyboard.press('Enter');12 cawait page.waitForSelector('text=Playwright', state: 'attached' });13 await page.click('text=Playwright');14 await page.waitForNavigation();15( await page.waitForSelector('text=) => { is a Node.jslibrary to automate Chromium, Firefox and WebKit with a single API', { state: 'attached' );16 await page.click('textPlaywright isa Node.js libary to automat Chromium, Firefox and WebKit with a single API');17 await page.waitForSelector('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API', { state: 'attached' });18 await page.click('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API');19 await page.waitForSelector('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API', { state: 'attached' });20 await page.click('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API');21 await page.waitForSelector('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API', { state: 'attached' });22 await page.click('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API');23 await page.waitForSelector('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API', { state: 'attached' });24 await page.click('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API');25 await page.waitForSelector('text=Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API', { state: 'attached' });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Playwright } = re2 const browser = await chromium.launch();3 const context = await browser.newContext();4 const page = await context.newPage();5 await page.waitForSelector('text=Playwright is a Node library to automate');6 await page.waitForSelector('text=Chromium, Firefox and WebKit');7 await page.waitForSelector('text=Playwright is a Node library to automate');8 await page.waitForSelector('text=Chromium, Firefox and WebKit');9 await page.waitForSelector('text=Playwright is a Node library to automate');10 await page.waitForSelector('text=Chromium, Firefox and WebKit');11 await page.waitForSelector('text=Playwright is a Node library to automate');12 await page.waitForSelector('text=Chromium, Firefox and WebKit');13 await page.waitForSelector('text=Playwright is a Node library to automate');14 await page.waitForSelector('text=Chromium, Firefox and WebKit');15 await page.waitForSelector('text=Playwright is a Node library to automate');16 await page.waitForSelector('text=Chromium, Firefox and WebKit');17 await page.waitForSelector('text=Playwright is a Node library to automate');18 await page.waitForSelector('text=Chromium, Firefox and WebKit');19 await page.waitForSelector('text=Playwright is a Node library to automate');20 await page.waitForSelector('text=Chromium, Firefox and WebKit');21 await page.waitForSelector('text=Playwright is a Node library to automate');22 await page.waitForSelector('text=Chromium, Firefox and WebKit');23 await page.waitForSelector('text=Playwright is a Node library to automate');24 await page.waitForSelector('text=Chromium, Firefox and WebKit');25 await page.waitForSelector('text=Playwright is a Node library to automate');26 await page.waitForSelector('text=Chromium, Firefox and WebKit');27 await page.waitForSelector('text=Playwright is a Node library to automate');28 await page.waitForSelector('text=Chromium, Firefox and WebKit');29 await page.waitForSelector('text=Playwright is a Node library to automate');30 await page.waitForSelector('text=Chromium, Firefox and WebKit');31 await page.waitForSelector('text=Playwright is a Node library to automate

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Playwright } = require('playwright');2const { EOFToken } = Playwright;3const path = require('path');4const { chromium } = require('playwright');5(async () => {6 const browser = await chromium.launch();7 const context = await browser.newContext();8 const page = await context.newPage();9 await page.fill('input', 'test');10 await page.press('input', EOFToken);11 await page.screenshot({ path: path.join(__dirname, 'example.png') });12 await browser.close();13})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { PlaywrightInternal } = require('playwright');2const internal = new PlaywrightInternal();3const { EOFToken } = internal;4const { PlaywrightInternal } = require('playwright');5const internal = new PlaywrightInternal();6const { EOFToken } = internal;7const { PlaywrightInternal } = require('playwrighth);8const internal = new PlaywrightInternal(t;9const { EOFToken } = internal/10const { PlaywrightInternal } = require('playwright');11const internal = new PlaywrightInternal();12const { EOFToken } = internal;13const { PlaywrightInternal } = require('playwright');14const internal = new PlaywrightInternal();15const { EOFToken } = internal;16const { PlaywrightInternal } = require('playwright');17const internal = new PlaywrightInternal();18const { EOFToken } = internal;19const { PlaywrightInternal } = require('playwright');20const internal = new PlaywrightInternal();21const { EOFToken } = internal;22const { PlaywrightInternal } = require('playwright');23const internal = new PlaywrightInternal();24const { EOFToken } = internal;25const { PlaywrightInternal } = require('playwright');26const internal = new PlaywrightInternal();27const { EOFToken } = internal;28const { PlaywrightInternal } = require('playwright');29const internal = new PlaywrightInternal();30const { EOFToken } = internal;31const { PlaywrightInternal } = require('playwright');32const internal = new PlaywrightInternal();33const { EOFToken } = internal;34const { PlaywrightInternal } = require('playwright');35const internal = new PlaywrightInternal();36const { EOFToken } = internal;37const { PlaywrightInternal } = require('playwright');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Page } = require('playwright/lib/server/page');2const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement');3const page = await browser.newPage();4const recorder = await page.context().newCDPSession(page);5await recorder.send('Page.enable');6await recorder.send('Page.startScreencast', {7});8recorder.once('Page.screencastFrame', async (event) => {9 console.log(event.data);10 await recorder.send('Page.stopScreencast');11 await page.close();12});13await page.waitForSelector('text=Google Search');14await page.click('text=Google Search');15await page.waitForSelector('input[name="q"]');16await page.fill('input[name="q"]', 'Hello World');17await page.press('input[name="q"]', 'Enter');18await page.waitForSelector('text=Hello World - Google Search');19await page.click('text=Hello World - Google Search');20await page.waitForSelector('input[name="q"]');21await page.fill('input[name="q"]', 'Hello World');22await page.press('input[name="q"]', 'Enter');23await page.waitForSelector('text=Hello World - Google Search');24await page.click('text=Hello World - Google Search');25await page.waitForSelector('input[name="q"]');26await page.fill('input[name="q"]', 'Hello World');27await page.press('input[name="q"]', 'Enter');28await page.waitForSelector('text=Hello World - Google Search');29await page.click('text=Hello World - Google Search');30await page.waitForSelector('input[name="q"]');31await page.fill('input[name="q"]', 'Hello World');32await page.press('input[name="q"]', 'Enter');33await page.waitForSelector('text=Hello World - Google Search');34await page.click('text=Hello World - Google Search');35await page.waitForSelector('input[name="q"]');36await page.fill('input[name="q"]', 'Hello World');37await page.press('input[name="q"]', 'Enter');38await page.waitForSelector('text=Hello World - Google Search');39await page.click('text=Hello World - Google Search');40await page.waitForSelector('input method of Playwright Internal APIlib/server/supplements/recorder/recorderSupplement.js');41 EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');42const { EOFToken/serversupplements/recorder/recorderSupplement.js');43const { EOFToken } = require('playwright/lib/server/supplements/recorderrecorderSupplement.js');44const { EOFToken } = require('laywright/lb/server/supplements/recorder/recorderSupplement.js45const { EOFToken } = require('p aywrightAlib/server/supplements/recorder/recorderSupplement.js');46const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');47const { EOFToken } = require('playwright/lib/server/suppleents/recorder/recorderSuplment.js');48const { EOFToken } = require('playwrightlib/server/supplements/recorder/recorderSupplement.js');49const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');50const { EOFToken } = require('playwright/lib/server/suppleents/recorder/recorderSuplement.js');51const { EOFToken } = require(playwright/lib/server/supplements/recorder/recorderSupplement.js'

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2const { InternalAPI } = require('playwright/lib/internal/api');3const { EOFToken } = require('playwright/lib/internal/ffmpeg/ffmpeg');4const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');5const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');6const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');7const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');8const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');9const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');10const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');11const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');12const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');13const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');14const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');15const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');16const { EOFToken } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2const { InternalAPI } = require('playwright/lib/internal/api');3const { EOFToken } = require('playwright/lib/internal/ffmpeg/ffmpeg');4const { createWriteStream } = require('fs');5const path = require('path');6(async () => {7 const browser = await playwright.chromium.launch();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {EOFToken} = require('playwright/lib/protocol/transport');2const {BrowserContext} = require('playwright/lib/server/browserContext');3const context = await browser.newContext();4const page = await context.newPage();5await page.waitForTimeout(1000);6await page.evaluate(() => {7 const input = document.querySelector('input[type="text"]');8 input.value = 'Hello World';9 input.dispatchEvent(new Event('input', { bubbles: true }));10});11await page.evaluate(() => {12 const input = document.querySelector('input[type="text"]');13 input.dispatchEvent(new Event('keydown', { bubbles: true, key: 'Enter' }));14});15await page.waitForTimeout(1000);16await page.evaluate(() => {17 const input = document.querySelector('input[type="text"]');18 input.dispatchEvent(new Event('keyup', { bubbles: true, key: 'Enter' }));19});20await page.waitForTimeout(1000);21await page.evaluate(() => {22 const input = document.querySelector('input[type="text"]');23 input.dispatchEvent(new Event('keydown', { bubbles: true, key: 'Enter' }));24});25await page.waitForTimeout(1000);26await page.evaluate(() => {27 const input = document.querySelector('input[type="text"]');28 input.dispatchEvent(new Event('keyup', { bubbles: true, key: 'Enter' }));29});30await page.waitForTimeout(1000);31await page.evaluate(() => {32 const input = document.querySelector('input[type="text"]');33 input.dispatchEvent(new Event('keydown', { bubbles: true, key: 'Enter' }));34});35await page.waitForTimeout(1000);36await page.evaluate(() => {37 const input = document.querySelector('input[type="text"]');38 input.dispatchEvent(new Event('keyup', { bubbles: true, key: 'Enter' }));39});40await page.waitForTimeout(1000);41await page.evaluate(() => {42 const input = document.querySelector('input[type="text"]');43 input.dispatchEvent(new Event('keydown', { bubbles: true, key: 'Enter' }));44});45await page.waitForTimeout(1000);46await page.evaluate(() => {47 const input = document.querySelector('input[type="text"]');48 input.dispatchEvent(new Event('keyup', { bubbles: true, key: 'Enter' }));49});50await page.waitForTimeout(1000);51await page.evaluate(() => {52 const input = document.querySelector('input[type="textt page = await browser.newPage();53 await page.waitForSelector('video');54 const video = await page.$('video');55 const videoURL = await video.getAttribute('src');56 const videoStream = await InternalAPI.createReadStream(videoURL);57 const videoWriteStream = createWriteStream(path.join(__dirname, 'test.mp4'));58 videoStream.pipe(videoWriteStream);59 await new Promise(resolve => {60 videoWriteStream.on('finish', resolve);61 });62 await browser.close();63})();64const playwright = require('playwright');65const { InternalAPI } = require('playwright/lib/internal/api');66const { EOFToken } = require('playwright/lib/internal/ffmpeg/ffmpeg');67const { createWriteStream } = require('fs');68const path = require('path');69(async () => {70 const browser = await playwright.chromium.launch();71 const page = await browser.newPage();72 await page.waitForSelector('video');73 const video = await page.$('video');74 const videoURL = await video.getAttribute('src');75 const videoStream = await InternalAPI.createReadStream(videoURL);76 const videoWriteStream = createWriteStream(path.join(__dirname, 'test2.mp4'));77 videoStream.pipe(videoWriteStream);78 await new Promise(resolve => {79 videoWriteStream.on('finish', resolve);80 });81 await browser.close();82})();83const playwright = require('playwright');84const { InternalAPI } = require('playwright/lib/internal/api');85const { EOFToken } = require('playwright/lib/internal/ffmpeg/ffmpeg');86const { createWriteStream } = require('fs');87const path = require('path');

Full Screen

Using AI Code Generation

copy

Full Screen

1const {EOFToken} = require('playwright/lib/protocol/transport');2const {BrowserContext} = require('playwright/lib/server/browserContext');3const context = await browser.newContext();4const page = await context.newPage();5await page.waitForTimeout(1000);6await page.evaluate(() => {7 const input = document.querySelector('input[type="text"]');8 input.value = 'Hello World';9 input.dispatchEvent(new Event('input', { bubbles: true }));10});11await page.evaluate(() => {12 const input = document.querySelector('input[type="text"]');13 input.dispatchEvent(new Event('keydown', { bubbles: true, key: 'Enter' }));14});15await page.waitForTimeout(1000);16await page.evaluate(() => {17 const input = document.querySelector('input[type="text"]');18 input.dispatchEvent(new Event('keyup', { bubbles: true, key: 'Enter' }));19});20await page.waitForTimeout(1000);21await page.evaluate(() => {22 const input = document.querySelector('input[type="text"]');23 input.dispatchEvent(new Event('keydown', { bubbles: true, key: 'Enter' }));24});25await page.waitForTimeout(1000);26await page.evaluate(() => {27 const input = document.querySelector('input[type="text"]');28 input.dispatchEvent(new Event('keyup', { bubbles: true, key: 'Enter' }));29});30await page.waitForTimeout(1000);31await page.evaluate(() => {32 const input = document.querySelector('input[type="text"]');33 input.dispatchEvent(new Event('keydown', { bubbles: true, key: 'Enter' }));34});35await page.waitForTimeout(1000);36await page.evaluate(() => {37 const input = document.querySelector('input[type="text"]');38 input.dispatchEvent(new Event('keyup', { bubbles: true, key: 'Enter' }));39});40await page.waitForTimeout(1000);41await page.evaluate(() => {42 const input = document.querySelector('input[type="text"]');43 input.dispatchEvent(new Event('keydown', { bubbles: true, key: 'Enter' }));44});45await page.waitForTimeout(1000);46await page.evaluate(() => {47 const input = document.querySelector('input[type="text"]');48 input.dispatchEvent(new Event('keyup', { bubbles: true, key: 'Enter' }));49});50await page.waitForTimeout(1000);51await page.evaluate(() => {52 const input = document.querySelector('input[type="text

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