Skip to content

Commit 4e00cdd

Browse files
authoredOct 14, 2021
SQL: Added identifier token (#3141)
1 parent a8bacc7 commit 4e00cdd

File tree

4 files changed

+122
-1
lines changed

4 files changed

+122
-1
lines changed
 

‎components/prism-sql.js

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ Prism.languages.sql = {
1515
greedy: true,
1616
lookbehind: true
1717
},
18+
'identifier': {
19+
pattern: /(^|[^@\\])`(?:\\[\s\S]|[^`\\]|``)*`/,
20+
greedy: true,
21+
lookbehind: true,
22+
inside: {
23+
'punctuation': /^`|`$/
24+
}
25+
},
1826
'function': /\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i, // Should we highlight user defined functions too?
1927
'keyword': /\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:COL|_INSERT)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|KEYS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURN(?:ING|S)?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/i,
2028
'boolean': /\b(?:FALSE|NULL|TRUE)\b/i,

‎components/prism-sql.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
`5Customers`
2+
`tableName~`
3+
` SELECT `
4+
foo.`GROUP`
5+
`a``b`
6+
7+
----------------------------------------------------
8+
9+
[
10+
["identifier", [
11+
["punctuation", "`"],
12+
"5Customers",
13+
["punctuation", "`"]
14+
]],
15+
16+
["identifier", [
17+
["punctuation", "`"],
18+
"tableName~",
19+
["punctuation", "`"]
20+
]],
21+
22+
["identifier", [
23+
["punctuation", "`"],
24+
" SELECT ",
25+
["punctuation", "`"]
26+
]],
27+
28+
"\r\nfoo",
29+
["punctuation", "."],
30+
["identifier", [
31+
["punctuation", "`"],
32+
"GROUP",
33+
["punctuation", "`"]
34+
]],
35+
36+
["identifier", [
37+
["punctuation", "`"],
38+
"a``b",
39+
["punctuation", "`"]
40+
]]
41+
]

‎tests/languages/sql/issue3140.test

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
select
2+
`t`.`col1`, `t`.`col2`, `t`.`col3`, `t`.`col4`
3+
from
4+
`test_table` as `t`
5+
6+
----------------------------------------------------
7+
8+
[
9+
["keyword", "select"],
10+
11+
["identifier", [
12+
["punctuation", "`"],
13+
"t",
14+
["punctuation", "`"]
15+
]],
16+
["punctuation", "."],
17+
["identifier", [
18+
["punctuation", "`"],
19+
"col1",
20+
["punctuation", "`"]
21+
]],
22+
["punctuation", ","],
23+
["identifier", [
24+
["punctuation", "`"],
25+
"t",
26+
["punctuation", "`"]
27+
]],
28+
["punctuation", "."],
29+
["identifier", [
30+
["punctuation", "`"],
31+
"col2",
32+
["punctuation", "`"]
33+
]],
34+
["punctuation", ","],
35+
["identifier", [
36+
["punctuation", "`"],
37+
"t",
38+
["punctuation", "`"]
39+
]],
40+
["punctuation", "."],
41+
["identifier", [
42+
["punctuation", "`"],
43+
"col3",
44+
["punctuation", "`"]
45+
]],
46+
["punctuation", ","],
47+
["identifier", [
48+
["punctuation", "`"],
49+
"t",
50+
["punctuation", "`"]
51+
]],
52+
["punctuation", "."],
53+
["identifier", [
54+
["punctuation", "`"],
55+
"col4",
56+
["punctuation", "`"]
57+
]],
58+
59+
["keyword", "from"],
60+
61+
["identifier", [
62+
["punctuation", "`"],
63+
"test_table",
64+
["punctuation", "`"]
65+
]],
66+
["keyword", "as"],
67+
["identifier", [
68+
["punctuation", "`"],
69+
"t",
70+
["punctuation", "`"]
71+
]]
72+
]

0 commit comments

Comments
 (0)
Please sign in to comment.