Matches all occurrences and returns token list

@param string                $source Source to match tokens

@param TokenFactoryInterface $factory

@return \Generator
517117
public function match($source, TokenFactoryInterface $factory)
    {
        $pos = 0;
        $len = strlen($this->_substr);

        while (($pos = strpos($source, $this->_substr, $pos)) !== false) {
            yield $factory->create(Token::NAME, ['pos' => $pos, 'length' => $len]);

            $pos += $len;
        }
    }
664640
public function validator(Factory $factory)
    {
        if (!$this->shouldBeValidated()) {
            return $factory->make([], []);
        }
        
        $rules = app()->call([$this, 'rules']);

        return $factory->make(
            $this->all(), $rules, $this->messages(), $this->attributes()
        );
    }
1218045
public function registerFactory($factory, $class)
    {
        $this[$factory] = $this->factory(function ($app) use ($class) {
            $obj = new $class;
            if ($obj instanceof FactoryInterface) {
                return $obj->create($app);
            } else {
                return $obj;
            }
        });
    }
707702
public function match($source)
    {
        $this->factory->setType(Token::START);

        return parent::match($source);
    }
625069
public function parse(Source $source)
    {
        $this->source = $source;
        $this->lexer = new Lexer($source);
        $this->token = $this->lexer->readToken(0);
        $this->cursor = 0;

        return $this->parseDocument();
    }
710730
public function highlight(string $source): string
    {
        $result = '';
        $previous = [];
        foreach ($this->getTokens($source) as $token) {
            $result .= $this->r->token($token, $previous);
            $previous = $token;
        }

        return $result;
    }
617988
private function getTokens(string $source): array
    {
        $tokens = [];
        $line = 0;

        foreach (token_get_all($source) as $token) {
            if (isset($token[2])) {
                $line = $token[2];
            }

            if (!is_array($token)) {
                $token = [$token, $token, $line];
            }

            $tokens[] = $token;
        }

        return $tokens;
    }
1214560
private function getClass(BuilderFactory $factory, string $newClassName, \ReflectionClass $class) : Builder
    {
        $parentClass = $class->name;
        $builder = $factory
            ->class($newClassName)
            ->extend($parentClass)
            ->implement('Ray\Aop\WeavedInterface');
        $builder = $this->addInterceptorProp($builder);

        return $this->addSerialisedAnnotationProp($builder, $class);
    }
1301912
protected static function parsePattern($source, \ArrayIterator $options) {
        $tokens = TokenIterator::fromPattern($source);
        $result = static::parseExpression($tokens, $options);
        if ($tokens->current() !== null) {
            $error = $tokens->getTokenError();
            throw new $error('Unexpected ending: '.join(' ', $tokens->left()));
        }
        return new Required($result);
    }
644718
private function createGeneratorFactory($generatorClass, \Closure $factory = null)
    {
        return function ($sourceClass, $prefixClass) use ($factory, $generatorClass) {
            if ($factory) {
                return $factory($sourceClass, $prefixClass, $this->generationIo, $this->definedClasses, $generatorClass);
            }

            return new $generatorClass($sourceClass, $prefixClass, $this->generationIo, null, $this->definedClasses);
        };
    }
889700
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $uuids = array();

        $count = filter_var(
            $input->getOption('count'),
            FILTER_VALIDATE_INT,
            array(
                'default' => 1,
                'min_range' => 1,
            )
        );

        if (((bool) $input->getOption('guid')) == true) {
            $features = new FeatureSet(true);

            Uuid::setFactory(new UuidFactory($features));
        }

        if (((bool) $input->getOption('comb')) === true) {
            Uuid::getFactory()->setRandomGenerator(
                new CombGenerator(
                    Uuid::getFactory()->getRandomGenerator(),
                    Uuid::getFactory()->getNumberConverter()
                )
            );
        }

        for ($i = 0; $i < $count; $i++) {
            $uuids[] = $this->createUuid(
                $input->getArgument('version'),
                $input->getArgument('namespace'),
                $input->getArgument('name')
            );
        }

        foreach ($uuids as $uuid) {
            $output->writeln((string) $uuid);
        }
    }
1343163
protected function publicFactoryAndSeed($factories, $seeds)
    {
        $factoryPath = database_path('factories/');
        $seedPath = database_path('seeds/');
        $factories = is_array($factories) ? $factories : [$factories];
        $seeds = is_array($seeds) ? $seeds : [$seeds];
        foreach ($factories as $factory) {
            Utils::copy($factory, $factoryPath . basename($factory), $this->dynamicVariables);
        }
        foreach ($seeds as $seed) {
            Utils::copy($seed, $seedPath . basename($seed), $this->dynamicVariables);
        }
    }
976382
protected function compile($source, $filename = null)
    {
        $tokens = $this->lexer->tokenize($source, $filename);
        $source = $this->parser->parse($tokens, $filename);

        return $source;
    }
874088
public function getAllCommentsSortedByParentAndIdAsc($source, $context)
    {
        /**
         * @var QueryBuilder
         */
        $queryBuilder = $this
            ->createQueryBuilder('c')
            ->where('c.source = :source')
            ->andWhere('c.context = :context')
            ->andWhere('c.enabled = :enabled')
            ->addOrderBy('c.parent', 'asc')
            ->addOrderBy('c.id', 'asc')
            ->setParameters([
                'source' => $source,
                'context' => $context,
                'enabled' => true,
            ]);

        $comments = $queryBuilder
            ->getQuery()
            ->getResult();

        return new ArrayCollection($comments);
    }
442410
public function match($source, TokenFactoryInterface $factory)
    {
        preg_match_all($this->regex, $source, $matches, PREG_OFFSET_CAPTURE);
        $matches = array_intersect_key($matches, $this->groups);

        foreach ($matches as $id => $group) {
            $name = $this->groups[$id];

            foreach ($group as $match) {
                if (empty($match) || $match[1] === -1) {
                    continue;
                }

                yield $factory->create($name, ['pos' => $match[1], 'length' => strlen($match[0])]);
            }
        }
    }
487696
public function execute(InputInterface $input, OutputInterface $output)
    {
        if (! $this->valid($input->getArgument('token'))) {
            return $this->tokenIsInvalid($output);
        }

        if (! $this->configExists()) {
            mkdir($this->homePath().'/.spark');
        }

        $this->storeToken($input->getArgument('token'));

        $this->tokenIsValid($output);
    }
935171
public function fillSource($source)
    {
        $ki = $this->keyIndex;
        $kn = $this->keyName;
        $index = $source->$ki;
        $name = $source->$kn;
        if ($index !== null) {
            if (!isset($this->names[$index])) {
                $message = 'Invalid index '.$this->contextKey.'#'.$index;
                throw new InvalidIndexed($message);
            }
            $newName = $this->names[$index];
            if ($name === null) {
                $source->$kn = $newName;
            } elseif ($name !== $newName) {
                $message = 'Mismatch '.$this->contextKey.'#'.$index.' and "'.$name.'"';
                throw new InvalidIndexed($message);
            }
            return true;
        } elseif ($name !== null) {
            $source->$ki = $this->add($name);
            return true;
        }
        return false;
    }