parse() 공개 정적인 메소드

public static parse ( Parser $parser, TokensList $list, array $options = [] ) : AlterOperation
$parser SqlParser\Parser The parser that serves as context.
$list SqlParser\TokensList The list of tokens that are being parsed.
$options array Parameters for parsing.
리턴 AlterOperation
예제 #1
0
 /**
  * @param Parser     $parser The instance that requests parsing.
  * @param TokensList $list   The list of tokens to be parsed.
  *
  * @return void
  */
 public function parse(Parser $parser, TokensList $list)
 {
     ++$list->idx;
     // Skipping `ALTER`.
     $this->options = OptionsArray::parse($parser, $list, static::$OPTIONS);
     // Skipping `TABLE`.
     $list->getNextOfTypeAndValue(Token::TYPE_KEYWORD, 'TABLE');
     // Parsing affected table.
     $this->table = Expression::parse($parser, $list, array('noAlias' => true, 'noBrackets' => true));
     ++$list->idx;
     // Skipping field.
     /**
      * The state of the parser.
      *
      * Below are the states of the parser.
      *
      *      0 -----------------[ alter operation ]-----------------> 1
      *
      *      1 -------------------------[ , ]-----------------------> 0
      *
      * @var int $state
      */
     $state = 0;
     for (; $list->idx < $list->count; ++$list->idx) {
         /**
          * Token parsed at this moment.
          *
          * @var Token $token
          */
         $token = $list->tokens[$list->idx];
         // End of statement.
         if ($token->type === Token::TYPE_DELIMITER) {
             break;
         }
         // Skipping whitespaces and comments.
         if ($token->type === Token::TYPE_WHITESPACE || $token->type === Token::TYPE_COMMENT) {
             continue;
         }
         if ($state === 0) {
             $this->altered[] = AlterOperation::parse($parser, $list);
             $state = 1;
         } elseif ($state === 1) {
             if ($token->type === Token::TYPE_OPERATOR && $token->value === ',') {
                 $state = 0;
             }
         }
     }
 }
예제 #2
0
 /**
  * @param Parser     $parser The instance that requests parsing.
  * @param TokensList $list   The list of tokens to be parsed.
  *
  * @return void
  */
 public function parse(Parser $parser, TokensList $list)
 {
     ++$list->idx;
     // Skipping `ALTER`.
     $this->options = OptionsArray::parse($parser, $list, static::$OPTIONS);
     ++$list->idx;
     // Parsing affected table.
     $this->table = Expression::parse($parser, $list, array('parseField' => 'table', 'breakOnAlias' => true));
     ++$list->idx;
     // Skipping field.
     /**
      * The state of the parser.
      *
      * Below are the states of the parser.
      *
      *      0 -----------------[ alter operation ]-----------------> 1
      *
      *      1 -------------------------[ , ]-----------------------> 0
      *
      * @var int $state
      */
     $state = 0;
     for (; $list->idx < $list->count; ++$list->idx) {
         /**
          * Token parsed at this moment.
          *
          * @var Token $token
          */
         $token = $list->tokens[$list->idx];
         // End of statement.
         if ($token->type === Token::TYPE_DELIMITER) {
             break;
         }
         // Skipping whitespaces and comments.
         if ($token->type === Token::TYPE_WHITESPACE || $token->type === Token::TYPE_COMMENT) {
             continue;
         }
         if ($state === 0) {
             $options = array();
             if ($this->options->has('DATABASE')) {
                 $options = AlterOperation::$DB_OPTIONS;
             } elseif ($this->options->has('TABLE')) {
                 $options = AlterOperation::$TABLE_OPTIONS;
             } elseif ($this->options->has('VIEW')) {
                 $options = AlterOperation::$VIEW_OPTIONS;
             }
             $this->altered[] = AlterOperation::parse($parser, $list, $options);
             $state = 1;
         } elseif ($state === 1) {
             if ($token->type === Token::TYPE_OPERATOR && $token->value === ',') {
                 $state = 0;
             }
         }
     }
 }