MCPcopy Index your code
hub / github.com/angular/angular / scanRegex

Method scanRegex

packages/compiler/src/expression_parser/lexer.ts:692–732  ·  view source on GitHub ↗
(tokenStart: number)

Source from the content-addressed store, hash-verified

690 }
691
692 private scanRegex(tokenStart: number): Token {
693 this.advance();
694 const textStart = this.index;
695 let inEscape = false;
696 let inCharacterClass = false;
697
698 while (true) {
699 const peek = this.peek;
700
701 if (peek === chars.$EOF) {
702 return this.error('Unterminated regular expression', 0);
703 }
704
705 if (inEscape) {
706 inEscape = false;
707 } else if (peek === chars.$BACKSLASH) {
708 inEscape = true;
709 } else if (peek === chars.$LBRACKET) {
710 inCharacterClass = true;
711 } else if (peek === chars.$RBRACKET) {
712 inCharacterClass = false;
713 } else if (peek === chars.$SLASH && !inCharacterClass) {
714 break;
715 }
716 this.advance();
717 }
718
719 // Note that we want the text without the slashes,
720 // but we still want the slashes to be part of the span.
721 const value = this.input.substring(textStart, this.index);
722 this.advance();
723 const bodyToken = newRegExpBodyToken(tokenStart, this.index, value);
724 const flagsToken = this.scanRegexFlags(this.index);
725
726 if (flagsToken !== null) {
727 this.tokens.push(bodyToken);
728 return flagsToken;
729 }
730
731 return bodyToken;
732 }
733
734 private scanRegexFlags(start: number): Token | null {
735 if (!chars.isAsciiLetter(this.peek)) {

Callers 1

scanTokenMethod · 0.95

Calls 5

advanceMethod · 0.95
errorMethod · 0.95
scanRegexFlagsMethod · 0.95
newRegExpBodyTokenFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected