Lexer.php
protected function readBracketContents(array $breakChars = null)
    {

        $breakChars = $breakChars ? $breakChars : [];
        $value = '';
        $prev = null;
        $char = null;
        $level = 0;
        $inString = false;
        $stringType = null;
        $finished = false;
        while (!$this->isAtEnd() && !$finished) {

            if ($this->isAtEnd())
                break;

            $prev = $char;
            $char = $this->peek();

            switch ($char) {
                case '"':
                case '\'':

                    if ($inString && $stringType === $char && $prev !== '\\')
                        $inString = false;
                    else if (!$inString) {

                        $inString = true;
                        $stringType = $char;
                    }
                    break;
                case '(':
                case '[':
                case '{':

                    if (!$inString)
                        $level++;
                    break;
                case ')':
                case ']':
                case '}':

                    if ($inString)
                        break;

                    if ($level === 0) {

                        $finished = true;
                        break;
                    }

                    $level--;
                    break;
            }

            if (in_array($char, $breakChars, true) && !$inString && $level === 0)
                $finished = true;

            if (!$finished) {

                $value .= $char;
                $this->consume();
            }
        }

        return trim($value);
    }
protected function readBracketContents(array $breakChars = null)
    {

        $breakChars = $breakChars ? $breakChars : [];
        $value = '';
        $prev = null;
        $char = null;
        $level = 0;
        $inString = false;
        $stringType = null;
        $finished = false;
        while (!$this->isAtEnd() && !$finished) {

            if ($this->isAtEnd())
                break;

            $prev = $char;
            $char = $this->peek();

            switch ($char) {
                case '"':
                case '\'':

                    if ($inString && $stringType === $char && $prev !== '\\')
                        $inString = false;
                    else if (!$inString) {

                        $inString = true;
                        $stringType = $char;
                    }
                    break;
                case '(':
                case '[':
                case '{':

                    if (!$inString)
                        $level++;
                    break;
                case ')':
                case ']':
                case '}':

                    if ($inString)
                        break;

                    if ($level === 0) {

                        $finished = true;
                        break;
                    }

                    $level--;
                    break;
            }

            if (in_array($char, $breakChars, true) && !$inString && $level === 0)
                $finished = true;

            if (!$finished) {

                $value .= $char;
                $this->consume();
            }
        }

        return trim($value);
    }
protected function readBracketContents ( array $ breakChars = null ) { $ breakChars = $ breakChars ? $ breakChars : [ ] ; $ value = '' ; $ prev = null ; $ char = null ; $ level = 0 ; $ inString = false ; $ stringType = null ; $ finished = false ; while ( ! $ this -> isAtEnd ( ) && ! $ finished ) { if ( $ this -> isAtEnd ( ) ) break ; $ prev = $ char ; $ char = $ this -> peek ( ) ; switch ( $ char ) { case '"' : case '\'' : if ( $ inString && $ stringType === $ char && $ prev !== '\\' ) $ inString = false ; else if ( ! $ inString ) { $ inString = true ; $ stringType = $ char ; } break ; case '(' : case '[' : case '{' : if ( ! $ inString ) $ level ++ ; break ; case ')' : case ']' : case '}' : if ( $ inString ) break ; if ( $ level === 0 ) { $ finished = true ; break ; } $ level -- ; break ; } if ( in_array ( $ char , $ breakChars , true ) && ! $ inString && $ level === 0 ) $ finished = true ; if ( ! $ finished ) { $ value .= $ char ; $ this -> consume ( ) ; } } return trim ( $ value ) ; }
Reads a "value", 'value' or value style string really gracefully.

It will stop on all chars passed to $breakChars as well as a closing ')'
when _not_ inside an expression initiated with either
", ', (, [ or {.

$breakChars might be [','] as an example to read sequential arguments
into an array. Scan for ',', skip spaces, repeat readBracketContents

Brackets are counted, strings are respected.

Inside a " string, \" escaping is possible, inside a ' string, \' escaping
is possible

As soon as a ) is found and we're outside a string and outside any kind of bracket,
the reading will stop and the value, including any quotes, will be returned

Examples:
('`' marks the parts that are read, understood and returned by this function)

<samp>
(arg1=`abc`, arg2=`"some expression"`, `'some string expression'`)
some-mixin(`'some arg'`, `[1, 2, 3, 4]`, `(isset($complex) ? $complex : 'complex')`)
and even
some-mixin(callback=`function($input) { return trim($input, '\'"'); }`)
</samp>

@param array|null $breakChars the chars to break on.

@return string the (possibly quote-enclosed) result string
Reads a value value or value style string really gracefully .