(self, ins, output)
return comment
Convert a one- or two-byte keyword token to ascii.
Convert a one- or two-byte keyword token to ascii.
Convert a one - or two - byte keyword token to ascii .
def _detokenise_keyword(self, ins, output):
        """Convert a one- or two-byte keyword token to ascii."""
        # try for single-byte token or two-byte token
        # if no match, first char is passed unchanged
        s = ins.read(1)
        try:
            keyword = self._token_to_keyword[s]
        except KeyError:
            s += ins.peek()
            try:
                keyword = self._token_to_keyword[s]
                ins.read(1)
            except KeyError:
                output += s[:1]
                return False
        # when we're here, s is an actual keyword token.
        # letter or number followed by token is separated by a space
        if (
                output and int2byte(output[-1]) in ALPHANUMERIC
                and s not in tk.OPERATOR
            ):
            output += b' '
        output += keyword
        comment = False
        if keyword == b"'":
            comment = True
        elif keyword == tk.KW_REM:
            nxt = ins.read(1)
            if nxt == tk.O_REM: # '
                # if next char is token('), we have the special value REM'
                # -- replaced by ' below.
                output += b"'"
            else:
                # otherwise, it's part of the comment or an EOL or whatever,
                # pass back to stream so it can be processed
                ins.seek(-1, len(nxt))
            comment = True
        # check for special cases
        #   [:REM']   ->  [']
        if len(output) > 4 and bytes(output[-5:]) == b":REM'":
            output[:] = output[:-5] + b"'"
        #   [WHILE+]  ->  [WHILE]
        elif len(output) > 5 and bytes(output[-6:]) == b'WHILE+':
            output[:] = output[:-1]
        #   [:ELSE]  ->  [ELSE]
        # note that anything before ELSE gets cut off,
        # e.g. if we have 1ELSE instead of :ELSE it also becomes ELSE
        # SIC: len(output) > 4 and str(output[-4:])
        elif len(output) > 4 and bytes(output[-4:]) == tk.KW_ELSE:
            if (
                    len(output) > 5 and int2byte(output[-5]) == b':' and
                    int2byte(output[-6]) in DIGITS
                ):
                output[:] = output[:-5] + b' ' + tk.KW_ELSE
            else:
                output[:] = output[:-5] + tk.KW_ELSE
        # token followed by token or number is separated by a space,
        # except operator tokens and SPC(, TAB(, FN, USR
        nxt = ins.peek()
        if (
                not comment
                and nxt not in tk.END_LINE + tk.OPERATOR + (
                    tk.O_REM, b'"', b',', b';', b' ', b':', b'(', b')', b'$',
                    b'%', b'!', b'#', b'_', b'@', b'~', b'|', b'`'
                )
                and s not in tk.OPERATOR + (tk.TAB, tk.SPC, tk.USR, tk.FN)
            ):
            # excluding TAB( SPC( and FN. \xD9 is ', \xD1 is FN, \xD0 is USR.
            output += b' '
        return comment
def _detokenise_keyword ( self , ins , output ) : # try for single-byte token or two-byte token # if no match, first char is passed unchanged s = ins . read ( 1 ) try : keyword = self . _token_to_keyword [ s ] except KeyError : s += ins . peek ( ) try : keyword = self . _token_to_keyword [ s ] ins . read ( 1 ) except KeyError : output += s [ : 1 ] return False # when we're here, s is an actual keyword token. # letter or number followed by token is separated by a space if ( output and int2byte ( output [ - 1 ] ) in ALPHANUMERIC and s not in tk . OPERATOR ) : output += b' ' output += keyword comment = False if keyword == b"'" : comment = True elif keyword == tk . KW_REM : nxt = ins . read ( 1 ) if nxt == tk . O_REM : # ' # if next char is token('), we have the special value REM' # -- replaced by ' below. output += b"'" else : # otherwise, it's part of the comment or an EOL or whatever, # pass back to stream so it can be processed ins . seek ( - 1 , len ( nxt ) ) comment = True # check for special cases #   [:REM']   ->  ['] if len ( output ) > 4 and bytes ( output [ - 5 : ] ) == b":REM'" : output [ : ] = output [ : - 5 ] + b"'" #   [WHILE+]  ->  [WHILE] elif len ( output ) > 5 and bytes ( output [ - 6 : ] ) == b'WHILE+' : output [ : ] = output [ : - 1 ] #   [:ELSE]  ->  [ELSE] # note that anything before ELSE gets cut off, # e.g. if we have 1ELSE instead of :ELSE it also becomes ELSE # SIC: len(output) > 4 and str(output[-4:]) elif len ( output ) > 4 and bytes ( output [ - 4 : ] ) == tk . KW_ELSE : if ( len ( output ) > 5 and int2byte ( output [ - 5 ] ) == b':' and int2byte ( output [ - 6 ] ) in DIGITS ) : output [ : ] = output [ : - 5 ] + b' ' + tk . KW_ELSE else : output [ : ] = output [ : - 5 ] + tk . KW_ELSE # token followed by token or number is separated by a space, # except operator tokens and SPC(, TAB(, FN, USR nxt = ins . peek ( ) if ( not comment and nxt not in tk . END_LINE + tk . OPERATOR + ( tk . O_REM , b'"' , b',' , b';' , b' ' , b':' , b'(' , b')' , b'$' , b'%' , b'!' , b'#' , b'_' , b'@' , b'~' , b'|' , b'`' ) and s not in tk . OPERATOR + ( tk . TAB , tk . SPC , tk . USR , tk . FN ) ) : # excluding TAB( SPC( and FN. \xD9 is ', \xD1 is FN, \xD0 is USR. output += b' ' return comment