def __init__(self, name_of_primitive: str): self._name__line_nums = ' '.join(( name_of_primitive, cl_syntax.cl_syntax_for_args(_ARGUMENTS__LINE_NUMS), )) self._name__line_matcher = _name__line_matcher(name_of_primitive) self._range_expr_parser = parse_string.StringFromTokensParser( parse_string.Configuration(names.RANGE_EXPR_SED_NAME, _RANGE_EXPR_REFERENCE_RESTRICTIONS)) self._line_matcher_parser = parse_line_matcher.parsers(False).simple choices = [ parsing.TokenSyntaxSetup( token_matchers.is_option( names.LINE_NUMBERS_FILTER_OPTION.name), self._parse_line_nums_variant, ), ] self._choice_parser = parsing.ParserOfOptionalChoiceWithDefault( choices, self._parse_line_matcher_variant, )
def __init__(self, phase_is_after_act: bool): self._phase_is_after_act = phase_is_after_act self._name_parser = parse_string.StringFromTokensParser( parse_string.Configuration(defs.VAR_NAME_ELEMENT, reference_restrictions.is_string__all_indirect_refs_are_strings()) ) self._value_parser = parse_str_src.default_parser_for(phase_is_after_act=self._phase_is_after_act) self._unset_keyword_matcher = token_matchers.is_unquoted_and_equals(defs.UNSET_IDENTIFIER)
) ], description, ) @property def see_also_targets(self) -> Sequence[SeeAlsoTarget]: return [syntax_elements.REGEX_SYNTAX_ELEMENT.cross_reference_target] _REGEX_ARGUMENT = syntax_elements.REGEX_SYNTAX_ELEMENT.argument _REPLACEMENT_ARGUMENT = a.Named(types.STRING_TYPE_INFO.syntax_element_name) _MISSING_REPLACEMENT_ARGUMENT_ERR_MSG = 'Missing ' + _REPLACEMENT_ARGUMENT.name _PARSE_REPLACEMENT_CONFIGURATION = parse_string.Configuration('REPLACEMENT') _TEXT_PARSER = TextParser({ 'preserve_new_lines_option': formatting.argument_option(names.PRESERVE_NEW_LINES_OPTION_NAME), '_REG_EX_': _REGEX_ARGUMENT.name, '_STRING_': _REPLACEMENT_ARGUMENT.name, 'plain_string': misc_texts.PLAIN_STRING, 'LINES_SELECTOR_MATCHER': names.LINES_SELECTION_OPTION.argument, 'line_matcher_model': matcher_model.LINE_MATCHER_MODEL, 'Note': headers.NOTE_LINE_HEADER, 'NL': formatting.string_constant('\\n'), 'LINES_ARE_SEPARATED_BY_NEW_LINE': misc_texts.LINES_ARE_SEPARATED_BY_NEW_LINE, }) _DESCRIPTION = """\ Replaces every {plain_string} matching {_REG_EX_} (on a single line) with {_STRING_}.
AccumulatedComponents.empty(), ) class _ParseAsCommand(ParserFromTokenParserBase[CommandSdv]): def __init__(self): super().__init__(consume_last_line_if_is_at_eol_after_parse=False) self._arguments_parser = parse_arguments.parser() def parse_from_token_parser(self, parser: TokenParser) -> CommandSdv: program_name = parse_string.parse_string_from_token_parser( parser, _PARSE_NAME_CONF) arguments = self._arguments_parser.parse_from_token_parser(parser) return CommandSdv(CommandDriverSdvForSystemProgram(program_name), arguments) _PROGRAM_NAME_STRING_REFERENCES_RESTRICTION = is_string__all_indirect_refs_are_strings( text_docs.single_pre_formatted_line_object( str_constructor.FormatMap( 'A program name must be defined in terms of {string_type}.', { 'string_type': define_symbol.TYPE_W_STR_RENDERING_INFO_DICT[ WithStrRenderingType.STRING].identifier }, ))) _PARSE_NAME_CONF = parse_string.Configuration( 'NAME', _PROGRAM_NAME_STRING_REFERENCES_RESTRICTION)
from exactly_lib.definitions.entity import syntax_elements from exactly_lib.impls.types.string_ import parse_string from exactly_lib.section_document.element_parsers.token_stream_parser import TokenParser, from_parse_source, \ ParserFromTokens from exactly_lib.section_document.parse_source import ParseSource from exactly_lib.symbol.sdv_structure import SymbolReference, SymbolName from exactly_lib.type_val_deps.sym_ref.w_str_rend_restrictions import reference_restrictions from exactly_lib.type_val_deps.types.list_ import list_sdvs as lrs from exactly_lib.type_val_deps.types.list_.list_sdv import ListSdv from exactly_lib.type_val_deps.types.string_.string_sdv import StringSdv from exactly_lib.util import either from . import generic_parser _STRING_ELEMENT_PARSE_CONFIGURATION = parse_string.Configuration( syntax_elements.STRING_SYNTAX_ELEMENT.singular_name, reference_restrictions.is_any_type_w_str_rendering(), ) def parse_list(source: ParseSource) -> ListSdv: with from_parse_source(source) as token_parser: return parse_list_from_token_parser(token_parser) def parse_list_from_token_parser(token_parser: TokenParser) -> ListSdv: return lrs.from_elements(_consume_elements_from_token_parser(token_parser)) def _consume_elements_from_token_parser(token_parser: TokenParser) -> List[lrs.ElementSdv]: return _ELEMENT_SEQUENCE_PARSER.parse(token_parser)
from exactly_lib.impls.instructions.multi_phase.utils.instruction_part_utils import PartsParserFromEmbryoParser, \ MainStepResultTranslatorForUnconditionalSuccess from exactly_lib.impls.types.string_ import parse_string from exactly_lib.impls.types.string_source import parse as parse_str_src from exactly_lib.section_document.element_parsers import token_stream_parser from exactly_lib.section_document.element_parsers.instruction_parser_exceptions import \ SingleInstructionInvalidArgumentException from exactly_lib.section_document.element_parsers.misc_utils import \ std_error_message_text_for_token_syntax_error_from_exception from exactly_lib.section_document.element_parsers.token_stream import TokenSyntaxError from exactly_lib.section_document.element_parsers.token_stream_parser import TokenParser from exactly_lib.type_val_deps.sym_ref.w_str_rend_restrictions import reference_restrictions from exactly_lib.util.parse import token_matchers from exactly_lib.util.str_.formatter import StringFormatter _VALUE_PARSE_CONFIGURATION = parse_string.Configuration(syntax_elements.STRING_SYNTAX_ELEMENT.singular_name) class EmbryoParser(embryo.InstructionEmbryoParserFromTokensWoFileSystemLocationInfo[None]): def __init__(self, phase_is_after_act: bool): self._phase_is_after_act = phase_is_after_act self._name_parser = parse_string.StringFromTokensParser( parse_string.Configuration(defs.VAR_NAME_ELEMENT, reference_restrictions.is_string__all_indirect_refs_are_strings()) ) self._value_parser = parse_str_src.default_parser_for(phase_is_after_act=self._phase_is_after_act) self._unset_keyword_matcher = token_matchers.is_unquoted_and_equals(defs.UNSET_IDENTIFIER) def _parse_from_tokens(self, token_parser: TokenParser) -> InstructionEmbryo[None]: try: phases = self._parse_phases(token_parser)
from exactly_lib.type_val_deps.types.path.rel_opts_configuration import RelOptionArgumentConfiguration from exactly_lib.type_val_deps.types.program.sdv.arguments import ArgumentsSdv from exactly_lib.util import either from exactly_lib.util.either import Either from exactly_lib.util.parse import token_matchers REL_OPTIONS_CONF = rel_opts_configuration.RelOptionsConfiguration( rel_opts_configuration.RELATIVITY_VARIANTS_FOR_ALL_EXCEPT_RESULT, RelOptionType.REL_HDS_CASE) REL_OPT_ARG_CONF = RelOptionArgumentConfiguration( REL_OPTIONS_CONF, syntax_elements.PROGRAM_ARGUMENT_SYNTAX_ELEMENT.singular_name, True) _STRING_CONFIGURATION = parse_string.Configuration( syntax_elements.PROGRAM_ARGUMENT_SYNTAX_ELEMENT.singular_name, reference_restrictions=None) def parser() -> Parser[ArgumentsSdv]: return _PARSER class _Parser(ParserFromTokenParserBase[ArgumentsSdv]): def __init__(self): super().__init__(consume_last_line_if_is_at_eol_after_parse=False, consume_last_line_if_is_at_eof_after_parse=False) self._elements_parser = generic_parser.ElementsUntilEndOfLineParser2( _ElementParser(), _MkElement(), )
class HereDocArgTokenMatcher(TokenMatcher): def matches(self, token: Token) -> bool: return (token.is_plain and token.string.startswith( string.HERE_DOCUMENT_MARKER_PREFIX)) class HereDocumentContentsParsingException( SingleInstructionInvalidArgumentException): def __init__(self, error_message: str): super().__init__(error_message) DEFAULT_CONFIGURATION = parse_string.Configuration( syntax_elements.RICH_STRING_SYNTAX_ELEMENT.singular_name, reference_restrictions=None) _SYNTAX_ELEMENT_NAME = _rs_syntax_elements.HERE_DOCUMENT_SYNTAX_ELEMENT_NAME class RichStringParser(ParserFromTokenParserBase[StringSdv]): def __init__(self, conf: parse_string.Configuration = DEFAULT_CONFIGURATION): super().__init__(False, False) self._sym_name_or_string_parser = SymbolNameOrStringRichStringParser( conf) self._string_parser = parse_string.StringFromTokensParser(conf) def parse_from_token_parser(self, token_parser: TokenParser) -> StringSdv: either_sym_name_or_string = self._sym_name_or_string_parser.parse_from_token_parser(
def parse(self, token_parser: TokenParser) -> IntegerSdv: string_sdv = self._string_parser.parse(token_parser) return integer_sdv.IntegerSdv(string_sdv, self._custom_integer_restriction) def validator_for_non_negative(actual: int) -> Optional[TextRenderer]: if actual < 0: return expected_found.unexpected_lines( _NON_NEGATIVE_INTEGER_ARGUMENT_DESCRIPTION, str(actual)) return None _NON_NEGATIVE_INTEGER_ARGUMENT_DESCRIPTION = 'An integer >= 0' _REFERENCE_RESTRICTIONS = is_string__all_indirect_refs_are_strings( text_docs.single_pre_formatted_line_object( str_constructor.FormatMap( 'The {INTEGER} argument must be made up of just {string_type} values.', { 'INTEGER': syntax_elements.INTEGER_SYNTAX_ELEMENT.argument.name, 'string_type': help_texts.ANY_TYPE_INFO_DICT[ValueType.STRING].identifier }))) _STRING_PARSER_CONFIGURATION = parse_string.Configuration( syntax_elements.INTEGER_SYNTAX_ELEMENT.singular_name, _REFERENCE_RESTRICTIONS, )
parse_source = ParseSource( _src('{soft_quote}{symbol_reference}{soft_quote} rest', soft_quote=SOFT_QUOTE_CHAR, symbol_reference=symbol_ref)) # ACT # actual = sut.parse_string_sdv_from_parse_source(parse_source) # ASSERT # assertion_on_result = assert_equals_string_sdv(single_symbol) assertion_on_result.apply_with_message(self, actual, 'result') assertion_on_parse_source = assert_source( remaining_part_of_current_line=asrt.equals('rest')) assertion_on_parse_source.apply_with_message(self, parse_source, 'parse_source') CONFIGURATION = sut.Configuration('string-arg') def _src(s: str, **kwargs) -> str: return s.format(**kwargs) def _single_line_source(s: str, **kwargs) -> TokenStream: return TokenStream(_src(s, **kwargs)) def _multi_line_source(lines: List[str], **kwargs) -> TokenStream: all_lines = '\n'.join([_src(line, **kwargs) for line in lines]) return TokenStream(all_lines)
from exactly_lib.definitions.entity import syntax_elements from exactly_lib.impls.types.string_ import parse_string from exactly_lib.section_document.element_parsers.token_stream_parser import TokenParser from exactly_lib.type_val_deps.types.string_.string_sdv import StringSdv 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) _GLOB_PATTERN_STRING_CONFIGURATION = parse_string.Configuration( syntax_elements.GLOB_PATTERN_SYNTAX_ELEMENT.singular_name, reference_restrictions=None)
def __init__(self): self._string_parser = parse_rich_string.SymbolNameOrStringRichStringParser( parse_string.Configuration( syntax_elements.STRING_SOURCE_SYNTAX_ELEMENT.singular_name))