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 _consume_elements_from_token_parser(token_parser: TokenParser) -> List[lrs.Element]: elements = [] while not token_parser.is_at_eol: next_token = token_parser.consume_mandatory_token('Invalid list element') elements.append(element_of(next_token)) return elements
def parse_integer_matcher(parser: TokenParser, name_of_lhs: str = 'LHS') -> IntegerMatcher: comparison_operator = parse_comparison_operator(parser) parser.require_is_not_at_eol(_MISSING_INTEGER_ARGUMENT) token = parser.consume_mandatory_token(_MISSING_INTEGER_ARGUMENT) try: integer_arg = python_evaluate(token.string) return IntegerMatcherFromComparisonOperator(name_of_lhs, comparison_operator, integer_arg) except NotAnIntegerException as ex: raise SingleInstructionInvalidArgumentException('Not an integer: ' + ex.value_string)
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_plain_list_element(parser: TokenParser) -> ArgumentsResolver: token = parser.consume_mandatory_token('Invalid list element') element = parse_list.element_of(token) return arguments_resolvers.new_without_validation(list_resolvers.from_elements([element]))
def parse_from_token_parser(self, parser: TokenParser) -> MatcherSdv[int]: parser.consume_mandatory_token('expecting single arbitrary token') return self._constant_result
def parse_simple_with_arg(parser: TokenParser) -> SimpleWithArg: token = parser.consume_mandatory_token('failed parse of simple expression with arg') return SimpleWithArg(token.string)
def parse_primitive_with_arg(parser: TokenParser) -> PrimitiveWithArg: token = parser.consume_mandatory_token( 'failed parse of simple expression with arg') return PrimitiveWithArg(token.string)