Example #1
0
 /**
  * @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 = $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 = FieldFragment::parse($parser, $list);
             $state = 1;
         } elseif ($state === 1) {
             if ($token->type === Token::TYPE_KEYWORD && ($token->value === 'ASC' || $token->value === 'DESC')) {
                 $expr->type = $token->value;
             } else {
                 if ($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;
 }
Example #2
0
 /**
  * Extracts the name of affected column.
  *
  * @param Parser     $parser The instance that requests parsing.
  * @param TokensList $list   The list of tokens to be parsed.
  * @param Token      $token  The token that is being parsed.
  *
  * @return void
  */
 public function after(Parser $parser, TokensList $list, Token $token)
 {
     // Parsing operation.
     ++$list->idx;
     $this->options->merge(OptionsFragment::parse($parser, $list, static::$OPTIONS));
     // Parsing affected field.
     ++$list->idx;
     $this->altered = FieldFragment::parse($parser, $list);
     //
     parent::after($parser, $list, $token);
 }
Example #3
0
 /**
  * @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 = new JoinKeyword();
     /**
      * The state of the parser.
      *
      * Below are the states of the parser.
      *
      *      0 -----------------------[ expr ]----------------------> 1
      *
      *      1 ------------------------[ ON ]-----------------------> 2
      *
      *      2 --------------------[ conditions ]-------------------> -1
      *
      * @var int
      */
     $state = 0;
     for (; $list->idx < $list->count; ++$list->idx) {
         /**
          * Token parsed at this moment.
          * @var 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->expr = FieldFragment::parse($parser, $list, array('skipColumn' => true));
             $state = 1;
         } elseif ($state === 1) {
             if ($token->type === Token::TYPE_KEYWORD && $token->value === 'ON') {
                 $state = 2;
             }
         } elseif ($state === 2) {
             $ret->on = WhereKeyword::parse($parser, $list);
             ++$list->idx;
             break;
         }
     }
     --$list->idx;
     return $ret;
 }
Example #4
0
 /**
  * @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 FieldFragment[]
  */
 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 = $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 = FieldFragment::parse($parser, $list);
             if ($expr === null) {
                 break;
             }
         }
     }
     // Last iteration was not processed.
     if ($expr !== null) {
         $ret[] = $expr;
     }
     --$list->idx;
     return $ret;
 }