diff --git a/ChangeLog b/ChangeLog index e25ea3133..67dc44ee7 100755 --- a/ChangeLog +++ b/ChangeLog @@ -14,7 +14,11 @@ $Source$ - Spacing around if statements - Added require statements for parser - Moved to global constants for size of keyword arrays + - Added CSS creation rules * libraries/sqlparser.data.php3: Merged + * config.inc.php3: + - Added SQL Parser variables + - Remove old SQL Parser variables 2002-07-24 Loïc Chapeaux * libraries/string.lib.php3: Function documentation diff --git a/config.inc.php3 b/config.inc.php3 index 3b6f48d50..7230d5197 100755 --- a/config.inc.php3 +++ b/config.inc.php3 @@ -283,14 +283,32 @@ $cfg['ModifyDeleteAtRight'] = FALSE; // show edit/delete links on right s $cfg['DefaultDisplay'] = 'horizontal'; // default display direction (horizontal|vertical) $cfg['RepeatCells'] = 100; // repeat header names every X cells? (0 = deactivate) -// Syntax coloring (Note: this feature will be implemented after 2.3.0) -$cfg['UseSyntaxColoring'] = TRUE; // use syntaxcoloring on output of SQL, might be a little slower -$cfg['colorFunctions'] = '#FF0000'; // Colors used for Syntaxcoloring of SQL Statements -$cfg['colorKeywords'] = '#990099'; -$cfg['colorStrings'] = '#008000'; -$cfg['colorColType'] = '#FF9900'; -$cfg['colorAdd'] = '#0000FF'; - +/** + * SQL Parser Settings + */ +$cfg['SQP']['enable'] = TRUE; // Totally turn off the SQL Parser (not recommended) +$cfg['SQP']['fmtType'] = 'html'; // Pretty-printing style to use on queries (html, none) +$cfg['SQP']['fmtInd'] = '1'; // Amount to indent each level (floats ok) +$cfg['SQP']['fmtIndUnit'] = 'em'; // Units for indenting each level (CSS Types - {em,px,pt}) +$cfg['SQP']['fmtColor'] = array( // Syntax colouring data + 'comment' => '#808000', + 'digit' => 'inherit', + 'digit_hex' => 'teal', + 'digit_integer' => 'teal', + 'digit_float' => 'aqua', + 'punct' => 'fuchsia', + 'alpha' => 'inherit', + 'alpha_columnType' => '#FF9900', + 'alpha_columnAttrib' => '#0000FF', + 'alpha_reservedWord' => '#990099', + 'alpha_functionName' => '#FF0000', + 'alpha_identifier' => 'black', + 'alpha_variable' => '#800000', + 'quote' => '#008000', + 'quote_double' => 'inherit', + 'quote_single' => 'inherit', + 'quote_backtick' => 'inherit' + ); /** * Available charsets for MySQL conversion. currently contains all which could @@ -404,63 +422,6 @@ if ($cfg['ShowFunctionFields']) { ); } // end if -// Keywords for syntax coloring -if ($cfg['UseSyntaxColoring']) { - $cfg['keywords'] = array( - 'SELECT', - 'INSERT', - 'LEFT', - 'INNER', - 'UPDATE', - 'REPLACE', - 'EXPLAIN', - 'FROM', - 'WHERE', - 'LIMIT', - 'INTO', - 'ALTER', - 'ADD', - 'DROP', - 'GROUP', - 'ORDER', - 'CHANGE', - 'CREATE', - 'DELETE', - 'VALUES' - ); -} // end if - -// Other reserved words for syntax coloring -if ($cfg['UseSyntaxColoring']) { - $cfg['additional'] = array( - 'TABLE', - 'DEFAULT', - 'NULL', - 'NOT', - 'INDEX', - 'PRIMARY', - 'KEY', - 'UNIQUE', - 'BINARY', - 'UNSIGNED', - 'ZEROFILL', - 'AUTO_INCREMENT', - 'AND', - 'OR', - 'DISTINCT', - 'DISTINCTROW', - 'BY', - 'ON', - 'JOIN', - 'BETWEEN', - 'IN', - 'IF', - 'ELSE', - 'SET' - ); -} - - /** * Unset magic_quotes_runtime - do not change! */ diff --git a/libraries/sqlparser.lib.php3 b/libraries/sqlparser.lib.php3 index c973b0f09..e188d3941 100644 --- a/libraries/sqlparser.lib.php3 +++ b/libraries/sqlparser.lib.php3 @@ -506,14 +506,15 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { function PMA_SQP_FormatHTML($arr) { - $str = ''; + $str = ''; $indent = 0; $bracketlevel = 0; $functionlevel = 0; $infunction = FALSE; $space_punct_listsep = ' '; $space_punct_listsep_functionName = ' '; - $space_alpha_reservedWord = '
'."\n"; + // $space_alpha_reservedWord = '
'."\n"; + $space_alpha_reservedWord = ' '; $keywordsWithBrackets = array( 'INDEX', 'INTO', @@ -522,16 +523,19 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { 'REFERENCES', 'UNIQUE' ); - $keywordsWithBrackets_size = count($keywordsWithBrackets); + //$keywordsWithBrackets_size = count($keywordsWithBrackets); + $keywordsWithBrackets_size = 6; + $keywordsForMath = array( + 'AND', + 'NOT', + 'NULL', + 'OR' + ); + $keywordsForMath_size = 4; + $arraysize = $arr['len']; $typearr = array(); if ($arraysize >= 0) { - /* array_push($typearr,NULL); - array_push($typearr,NULL); - array_push($typearr,NULL); - array_push($typearr,$arr[0]['type']); - array_push($typearr,$arr[1]['type']); */ - $typearr[0] = NULL; $typearr[1] = NULL; $typearr[2] = NULL; @@ -563,7 +567,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { switch($typearr[2]) { case 'white_newline': - $after = '
'; +// $after = '
'; $before = ''; break; case 'punct_bracket_open_round': @@ -576,10 +580,21 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { $after .= ' '; } else { $indent++; - $after .= '
'."\n"; + $after .= '
'; } break; - case 'punct_qualifier': + case 'alpha_identifier': + if(($typearr[1] == 'punct_qualifier') || ($typearr[3] == 'punct_qualifier')) { + $after = ''; + $before = ''; + } + if($typearr[3] == 'alpha_columnType') { + $after .= ' '; + } + break; + case 'punct_qualifier': + $before = ''; + $after = ''; break; case 'punct_listsep': if ($infunction == TRUE) { @@ -589,11 +604,21 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { } break; case 'punct_queryend': - if (($typearr[3] != 'white_newline') && ($typearr[3] != 'comment_mysql')&& ($typearr[3] != 'comment_ansi') ) { - $after .= '
'."\n"; + if ( ($typearr[3] != 'comment_mysql')&& ($typearr[3] != 'comment_ansi') ) { + $after .= '
'; + $after .= '
'; } + $space_punct_listsep = ' '; + $space_punct_listsep_functionName = ' '; + $space_alpha_reservedWord = ' '; break; - case 'comment': + case 'comment_mysql': + case 'comment_ansi': + $after .= '
'; + break; + case 'punct': + $after .= ' '; + $before .= ' '; break; case 'punct_bracket_close_round': $bracketlevel--; @@ -606,32 +631,48 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { } $infunction = ($functionlevel > 0) ? TRUE : FALSE; break; - + case 'alpha_columnType': + if ($typearr[3] == 'alpha_columnAttrib') { + $after .= ' '; + } + break; case 'alpha_reservedWord': - if ( ($typearr[1] != 'alpha_reservedWord') && ($typearr[1] != 'punct_level_plus') && ($typearr[1] != 'white_newline')) { + $upper = $arr[$i]['data']; + if ( ($typearr[1] != 'alpha_reservedWord') && ($typearr[1] != 'punct_level_plus') && (!PMA_STR_BinarySearchInArr($upper,$keywordsForMath,$keywordsForMath_size))) { $before .= $space_alpha_reservedWord; + } else { + $before .= ' '; } - switch(strtoupper($arr[$i]['data'])) { + switch($upper) { case 'CREATE': - $space_punct_listsep = '
'."\n"; + $space_punct_listsep = '
'; $space_alpha_reservedWord = ' '; break; + case 'EXPLAIN': + case 'DESCRIBE': + case 'SET': + case 'ALTER': + case 'DELETE': + case 'SHOW': + case 'DROP': case 'UPDATE': - $space_punct_listsep = '
'."\n"; + case 'TRUNCATE': + $space_punct_listsep = '
'; $space_alpha_reservedWord = ' '; break; case 'INSERT': - $space_punct_listsep = '
'."\n"; - $space_alpha_reservedWord = '
'."\n"; + case 'REPLACE': + $space_punct_listsep = '
'; + $space_alpha_reservedWord = '
'; break; case 'VALUES': $space_punct_listsep = ' '; - $space_alpha_reservedWord = '
'."\n"; + $space_alpha_reservedWord = '
'; break; case 'SELECT': $space_punct_listsep = ' '; - $space_alpha_reservedWord = '
'."\n"; + $space_alpha_reservedWord = '
'; break; default: break; @@ -639,17 +680,68 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { $after .= " "; break; - + case 'digit_integer': + case 'digit_float': + case 'digit_hex': + if($infunction && $typearr[3] == 'punct_bracket_close_round') { + $after .= ' '; + } + break; + case 'quote_double': + case 'quote_single': + $before .= ' '; + if($infunction && $typearr[3] == 'punct_bracket_close_round') { + $after .= ' '; + } + break; default: break; } - if ($typearr[3] != 'punct_qualifier') { +/* if ($typearr[3] != 'punct_qualifier') { $after .= ' '; - } + } */ + //$after .= "\n"; $str .= $before.PMA_SQP_FormatHTML_colorize($arr[$i]).$after; } + $str .= ''; return $str; } + function PMA_SQP_BuildCssRule($classname,$property,$value) + { + return '.'.$classname.' { '.$property.': '.$value.'; } '."\n"; + } + + function PMA_SQP_BuildCssData() + { + global $cfg; + $css_string = << $col) { + $css_string .= PMA_SQP_BuildCssRule('syntax_'.$key, 'color', $col); + } + for($i = 0; $i < 8; $i++) { + $css_string .= PMA_SQP_BuildCssRule('syntax_indent'.$i, 'margin-left', ($i * $cfg['SQP']['fmt']['indent']).$cfg['SQP']['fmt']['indentunits']); + } + return $css_string; + + } + } // $__PMA_SQP_LIB__