-
-
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" token with "whitespace" and "identifier" tokens, with fallback to "unknown" token. 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" token. Fixes: #147.
- Loading branch information
Showing
3 changed files
with
85 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
Oops, something went wrong.