Beispiel #1
0
 public function __construct(Dialect $aDialect = null)
 {
     $this->aDialect = $aDialect ?: Dialect::singleton();
     // 运算符
     foreach ($this->aDialect->operators() as $sOperator) {
         $this->arrOperators[strlen($sOperator)][] = $sOperator;
     }
     krsort($this->arrOperators);
     // comment
     foreach ($this->aDialect->comments() as $sBegin => $sEnd) {
         $this->arrComments[strlen($sBegin)][$sBegin] = $sEnd;
     }
     krsort($this->arrComments);
 }
Beispiel #2
0
 /**
  * @return AbstractParser
  */
 public function create($bShare = true, Dialect $aDialect = null, $sAction = 'statement')
 {
     if ($bShare and isset($this->arrShareParsers[$sAction])) {
         return $this->arrShareParsers[$sAction];
     }
     if (!$aDialect) {
         $aDialect = Dialect::singleton();
     }
     switch ($sAction) {
         case 'statement':
             $aParser = self::createParserInstace('AbstractParser', $aDialect)->addChildState($this->create($bShare, $aDialect, 'insert'))->addChildState($this->create($bShare, $aDialect, 'replace'))->addChildState($this->create($bShare, $aDialect, 'delete'))->addChildState($this->create($bShare, $aDialect, 'update'))->addChildState($this->create($bShare, $aDialect, 'select'))->addChildState($this->create($bShare, $aDialect, 'create'))->addChildState($this->create($bShare, $aDialect, 'drop'))->addChildState($this->create($bShare, $aDialect, 'from'))->addChildState($this->create($bShare, $aDialect, 'where'))->addChildState($this->create($bShare, $aDialect, 'group'))->addChildState($this->create($bShare, $aDialect, 'order'))->addChildState($this->create($bShare, $aDialect, 'limit'))->addChildState($this->create($bShare, $aDialect, 'set'))->addChildState($this->create($bShare, $aDialect, 'values'))->addChildState($this->create($bShare, $aDialect, 'table-keyword'));
             break;
         case 'select':
             $aParser = self::createParserInstace('ClauseParser', $aDialect, 'select')->addChildState($this->create($bShare, $aDialect, 'function'))->addChildState($this->create($bShare, $aDialect, 'column'));
             break;
         case 'replace':
         case 'insert':
             $aParser = self::createParserInstace('ClauseParser', $aDialect, 'insert')->addChildState($this->create($bShare, $aDialect, 'into'))->addChildState($this->create($bShare, $aDialect, 'column'))->addChildState($this->create($bShare, $aDialect, 'values'));
             break;
         case 'update':
             $aParser = self::createParserInstace('ClauseParser', $aDialect, 'update');
             break;
         case 'delete':
             $aParser = self::createParserInstace('ClauseParser', $aDialect, 'delete')->addChildState($this->create($bShare, $aDialect, 'from'));
             break;
         case 'into':
             $aParser = self::createParserInstace('IntoParser', $aDialect)->addChildState($this->create($bShare, $aDialect, 'table'));
             break;
         case 'from':
             $aParser = self::createParserInstace('ClauseParser', $aDialect, 'from')->addChildState($this->create($bShare, $aDialect, 'subquery'))->addChildState($this->create($bShare, $aDialect, 'table'))->addChildState($this->create($bShare, $aDialect, 'join'));
             break;
         case 'join':
             $aParser = self::createParserInstace('TableJoinParser', $aDialect)->addChildState($this->create($bShare, $aDialect, 'table'))->addChildState($this->create($bShare, $aDialect, 'on'))->addChildState($this->create($bShare, $aDialect, 'using'));
             break;
         case 'using':
             $aParser = self::createParserInstace('ClauseParser', $aDialect, 'using')->addChildState($this->create($bShare, $aDialect, 'column'));
             break;
         case 'on':
         case 'where':
             $aParser = self::createParserInstace('ClauseParser', $aDialect, $sAction)->addChildState($this->create($bShare, $aDialect, 'function'))->addChildState($this->create($bShare, $aDialect, 'column'));
             break;
         case 'group':
             $aParser = self::createParserInstace('ClauseParser', $aDialect, 'group')->addChildState($this->create($bShare, $aDialect, 'column'));
             break;
         case 'order':
             $aParser = self::createParserInstace('ClauseParser', $aDialect, 'order')->addChildState($this->create($bShare, $aDialect, 'column'));
             break;
         case 'limit':
             $aParser = self::createParserInstace('ClauseParser', $aDialect, 'limit');
             break;
         case 'set':
             $aParser = self::createParserInstace('SetParser', $aDialect)->addChildState($this->create($bShare, $aDialect, 'function'))->addChildState($this->create($bShare, $aDialect, 'column'));
             break;
         case 'values':
             $aParser = self::createParserInstace('ValuesParser', $aDialect)->addChildState($this->create($bShare, $aDialect, 'function'))->addChildState($this->create($bShare, $aDialect, 'column'))->addChildState($this->create($bShare, $aDialect, 'subquery'));
             break;
         case 'column':
             $aParser = self::createParserInstace('ColumnParser', $aDialect);
             break;
         case 'table':
             $aParser = self::createParserInstace('TableParser', $aDialect);
             break;
         case 'table-keyword':
             $aParser = self::createParserInstace('TableKeywordParser', $aDialect);
             break;
         case 'subquery':
             $aParser = self::createParserInstace('SubQueryParser', $aDialect);
             break;
         case 'function':
             $aParser = self::createParserInstace('FunctionParser', $aDialect);
             break;
         case 'create':
             $aParser = self::createParserInstace('ClauseParser', $aDialect, 'create')->addChildState($this->create($bShare, $aDialect, 'table-keyword'));
             break;
         case 'drop':
             $aParser = self::createParserInstace('ClauseParser', $aDialect, 'drop')->addChildState($this->create($bShare, $aDialect, 'table-keyword'));
             break;
     }
     if ($bShare) {
         $this->arrShareParsers[$sAction] = $aParser;
     }
     return $aParser;
 }