(self, word, allow_nonnum, typechar=None)
return self.new_single().from_decimal(mantissa, exp10)
Convert representation to value.
Convert representation to value.
Convert representation to value .
def from_repr(self, word, allow_nonnum, typechar=None):
        """Convert representation to value."""
        # keep as string if typechar asks for it, ignore typechar otherwise
        if typechar == STR:
            return self.new_string().from_str(word)
        # skip spaces and line feeds (but not NUL).
        word = word.lstrip(b' \n').upper()
        if not word:
            return self.new_integer()
        if word[:2] == b'&H':
            return self.new_integer().from_hex(word[2:])
        elif word[:1] == b'&':
            return self.new_integer().from_oct(word[2:] if word[1:2] == 'O' else word[1:])
        # we need to try to convert to int first,
        # mainly so that the tokeniser can output the right token type
        try:
            return self.new_integer().from_str(word)
        except ValueError as e:
            # non-integer characters, try a float
            pass
        except error.BASICError as e:
            if e.err != error.OVERFLOW: # pragma: no cover
                # shouldn't happen, from_str only raises Overflow
                raise
        # if allow_nonnum == False, raises ValueError for non-numerical characters
        is_double, mantissa, exp10 = numbers.str_to_decimal(word, allow_nonnum)
        if is_double:
            return self.new_double().from_decimal(mantissa, exp10)
        return self.new_single().from_decimal(mantissa, exp10)
def from_repr ( self , word , allow_nonnum , typechar = None ) : # keep as string if typechar asks for it, ignore typechar otherwise if typechar == STR : return self . new_string ( ) . from_str ( word ) # skip spaces and line feeds (but not NUL). word = word . lstrip ( b' \n' ) . upper ( ) if not word : return self . new_integer ( ) if word [ : 2 ] == b'&H' : return self . new_integer ( ) . from_hex ( word [ 2 : ] ) elif word [ : 1 ] == b'&' : return self . new_integer ( ) . from_oct ( word [ 2 : ] if word [ 1 : 2 ] == 'O' else word [ 1 : ] ) # we need to try to convert to int first, # mainly so that the tokeniser can output the right token type try : return self . new_integer ( ) . from_str ( word ) except ValueError as e : # non-integer characters, try a float pass except error . BASICError as e : if e . err != error . OVERFLOW : # pragma: no cover # shouldn't happen, from_str only raises Overflow raise # if allow_nonnum == False, raises ValueError for non-numerical characters is_double , mantissa , exp10 = numbers . str_to_decimal ( word , allow_nonnum ) if is_double : return self . new_double ( ) . from_decimal ( mantissa , exp10 ) return self . new_single ( ) . from_decimal ( mantissa , exp10 )