当前位置: 首页>>代码示例>>PHP>>正文


PHP Expression::parse方法代码示例

本文整理汇总了PHP中SqlParser\Components\Expression::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Expression::parse方法的具体用法?PHP Expression::parse怎么用?PHP Expression::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SqlParser\Components\Expression的用法示例。


在下文中一共展示了Expression::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parse

 /**
  * @param Parser     $parser  The parser that serves as context.
  * @param TokensList $list    The list of tokens that are being parsed.
  * @param array      $options Parameters for parsing.
  *
  * @return Expression[]
  */
 public static function parse(Parser $parser, TokensList $list, array $options = array())
 {
     $ret = array();
     /**
      * The state of the parser.
      *
      * Below are the states of the parser.
      *
      *      0 ----------------------[ array ]---------------------> 1
      *
      *      1 ------------------------[ , ]------------------------> 0
      *      1 -----------------------[ else ]----------------------> (END)
      *
      * @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 ($token->type === Token::TYPE_KEYWORD && $token->flags & Token::FLAG_KEYWORD_RESERVED && ~$token->flags & Token::FLAG_KEYWORD_FUNCTION && $token->value !== 'DUAL' && $token->value !== 'NULL' && $token->value !== 'CASE') {
             // No keyword is expected.
             break;
         }
         if ($state === 0) {
             if ($token->type === Token::TYPE_KEYWORD && $token->value === 'CASE') {
                 $expr = CaseExpression::parse($parser, $list, $options);
             } else {
                 $expr = Expression::parse($parser, $list, $options);
             }
             if ($expr === null) {
                 break;
             }
             $ret[] = $expr;
             $state = 1;
         } elseif ($state === 1) {
             if ($token->value === ',') {
                 $state = 0;
             } else {
                 break;
             }
         }
     }
     if ($state === 0) {
         $parser->error(__('An expression was expected.'), $list->tokens[$list->idx]);
     }
     --$list->idx;
     return $ret;
 }
开发者ID:phpmyadmin,项目名称:sql-parser,代码行数:67,代码来源:ExpressionArray.php

示例2: testParseErr

 /**
  * @dataProvider testParseErrProvider
  */
 public function testParseErr($expr, $error)
 {
     $parser = new Parser();
     Expression::parse($parser, $this->getTokensList($expr));
     $errors = $this->getErrorsAsArray($parser);
     $this->assertEquals($errors[0][0], $error);
 }
开发者ID:elrossco22,项目名称:sql-parser,代码行数:10,代码来源:ExpressionTest.php

示例3: parse

 /**
  * @param Parser     $parser  The parser that serves as context.
  * @param TokensList $list    The list of tokens that are being parsed.
  * @param array      $options Parameters for parsing.
  *
  * @return OrderKeyword[]
  */
 public static function parse(Parser $parser, TokensList $list, array $options = array())
 {
     $ret = array();
     $expr = new OrderKeyword();
     /**
      * The state of the parser.
      *
      * Below are the states of the parser.
      *
      *      0 ----------------------[ field ]----------------------> 1
      *
      *      1 ------------------------[ , ]------------------------> 0
      *      1 -------------------[ ASC / DESC ]--------------------> 1
      *
      * @var int
      */
     $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) {
             $expr->field = Expression::parse($parser, $list);
             $state = 1;
         } elseif ($state === 1) {
             if ($token->type === Token::TYPE_KEYWORD && ($token->value === 'ASC' || $token->value === 'DESC')) {
                 $expr->type = $token->value;
             } elseif ($token->type === Token::TYPE_OPERATOR && $token->value === ',') {
                 if (!empty($expr->field)) {
                     $ret[] = $expr;
                 }
                 $expr = new OrderKeyword();
                 $state = 0;
             } else {
                 break;
             }
         }
     }
     // Last iteration was not processed.
     if (!empty($expr->field)) {
         $ret[] = $expr;
     }
     --$list->idx;
     return $ret;
 }
开发者ID:BrunoChauvet,项目名称:phpmyadmin,代码行数:62,代码来源:OrderKeyword.php

示例4: parse

 /**
  * @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;
             }
         }
     }
 }
开发者ID:pboutin44,项目名称:maintest,代码行数:61,代码来源:AlterStatement.php

示例5: parse

 /**
  * @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;
         } else {
             if ($state === 1) {
                 if ($token->type === Token::TYPE_OPERATOR && $token->value === ',') {
                     $state = 0;
                 }
             }
         }
     }
 }
开发者ID:altesien,项目名称:FinalProject,代码行数:56,代码来源:AlterStatement.php

示例6: parse

 /**
  * @param Parser     $parser  The parser that serves as context.
  * @param TokensList $list    The list of tokens that are being parsed.
  * @param array      $options Parameters for parsing.
  *
  * @return Expression[]
  */
 public static function parse(Parser $parser, TokensList $list, array $options = array())
 {
     $ret = array();
     $expr = null;
     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 ($token->type === Token::TYPE_KEYWORD && $token->flags & Token::FLAG_KEYWORD_RESERVED) {
             // No keyword is expected.
             break;
         }
         if ($token->type === Token::TYPE_OPERATOR && $token->value === ',') {
             $ret[] = $expr;
         } else {
             $expr = Expression::parse($parser, $list, $options);
             if ($expr === null) {
                 break;
             }
         }
     }
     // Last iteration was not processed.
     if ($expr !== null) {
         $ret[] = $expr;
     }
     --$list->idx;
     return $ret;
 }
开发者ID:BrunoChauvet,项目名称:phpmyadmin,代码行数:45,代码来源:ExpressionArray.php

示例7: parse

 /**
  * @param Parser     $parser  The parser that serves as context.
  * @param TokensList $list    The list of tokens that are being parsed.
  * @param array      $options Parameters for parsing.
  *
  * @return PartitionDefinition
  */
 public static function parse(Parser $parser, TokensList $list, array $options = array())
 {
     $ret = new PartitionDefinition();
     /**
      * The state of the parser.
      *
      * Below are the states of the parser.
      *
      *      0 -------------[ PARTITION | SUBPARTITION ]------------> 1
      *
      *      1 -----------------------[ name ]----------------------> 2
      *
      *      2 ----------------------[ VALUES ]---------------------> 3
      *
      *      3 ---------------------[ LESS THAN ]-------------------> 4
      *      3 ------------------------[ IN ]-----------------------> 4
      *
      *      4 -----------------------[ expr ]----------------------> 5
      *
      *      5 ----------------------[ options ]--------------------> 6
      *
      *      6 ------------------[ subpartitions ]------------------> (END)
      *
      * @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) {
             $ret->isSubpartition = $token->type === Token::TYPE_KEYWORD && $token->value === 'SUBPARTITION';
             $state = 1;
         } elseif ($state === 1) {
             $ret->name = $token->value;
             $state = $ret->isSubpartition ? 5 : 2;
         } elseif ($state === 2) {
             $state = 3;
         } elseif ($state === 3) {
             $ret->type = $token->value;
             $state = 4;
         } elseif ($state === 4) {
             if ($token->value === 'MAXVALUE') {
                 $ret->expr = $token->value;
             } else {
                 $ret->expr = Expression::parse($parser, $list, array('bracketsDelimited' => true, 'noAlias' => true));
             }
             $state = 5;
         } elseif ($state === 5) {
             $ret->options = OptionsArray::parse($parser, $list, static::$OPTIONS);
             $state = 6;
         } elseif ($state === 6) {
             if ($token->type === Token::TYPE_OPERATOR && $token->value === '(') {
                 $ret->subpartitions = ArrayObj::parse($parser, $list, array('type' => 'SqlParser\\Components\\PartitionDefinition'));
                 ++$list->idx;
             }
             break;
         }
     }
     --$list->idx;
     return $ret;
 }
开发者ID:WSDC-NITWarangal,项目名称:phpmyadmin,代码行数:80,代码来源:PartitionDefinition.php

示例8: parse

 /**
  * @param Parser     $parser  The parser that serves as context.
  * @param TokensList $list    The list of tokens that are being parsed.
  * @param array      $options Parameters for parsing.
  *
  * @return RenameOperation[]
  */
 public static function parse(Parser $parser, TokensList $list, array $options = array())
 {
     $ret = array();
     $expr = new RenameOperation();
     /**
      * The state of the parser.
      *
      * Below are the states of the parser.
      *
      *      0 ---------------------[ old name ]--------------------> 1
      *
      *      1 ------------------------[ TO ]-----------------------> 2
      *
      *      2 ---------------------[ old name ]--------------------> 3
      *
      *      3 ------------------------[ , ]------------------------> 0
      *      3 -----------------------[ else ]----------------------> (END)
      *
      * @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) {
             $expr->old = Expression::parse($parser, $list, array('noAlias' => true, 'noBrackets' => true, 'skipColumn' => true));
             if (empty($expr->old)) {
                 $parser->error(__('The old name of the table was expected.'), $token);
             }
             $state = 1;
         } elseif ($state === 1) {
             if ($token->type === Token::TYPE_KEYWORD && $token->value === 'TO') {
                 $state = 2;
             } else {
                 $parser->error(__('Keyword "TO" was expected.'), $token);
                 break;
             }
         } elseif ($state === 2) {
             $expr->new = Expression::parse($parser, $list, array('noBrackets' => true, 'skipColumn' => true, 'noAlias' => true));
             if (empty($expr->new)) {
                 $parser->error(__('The new name of the table was expected.'), $token);
             }
             $state = 3;
         } elseif ($state === 3) {
             if ($token->type === Token::TYPE_OPERATOR && $token->value === ',') {
                 $ret[] = $expr;
                 $expr = new RenameOperation();
                 $state = 0;
             } else {
                 break;
             }
         }
     }
     if ($state !== 3) {
         $parser->error(__('A rename operation was expected.'), $list->tokens[$list->idx - 1]);
     }
     // Last iteration was not saved.
     if (!empty($expr->old)) {
         $ret[] = $expr;
     }
     --$list->idx;
     return $ret;
 }
开发者ID:altesien,项目名称:FinalProject,代码行数:82,代码来源:RenameOperation.php

示例9: parse

 /**
  * @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 `CREATE`.
     // Parsing options.
     $this->options = OptionsArray::parse($parser, $list, static::$OPTIONS);
     ++$list->idx;
     // Skipping last option.
     // Parsing the field name.
     $this->name = Expression::parse($parser, $list, array('noAlias' => true, 'noBrackets' => true, 'skipColumn' => true));
     ++$list->idx;
     // Skipping field.
     if ($this->options->has('DATABASE')) {
         $this->entityOptions = OptionsArray::parse($parser, $list, static::$DB_OPTIONS);
     } elseif ($this->options->has('TABLE')) {
         $this->fields = FieldDefinition::parse($parser, $list);
         ++$list->idx;
         $this->entityOptions = OptionsArray::parse($parser, $list, static::$TABLE_OPTIONS);
     } elseif ($this->options->has('PROCEDURE') || $this->options->has('FUNCTION')) {
         $this->parameters = ParameterDefinition::parse($parser, $list);
         if ($this->options->has('FUNCTION')) {
             $token = $list->getNextOfType(Token::TYPE_KEYWORD);
             if ($token->value !== 'RETURNS') {
                 $parser->error('\'RETURNS\' keyword was expected.', $token);
             } else {
                 ++$list->idx;
                 $this->return = DataType::parse($parser, $list);
             }
         }
         ++$list->idx;
         $this->entityOptions = OptionsArray::parse($parser, $list, static::$FUNC_OPTIONS);
         ++$list->idx;
         for (; $list->idx < $list->count; ++$list->idx) {
             $token = $list->tokens[$list->idx];
             $this->body[] = $token;
         }
     } else {
         if ($this->options->has('VIEW')) {
             $token = $list->getNext();
             // Skipping whitespaces and comments.
             // Parsing columns list.
             if ($token->type === Token::TYPE_OPERATOR && $token->value === '(') {
                 --$list->idx;
                 // getNext() also goes forward one field.
                 $this->fields = ArrayObj::parse($parser, $list);
                 ++$list->idx;
                 // Skipping last token from the array.
                 $list->getNext();
             }
             // Parsing the `AS` keyword.
             for (; $list->idx < $list->count; ++$list->idx) {
                 $token = $list->tokens[$list->idx];
                 if ($token->type === Token::TYPE_DELIMITER) {
                     break;
                 }
                 $this->body[] = $token;
             }
         } else {
             if ($this->options->has('TRIGGER')) {
                 // Parsing the time and the event.
                 $this->entityOptions = OptionsArray::parse($parser, $list, static::$TRIGGER_OPTIONS);
                 ++$list->idx;
                 $list->getNextOfTypeAndValue(Token::TYPE_KEYWORD, 'ON');
                 ++$list->idx;
                 // Skipping `ON`.
                 // Parsing the name of the table.
                 $this->table = Expression::parse($parser, $list, array('noAlias' => true, 'noBrackets' => true, 'skipColumn' => true));
                 ++$list->idx;
                 $list->getNextOfTypeAndValue(Token::TYPE_KEYWORD, 'FOR EACH ROW');
                 ++$list->idx;
                 // Skipping `FOR EACH ROW`.
                 for (; $list->idx < $list->count; ++$list->idx) {
                     $token = $list->tokens[$list->idx];
                     $this->body[] = $token;
                 }
             }
         }
     }
 }
开发者ID:BrunoChauvet,项目名称:phpmyadmin,代码行数:85,代码来源:CreateStatement.php

示例10: parse

 /**
  * @param Parser     $parser  The parser that serves as context.
  * @param TokensList $list    The list of tokens that are being parsed.
  * @param array      $options Parameters for parsing.
  *
  * @return OptionsArray
  */
 public static function parse(Parser $parser, TokensList $list, array $options = array())
 {
     $ret = new OptionsArray();
     /**
      * The ID that will be assigned to duplicate options.
      *
      * @var int $lastAssignedId
      */
     $lastAssignedId = count($options) + 1;
     /**
      * The option that was processed last time.
      *
      * @var array $lastOption
      */
     $lastOption = null;
     /**
      * The index of the option that was processed last time.
      *
      * @var int $lastOptionId
      */
     $lastOptionId = 0;
     /**
      * Counts brackets.
      *
      * @var int $brackets
      */
     $brackets = 0;
     /**
      * The state of the parser.
      *
      * Below are the states of the parser.
      *
      *      0 ---------------------[ option ]----------------------> 1
      *
      *      1 -------------------[ = (optional) ]------------------> 2
      *
      *      2 ----------------------[ value ]----------------------> 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 comments.
         if ($token->type === Token::TYPE_COMMENT) {
             continue;
         }
         // Skipping whitespace if not parsing value.
         if ($token->type === Token::TYPE_WHITESPACE && $brackets === 0) {
             continue;
         }
         if ($lastOption === null) {
             $upper = strtoupper($token->token);
             if (isset($options[$upper])) {
                 $lastOption = $options[$upper];
                 $lastOptionId = is_array($lastOption) ? $lastOption[0] : $lastOption;
                 $state = 0;
                 // Checking for option conflicts.
                 // For example, in `SELECT` statements the keywords `ALL`
                 // and `DISTINCT` conflict and if used together, they
                 // produce an invalid query.
                 //
                 // Usually, tokens can be identified in the array by the
                 // option ID, but if conflicts occur, a generated option ID
                 // is used.
                 //
                 // The first pseudo duplicate ID is the maximum value of the
                 // real options (e.g.  if there are 5 options, the first
                 // fake ID is 6).
                 if (isset($ret->options[$lastOptionId])) {
                     $parser->error(sprintf(__('This option conflicts with "%1$s".'), is_array($ret->options[$lastOptionId]) ? $ret->options[$lastOptionId]['name'] : $ret->options[$lastOptionId]), $token);
                     $lastOptionId = $lastAssignedId++;
                 }
             } else {
                 // There is no option to be processed.
                 break;
             }
         }
         if ($state === 0) {
             if (!is_array($lastOption)) {
                 // This is a just keyword option without any value.
                 // This is the beginning and the end of it.
                 $ret->options[$lastOptionId] = $token->value;
                 $lastOption = null;
//.........这里部分代码省略.........
开发者ID:phpmyadmin,项目名称:sql-parser,代码行数:101,代码来源:OptionsArray.php

示例11: parse

 /**
  * @param Parser     $parser  The parser that serves as context.
  * @param TokensList $list    The list of tokens that are being parsed.
  * @param array      $options Parameters for parsing.
  *
  * @return JoinKeyword[]
  */
 public static function parse(Parser $parser, TokensList $list, array $options = array())
 {
     $ret = array();
     $expr = new JoinKeyword();
     /**
      * The state of the parser.
      *
      * Below are the states of the parser.
      *
      *      0 -----------------------[ JOIN ]----------------------> 1
      *
      *      1 -----------------------[ expr ]----------------------> 2
      *
      *      2 ------------------------[ ON ]-----------------------> 3
      *      2 -----------------------[ USING ]---------------------> 4
      *
      *      3 --------------------[ conditions ]-------------------> 0
      *
      *      4 ----------------------[ columns ]--------------------> 0
      *
      * @var int $state
      */
     $state = 0;
     // By design, the parser will parse first token after the keyword.
     // In this case, the keyword must be analyzed too, in order to determine
     // the type of this join.
     if ($list->idx > 0) {
         --$list->idx;
     }
     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) {
             if ($token->type === Token::TYPE_KEYWORD && !empty(static::$JOINS[$token->value])) {
                 $expr->type = static::$JOINS[$token->value];
                 $state = 1;
             } else {
                 break;
             }
         } elseif ($state === 1) {
             $expr->expr = Expression::parse($parser, $list, array('field' => 'table'));
             $state = 2;
         } elseif ($state === 2) {
             if ($token->type === Token::TYPE_KEYWORD) {
                 if ($token->value === 'ON') {
                     $state = 3;
                 } elseif ($token->value === 'USING') {
                     $state = 4;
                 }
             }
         } elseif ($state === 3) {
             $expr->on = Condition::parse($parser, $list);
             $ret[] = $expr;
             $expr = new JoinKeyword();
             $state = 0;
         } elseif ($state === 4) {
             $expr->using = ArrayObj::parse($parser, $list);
             $ret[] = $expr;
             $expr = new JoinKeyword();
             $state = 0;
         }
     }
     if (!empty($expr->type)) {
         $ret[] = $expr;
     }
     --$list->idx;
     return $ret;
 }
开发者ID:elrossco22,项目名称:sql-parser,代码行数:87,代码来源:JoinKeyword.php

示例12: parse

 /**
  * @param Parser     $parser  The parser that serves as context.
  * @param TokensList $list    The list of tokens that are being parsed.
  * @param array      $options Parameters for parsing.
  *
  * @return AlterOperation
  */
 public static function parse(Parser $parser, TokensList $list, array $options = array())
 {
     $ret = new AlterOperation();
     /**
      * Counts brackets.
      *
      * @var int $brackets
      */
     $brackets = 0;
     /**
      * The state of the parser.
      *
      * Below are the states of the parser.
      *
      *      0 ---------------------[ options ]---------------------> 1
      *
      *      1 ----------------------[ field ]----------------------> 2
      *
      *      2 -------------------------[ , ]-----------------------> 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 comments.
         if ($token->type === Token::TYPE_COMMENT) {
             continue;
         }
         // Skipping whitespaces.
         if ($token->type === Token::TYPE_WHITESPACE) {
             if ($state === 2) {
                 // When parsing the unknown part, the whitespaces are
                 // included to not break anything.
                 $ret->unknown[] = $token;
             }
             continue;
         }
         if ($state === 0) {
             $ret->options = OptionsArray::parse($parser, $list, static::$OPTIONS);
             $state = 1;
         } elseif ($state === 1) {
             $ret->field = Expression::parse($parser, $list, array('noAlias' => true, 'noBrackets' => true));
             if ($ret->field === null) {
                 // No field was read. We go back one token so the next
                 // iteration will parse the same token, but in state 2.
                 --$list->idx;
             }
             $state = 2;
         } elseif ($state === 2) {
             if ($token->type === Token::TYPE_OPERATOR) {
                 if ($token->value === '(') {
                     ++$brackets;
                 } elseif ($token->value === ')') {
                     --$brackets;
                 } elseif ($token->value === ',' && $brackets === 0) {
                     break;
                 }
             }
             $ret->unknown[] = $token;
         }
     }
     if ($ret->options->isEmpty()) {
         $parser->error(__('Unrecognized alter operation.'), $list->tokens[$list->idx]);
     }
     --$list->idx;
     return $ret;
 }
开发者ID:pjiahao,项目名称:phpmyadmin,代码行数:84,代码来源:AlterOperation.php

示例13: parse

 /**
  * @param Parser     $parser  The parser that serves as context.
  * @param TokensList $list    The list of tokens that are being parsed.
  * @param array      $options Parameters for parsing.
  *
  * @return Reference
  */
 public static function parse(Parser $parser, TokensList $list, array $options = array())
 {
     $ret = new Reference();
     /**
      * The state of the parser.
      *
      * Below are the states of the parser.
      *
      *      0 ----------------------[ table ]---------------------> 1
      *
      *      1 ---------------------[ columns ]--------------------> 2
      *
      *      2 ---------------------[ options ]--------------------> (END)
      *
      * @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) {
             $ret->table = Expression::parse($parser, $list, array('parseField' => 'table', 'breakOnAlias' => true));
             $state = 1;
         } elseif ($state === 1) {
             $ret->columns = ArrayObj::parse($parser, $list)->values;
             $state = 2;
         } elseif ($state === 2) {
             $ret->options = OptionsArray::parse($parser, $list, static::$REFERENCES_OPTIONS);
             ++$list->idx;
             break;
         }
     }
     --$list->idx;
     return $ret;
 }
开发者ID:flash1452,项目名称:phpmyadmin,代码行数:54,代码来源:Reference.php

示例14: parse

 /**
  * @param Parser     $parser  The parser that serves as context.
  * @param TokensList $list    The list of tokens that are being parsed.
  * @param array      $options Parameters for parsing.
  *
  * @return RenameOperation
  */
 public static function parse(Parser $parser, TokensList $list, array $options = array())
 {
     $ret = array();
     $expr = new RenameOperation();
     /**
      * The state of the parser.
      *
      * Below are the states of the parser.
      *
      *      0 ---------------------[ old name ]--------------------> 1
      *
      *      1 ------------------------[ TO ]-----------------------> 2
      *
      *      2 ---------------------[ old name ]--------------------> 3
      *
      *      3 ------------------------[ , ]------------------------> 0
      *      3 -----------------------[ else ]----------------------> -1
      *
      * @var int
      */
     $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 ($token->type === Token::TYPE_KEYWORD && $token->flags & Token::FLAG_KEYWORD_RESERVED) {
             if ($state === 1 && $token->value === 'TO') {
                 $state = 2;
                 continue;
             }
             // No other keyword is expected.
             break;
         }
         if ($token->type === Token::TYPE_OPERATOR) {
             if ($state === 3 && $token->value === ',') {
                 $ret[] = $expr;
                 $expr = new RenameOperation();
                 $state = 0;
                 continue;
             }
             // No other operator is expected.
             break;
         }
         if ($state == 0) {
             $expr->old = Expression::parse($parser, $list, array('noAlias' => true, 'noBrackets' => true, 'skipColumn' => true));
             $state = 1;
         } elseif ($state == 2) {
             $expr->new = Expression::parse($parser, $list, array('noBrackets' => true, 'skipColumn' => true, 'noAlias' => true));
             $state = 3;
         }
     }
     // Last iteration was not saved.
     if (!empty($expr->old)) {
         $ret[] = $expr;
     }
     --$list->idx;
     return $ret;
 }
开发者ID:BrunoChauvet,项目名称:phpmyadmin,代码行数:75,代码来源:RenameOperation.php

示例15: parse

 /**
  * @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 `CREATE`.
     // Parsing options.
     $this->options = OptionsArray::parse($parser, $list, static::$OPTIONS);
     ++$list->idx;
     // Skipping last option.
     // Parsing the field name.
     $this->name = Expression::parse($parser, $list, array('noAlias' => true, 'noBrackets' => true, 'skipColumn' => true));
     if (!isset($this->name) || $this->name === '') {
         $parser->error(__('The name of the entity was expected.'), $list->tokens[$list->idx]);
     } else {
         ++$list->idx;
         // Skipping field.
     }
     if ($this->options->has('DATABASE')) {
         $this->entityOptions = OptionsArray::parse($parser, $list, static::$DB_OPTIONS);
     } elseif ($this->options->has('TABLE')) {
         $this->fields = CreateDefinition::parse($parser, $list);
         if (empty($this->fields)) {
             $parser->error(__('At least one column definition was expected.'), $list->tokens[$list->idx]);
         }
         ++$list->idx;
         $this->entityOptions = OptionsArray::parse($parser, $list, static::$TABLE_OPTIONS);
         /**
          * The field that is being filled (`partitionBy` or
          * `subpartitionBy`).
          *
          * @var string $field
          */
         $field = null;
         /**
          * The number of brackets. `false` means no bracket was found
          * previously. At least one bracket is required to validate the
          * expression.
          *
          * @var int|bool $brackets
          */
         $brackets = false;
         /*
          * Handles partitions.
          */
         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 comments.
             if ($token->type === Token::TYPE_COMMENT) {
                 continue;
             }
             if ($token->type === Token::TYPE_KEYWORD && $token->value === 'PARTITION BY') {
                 $field = 'partitionBy';
                 $brackets = false;
             } elseif ($token->type === Token::TYPE_KEYWORD && $token->value === 'SUBPARTITION BY') {
                 $field = 'subpartitionBy';
                 $brackets = false;
             } elseif ($token->type === Token::TYPE_KEYWORD && $token->value === 'PARTITIONS') {
                 $token = $list->getNextOfType(Token::TYPE_NUMBER);
                 --$list->idx;
                 // `getNextOfType` also advances one position.
                 $this->partitionsNum = $token->value;
             } elseif ($token->type === Token::TYPE_KEYWORD && $token->value === 'SUBPARTITIONS') {
                 $token = $list->getNextOfType(Token::TYPE_NUMBER);
                 --$list->idx;
                 // `getNextOfType` also advances one position.
                 $this->subpartitionsNum = $token->value;
             } elseif (!empty($field)) {
                 /*
                  * Handling the content of `PARTITION BY` and `SUBPARTITION BY`.
                  */
                 // Counting brackets.
                 if ($token->type === Token::TYPE_OPERATOR && $token->value === '(') {
                     // This is used instead of `++$brackets` because,
                     // initially, `$brackets` is `false` cannot be
                     // incremented.
                     $brackets = $brackets + 1;
                 } elseif ($token->type === Token::TYPE_OPERATOR && $token->value === ')') {
                     --$brackets;
                 }
                 // Building the expression used for partitioning.
                 $this->{$field} .= $token->type === Token::TYPE_WHITESPACE ? ' ' : $token->token;
                 // Last bracket was read, the expression ended.
                 // Comparing with `0` and not `false`, because `false` means
                 // that no bracket was found and at least one must is
                 // required.
                 if ($brackets === 0) {
//.........这里部分代码省略.........
开发者ID:FuhrerMalkovich,项目名称:Blogpost,代码行数:101,代码来源:CreateStatement.php


注:本文中的SqlParser\Components\Expression::parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。