diff options
-rw-r--r-- | src/Context.php | 2 | ||||
-rw-r--r-- | src/Lexer.php | 2 | ||||
-rw-r--r-- | src/Utils/Formatter.php | 7 | ||||
-rw-r--r-- | tests/Lexer/TokenTest.php | 6 | ||||
-rw-r--r-- | tests/Utils/FormatterTest.php | 42 |
5 files changed, 57 insertions, 2 deletions
diff --git a/src/Context.php b/src/Context.php index 3f51dc7..c9ff19e 100644 --- a/src/Context.php +++ b/src/Context.php @@ -409,7 +409,7 @@ abstract class Context return Token::FLAG_SYMBOL_VARIABLE; } elseif ($str[0] === '`') { return Token::FLAG_SYMBOL_BACKTICK; - } elseif ($str[0] === ':') { + } elseif ($str[0] === ':' || $str[0] === '?') { return Token::FLAG_SYMBOL_PARAMETER; } diff --git a/src/Lexer.php b/src/Lexer.php index 53545af..7fc1a75 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -877,7 +877,7 @@ class Lexer extends Core $flags |= Token::FLAG_SYMBOL_SYSTEM; } } elseif ($flags & Token::FLAG_SYMBOL_PARAMETER) { - if ($this->last + 1 < $this->len) { + if ($token !== '?' && $this->last + 1 < $this->len) { ++$this->last; } } else { diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php index 94d908c..3b17a2b 100644 --- a/src/Utils/Formatter.php +++ b/src/Utils/Formatter.php @@ -227,6 +227,13 @@ class Formatter ], [ 'type' => Token::TYPE_SYMBOL, + 'flags' => Token::FLAG_SYMBOL_PARAMETER, + 'html' => 'class="sql-parameter"', + 'cli' => "\x1b[31m", + 'function' => '', + ], + [ + 'type' => Token::TYPE_SYMBOL, 'flags' => 0, 'html' => 'class="sql-variable"', 'cli' => "\x1b[36m", diff --git a/tests/Lexer/TokenTest.php b/tests/Lexer/TokenTest.php index 370824e..ba61e32 100644 --- a/tests/Lexer/TokenTest.php +++ b/tests/Lexer/TokenTest.php @@ -75,6 +75,12 @@ class TokenTest extends TestCase $tok = new Token('@`foo`', Token::TYPE_SYMBOL, Token::FLAG_SYMBOL_VARIABLE); $this->assertEquals($tok->value, 'foo'); + + $tok = new Token(':foo', Token::TYPE_SYMBOL, Token::FLAG_SYMBOL_PARAMETER); + $this->assertEquals($tok->value, 'foo'); + + $tok = new Token('?', Token::TYPE_SYMBOL, Token::FLAG_SYMBOL_PARAMETER); + $this->assertEquals($tok->value, '?'); } public function testInlineToken() diff --git a/tests/Utils/FormatterTest.php b/tests/Utils/FormatterTest.php index de9ed8b..08b7377 100644 --- a/tests/Utils/FormatterTest.php +++ b/tests/Utils/FormatterTest.php @@ -506,6 +506,48 @@ class FormatterTest extends TestCase "\x1b[0m", 'html' => '<span class="sql-reserved">JOIN</span> tbl2 <span class="sql-reserved">ON</span> c1 = c2', ], + 'named param' => [ + 'query' => 'select * from tbl where col = :param', + 'text' => 'SELECT' . "\n" . + ' *' . "\n" . + 'FROM' . "\n" . + ' tbl' . "\n" . + 'WHERE' . "\n" . + ' col = :param', + 'cli' => "\x1b[35mSELECT" . "\n" . + " \x1b[39m*" . "\n" . + "\x1b[35mFROM" . "\n" . + " \x1b[39mtbl" . "\n" . + "\x1b[35mWHERE" . "\n" . + " \x1b[39mcol = \x1b[31m:param" . "\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . + ' *' . '<br/>' . + '<span class="sql-reserved">FROM</span>' . '<br/>' . + ' tbl' . '<br/>' . + '<span class="sql-reserved">WHERE</span>' . '<br/>' . + ' col = <span class="sql-parameter">:param</span>', + ], + 'anon param' => [ + 'query' => 'select * from tbl where col = ?', + 'text' => 'SELECT' . "\n" . + ' *' . "\n" . + 'FROM' . "\n" . + ' tbl' . "\n" . + 'WHERE' . "\n" . + ' col = ?', + 'cli' => "\x1b[35mSELECT" . "\n" . + " \x1b[39m*" . "\n" . + "\x1b[35mFROM" . "\n" . + " \x1b[39mtbl" . "\n" . + "\x1b[35mWHERE" . "\n" . + " \x1b[39mcol = \x1b[31m?" . "\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . + ' *' . '<br/>' . + '<span class="sql-reserved">FROM</span>' . '<br/>' . + ' tbl' . '<br/>' . + '<span class="sql-reserved">WHERE</span>' . '<br/>' . + ' col = <span class="sql-parameter">?</span>', + ], ]; } } |