MCPcopy Create free account
hub / github.com/microsoft/typescript-go / scanCharacterEscape

Method scanCharacterEscape

internal/scanner/regexp.go:436–474  ·  view source on GitHub ↗

CharacterEscape ::= | `c` ControlLetter | IdentityEscape | (Other sequences handled by `scanEscapeSequence`) IdentityEscape ::= | '^' | '$' | '/' | '\' | '.' | '*' | '+' | '?' | '(' | ')' | '[' | ']' | '{' | '}' | '|' | [~AnyUnicodeMode] (any other non-identifier characters)

(atomEscape bool)

Source from the content-addressed store, hash-verified

434// | '^' | '$' | '/' | '\' | '.' | '*' | '+' | '?' | '(' | ')' | '[' | ']' | '{' | '}' | '|'
435// | [~AnyUnicodeMode] (any other non-identifier characters)
436func (p *regExpParser) scanCharacterEscape(atomEscape bool) string {
437 debug.Assert(p.pos() > 0 && p.text()[p.pos()-1] == '\\')
438 ch := p.char()
439 switch ch {
440 case -1:
441 p.error(diagnostics.Undetermined_character_escape, p.pos()-1, 1)
442 return "\\"
443 case 'c':
444 p.incPos(1)
445 ch = p.char()
446 if stringutil.IsASCIILetter(ch) {
447 p.incPos(1)
448 return string(ch & 0x1f)
449 }
450 if p.anyUnicodeModeOrNonAnnexB {
451 p.error(diagnostics.X_c_must_be_followed_by_an_ASCII_letter, p.pos()-2, 2)
452 } else if atomEscape {
453 p.incPos(-1)
454 return "\\"
455 }
456 return string(ch)
457 case '^', '$', '/', '\\', '.', '*', '+', '?', '(', ')', '[', ']', '{', '}', '|':
458 p.incPos(1)
459 return string(ch)
460 default:
461 p.incPos(-1) // back up to include the backslash for scanEscapeSequence
462 flags := EscapeSequenceScanningFlagsRegularExpression
463 if p.annexB {
464 flags |= EscapeSequenceScanningFlagsAnnexB
465 }
466 if p.anyUnicodeMode {
467 flags |= EscapeSequenceScanningFlagsAnyUnicodeMode
468 }
469 if atomEscape {
470 flags |= EscapeSequenceScanningFlagsAtomEscape
471 }
472 return p.scanner.scanEscapeSequence(flags)
473 }
474}
475
476func (p *regExpParser) scanGroupName(isReference bool) {
477 debug.Assert(p.pos() > 0 && p.text()[p.pos()-1] == '<')

Callers 3

scanAtomEscapeMethod · 0.95
scanClassSetCharacterMethod · 0.95
scanClassAtomMethod · 0.95

Calls 9

posMethod · 0.95
textMethod · 0.95
charMethod · 0.95
errorMethod · 0.95
incPosMethod · 0.95
AssertFunction · 0.92
IsASCIILetterFunction · 0.92
scanEscapeSequenceMethod · 0.80
stringEnum · 0.50

Tested by

no test coverage detected