public parse()

in tsdoc/src/parser/NodeParser.ts [78:185]


  public parse(): void {
    const tokenReader: TokenReader = new TokenReader(this._parserContext);

    let done: boolean = false;
    while (!done) {
      // Extract the next token
      switch (tokenReader.peekTokenKind()) {
        case TokenKind.EndOfInput:
          done = true;
          break;
        case TokenKind.Newline:
          this._pushAccumulatedPlainText(tokenReader);
          tokenReader.readToken();
          this._pushNode(
            new DocSoftBreak({
              parsed: true,
              configuration: this._configuration,
              softBreakExcerpt: tokenReader.extractAccumulatedSequence()
            })
          );
          break;
        case TokenKind.Backslash:
          this._pushAccumulatedPlainText(tokenReader);
          this._pushNode(this._parseBackslashEscape(tokenReader));
          break;
        case TokenKind.AtSign:
          this._pushAccumulatedPlainText(tokenReader);
          this._parseAndPushBlock(tokenReader);
          break;
        case TokenKind.LeftCurlyBracket: {
          this._pushAccumulatedPlainText(tokenReader);

          const marker: number = tokenReader.createMarker();
          const docNode: DocNode = this._parseInlineTag(tokenReader);
          const docComment: DocComment = this._parserContext.docComment;

          if (docNode instanceof DocInheritDocTag) {
            // The @inheritDoc tag is irregular because it looks like an inline tag, but
            // it actually represents the entire comment body
            const tagEndMarker: number = tokenReader.createMarker() - 1;
            if (docComment.inheritDocTag === undefined) {
              this._parserContext.docComment.inheritDocTag = docNode;
            } else {
              this._pushNode(
                this._backtrackAndCreateErrorRange(
                  tokenReader,
                  marker,
                  tagEndMarker,
                  TSDocMessageId.ExtraInheritDocTag,
                  'A doc comment cannot have more than one @inheritDoc tag'
                )
              );
            }
          } else {
            this._pushNode(docNode);
          }
          break;
        }
        case TokenKind.RightCurlyBracket:
          this._pushAccumulatedPlainText(tokenReader);
          this._pushNode(
            this._createError(
              tokenReader,
              TSDocMessageId.EscapeRightBrace,
              'The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag'
            )
          );
          break;
        case TokenKind.LessThan:
          this._pushAccumulatedPlainText(tokenReader);
          // Look ahead two tokens to see if this is "<a>" or "</a>".
          if (tokenReader.peekTokenAfterKind() === TokenKind.Slash) {
            this._pushNode(this._parseHtmlEndTag(tokenReader));
          } else {
            this._pushNode(this._parseHtmlStartTag(tokenReader));
          }
          break;
        case TokenKind.GreaterThan:
          this._pushAccumulatedPlainText(tokenReader);
          this._pushNode(
            this._createError(
              tokenReader,
              TSDocMessageId.EscapeGreaterThan,
              'The ">" character should be escaped using a backslash to avoid confusion with an HTML tag'
            )
          );
          break;
        case TokenKind.Backtick:
          this._pushAccumulatedPlainText(tokenReader);

          if (
            tokenReader.peekTokenAfterKind() === TokenKind.Backtick &&
            tokenReader.peekTokenAfterAfterKind() === TokenKind.Backtick
          ) {
            this._pushNode(this._parseFencedCode(tokenReader));
          } else {
            this._pushNode(this._parseCodeSpan(tokenReader));
          }
          break;
        default:
          // If nobody recognized this token, then accumulate plain text
          tokenReader.readToken();
          break;
      }
    }
    this._pushAccumulatedPlainText(tokenReader);
    this._performValidationChecks();
  }