def _parse_selector(self, scoped=True, allow_periods_in_scope=False):
if self._current_token.kind != tokenize.NAME:<EOL><INDENT>self._raise_syntax_error('<STR_LIT>')<EOL><DEDENT>begin_line_num = self._current_token.begin[<NUM_LIT:0>]<EOL>begin_char_num = self._current_token.begin[<NUM_LIT:1>]<EOL>end_char_num = self._current_token.end[<NUM_LIT:1>]<EOL>line = self._current_token.line<EOL>selector_parts = []<EOL>step_parity = <NUM_LIT:0><EOL>while (step_parity == <NUM_LIT:0> and self._current_token.kind == tokenize.NAME or<EOL>step_parity == <NUM_LIT:1> and self._current_token.value in ('<STR_LIT:/>', '<STR_LIT:.>')):<EOL><INDENT>selector_parts.append(self._current_token.value)<EOL>step_parity = not step_parity<EOL>end_char_num = self._current_token.end[<NUM_LIT:1>]<EOL>self._advance_one_token()<EOL><DEDENT>self._skip_whitespace_and_comments()<EOL>scoped_selector = '<STR_LIT>'.join(selector_parts)<EOL>untokenized_scoped_selector = line[begin_char_num:end_char_num]<EOL>scope_re = IDENTIFIER_RE<EOL>if allow_periods_in_scope:<EOL><INDENT>scope_re = MODULE_RE<EOL><DEDENT>selector_re = MODULE_RE<EOL>scope_parts = scoped_selector.split('<STR_LIT:/>')<EOL>valid_format = all(scope_re.match(scope) for scope in scope_parts[:-<NUM_LIT:1>])<EOL>valid_format &= bool(selector_re.match(scope_parts[-<NUM_LIT:1>]))<EOL>valid_format &= bool(scoped or len(scope_parts) == <NUM_LIT:1>)<EOL>if untokenized_scoped_selector != scoped_selector or not valid_format:<EOL><INDENT>location = (self._filename, begin_line_num, begin_char_num + <NUM_LIT:1>, line)<EOL>self._raise_syntax_error('<STR_LIT>', location)<EOL><DEDENT>return scoped_selector<EOL>
Parse a (possibly scoped) selector.

        A selector is a sequence of one or more valid Python-style identifiers
        separated by periods (see also `SelectorMap`). A scoped selector is a
        selector that may be preceded by scope names (separated by slashes).

        Args:
          scoped: Whether scopes are allowed.
          allow_periods_in_scope: Whether to allow period characters in the scope
            names preceding the selector.

        Returns:
          The parsed selector (as a string).

        Raises:
          SyntaxError: If the scope or selector is malformatted.