(self, tok_pattern)
return None
Match the token under the cursor, and advance the cursor if matched.

        If tok_pattern is not TokSpace, TokNewline, or TokComment,
        this method consumes all whitespace, newline, and comment
        tokens prior to the matched token, and returns them with the
        token. If the first non-space token does not match, the cursor
        returns to where it was before the call.

        If self._max_pos is not None, then the cursor is not allowed
        to advance past that position. If consuming whitespace and the
        accepted token would leave the cursor past this point, the
        cursor is rewound to the beginning and the method returns
        None. This mechanism is exclusively for supporting short-if.

        Args:
          tok_pattern: The lexer.Token subclass or subclass instance
            to match. If tok is a subclass, the current token matches
            if it has the same subclass. If tok is an instance, the
            current token matches if it has the same subclass and
            equal data.

        Returns:
          If the token under the cursor matches, returns the token. Otherwise
          None.
Match the token under the cursor, and advance the cursor if matched.
Match the token under the cursor and advance the cursor if matched .
def _accept(self, tok_pattern):
        """Match the token under the cursor, and advance the cursor if matched.

        If tok_pattern is not TokSpace, TokNewline, or TokComment,
        this method consumes all whitespace, newline, and comment
        tokens prior to the matched token, and returns them with the
        token. If the first non-space token does not match, the cursor
        returns to where it was before the call.

        If self._max_pos is not None, then the cursor is not allowed
        to advance past that position. If consuming whitespace and the
        accepted token would leave the cursor past this point, the
        cursor is rewound to the beginning and the method returns
        None. This mechanism is exclusively for supporting short-if.

        Args:
          tok_pattern: The lexer.Token subclass or subclass instance
            to match. If tok is a subclass, the current token matches
            if it has the same subclass. If tok is an instance, the
            current token matches if it has the same subclass and
            equal data.

        Returns:
          If the token under the cursor matches, returns the token. Otherwise
          None.

        """
        start_pos = self._pos

        # Find the first non-space token (unless accepting a space).
        while True:
            cur_tok = self._peek()
            if (cur_tok is None or
                cur_tok.matches(tok_pattern) or
                (not isinstance(cur_tok, lexer.TokSpace) and
                 not isinstance(cur_tok, lexer.TokNewline) and
                 not isinstance(cur_tok, lexer.TokComment))):
                break
            self._pos += 1

        if (cur_tok is not None and
            cur_tok.matches(tok_pattern) and
                (self._max_pos is None or self._pos < self._max_pos)):
            self._pos += 1
            return cur_tok

        self._pos = start_pos
        return None
def _accept ( self , tok_pattern ) : start_pos = self . _pos # Find the first non-space token (unless accepting a space). while True : cur_tok = self . _peek ( ) if ( cur_tok is None or cur_tok . matches ( tok_pattern ) or ( not isinstance ( cur_tok , lexer . TokSpace ) and not isinstance ( cur_tok , lexer . TokNewline ) and not isinstance ( cur_tok , lexer . TokComment ) ) ) : break self . _pos += 1 if ( cur_tok is not None and cur_tok . matches ( tok_pattern ) and ( self . _max_pos is None or self . _pos < self . _max_pos ) ) : self . _pos += 1 return cur_tok self . _pos = start_pos return None