private function parseList($parentNode, int $listParseContext) {
        $savedParseContext = $this->currentParseContext;
        $this->currentParseContext |= 1 << $listParseContext;
        $parseListElementFn = $this->getParseListElementFn($listParseContext);

        $nodeArray = array();
        while (!$this->isListTerminator($listParseContext)) {
            if ($this->isValidListElement($listParseContext, $this->getCurrentToken())) {
                $element = $parseListElementFn($parentNode);
                if ($element instanceof Node) {
                    $element->parent = $parentNode;
                    if ($element instanceof InlineHtml && $element->echoStatement && $listParseContext === ParseContext::SourceElements) {
                        $nodeArray[] = $element->echoStatement;
                        $element->echoStatement->parent = $parentNode;
                        $element->echoStatement = null;
                    }
                }
                $nodeArray[] = $element;
                continue;
            }

            // Error handling logic:
            // The current parse context does not know how to handle the current token,
            // so check if the enclosing contexts know what to do. If so, we assume that
            // the list has completed parsing, and return to the enclosing context.
            //
            // Example:
            //     class A {
            //         function foo() {
            //            return;
            //      // } <- MissingToken (generated when we try to "eat" the closing brace)
            //
            //         public function bar() {
            //         }
            //     }
            //
            // In the case above, the Method ParseContext doesn't know how to handle "public", but
            // the Class ParseContext will know what to do with it. So we abort the Method ParseContext,
            // and return to the Class ParseContext. This enables us to generate a tree with a single
            // class that contains two method nodes, even though there was an error present in the first method.
            if ($this->isCurrentTokenValidInEnclosingContexts()) {
                break;
            }

            // None of the enclosing contexts know how to handle the token. Generate a
            // SkippedToken, and continue parsing in the current context.
            // Example:
            //     class A {
            //         function foo() {
            //            return;
            //            & // <- SkippedToken
            //         }
            //     }
            $token = new SkippedToken($this->getCurrentToken());
            $nodeArray[] = $token;
            $this->advanceToken();
        }

        $this->currentParseContext = $savedParseContext;

        return $nodeArray;
    }
private function parseList($parentNode, int $listParseContext) {
        $savedParseContext = $this->currentParseContext;
        $this->currentParseContext |= 1 << $listParseContext;
        $parseListElementFn = $this->getParseListElementFn($listParseContext);

        $nodeArray = array();
        while (!$this->isListTerminator($listParseContext)) {
            if ($this->isValidListElement($listParseContext, $this->getCurrentToken())) {
                $element = $parseListElementFn($parentNode);
                if ($element instanceof Node) {
                    $element->parent = $parentNode;
                    if ($element instanceof InlineHtml && $element->echoStatement && $listParseContext === ParseContext::SourceElements) {
                        $nodeArray[] = $element->echoStatement;
                        $element->echoStatement->parent = $parentNode;
                        $element->echoStatement = null;
                    }
                }
                $nodeArray[] = $element;
                continue;
            }

            // Error handling logic:
            // The current parse context does not know how to handle the current token,
            // so check if the enclosing contexts know what to do. If so, we assume that
            // the list has completed parsing, and return to the enclosing context.
            //
            // Example:
            //     class A {
            //         function foo() {
            //            return;
            //      // } <- MissingToken (generated when we try to "eat" the closing brace)
            //
            //         public function bar() {
            //         }
            //     }
            //
            // In the case above, the Method ParseContext doesn't know how to handle "public", but
            // the Class ParseContext will know what to do with it. So we abort the Method ParseContext,
            // and return to the Class ParseContext. This enables us to generate a tree with a single
            // class that contains two method nodes, even though there was an error present in the first method.
            if ($this->isCurrentTokenValidInEnclosingContexts()) {
                break;
            }

            // None of the enclosing contexts know how to handle the token. Generate a
            // SkippedToken, and continue parsing in the current context.
            // Example:
            //     class A {
            //         function foo() {
            //            return;
            //            & // <- SkippedToken
            //         }
            //     }
            $token = new SkippedToken($this->getCurrentToken());
            $nodeArray[] = $token;
            $this->advanceToken();
        }

        $this->currentParseContext = $savedParseContext;

        return $nodeArray;
    }
private function parseList ( $ parentNode , int $ listParseContext ) { $ savedParseContext = $ this -> currentParseContext ; $ this -> currentParseContext |= 1 << $ listParseContext ; $ parseListElementFn = $ this -> getParseListElementFn ( $ listParseContext ) ; $ nodeArray = array ( ) ; while ( ! $ this -> isListTerminator ( $ listParseContext ) ) { if ( $ this -> isValidListElement ( $ listParseContext , $ this -> getCurrentToken ( ) ) ) { $ element = $ parseListElementFn ( $ parentNode ) ; if ( $ element instanceof Node ) { $ element -> parent = $ parentNode ; if ( $ element instanceof InlineHtml && $ element -> echoStatement && $ listParseContext === ParseContext :: SourceElements ) { $ nodeArray [ ] = $ element -> echoStatement ; $ element -> echoStatement -> parent = $ parentNode ; $ element -> echoStatement = null ; } } $ nodeArray [ ] = $ element ; continue ; } // Error handling logic: // The current parse context does not know how to handle the current token, // so check if the enclosing contexts know what to do. If so, we assume that // the list has completed parsing, and return to the enclosing context. // // Example: //     class A { //         function foo() { //            return; //      // } <- MissingToken (generated when we try to "eat" the closing brace) // //         public function bar() { //         } //     } // // In the case above, the Method ParseContext doesn't know how to handle "public", but // the Class ParseContext will know what to do with it. So we abort the Method ParseContext, // and return to the Class ParseContext. This enables us to generate a tree with a single // class that contains two method nodes, even though there was an error present in the first method. if ( $ this -> isCurrentTokenValidInEnclosingContexts ( ) ) { break ; } // None of the enclosing contexts know how to handle the token. Generate a // SkippedToken, and continue parsing in the current context. // Example: //     class A { //         function foo() { //            return; //            & // <- SkippedToken //         } //     } $ token = new SkippedToken ( $ this -> getCurrentToken ( ) ) ; $ nodeArray [ ] = $ token ; $ this -> advanceToken ( ) ; } $ this -> currentParseContext = $ savedParseContext ; return $ nodeArray ; }
Parse a list of elements for a given ParseContext until a list terminator associated
with that ParseContext is reached. Additionally abort parsing when an element is reached
that is invalid in the current context, but valid in an enclosing context. If an element
is invalid in both current and enclosing contexts, generate a SkippedToken, and continue.
@param Node $parentNode
@param int $listParseContext
@return array
Parse a list of elements for a given ParseContext until a list terminator associated with that ParseContext is reached . Additionally abort parsing when an element is reached that is invalid in the current context but valid in an enclosing context . If an element is invalid in both current and enclosing contexts generate a SkippedToken and continue .