def _parse_exe_file_ref(tokens: TokenStream) -> FileRefResolver:
    token = tokens.head
    if token.is_plain and option_parsing.matches(syntax_elements.PYTHON_EXECUTABLE_OPTION_NAME, token.string):
        tokens.consume()
        return file_ref_resolvers.constant(file_refs.absolute_file_name(sys.executable))
    else:
        return parse_file_ref.parse_file_ref(tokens, conf=syntax_elements.REL_OPTION_ARG_CONF)
Example #2
0
def _parse_rel_option_type(options: RelOptionsConfiguration,
                           source: TokenStream) -> RelOptionType:
    option_str = source.head.string
    rel_option_type = _resolve_relativity_option_type(option_str)
    if rel_option_type not in options.accepted_options:
        return _raise_invalid_option(option_str, options)
    source.consume()
    return rel_option_type
Example #3
0
def _parse_rel_option_type(options: RelOptionsConfiguration,
                           source: TokenStream) -> RelOptionType:
    option_str = source.head.string
    rel_option_type = _resolve_relativity_option_type(option_str)
    if rel_option_type not in options.accepted_options:
        return _raise_invalid_option(option_str, options)
    source.consume()
    return rel_option_type
Example #4
0
def _try_parse_rel_symbol_option(options: RelOptionsConfiguration,
                                 source: TokenStream) -> Optional[SymbolReference]:
    option_str = source.head.string
    if not option_parsing.matches(REL_SYMBOL_OPTION_NAME, option_str):
        return None
    source.consume()
    if source.is_null:
        msg = 'Missing symbol name argument for {} option'.format(option_str)
        raise SingleInstructionInvalidArgumentException(msg)
    _raise_invalid_argument_exception_if_symbol_does_not_have_valid_syntax(source.head, option_str)
    symbol_name = source.consume().string
    return SymbolReference(symbol_name,
                           reference_restrictions_for_path_symbol(options.accepted_relativity_variants))
Example #5
0
def _try_parse_rel_symbol_option(
        options: RelOptionsConfiguration,
        source: TokenStream) -> Optional[SymbolReference]:
    option_str = source.head.string
    if not option_parsing.matches(REL_SYMBOL_OPTION_NAME, option_str):
        return None
    source.consume()
    if source.is_null:
        msg = 'Missing symbol name argument for {} option'.format(option_str)
        raise SingleInstructionInvalidArgumentException(msg)
    _raise_invalid_argument_exception_if_symbol_does_not_have_valid_syntax(
        source.head, option_str)
    symbol_name = source.consume().string
    return SymbolReference(
        symbol_name,
        reference_restrictions_for_path_symbol(
            options.accepted_relativity_variants))
Example #6
0
 def _parse_set(self, variable_name: str, tokens_for_value: TokenStream) -> TheInstructionEmbryo:
     if tokens_for_value.is_null:
         raise SingleInstructionInvalidArgumentException(_format('Missing {VALUE}.'))
     value_token = tokens_for_value.consume()
     if not tokens_for_value.is_null:
         raise SingleInstructionInvalidArgumentException(_format('Superfluous arguments.'))
     value_resolver = parse_string.parse_string_resolver_from_token(value_token,
                                                                    is_any_data_type())
     executor = _SetExecutor(variable_name, value_resolver)
     return TheInstructionEmbryo(executor, value_resolver.references)
Example #7
0
    def _with_non_empty_token_stream(
            self, tokens: TokenStream) -> Either[SymbolName, PathSdv]:
        initial_argument_string = tokens.remaining_part_of_current_line
        relativity_info = parse_explicit_relativity_info(
            self.conf.rel_opt_conf.options, self.conf.source_file_location,
            tokens)

        if not self.conf.rel_opt_conf.path_suffix_is_required and tokens.remaining_part_of_current_line_is_empty:
            if relativity_info is None:
                return self._result_from_no_arguments()
            else:
                path_part_sdv2_path_sdv = self._path_constructor(
                    relativity_info)
                return Either.of_right(
                    path_part_sdv2_path_sdv(path_part_sdvs.empty()))

        if tokens.look_ahead_state is LookAheadState.SYNTAX_ERROR:
            raise SingleInstructionInvalidArgumentException(
                std_error_message_text_for_token_syntax_error(
                    tokens.head_syntax_error_description))
        elif tokens.look_ahead_state is LookAheadState.NULL:
            raise SingleInstructionInvalidArgumentException(
                'Missing {}: {}'.format(
                    self.conf.rel_opt_conf.argument_syntax_name,
                    initial_argument_string))

        head_token = tokens.head

        if reserved_tokens.IS_RESERVED_WORD.matches(head_token):
            raise SingleInstructionInvalidArgumentException(
                'Illegal file name: {}'.format(head_token.string))
        elif head_token.type is TokenType.PLAIN:
            ensure_is_not_option_argument(head_token.source_string)

        tokens.consume()
        if relativity_info is None:
            return self._without_explicit_relativity(head_token)
        else:
            path_part_2_path_sdv = self._path_constructor(relativity_info)
            return Either.of_right(
                self._with_explicit_relativity(head_token,
                                               path_part_2_path_sdv))
Example #8
0
def parse_fragments_from_tokens__w_is_plain(
        tokens: TokenStream,
        conf: Configuration = DEFAULT_CONFIGURATION) -> Tuple[bool, List[symbol_syntax.Fragment]]:
    """
    Consumes a single token.
    :raises SingleInstructionInvalidArgumentException: Missing argument
    """

    if tokens.is_null:
        raise SingleInstructionInvalidArgumentException('Expecting {} argument'.format(conf.argument_name))
    string_token = tokens.consume()
    if string_token.is_plain and string_token.source_string in reserved_words.RESERVED_TOKENS:
        raise SingleInstructionInvalidArgumentException(
            'Illegal {}: {}'.format(conf.argument_name,
                                    string_token.source_string),
        )
    return string_token.is_plain, parse_fragments_from_token(string_token)
Example #9
0
def _parse_rel_source_file(source: TokenStream) -> bool:
    option_str = source.head.string
    if option_parsing.matches(REL_SOURCE_FILE_DIR_OPTION_NAME, option_str):
        source.consume()
        return True
    return False
Example #10
0
def _parse_rel_source_file(source: TokenStream) -> bool:
    option_str = source.head.string
    if option_parsing.matches(REL_SOURCE_FILE_DIR_OPTION_NAME, option_str):
        source.consume()
        return True
    return False