scanRegexpBody method

Token scanRegexpBody(
  1. Token slash
)

Scan a regular expression literal, where the opening token has already been scanned This is called directly from the parser. The opening token slash can be a "/" or a "/=" token

Implementation

Token scanRegexpBody(Token slash) {
  bool inCharClass =
      false; // If true, we are inside a bracket. A slash in here does not terminate the literal. They are not nestable.
  int x = current;
  while (inCharClass || x != char.SLASH) {
    switch (x) {
      case char.NULL:
        fail("Unterminated regexp");
        break;
      case char.LBRACKET:
        inCharClass = true;
        break;
      case char.RBRACKET:
        inCharClass = false;
        break;
      case char.BACKSLASH:
        x = next();
        if (isEOL(x)) fail("Unterminated regexp");
        break;
      case char.CR:
      case char.LF:
      case char.LS:
      case char.PS:
        fail("Unterminated regexp");
    }
    x = next();
  }
  x = next(); // Move past the terminating "/"
  while (isNamePart(x)) {
    // Parse flags
    x = next();
  }
  return emitToken(Token.REGEXP,
      new String.fromCharCodes(input.getRange(slash.startOffset, index)));
}