Parse parenthesized value

@param array $out

@return boolean
165208
protected function parenValue(&$out)
    {
        $s = $this->seek();

        $inParens = $this->inParens;

        if ($this->literal('(')) {
            if ($this->literal(')')) {
                $out = [Type::T_LIST, '', []];

                return true;
            }

            $this->inParens = true;

            if ($this->expression($exp) && $this->literal(')')) {
                $out = $exp;
                $this->inParens = $inParens;

                return true;
            }
        }

        $this->inParens = $inParens;
        $this->seek($s);

        return false;
    }
903983
private function xml2array($xmlObject, $out = array())
    {
        foreach ($xmlObject->attributes() as $attr => $val) {
            $out['@attributes'][$attr] = (string)$val;
        }
        $hasChilds = false;
        foreach ($xmlObject as $index => $node) {
            $hasChilds = true;
            $out[$index][] = $this->xml2array($node);
        }
        if (!$hasChilds && $val = (string)$xmlObject) {
            $out['@value'] = $val;
        }
        foreach ($out as $key => $vals) {
            if (is_array($vals)
                && count($vals) === 1
                && array_key_exists(0, $vals)
            ) {
                $out[$key] = $vals[0];
            }
        }

        return $out;
    }
396124
protected function hasOneOrManyDeepThroughParents(array $through)
    {
        return array_map(function ($class) {
            $segments = preg_split('/\s+as\s+/i', $class);

            $instance = Str::contains($segments[0], '\\')
                ? new $segments[0]
                : (new Pivot)->setTable($segments[0]);

            if (isset($segments[1])) {
                $instance->setTable($instance->getTable().' as '.$segments[1]);
            }

            return $instance;
        }, $through);
    }
915958
protected function value(&$out)
    {
        $s = $this->seek();

        if ($this->literal('url(') && $this->match('data:([a-z]+)\/([a-z0-9.+-]+);base64,', $m, false)) {
            $len = strspn($this->buffer, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwyxz0123456789+/=', $this->count);

            $this->count += $len;

            if ($this->literal(')')) {
                $content = substr($this->buffer, $s, $this->count - $s);
                $out = [Type::T_KEYWORD, $content];

                return true;
            }
        }

        $this->seek($s);

        if ($this->literal('not', false) && $this->whitespace() && $this->value($inner)) {
            $out = [Type::T_UNARY, 'not', $inner, $this->inParens];

            return true;
        }

        $this->seek($s);

        if ($this->literal('not', false) && $this->parenValue($inner)) {
            $out = [Type::T_UNARY, 'not', $inner, $this->inParens];

            return true;
        }

        $this->seek($s);

        if ($this->literal('+') && $this->value($inner)) {
            $out = [Type::T_UNARY, '+', $inner, $this->inParens];

            return true;
        }

        $this->seek($s);

        // negation
        if ($this->literal('-', false) &&
            ($this->variable($inner) ||
            $this->unit($inner) ||
            $this->parenValue($inner))
        ) {
            $out = [Type::T_UNARY, '-', $inner, $this->inParens];

            return true;
        }

        $this->seek($s);

        if ($this->parenValue($out) ||
            $this->interpolation($out) ||
            $this->variable($out) ||
            $this->color($out) ||
            $this->unit($out) ||
            $this->string($out) ||
            $this->func($out) ||
            $this->progid($out)
        ) {
            return true;
        }

        if ($this->keyword($keyword)) {
            if ($keyword === 'null') {
                $out = [Type::T_NULL];
            } else {
                $out = [Type::T_KEYWORD, $keyword];
            }

            return true;
        }

        return false;
    }
327580
private function parseValue()
    {
        $this->getNextToken();

        if ($this->tokenIs(T_ARRAY) || $this->tokenIs('[')) {
            // Sub array with key.
            $this->debug('Sub array with key.');
            $subparser = new ArrayParser($this->parser, ($this->level + 1));
            $subparser->parse();
        } else {
            // String item with key.
            $this->debug('String item with key.');
            $subparser = new StringValue($this->parser, ($this->level + 1));
            $subparser->parse();

            $this->parser->setValue($this->parser->getStack(), $subparser->getValue());
        }
    }
984055
public function parseSubscript($out)
    {
        while (true) {
            if ($this->stream->nextIf('.')) {

                if (!$this->stream->test(T_STRING)) {
                    $this->stream->prev();
                    break;
                }

                $val = $this->stream->next()->getValue();
                $out = sprintf("\$this->getAttribute(%s, '%s'", $out, $val);

                if ($this->stream->test('(')) {
                    $out .= sprintf(", array%s, 'method')", $this->parseExpression());
                } else {
                    $out .= ")";
                }

            } elseif ($this->stream->nextIf('[')) {

                $exp = '';

                while (!$this->stream->test(']')) {
                    $exp .= $this->parseExpression();
                }

                $this->stream->expect(']');
                $this->stream->next();

                $out = sprintf("\$this->getAttribute(%s, %s, array(), 'array')", $out, $exp);

            } else {
                break;
            }
        }

        return $out;
    }
84734
function parse ($input = null, $offset = null, $limit = null, $conditions = null) {
		if ( $input === null ) $input = $this->file;
		if ( !empty($input) ) {
			if ( $offset !== null ) $this->offset = $offset;
			if ( $limit !== null ) $this->limit = $limit;
			if ( count($conditions) > 0 ) $this->conditions = $conditions;
			if ( is_readable($input) ) {
				$this->data = $this->parse_file($input);
			} else {
				$this->file_data = &$input;
				$this->data = $this->parse_string();
			}
			if ( $this->data === false ) return false;
		}
		return true;
	}
437975
protected function selectorSingle(&$out) {
        $oldWhite = $this->eatWhiteDefault;
        $this->eatWhiteDefault = false;

        $parts = array();

        if ($this->literal("*", false)) {
            $parts[] = "*";
        }

        while (true) {
            // see if we can stop early
            if ($this->match("\s*[{,]", $m)) {
                $this->count--;
                break;
            }

            $s = $this->seek();
            // self
            if ($this->literal("&", false)) {
                $parts[] = scssc::$selfSelector;
                continue;
            }

            if ($this->literal(".", false)) {
                $parts[] = ".";
                continue;
            }

            if ($this->literal("|", false)) {
                $parts[] = "|";
                continue;
            }

            // for keyframes
            if ($this->unit($unit)) {
                $parts[] = $unit;
                continue;
            }

            if ($this->keyword($name)) {
                $parts[] = $name;
                continue;
            }

            if ($this->interpolation($inter)) {
                $parts[] = $inter;
                continue;
            }

            if ($this->literal('%', false) && $this->placeholder($placeholder)) {
                $parts[] = '%';
                $parts[] = $placeholder;
                continue;
            }

            if ($this->literal("#", false)) {
                $parts[] = "#";
                continue;
            }

            // a pseudo selector
            if ($this->match("::?", $m) && $this->mixedKeyword($nameParts)) {
                $parts[] = $m[0];
                foreach ($nameParts as $sub) {
                    $parts[] = $sub;
                }

                $ss = $this->seek();
                if ($this->literal("(") &&
                    ($this->openString(")", $str, "(") || true ) &&
                    $this->literal(")"))
                {
                    $parts[] = "(";
                    if (!empty($str)) $parts[] = $str;
                    $parts[] = ")";
                } else {
                    $this->seek($ss);
                }

                continue;
            } else {
                $this->seek($s);
            }

            // attribute selector
            // TODO: replace with open string?
            if ($this->literal("[", false)) {
                $attrParts = array("[");
                // keyword, string, operator
                while (true) {
                    if ($this->literal("]", false)) {
                        $this->count--;
                        break; // get out early
                    }

                    if ($this->match('\s+', $m)) {
                        $attrParts[] = " ";
                        continue;
                    }
                    if ($this->string($str)) {
                        $attrParts[] = $str;
                        continue;
                    }

                    if ($this->keyword($word)) {
                        $attrParts[] = $word;
                        continue;
                    }

                    if ($this->interpolation($inter, false)) {
                        $attrParts[] = $inter;
                        continue;
                    }

                    // operator, handles attr namespace too
                    if ($this->match('[|-~\$\*\^=]+', $m)) {
                        $attrParts[] = $m[0];
                        continue;
                    }

                    break;
                }

                if ($this->literal("]", false)) {
                    $attrParts[] = "]";
                    foreach ($attrParts as $part) {
                        $parts[] = $part;
                    }
                    continue;
                }
                $this->seek($s);
                // should just break here?
            }

            break;
        }

        $this->eatWhiteDefault = $oldWhite;

        if (count($parts) == 0) return false;

        $out = $parts;
        return true;
    }
633760
private function parseItem()
    {
        $subparser = new StringValue($this->parser, ($this->level + 1));
        $subparser->parse();

        $key = $subparser->getValue();

        $this->debug('key: ' . var_export($key, true));

        if ($this->tokenIs(T_DOUBLE_ARROW)) {
            // We MUST have an key when double arrow is encountered.
            if ($key === null) {
                $this->bailUnexpectedToken();
            }

            $this->pushStack($key);
            $this->parseValue();
            $this->popStack();
        } elseif ($this->tokenIs(',') || $this->tokenIs(')') || $this->tokenIs(']')) {
            // String item without key.
            $this->debug('String item without key.');
            $this->pushStack($this->counter++);
            $this->parser->setValue($this->parser->getStack(), $key);
            $this->popStack();
        }

        if ($this->tokenIs(',')) {
            $this->getNextToken();
            return true;
        }
        if ($this->tokenIs(')') || $this->tokenIs(']')) {
            $this->debug('closing bracket.');
            $this->getNextToken();

            return false;
        }

        return true;
    }
1308375
private function parseKeys(array $arr) {
        $output = $this->getArrayValue();
        $append_regex = '/\s*\+\s*$/';
        foreach ($arr as $k => $v) {
            if (is_array($v) && FALSE === strpos($k, '.')) {
                // this element represents a section; recursively parse the value
                $output[$k] = $this->parseKeys($v);
            } else {
                // if the key ends in a +, it means we should append to the previous value, if applicable
                $append = false;
                if (preg_match($append_regex, $k)) {
                    $k = preg_replace($append_regex, '', $k);
                    $append = true;
                }

                // transform "a.b.c = x" into $output[a][b][c] = x
                $current = & $output;

                $path = $this->property_nesting ? explode('.', $k) : array($k);
                while (($current_key = array_shift($path)) !== null) {
                    if ('string' === gettype($current)) {
                        $current = array($current);
                    }

                    if (!array_key_exists($current_key, $current)) {
                        if (!empty($path)) {
                            $current[$current_key] = $this->getArrayValue();
                        } else {
                            $current[$current_key] = null;
                        }
                    }
                    $current = & $current[$current_key];
                }

                // parse value
                $value = $v;
                if (!is_array($v)) {
                  $value = $this->parseValue($v);
                }

                if ($append && $current !== null) {
                    if (is_array($value)) {
                        if (!is_array($current)) {
                            throw new LogicException("Cannot append array to inherited value '{$k}'");
                        }
                        $value = array_merge($current, $value);
                    } else {
                        $value = $current . $value;
                    }
                }

                $current = $value;
            }
        }

        return $output;
    }
627331
protected function parseValue($value) {
		$value = trim($value);
		if ('' == $value) {
			//return as boolean
			return true;
		}
		return $this->valueParser->parse($value); 
	}
184336
function parse()
    {
        $criteria        = $this->criteria;
        $expectAsLiteral = $this->expectAsLiteral;


        $TOKENS  = preg_quote(static::TOKENS);

        $expectAsLiteral = (empty($expectAsLiteral)) ? '/@+-.' : $expectAsLiteral;
        $LITERAL = preg_quote($expectAsLiteral).'A-Za-z0-9_';


        $currentPos = 0;
        $length     = strlen($criteria);
        $parts      = [];
        $levelParts = [&$parts];
        $level      = 0;

        while ($currentPos < $length)
        {
            preg_match("(\G(?P<_literal_>[$LITERAL]*)(?P<_token_>[$TOKENS]|$))"
                , $criteria
                , $matches
                , 0
                , $currentPos
            );

            if ( empty($matches) )
                break;

            if (! empty($matches['_literal_']) ) {
                $levelParts[$level][] = ['_literal_' => $matches['_literal_']];
                $currentPos += strlen($matches['_literal_']);
            }

            # Deal With Token:
            if ( !isset($matches['_token_']) || $matches['_token_'] == '' )
                continue;

            $currentPos += strlen($matches['_token_']);
            $Token = $matches['_token_'];

            ## Regular Expression Token
            #
            #
            if ($Token === '~') {
                // ^ match any character that is not in list
                $pmatch = preg_match("/~(?P<_delimiter_>[^~]+)~/"
                    , $criteria
                    , $matches
                    , 0
                    , 0
                );
                if (! $pmatch )
                    throw new \RuntimeException('Miss usage of ~ ~ token.');

                $val['_regex_'] = $matches['_delimiter_'];
                $levelParts[$level][] = $val;

                $currentPos += strlen($matches[0])+2/*~x~*/;
            }
            ##
            # Variable
            # /:hash_id~\w{24}~
            #
            elseif ($Token === ':') {
                // ^$TOKENS  match any character that is not in list
                $pmatch = preg_match("(\G(?P<_name_>[^$TOKENS]+)(?:~(?P<_delimiter_>[^~]+)~)?:?)"
                    , $criteria
                    , $matches
                    , 0
                    , $currentPos
                );

                if (! $pmatch && !(isset($matches['_name_']) && isset($matches['_delimiter_'])) )
                    throw new \RuntimeException(
                        'Found empty parameter name or delimiter on (%s).'
                        , $criteria
                    );

                $parameter = $matches['_name_'];
                $val       = ['_parameter_' => $parameter];
                if (isset($matches['_delimiter_']))
                    $val[$parameter] = $matches['_delimiter_'];

                $levelParts[$level][] = $val;
                $currentPos += strlen($matches[0]);
            }

            ## Literal Token
            #  localhost\:port
            #
            elseif ($Token === '\\') {
                // Consider next character as Literal
                $nextChar = $currentPos += 1;
                $levelParts[$level][]   = ['_literal_' => $criteria[$nextChar]];
            }

            ## Optional Part
            #  /<u/:username~[a-zA-Z0-9._]+~><-:userid~\w{24}~>
            #
            elseif ($Token === '<') {
                if (! isset($va) ) {
                    $va = [];
                    $n = 0;
                }

                $n++;
                $va[$n] = [];
                $levelParts[$level][] = ['_optional_' => &$va[$n]];
                $level++;
                $levelParts[$level] = &$va[$n];
            }
            ## Close Optional ##
            elseif ($Token === '>') {
                unset($levelParts[$level]);
                $level--;

                if ($level < 0)
                    throw new \RuntimeException('Found closing bracket without matching opening bracket');
            }

            else
                // Recognized unused token return immanently
                $levelParts[$level][]   = ['_token_' => $Token];

        } // end while

        if ($level > 0)
            throw new \RuntimeException('Found unbalanced brackets');


        return ParsedCriteria::of($parts);
    }
882663
public function canParse($data)
	{
		$data = trim($data);

		if ($data && strpos($data, '=') === false)
		{
			return false;
		}

		if ((substr($data, 0, 1) == '{') && (substr($data, -1, 1) == '}'))
		{
			return false;
		}

		$obj = @parse_ini_string($data);

		if (!$obj)
		{
			return false;
		}

		return true;
	}
826367
public function parseOutput($output)
    {
        //if error code is returned, api OR the app will return an integer error code
        if ($this->isnum($output)) {
            switch ($output) {

                case 20:
                    return $this->lang['reports']['20'];
                    break;

                case 21:
                    return $this->lang['reports']['21'];
                    break;

                case 22:
                    return $this->lang['reports']['22'];
                    break;

                case 23:
                    return $this->lang['reports']['23'];
                    break;

                case 24:
                    return $this->lang['reports']['24'];
                    break;

                case 25:
                    return $this->lang['reports']['25'];
                    break;

                case 30:
                    return $this->lang['reports']['30'];
                    break;


                //In-app messages:
                case 100:
                    return $this->lang['app'][0];
                    break;

                case 101:
                    return $this->lang['app'][1];
                    break;

                case 102:
                    return $this->lang['app'][2];
                    break;

                default:
                    return $this->lang['reports']['999'];
                    break;

            }

            //returns from Mutlucell
        } elseif (preg_match('/(\$[0-9]+\#[0-9]+\.[0-9]+)/i', $output)) {
            //returned output is formatted like $ID#STATUS
            //E.g: $1234567#1.0
            $output = explode('#', $output);

            $status = $output[1];
            if ($status == '0.0') {
                return $this->lang['app']['101'];
            } else {
                return $this->lang['app']['100'];
            }

            //Unknown error
        } else {
            return $output;
        }
    }
461042
function parse($str) {
		preg_match_all('/(\w+)\h*=\h*(.+?)(?=,|$)/',
			$str,$pairs,PREG_SET_ORDER);
		$out=array();
		foreach ($pairs as $pair)
			$out[$pair[1]]=trim($pair[2]);
		return $out;
	}
523555
protected function parseFunction( ADT_PHP_File $parent, $matches )
	{
		$function	= new ADT_PHP_Function( $matches[6] );
		$function->setParent( $parent );
		$function->setLine( $this->lineNumber );

		if( trim( $matches[7] ) )
		{
			$paramList	= array();
			foreach( explode( ",", $matches[7] ) as $param )
			{
				$param	 = trim( $param );
				if( !preg_match( $this->regexParam, $param, $matches ) )
					continue;
				$function->setParameter( $this->parseParameter( $function, $matches ) );
			}
		}
		if( $this->openBlocks )
		{
			$methodBlock	= array_pop( $this->openBlocks );
			$this->decorateCodeDataWithDocData( $function, $methodBlock );
			$this->openBlocks	= array();
		}
		return $function;
	}
1132618
protected function parse_output() {
		foreach ( $this->output as $output ) {
			$skip = false;

			// Apply any sanitization callbacks defined.
			$value = $this->apply_sanitize_callback( $output, $this->value );

			// Skip if value is empty.
			if ( '' === $this->value ) {
				$skip = true;
			}

			// No need to proceed this if the current value is the same as in the "exclude" value.
			if ( isset( $output['exclude'] ) && is_array( $output['exclude'] ) ) {
				foreach ( $output['exclude'] as $exclude ) {
					if ( is_array( $value ) ) {
						if ( is_array( $exclude ) ) {
							$diff1 = array_diff( $value, $exclude );
							$diff2 = array_diff( $exclude, $value );

							if ( empty( $diff1 ) && empty( $diff2 ) ) {
								$skip = true;
							}
						}
						// If 'choice' is defined check for sub-values too.
						// Fixes https://github.com/aristath/kirki/issues/1416.
						if ( isset( $output['choice'] ) && isset( $value[ $output['choice'] ] ) && $exclude == $value[ $output['choice'] ] ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
							$skip = true;
						}
					}
					if ( $skip ) {
						continue;
					}

					// Skip if value is defined as excluded.
					if ( $exclude === $value || ( '' === $exclude && empty( $value ) ) ) {
						$skip = true;
					}
				}
			}
			if ( $skip ) {
				continue;
			}

			// Apply any value patterns defined.
			$value = $this->apply_value_pattern( $output, $value );

			if ( isset( $output['element'] ) && is_array( $output['element'] ) ) {
				$output['element'] = array_unique( $output['element'] );
				sort( $output['element'] );
				$output['element'] = implode( ',', $output['element'] );
			}

			$value = $this->process_value( $value, $output );

			if ( ( is_admin() && ! is_customize_preview() ) || ( isset( $_GET['editor'] ) && '1' === $_GET['editor'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification

				// Check if this is an admin style.
				if ( ! isset( $output['context'] ) || ! in_array( 'editor', $output['context'], true ) ) {
					continue;
				}
			} elseif ( isset( $output['context'] ) && ! in_array( 'front', $output['context'], true ) ) {

				// Check if this is a frontend style.
				continue;
			}
			$this->process_output( $output, $value );
		}
	}