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)
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)
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)