Lexer.php
protected function scanFor(array $scans, $throwException = false)
    {

        while (!$this->isAtEnd()) {

            $found = false;
            foreach ($scans as $name) {

                foreach (call_user_func([$this, 'scan'.ucfirst($name)]) as $token) {

                    $found = true;
                    yield $token;
                }

                if ($found)
                    continue 2;
            }

            $spaces = $this->readSpaces();
            if (!empty($spaces) && !$this->isAtEnd())
                continue;

            if ($throwException) {

                $this->throwException(
                    'Unexpected `'.htmlentities($this->peek(20), \ENT_QUOTES).'`, '
                    .implode(', ', $scans).' expected'
                );
            } else
                return;
        }
    }
protected function scanFor(array $scans, $throwException = false)
    {

        while (!$this->isAtEnd()) {

            $found = false;
            foreach ($scans as $name) {

                foreach (call_user_func([$this, 'scan'.ucfirst($name)]) as $token) {

                    $found = true;
                    yield $token;
                }

                if ($found)
                    continue 2;
            }

            $spaces = $this->readSpaces();
            if (!empty($spaces) && !$this->isAtEnd())
                continue;

            if ($throwException) {

                $this->throwException(
                    'Unexpected `'.htmlentities($this->peek(20), \ENT_QUOTES).'`, '
                    .implode(', ', $scans).' expected'
                );
            } else
                return;
        }
    }
protected function scanFor ( array $ scans , $ throwException = false ) { while ( ! $ this -> isAtEnd ( ) ) { $ found = false ; foreach ( $ scans as $ name ) { foreach ( call_user_func ( [ $ this , 'scan' . ucfirst ( $ name ) ] ) as $ token ) { $ found = true ; yield $ token ; } if ( $ found ) continue 2 ; } $ spaces = $ this -> readSpaces ( ) ; if ( ! empty ( $ spaces ) && ! $ this -> isAtEnd ( ) ) continue ; if ( $ throwException ) { $ this -> throwException ( 'Unexpected `' . htmlentities ( $ this -> peek ( 20 ) , \ ENT_QUOTES ) . '`, ' . implode ( ', ' , $ scans ) . ' expected' ) ; } else return ; } }
Keeps scanning for all types of tokens passed as the first argument.

If one token is encountered that's not in $scans, the function breaks
or throws an exception, if the second argument is true

The passed scans get converted to methods
e.g. newLine => scanNewLine, blockExpansion => scanBlockExpansion etc.

@param array      $scans          the scans to perform
@param bool|false $throwException throw an exception if no tokens in $scans found anymore

@return \Generator the generator yielding all tokens found
@throws Exception
Keeps scanning for all types of tokens passed as the first argument .