-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace "default" segment with "whitespace" and "identifier" segments, with fallback to "unknown" segment. Also, classify backticked identifiers like `foo` as "identifier" rather than "string". This allows for identifiers to be styled independently from strings and whitespace. It also simplifies getSegments() from 30 lines down to 5, by removing the special-case code for the "default" segment. BREAKING CHANGE: The `default` segment has been split into `identifier` and `whitespace` segments. There's also a new `unknown` segment that will only show up for malformed SQL such as an unclosed string. However, the highlight() function works largely the same as before, both normal mode and HTML mode, except for the bug fix to stop classifying identifiers as strings. In other words, SQL like select * from EMP where NAME="John Smith" will get highlighted the same as before, i.e. no syntax highlighting for EMP or NAME. Fixes #147
- Loading branch information
Showing
4 changed files
with
87 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,13 +59,13 @@ document.body.innerHTML += highlighted | |
**Output:** | ||
```html | ||
<span class="sql-hl-keyword">SELECT</span> | ||
<span class="sql-hl-string">`id`</span> | ||
<span class="sql-hl-identifier">`id`</span> | ||
<span class="sql-hl-special">,</span> | ||
<span class="sql-hl-string">`username`</span> | ||
<span class="sql-hl-identifier">`username`</span> | ||
<span class="sql-hl-keyword">FROM</span> | ||
<span class="sql-hl-string">`users`</span> | ||
<span class="sql-hl-identifier">`users`</span> | ||
<span class="sql-hl-keyword">WHERE</span> | ||
<span class="sql-hl-string">`email`</span> | ||
<span class="sql-hl-identifier">`email`</span> | ||
<span class="sql-hl-special">=</span> | ||
<span class="sql-hl-string">'[email protected]'</span> | ||
``` | ||
|
@@ -112,22 +112,22 @@ console.log(segments) | |
```js | ||
[ | ||
{ name: 'keyword', content: 'SELECT' }, | ||
{ name: 'default', content: ' ' }, | ||
{ name: 'string', content: '`id`' }, | ||
{ name: 'whitespace', content: ' ' }, | ||
{ name: 'identifier', content: '`id`' }, | ||
{ name: 'special', content: ',' }, | ||
{ name: 'default', content: ' ' }, | ||
{ name: 'string', content: '`username`' }, | ||
{ name: 'default', content: ' ' }, | ||
{ name: 'whitespace', content: ' ' }, | ||
{ name: 'identifier', content: '`username`' }, | ||
{ name: 'whitespace', content: ' ' }, | ||
{ name: 'keyword', content: 'FROM' }, | ||
{ name: 'default', content: ' ' }, | ||
{ name: 'string', content: '`users`' }, | ||
{ name: 'default', content: ' ' }, | ||
{ name: 'whitespace', content: ' ' }, | ||
{ name: 'identifier', content: '`users`' }, | ||
{ name: 'whitespace', content: ' ' }, | ||
{ name: 'keyword', content: 'WHERE' }, | ||
{ name: 'default', content: ' ' }, | ||
{ name: 'string', content: '`email`' }, | ||
{ name: 'default', content: ' ' }, | ||
{ name: 'whitespace', content: ' ' }, | ||
{ name: 'identifier', content: '`email`' }, | ||
{ name: 'whitespace', content: ' ' }, | ||
{ name: 'special', content: '=' }, | ||
{ name: 'default', content: ' ' }, | ||
{ name: 'whitespace', content: ' ' }, | ||
{ name: 'string', content: "'[email protected]'" } | ||
] | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.