code: def scan(self):
          
  
          self.pre_scan()
  
          token = None
          end = len(self.source)
  
          while self.pos < end:
  
              best_pat = None
              best_pat_len = 0
  
              # Check patterns
              for p, regexp in self.patterns:
                  m = regexp.match(self.source, self.pos)
                  if m:
                      best_pat = p
                      best_pat_len = len(m.group(0))
                      break
  
              if best_pat is None:
                  raise SyntaxError(
                      "SyntaxError[@char {0}: {1}]".format(
                          self.pos, "Bad token."))
  
              # Ignore patterns
              if best_pat in self.ignore:
                  self.pos += best_pat_len
                  continue
  
              # Create token
              token = (
                  best_pat,
                  self.source[self.pos:self.pos + best_pat_len],
                  self.pos,
                  self.pos + best_pat_len,
              )
  
              self.pos = token[-1]
              self.tokens.append(token)
docs: Scan source and grab tokens.