Kahlan\Jit\TokenStream::next PHP Method

next() public method

Move to the next token of a given type.
public next ( mixed $type = false ) : string | null
$type mixed Token type to search for.
return string | null Returns the skipped text content (the current is not saved).
    public function next($type = false)
    {
        if ($type === false || $type === true) {
            $this->_current++;
            return $this->current($type);
        }
        $content = '';
        $start = $this->_current++;
        $count = $this->count();
        $list = array_fill_keys((array) $type, true);
        while ($this->_current < $count) {
            $content .= $this->_data[$this->_current][1];
            if (isset($list[$this->_data[$this->_current][0]])) {
                return $content;
            }
            $this->_current++;
        }
        $this->_current = $start;
    }

Usage Example

Esempio n. 1
0
         $actual = $stream->nextMatchingBracket();
         expect($actual)->toBe('{ { } }');
     });
     it("bails out nicely if there's no further tags", function () {
         $stream = new TokenStream(['source' => '']);
         $actual = $stream->nextMatchingBracket();
         expect($actual)->toBe(null);
     });
     it("bails out nicely if the current tags is not an open tags", function () {
         $stream = new TokenStream(['source' => '<?php ?>']);
         $actual = $stream->nextMatchingBracket();
         expect($actual)->toBe(null);
     });
     it("cancels the lookup if there's no closing tags", function () {
         $stream = new TokenStream(['source' => '<?php { { } ?>']);
         $stream->next('{');
         $actual = $stream->nextMatchingBracket();
         expect($actual)->toBe(null);
         expect($stream->getValue())->toBe('{');
     });
 });
 describe("->prev()", function () {
     it("moves prev", function () {
         $key = $this->stream->key();
         $this->stream->next();
         $this->stream->prev();
         expect($key)->not->toBe($this->stream->current());
     });
     it("gets the previous token value", function () {
         $this->stream->seek(1);
         $actual = $this->stream->prev();