code: def scan(self, restrict):
          
          # Keep looking for a token, ignoring any in self.ignore
          while True:
              # Search the patterns for a match, with earlier
              # tokens in the list having preference
              best_pat = None
              best_pat_len = 0
              for p, regexp in self.patterns:
                  # First check to see if we're restricting to this token
                  if restrict and p not in restrict and p not in self.ignore:
                      continue
                  m = regexp.match(self.input, self.pos)
                  if m:
                      # We got a match
                      best_pat = p
                      best_pat_len = len(m.group(0))
                      break
  
              # If we didn't find anything, raise an error
              if best_pat is None:
                  msg = "Bad Token"
                  if restrict:
                      msg = "Trying to find one of " + ", ".join(restrict)
                  raise SyntaxError(self.pos, msg)
  
              # If we found something that isn't to be ignored, return it
              if best_pat in self.ignore:
                  # This token should be ignored ..
                  self.pos += best_pat_len
              else:
                  end_pos = self.pos + best_pat_len
                  # Create a token with this data
                  token = (
                      self.pos,
                      end_pos,
                      best_pat,
                      self.input[self.pos:end_pos]
                  )
                  self.pos = end_pos
                  # Only add this token if it's not in the list
                  # (to prevent looping)
                  if not self.tokens or token != self.tokens[-1]:
                      self.tokens.append(token)
                      self.restrictions.append(restrict)
                      return 1
                  break
          return 0
docs: Should scan another token and add it to the list, self.tokens,
          and add the restriction to self.restrictions