def parse_from_token_parser(self, parser: TokenParser) -> int: parser.require_has_valid_head_token('INTEGER') int_token = parser.consume_mandatory_token('err msg format string') try: return int(int_token.string) except ValueError: raise SingleInstructionInvalidArgumentException('Not an int: ' + int_token.string)
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(self, token_parser: TokenParser) -> StringTransformerSdv: token_parser.require_has_valid_head_token(_REGEX_ARGUMENT.name) mb_line_matcher = self._parser_of_lines_selection.parse_from_token_parser(token_parser) preserve_new_lines = token_parser.consume_optional_option(names.PRESERVE_NEW_LINES_OPTION_NAME) regex_sdv = self._parser_of_regex.parse_from_token_parser(token_parser) replacement = self._parser_of_replacement.parse(token_parser) return _impl.Sdv(mb_line_matcher, preserve_new_lines, regex_sdv, replacement)
def parse(expectation_type: ExpectationType, token_parser: TokenParser) -> StringMatcherResolver: token_parser.require_has_valid_head_token(_EXPECTED_SYNTAX_ELEMENT_FOR_EQUALS) expected_contents = parse_here_doc_or_file_ref.parse_from_token_parser( token_parser, EXPECTED_FILE_REL_OPT_ARG_CONFIG, consume_last_here_doc_line=False) return value_resolver( expectation_type, expected_contents, )
def parse(self, token_parser: TokenParser) -> FilesSourceSdv: file_specs = self._parse_file_specs(token_parser) token_parser.require_has_valid_head_token(_FILE_NAME_OR_SET_END) token_parser.consume_mandatory_keyword__part_of_syntax_element( syntax.FILE_LIST_END, False, syntax_elements.FILES_SOURCE_SYNTAX_ELEMENT.singular_name, ) return file_list.Sdv(file_specs)
def _parse_constant(tokens: TokenParser) -> FilesConditionSdv: elements = _parse_elements(tokens) tokens.require_has_valid_head_token(_FILE_NAME_OR_SET_END) tokens.consume_mandatory_keyword__part_of_syntax_element( syntax.LITERAL_END, False, syntax_elements.FILES_CONDITION_SYNTAX_ELEMENT.singular_name, ) return files_conditions.new_constant(elements)
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_from_token_parser( self, token_parser: TokenParser) -> Optional[StringSdv]: if not self._here_document_is_mandatory and token_parser.is_at_eol: return None token_parser.require_has_valid_head_token( _rs_syntax_elements.HERE_DOCUMENT_SYNTAX_ELEMENT_NAME) first_token = token_parser.token_stream.head if first_token.is_quoted: return _raise_not_a_here_doc_exception( token_parser.remaining_part_of_current_line) start_token = token_parser.consume_mandatory_token( 'impl: will succeed since because of check above') return self._parse_from_start_str(start_token.string, token_parser)
def parse_from_token_parser( self, token_parser: TokenParser) -> Either[str, StringSdv]: token_parser.require_has_valid_head_token(self._conf.argument_name) head = token_parser.head if head.source_string.startswith(string.HERE_DOCUMENT_MARKER_PREFIX): string_sdv = self._here_doc_parser.parse_from_token_parser( token_parser) return Either.of_right(string_sdv) elif TEXT_UNTIL_EOL_TOKEN_MATCHER.matches(head): token_parser.consume_head() string_sdv = parse_string.parse_rest_of_line_as_single_string( token_parser, strip_space=True) return Either.of_right(string_sdv) else: return self._plain_string_parser.parse(token_parser)
def parse_file_maker(instruction_config: InstructionConfig, parser: TokenParser) -> FileMaker: parser.require_has_valid_head_token(instruction_config.syntax_element) head_source_string = parser.token_stream.head.source_string if is_option_string(head_source_string): return _parse_file_maker_with_transformation(instruction_config, parser) else: if head_source_string.startswith(parse_here_document.DOCUMENT_MARKER_PREFIX): contents = parse_here_document.parse_as_last_argument_from_token_parser(True, parser) return FileMakerForConstantContents(contents) else: contents = parse_string_from_token_parser(parser) parser.report_superfluous_arguments_if_not_at_eol() return FileMakerForConstantContents(contents)
def parse(token_parser: TokenParser) -> LineMatcherResolver: 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=True) return resolver(regex_resolver)
def parse(token_parser: TokenParser) -> StringSdv: token_parser.require_has_valid_head_token( _GLOB_PATTERN_STRING_CONFIGURATION.argument_name) return parse_string.parse_string_from_token_parser( token_parser, _GLOB_PATTERN_STRING_CONFIGURATION)