def parse_from_token_parser(self, token_parser: TokenParser) -> RegexSdv: token_parser.require_has_valid_head_token( syntax_elements.REGEX_SYNTAX_ELEMENT.singular_name) is_ignore_case = token_parser.consume_and_handle_optional_option( False, lambda x: True, IGNORE_CASE_OPTION_NAME) regex_pattern = self._string_parser.parse_from_token_parser( token_parser) return _RegexSdv(is_ignore_case, regex_pattern)
def parse_optional_option(token_parser: TokenParser) -> StringTransformerSdv: """ :return: The identity transformer, if transformer option is not given. """ return token_parser.consume_and_handle_optional_option( IDENTITY_TRANSFORMER_SDV, _PARSER__ANY_LINE__SIMPLE.parse_from_token_parser, string_transformer.WITH_TRANSFORMED_CONTENTS_OPTION_NAME)
def parse_from_token_parser(self, parser: TokenParser) -> ComparisonActualFileConstructor: def _parse_program(_parser: TokenParser) -> ComparisonActualFileConstructor: program = parse_program.parse_program(_parser) return _ComparisonActualFileConstructorForProgram(self._checked_file, program) return parser.consume_and_handle_optional_option(self._default, _parse_program, OUTPUT_FROM_PROGRAM_OPTION_NAME)
def parse_optional_selection_resolver2(parser: TokenParser) -> Optional[FileMatcherResolver]: parser = token_stream_parser.token_parser_with_additional_error_message_format_map( parser, ADDITIONAL_ERROR_MESSAGE_TEMPLATE_FORMATS) return parser.consume_and_handle_optional_option( None, parse_resolver, SELECTION_OPTION.name)
def parse_optional_selection_resolver(parser: TokenParser) -> FileMatcherResolver: parser = token_stream_parser.token_parser_with_additional_error_message_format_map( parser, ADDITIONAL_ERROR_MESSAGE_TEMPLATE_FORMATS) return parser.consume_and_handle_optional_option( CONSTANT_TRUE_MATCHER_RESOLVER, parse_resolver, SELECTION_OPTION.name)
def parse( self, token_parser: TokenParser, ) -> FullDepsWithDetailsDescriptionSdv[ ModelConstructor[FilesMatcherModel]]: return token_parser.consume_and_handle_optional_option( dir_contents.MODEL_CONSTRUCTOR__NON_RECURSIVE, self._parse_recursive, file_or_dir_contents.RECURSIVE_OPTION.name, )
def parse_from_token_parser(token_parser: TokenParser, conf: RelOptionArgumentConfiguration = CONFIGURATION, consume_last_here_doc_line: bool = True) -> StringOrFileRefResolver: token_parser.require_head_token_has_valid_syntax() file_ref = token_parser.consume_and_handle_optional_option( None, functools.partial(parse_file_ref.parse_file_ref_from_token_parser, conf), FILE_ARGUMENT_OPTION) if file_ref is not None: return StringOrFileRefResolver(SourceType.PATH, None, file_ref) else: source_type, resolver = parse_string_or_here_doc_from_token_parser(token_parser, consume_last_here_doc_line) return StringOrFileRefResolver(source_type, resolver, None)
def parse(expectation_type: ExpectationType, token_parser: TokenParser) -> StringMatcherResolver: is_full_match = token_parser.consume_and_handle_optional_option(False, lambda parser: True, matcher_options.FULL_MATCH_ARGUMENT_OPTION) token_parser.require_has_valid_head_token(syntax_elements.REGEX_SYNTAX_ELEMENT.singular_name) source_type, regex_resolver = parse_regex.parse_regex2(token_parser, must_be_on_same_line=False) return value_resolver( expectation_type, is_full_match, regex_resolver, )
def parse_regex2(parser: TokenParser, must_be_on_same_line: bool = True, consume_last_here_doc_line: bool = False) -> Tuple[SourceType, RegexResolver]: if must_be_on_same_line: parser.require_is_not_at_eol(MISSING_REGEX_ARGUMENT_ERR_MSG) is_ignore_case = parser.consume_and_handle_optional_option(False, lambda x: True, IGNORE_CASE_OPTION_NAME) if must_be_on_same_line: parser.require_is_not_at_eol(MISSING_REGEX_ARGUMENT_ERR_MSG) source_type, regex_pattern = parse_string_or_here_doc_from_token_parser(parser, consume_last_here_doc_line) return source_type, _RegexResolver(is_ignore_case, regex_pattern)
def _parse_phases(token_parser: TokenParser) -> FrozenSet[_impl.Phase]: return token_parser.consume_and_handle_optional_option( _ALL_PHASES, _parse_phase_spec_option_argument, defs.PHASE_SPEC__OPTION_NAME, )
def parse(token_parser: TokenParser) -> StringMatcherSdv: is_full_match = token_parser.consume_and_handle_optional_option( False, lambda parser: True, matcher_options.FULL_MATCH_ARGUMENT_OPTION) regex_sdv = _PARSER_OF_REGEX.parse_from_token_parser(token_parser) return matches.sdv(is_full_match, regex_sdv)
def parse_from_token_parser( self, parser: TokenParser) -> ComparisonActualFileConstructor: return parser.consume_and_handle_optional_option( self._default, self._parse_program, defs.OUTPUT_FROM_PROGRAM_OPTION_NAME)