public function scanToken($className, $pattern, $modifiers = null)
    {
        if (!$this->reader->match($pattern, $modifiers)) {
            return;
        }

        $data = $this->reader->getMatchData();

        $token = $this->createToken($className);
        $this->reader->consume();
        foreach ($data as $key => $value) {
            $method = 'set'.ucfirst($key);

            if (method_exists($token, $method)) {
                call_user_func([$token, $method], $value);
            }
        }

        yield $this->endToken($token);
    }
public function scanToken($className, $pattern, $modifiers = null)
    {
        if (!$this->reader->match($pattern, $modifiers)) {
            return;
        }

        $data = $this->reader->getMatchData();

        $token = $this->createToken($className);
        $this->reader->consume();
        foreach ($data as $key => $value) {
            $method = 'set'.ucfirst($key);

            if (method_exists($token, $method)) {
                call_user_func([$token, $method], $value);
            }
        }

        yield $this->endToken($token);
    }
public function scanToken ( $ className , $ pattern , $ modifiers = null ) { if ( ! $ this -> reader -> match ( $ pattern , $ modifiers ) ) { return ; } $ data = $ this -> reader -> getMatchData ( ) ; $ token = $ this -> createToken ( $ className ) ; $ this -> reader -> consume ( ) ; foreach ( $ data as $ key => $ value ) { $ method = 'set' . ucfirst ( $ key ) ; if ( method_exists ( $ token , $ method ) ) { call_user_func ( [ $ token , $ method ] , $ value ) ; } } yield $ this -> endToken ( $ token ) ; }
Quickly scans for a token by a single regular expression pattern.

If the pattern matches, this method will yield a new token. If not, it will yield nothing

All named capture groups are converted to `set*()`-methods, e.g.
`(?:<name>[a-z]+)` will automatically call `setName(<matchedValue>)` on the token.

This method could be written without generators, but the way its designed is easier to use
in scanners as you can simply return it's value without having to check for it to be null.


@param $className
@param $pattern
@param null $modifiers

@return \Generator
Quickly scans for a token by a single regular expression pattern .