From 0c0d10300ae8f4dc73cd3bd6b5bd75aa7262becd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?fuula-set=C3=A4?= Date: Thu, 3 Feb 2022 09:20:55 +0200 Subject: [PATCH] Added Postgresql array operators. --- lib/SqlFormatter.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/SqlFormatter.php b/lib/SqlFormatter.php index 49e1d2f..3a73aa1 100644 --- a/lib/SqlFormatter.php +++ b/lib/SqlFormatter.php @@ -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;"'; @@ -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. @@ -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; @@ -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(