def _maybe_parse_macro(self): """Try to parse an macro (%scope/name).""" if self._current_token.string != '%': return False, None location = self._current_location() self._advance_one_token() scoped_name = self._parse_selector(allow_periods_in_scope=True) with utils.try_with_location(location): macro = self._delegate.macro(scoped_name) return True, macro
def _maybe_parse_identifier_reference(self): """Try to parse a identifier reference([package.package.]var_or_fn_or_cls_name""" location = self._current_location() if self._current_token.kind != tokenize.NAME: self._raise_syntax_error('Unexpected token.') begin_line_num = self._current_token.begin[0] begin_char_num = self._current_token.begin[1] end_char_num = self._current_token.end[1] line = self._current_token.line identifier_parts = [] # This accepts an alternating sequence of NAME or '.' tokens. step_parity = 0 while (step_parity == 0 and self._current_token.kind == tokenize.NAME or step_parity == 1 and self._current_token.value == '.'): identifier_parts.append(self._current_token.value) step_parity = not step_parity end_char_num = self._current_token.end[1] self._advance_one_token() self._skip_whitespace_and_comments() identifier = ''.join(identifier_parts) untokenized_identifier = line[begin_char_num:end_char_num] valid_format = MODULE_RE.match(identifier) if untokenized_identifier != identifier or not valid_format: location = (self._filename, begin_line_num, begin_char_num + 1, line) self._raise_syntax_error('Malformatted identifier.', location) evaluate = False args = [] kwargs = dict() if self._current_token.value == '(': evaluate = True args, kwargs = self._parse_args_kwargs() self._skip_whitespace_and_comments() with utils.try_with_location(location): reference = self._delegate.identifier_reference( identifier, evaluate, args, kwargs) return True, reference
def _maybe_parse_configurable_reference(self): """Try to parse a configurable reference (@[scope/name/]fn_name[()]).""" if self._current_token.value != '@': return False, None location = self._current_location() self._advance_one_token() scoped_name = self._parse_selector(allow_periods_in_scope=True) evaluate = False if self._current_token.value == '(': evaluate = True self._advance() if self._current_token.value != ')': self._raise_syntax_error("Expected ')'.") self._advance_one_token() self._skip_whitespace_and_comments() with utils.try_with_location(location): reference = self._delegate.configurable_reference(scoped_name, evaluate) return True, reference
def _maybe_parse_configurable_reference(self): """Try to parse a configurable reference (@[scope/name/]fn_name[()]).""" if self._current_token.value != '@': return False, None location = self._current_location() self._advance_one_token() scoped_name = self._parse_selector(allow_periods_in_scope=True) evaluate = False args = [] kwargs = dict() if self._current_token.value == '(': evaluate = True args, kwargs = self._parse_args_kwargs() self._skip_whitespace_and_comments() with utils.try_with_location(location): reference = self._delegate.configurable_reference( scoped_name, evaluate, args, kwargs) return True, reference