summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Dorn <jeremy@jeremydorn.com>2013-03-31 15:21:10 -0700
committerJeremy Dorn <jeremy@jeremydorn.com>2013-03-31 15:21:10 -0700
commit4ca0c1b7e6501ec3404c07675372cf6076d8628b (patch)
treee4d90fe894dc595a700876bc56237be13201baaf
parentfa92df63b164d001a37db5bf1460ef8ce3271a11 (diff)
downloadsql-formatter-4ca0c1b7e6501ec3404c07675372cf6076d8628b.zip
sql-formatter-4ca0c1b7e6501ec3404c07675372cf6076d8628b.tar.gz
sql-formatter-4ca0c1b7e6501ec3404c07675372cf6076d8628b.tar.bz2
Fixing bug with comment formatting. Fixes #36
-rw-r--r--lib/SqlFormatter.php22
-rw-r--r--tests/format-highlight.html7
-rw-r--r--tests/format.html7
3 files changed, 21 insertions, 15 deletions
diff --git a/lib/SqlFormatter.php b/lib/SqlFormatter.php
index 6f589a5..c96a3a1 100644
--- a/lib/SqlFormatter.php
+++ b/lib/SqlFormatter.php
@@ -394,17 +394,6 @@ class SqlFormatter
$increase_block_indent = false;
array_unshift($indent_types,'block');
}
-
- // Display comments directly where they appear in the source
- if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
- if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
- $return .= "\n" . str_repeat($tab,$indent_level);
- }
-
- $return .= $highlighted;
- $newline = true;
- continue;
- }
// If we need a new line before the token
if ($newline) {
@@ -416,6 +405,17 @@ class SqlFormatter
$added_newline = false;
}
+ // Display comments directly where they appear in the source
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
+ $return .= "\n" . str_repeat($tab,$indent_level);
+ }
+
+ $return .= $highlighted;
+ $newline = true;
+ continue;
+ }
+
if($inline_parentheses) {
// End of inline parentheses
if($token[self::TOKEN_VALUE] === ')') {
diff --git a/tests/format-highlight.html b/tests/format-highlight.html
index c6d0a98..095f770 100644
--- a/tests/format-highlight.html
+++ b/tests/format-highlight.html
@@ -733,14 +733,17 @@
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span>
<span >*</span>
-<span style="font-weight:bold;">FROM</span> <span style="color: #aaa;">-- This is another comment</span>
+<span style="font-weight:bold;">FROM</span>
+ <span style="color: #aaa;">-- This is another comment</span>
<span style="color: #333;">MyTable</span> <span style="color: #aaa;"># One final comment</span>
+
<span style="color: #aaa;">/* This is a block comment
*/</span>
<span style="font-weight:bold;">WHERE</span>
<span style="color: green;">1</span> <span >=</span> <span style="color: green;">2</span><span >;</span></pre>
-<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span> <span style="color: #aaa;">-- This is a test</span></pre>
+<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span>
+ <span style="color: #aaa;">-- This is a test</span></pre>
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span>
<span style="color: #333;">Test</span>
diff --git a/tests/format.html b/tests/format.html
index 1b35c61..19212c6 100644
--- a/tests/format.html
+++ b/tests/format.html
@@ -733,14 +733,17 @@ DROP
SELECT
*
-FROM -- This is another comment
+FROM
+ -- This is another comment
MyTable # One final comment
+
/* This is a block comment
*/
WHERE
1 = 2;
-SELECT -- This is a test
+SELECT
+ -- This is a test
SELECT
Test