Esempio n. 1
0
 /**
  * @override
  */
 protected function next_token()
 {
     do {
         $t = parent::next_token();
     } while (is_array($t) && ($t[0] === T_WHITESPACE || $t[0] === T_COMMENT || $t[0] === T_DOC_COMMENT));
     return $t;
 }
Esempio n. 2
0
 /**
  * @override
  */
 protected function next_token()
 {
     $s = $this->t;
     $this->newline = false;
     do {
         $tok = parent::next_token();
         if (!$tok) {
             parent::fail('Failed to get next token');
         }
     } while ($tok[0] === J_LINE_TERMINATOR && ($this->newline = true));
     if ($this->newline) {
         // Handle [no LineTerminator here] rules:
         // When, as the program is parsed from left to right, a token is encountered that is allowed by some
         // production of the grammar, but the production is a restricted production and the token would be the
         // first token for a terminal or nonterminal immediately following the annotation "[no LineTerminator here]"
         // within the restricted production (and therefore such a token is called a restricted token), and
         // the restricted token is separated from the previous token by at least one LineTerminator, then a
         // semicolon is automatically inserted before the restricted token.
         switch ($s) {
             case J_CONTINUE:
             case J_BREAK:
             case J_RETURN:
                 $this->insert_semicolon();
                 return $this->tok;
             case J_THROW:
                 // "throw ;" is invalid
                 return parent::fail('No line terminator after %s', $this->token_name($s));
         }
         // Ensure that Postfix operators are not grouped with preceeding symbol;
         // They must instead end up as a Unary expression if there was a line break
         if ($s !== ';' && ($tok[0] === '++' || $tok[0] === '--')) {
             $this->insert_semicolon();
             return $this->tok;
         }
     }
     return $tok;
 }