private function lexExpression()
    {
        $statementMethods = $this->getStatementLexingMethods();

        while (!$this->atEof()) {
            reset($statementMethods);
            $matchedStatement = false;

            // This is essentially a foreach loop that can be reset
            while (list($statementOpenDelimiter, $methodName) = each($statementMethods)) {
                if ($this->matches($statementOpenDelimiter)) {
                    // This is an unescaped statement
                    $matchedStatement = true;
                    $this->{$methodName}();

                    // Now that we've matched, we want to reset the loop so that longest delimiters are matched first
                    reset($statementMethods);
                } elseif ($this->getCurrentChar() === '\\') {
                    // Now that we know we're on an escape character, spend the resources to check for a match
                    if ($this->matches("\\$statementOpenDelimiter")) {
                        // This is an escaped statement
                        $this->expressionBuffer .= $statementOpenDelimiter;
                    }
                }
            }

            // Handle any text outside statements
            if (!$matchedStatement && !$this->atEof()) {
                $currentChar = $this->getCurrentChar();
                $this->expressionBuffer .= $currentChar;
                $this->cursor++;

                // Keep on going if we're seeing alphanumeric text
                while (ctype_alnum($this->getCurrentChar())) {
                    $currentChar = $this->getCurrentChar();
                    $this->expressionBuffer .= $currentChar;
                    $this->cursor++;
                }
            } else {
                $this->flushExpressionBuffer();
            }
        }

        // Flush anything left over in the buffer
        $this->flushExpressionBuffer();
    }
private function lexExpression()
    {
        $statementMethods = $this->getStatementLexingMethods();

        while (!$this->atEof()) {
            reset($statementMethods);
            $matchedStatement = false;

            // This is essentially a foreach loop that can be reset
            while (list($statementOpenDelimiter, $methodName) = each($statementMethods)) {
                if ($this->matches($statementOpenDelimiter)) {
                    // This is an unescaped statement
                    $matchedStatement = true;
                    $this->{$methodName}();

                    // Now that we've matched, we want to reset the loop so that longest delimiters are matched first
                    reset($statementMethods);
                } elseif ($this->getCurrentChar() === '\\') {
                    // Now that we know we're on an escape character, spend the resources to check for a match
                    if ($this->matches("\\$statementOpenDelimiter")) {
                        // This is an escaped statement
                        $this->expressionBuffer .= $statementOpenDelimiter;
                    }
                }
            }

            // Handle any text outside statements
            if (!$matchedStatement && !$this->atEof()) {
                $currentChar = $this->getCurrentChar();
                $this->expressionBuffer .= $currentChar;
                $this->cursor++;

                // Keep on going if we're seeing alphanumeric text
                while (ctype_alnum($this->getCurrentChar())) {
                    $currentChar = $this->getCurrentChar();
                    $this->expressionBuffer .= $currentChar;
                    $this->cursor++;
                }
            } else {
                $this->flushExpressionBuffer();
            }
        }

        // Flush anything left over in the buffer
        $this->flushExpressionBuffer();
    }
private function lexExpression ( ) { $ statementMethods = $ this -> getStatementLexingMethods ( ) ; while ( ! $ this -> atEof ( ) ) { reset ( $ statementMethods ) ; $ matchedStatement = false ; // This is essentially a foreach loop that can be reset while ( list ( $ statementOpenDelimiter , $ methodName ) = each ( $ statementMethods ) ) { if ( $ this -> matches ( $ statementOpenDelimiter ) ) { // This is an unescaped statement $ matchedStatement = true ; $ this -> { $ methodName } ( ) ; // Now that we've matched, we want to reset the loop so that longest delimiters are matched first reset ( $ statementMethods ) ; } elseif ( $ this -> getCurrentChar ( ) === '\\' ) { // Now that we know we're on an escape character, spend the resources to check for a match if ( $ this -> matches ( "\\$statementOpenDelimiter" ) ) { // This is an escaped statement $ this -> expressionBuffer .= $ statementOpenDelimiter ; } } } // Handle any text outside statements if ( ! $ matchedStatement && ! $ this -> atEof ( ) ) { $ currentChar = $ this -> getCurrentChar ( ) ; $ this -> expressionBuffer .= $ currentChar ; $ this -> cursor ++ ; // Keep on going if we're seeing alphanumeric text while ( ctype_alnum ( $ this -> getCurrentChar ( ) ) ) { $ currentChar = $ this -> getCurrentChar ( ) ; $ this -> expressionBuffer .= $ currentChar ; $ this -> cursor ++ ; } } else { $ this -> flushExpressionBuffer ( ) ; } } // Flush anything left over in the buffer $ this -> flushExpressionBuffer ( ) ; }
Lexes an expression

@throws RuntimeException Thrown if there was an invalid token
Lexes an expression