Skip to content

Commit 8b9175b

Browse files
authoredOct 9, 2023
feat: Add support for time units in PRQL (#5324)
* Update prql_highlight_rules.js * Update prql_highlight_rules.js
1 parent e2eed5f commit 8b9175b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed
 

‎src/mode/prql_highlight_rules.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ var PrqlHighlightRules = function() {
3535
"support.type": builtinTypes
3636
}, "identifier");
3737

38-
var escapeRe = /\\(\d+|['"\\&bfnrt]|u[0-9a-fA-F]{4})/;
38+
var escapeRe = /\\(\d+|['"\\&bfnrt]|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2})/;
3939
var identifierRe = /[A-Za-z_][a-z_A-Z0-9]/.source;
40+
var numRe = /(?:\d\d*(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+\b)?/.source;
4041
var bidi = "[\\u202A\\u202B\\u202D\\u202E\\u2066\\u2067\\u2068\\u202C\\u2069]";
4142

4243
this.$rules = {
@@ -54,7 +55,7 @@ var PrqlHighlightRules = function() {
5455
regex: 'r"',
5556
next: "rstring"
5657
}, {
57-
token: "string",
58+
token: "string.single",
5859
start: "'",
5960
end: "'"
6061
}, {
@@ -63,17 +64,20 @@ var PrqlHighlightRules = function() {
6364
}, {
6465
token: "constant.language",
6566
regex: "^" + identifierRe + "*"
67+
}, {
68+
token : ["constant.numeric", "keyword"],
69+
regex : "(" + numRe + ")(years|months|weeks|days|hours|minutes|seconds|milliseconds|microseconds)"
6670
}, {
6771
token: "constant.numeric", // hexadecimal, octal and binary
6872
regex: /0(?:[xX][0-9a-fA-F]+|[oO][0-7]+|[bB][01]+)\b/
6973
}, {
7074
token: "constant.numeric", // decimal integers and floats
71-
regex: /(?:\d\d*(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+\b)?/
75+
regex: numRe
7276
}, {
73-
token: "comment.block",
77+
token: "comment.block.documentation",
7478
regex: "#!.*"
7579
}, {
76-
token: "comment.line",
80+
token: "comment.line.number-sign",
7781
regex: "#.*"
7882
}, {
7983
token: "keyword.operator",
@@ -122,7 +126,7 @@ var PrqlHighlightRules = function() {
122126
token: "invalid.illegal",
123127
regex: bidi
124128
}, {
125-
defaultToken: "string"
129+
defaultToken: "string.double"
126130
}],
127131
stringGap: [{
128132
token: "text",

0 commit comments

Comments
 (0)
Please sign in to comment.