From f0567649ff6538f176571ba02d30a3d47de92a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Jure=C4=8Dko?= Date: Fri, 11 Dec 2020 14:45:36 +0100 Subject: [PATCH] Added method setBoundaries --- lib/SqlFormatter.php | 9 ++++++++- tests/SqlFormatterTest.php | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/SqlFormatter.php b/lib/SqlFormatter.php index 4d5774f..1dab84d 100644 --- a/lib/SqlFormatter.php +++ b/lib/SqlFormatter.php @@ -102,7 +102,8 @@ class SqlFormatter ); // Punctuation that can be used as a boundary between other tokens - protected static $boundaries = array(',', ';',':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#'); + const DEFAULT_BOUNDARIES = array(',', ';',':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#'); + protected static $boundaries = self::DEFAULT_BOUNDARIES; // For HTML syntax highlighting // Styles applied to different token types @@ -178,6 +179,12 @@ public static function getCacheStats() ); } + public static function setBoundaries(array $boundaries) + { + self::$boundaries = $boundaries; + self::$regex_boundaries = '('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$boundaries)).')'; + } + /** * Stuff that only needs to be done once. Builds regular expressions and sorts the reserved words. */ diff --git a/tests/SqlFormatterTest.php b/tests/SqlFormatterTest.php index 3697a94..b934885 100644 --- a/tests/SqlFormatterTest.php +++ b/tests/SqlFormatterTest.php @@ -114,6 +114,7 @@ function testCacheStats() { public function testSynapseTempTables() { // In Azure Synapse is # char reserved for temp tables, not for comments + SqlFormatter::setBoundaries(array_diff(SqlFormatter::DEFAULT_BOUNDARIES, ['#'])); SqlFormatter::$comment_tokens = [ ['--'], ]; @@ -122,7 +123,7 @@ public function testSynapseTempTables() { $sqlWithComment = "-- This is comment\n" . $sql; $expected = <<