Skip to content

Added Postgresql array operators. #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/SqlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class SqlFormatter
// Punctuation that can be used as a boundary between other tokens
protected static $boundaries = array(',', ';',':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#');

// Postgresql array-operators
protected static $pgsql_arrayoperators = array("<@", "@>");

// For HTML syntax highlighting
// Styles applied to different token types
public static $quote_attributes = 'style="color: blue;"';
Expand Down Expand Up @@ -149,6 +152,7 @@ class SqlFormatter
protected static $regex_reserved_newline;
protected static $regex_reserved_toplevel;
protected static $regex_function;
protected static $regex_pgsql_arrays;

// Cache variables
// Only tokens shorter than this size will be cached. Somewhere between 10 and 20 seems to work well for most cases.
Expand Down Expand Up @@ -189,6 +193,8 @@ protected static function init()
self::$regex_reserved_toplevel = str_replace(' ','\\s+','('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$reserved_toplevel)).')');
self::$regex_reserved_newline = str_replace(' ','\\s+','('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$reserved_newline)).')');

self::$regex_pgsql_arrays = '('.implode('|', array_map(array(__CLASS__, 'quote_regex'), self::$pgsql_arrayoperators)).')';

self::$regex_function = '('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$functions)).')';

self::$init = true;
Expand Down Expand Up @@ -274,6 +280,14 @@ protected static function getNextToken($string, $previous = null)
);
}

// Postgresql specials, we don't want to touch them
if (preg_match('/^('.self::$regex_pgsql_arrays.')/', $string, $matches)) {
return array(
self::TOKEN_VALUE => $matches[1],
self::TOKEN_TYPE => self::TOKEN_TYPE_BOUNDARY
);
}

// Boundary Character (punctuation and symbols)
if (preg_match('/^('.self::$regex_boundaries.')/',$string,$matches)) {
return array(
Expand Down