def _error_nud_token(self, token): if token['type'] == 'eof': raise exceptions.IncompleteExpressionError(token['start'], token['value'], token['type']) raise exceptions.ParseError(token['start'], token['value'], token['type'], 'Invalid token.')
def _raise_parse_error_maybe_eof(self, expected_type, token): lex_position = token['start'] actual_value = token['value'] actual_type = token['type'] if actual_type == 'eof': raise exceptions.IncompleteExpressionError(lex_position, actual_value, actual_type) message = 'Expecting: %s, got: %s' % (expected_type, actual_type) raise exceptions.ParseError(lex_position, actual_value, actual_type, message)
def _match_multiple_tokens(self, token_types): if self._current_token() not in token_types: t = self._lookahead_token(0) lex_position = t['start'] actual_value = t['value'] actual_type = t['type'] if actual_type == 'eof': raise exceptions.IncompleteExpressionError( lex_position, actual_value, actual_type) else: message = 'Expecting: %s, got: %s' % (token_types, actual_type) raise exceptions.ParseError(lex_position, actual_value, actual_type, message) self._advance()
def _match(self, token_type=None): # inline'd self._current_token() if self._current_token() == token_type: # inline'd self._advance() self._advance() else: t = self._lookahead_token(0) lex_position = t['start'] actual_value = t['value'] actual_type = t['type'] if actual_type == 'eof': raise exceptions.IncompleteExpressionError( lex_position, actual_value, actual_type) else: message = 'Expecting: %s, got: %s' % (token_type, actual_type) raise exceptions.ParseError(lex_position, actual_value, actual_type, message)
def _error_nud_token(self, token): if token['type'] == 'eof': raise exceptions.IncompleteExpressionError(token['start'], token['value'], token['type']) self._raise_parse_error_for_token(token, 'invalid token')