(self)
Parse from the current pointer in current codestream.
Parse from the current pointer in current codestream.
Parse from the current pointer in current codestream .
def parse(self):
        """Parse from the current pointer in current codestream."""
        while True:
            # check input and BASIC events. may raise Break, Reset or Exit
            self._queues.check_events(self._basic_events.enabled)
            try:
                self.handle_basic_events()
                ins = self.get_codestream()
                self.current_statement = ins.tell()
                c = ins.skip_blank_read()
                # parse line number or : at start of statement
                if c in tk.END_LINE:
                    # line number marker, new statement
                    token = ins.read(4)
                    # end of program or truncated file
                    if token[:2] == b'\0\0' or len(token) < 4:
                        if c == b'\0' and self.error_resume:
                            # unfinished error handler: no RESUME (don't trap this)
                            self.error_handle_mode = True
                            # get line number right
                            raise error.BASICError(error.NO_RESUME, ins.tell()-len(token)-2)
                        # stream has ended
                        self.set_pointer(False)
                        return
                    if self.tron:
                        linenum = struct.unpack_from('<H', token, 2)
                        self._console.write(b'[%i]' % linenum)
                    self.step(token)
                elif c not in (b':', tk.THEN, tk.ELSE, tk.GOTO):
                    # new statement or branch of an IF statement allowed, nothing else
                    raise error.BASICError(error.STX)
                self.parser.parse_statement(ins)
            except error.BASICError as e:
                self.trap_error(e)
def parse ( self ) : while True : # check input and BASIC events. may raise Break, Reset or Exit self . _queues . check_events ( self . _basic_events . enabled ) try : self . handle_basic_events ( ) ins = self . get_codestream ( ) self . current_statement = ins . tell ( ) c = ins . skip_blank_read ( ) # parse line number or : at start of statement if c in tk . END_LINE : # line number marker, new statement token = ins . read ( 4 ) # end of program or truncated file if token [ : 2 ] == b'\0\0' or len ( token ) < 4 : if c == b'\0' and self . error_resume : # unfinished error handler: no RESUME (don't trap this) self . error_handle_mode = True # get line number right raise error . BASICError ( error . NO_RESUME , ins . tell ( ) - len ( token ) - 2 ) # stream has ended self . set_pointer ( False ) return if self . tron : linenum = struct . unpack_from ( '<H' , token , 2 ) self . _console . write ( b'[%i]' % linenum ) self . step ( token ) elif c not in ( b':' , tk . THEN , tk . ELSE , tk . GOTO ) : # new statement or branch of an IF statement allowed, nothing else raise error . BASICError ( error . STX ) self . parser . parse_statement ( ins ) except error . BASICError as e : self . trap_error ( e )