public function parseOne(string $input, int $pos, array $preferredTokens = []): ?Match
    {
        $length = strlen($input);
        if ($pos >= $length) {
            return null;
        }

        $this->compile();

        $whitespace_length = $this->getWhitespaceLength($input, $pos);
        if ($whitespace_length) {
            $pos += $whitespace_length;
            if ($pos >= $length) {
                return null;
            }
        }

        $match = $this->match($input, $pos, $preferredTokens);
        if (!$match) {
            $near = substr($input, $pos, self::DUMP_NEAR_LENGTH);
            if ("" === $near || false === $near) {
                $near = '<EOF>';
            } else {
                $near = '"' . $near . '"';
            }
            throw new UnknownCharacterException(
                "Cannot parse none of expected tokens near $near",
                $pos
            );
        }

        return $match;
    }
public function parseOne(string $input, int $pos, array $preferredTokens = []): ?Match
    {
        $length = strlen($input);
        if ($pos >= $length) {
            return null;
        }

        $this->compile();

        $whitespace_length = $this->getWhitespaceLength($input, $pos);
        if ($whitespace_length) {
            $pos += $whitespace_length;
            if ($pos >= $length) {
                return null;
            }
        }

        $match = $this->match($input, $pos, $preferredTokens);
        if (!$match) {
            $near = substr($input, $pos, self::DUMP_NEAR_LENGTH);
            if ("" === $near || false === $near) {
                $near = '<EOF>';
            } else {
                $near = '"' . $near . '"';
            }
            throw new UnknownCharacterException(
                "Cannot parse none of expected tokens near $near",
                $pos
            );
        }

        return $match;
    }
public function parseOne ( string $ input , int $ pos , array $ preferredTokens = [ ] ) : ? Match { $ length = strlen ( $ input ) ; if ( $ pos >= $ length ) { return null ; } $ this -> compile ( ) ; $ whitespace_length = $ this -> getWhitespaceLength ( $ input , $ pos ) ; if ( $ whitespace_length ) { $ pos += $ whitespace_length ; if ( $ pos >= $ length ) { return null ; } } $ match = $ this -> match ( $ input , $ pos , $ preferredTokens ) ; if ( ! $ match ) { $ near = substr ( $ input , $ pos , self :: DUMP_NEAR_LENGTH ) ; if ( "" === $ near || false === $ near ) { $ near = '<EOF>' ; } else { $ near = '"' . $ near . '"' ; } throw new UnknownCharacterException ( "Cannot parse none of expected tokens near $near" , $ pos ) ; } return $ match ; }
Parse one next token from input at the given offset
@param string $input Input text to parse
@param int $pos Offset to parse at
@param string[] $preferredTokens Preferred tokens types to match first
@return Match|null Returns match on success match. Returns `null` on EOF.
@throws UnknownCharacterException
Parse one next token from input at the given offset