Example #1
0
 def _parse_modifier(self, token_parser: TokenParser) -> _impl.ModifierSdv:
     if (token_parser.has_valid_head_token() and
             self._unset_keyword_matcher.matches(token_parser.head)):
         token_parser.consume_head()
         return self._parse_unset(token_parser)
     else:
         return self._parse_set(token_parser)
def parse_mandatory_choice_with_default(parser: TokenParser,
                                        syntax_element_name: str,
                                        choices: Iterable[TokenSyntaxSetup[PARSE_RESULT]],
                                        default: ParserFromTokenParser) -> PARSE_RESULT:
    parser.require_existing_valid_head_token(syntax_element_name)
    for syntax_setup in choices:
        if syntax_setup.matcher.matches(parser.head):
            parser.consume_head()
            return syntax_setup.parser_after_token(parser)
    return default(parser)
Example #3
0
def parse_mandatory_choice(
    token_parser: TokenParser,
    syntax_element: str,
    choices: Sequence[TokenSyntaxSetup[PARSE_RESULT]],
) -> PARSE_RESULT:
    token_parser.require_existing_valid_head_token(syntax_element)
    for syntax_setup in choices:
        if syntax_setup.matcher.matches(token_parser.head):
            token_parser.consume_head()
            return syntax_setup.parser_after_token(token_parser)
    return token_parser.report_missing(syntax_element)
Example #4
0
def parse_optional_choice_with_default(
    token_parser: TokenParser,
    choices: Sequence[TokenSyntaxSetup[PARSE_RESULT]],
    default: Callable[[TokenParser], PARSE_RESULT],
) -> PARSE_RESULT:
    if token_parser.has_valid_head_token_on_current_line():
        head_token = token_parser.head
        for syntax_setup in choices:
            if syntax_setup.matcher.matches(head_token):
                token_parser.consume_head()
                return syntax_setup.parser_after_token(token_parser)
    return default(token_parser)
Example #5
0
def parse_mandatory_choice_with_default(
    token_parser: TokenParser,
    syntax_element: str,
    choices: Sequence[TokenSyntaxSetup[PARSE_RESULT]],
    default: Callable[[TokenParser], PARSE_RESULT],
) -> PARSE_RESULT:
    token_parser.require_existing_valid_head_token(syntax_element)
    for syntax_setup in choices:
        if syntax_setup.matcher.matches(token_parser.head):
            token_parser.consume_head()
            return syntax_setup.parser_after_token(token_parser)
    return default(token_parser)
Example #6
0
 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)