Skip to content

Commit

Permalink
feat: Add support for time units in PRQL (#5324)
Browse files Browse the repository at this point in the history
* Update prql_highlight_rules.js

* Update prql_highlight_rules.js
  • Loading branch information
vanillajonathan authored Oct 9, 2023
1 parent e2eed5f commit 8b9175b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/mode/prql_highlight_rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ var PrqlHighlightRules = function() {
"support.type": builtinTypes
}, "identifier");

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

this.$rules = {
Expand All @@ -54,7 +55,7 @@ var PrqlHighlightRules = function() {
regex: 'r"',
next: "rstring"
}, {
token: "string",
token: "string.single",
start: "'",
end: "'"
}, {
Expand All @@ -63,17 +64,20 @@ var PrqlHighlightRules = function() {
}, {
token: "constant.language",
regex: "^" + identifierRe + "*"
}, {
token : ["constant.numeric", "keyword"],
regex : "(" + numRe + ")(years|months|weeks|days|hours|minutes|seconds|milliseconds|microseconds)"
}, {
token: "constant.numeric", // hexadecimal, octal and binary
regex: /0(?:[xX][0-9a-fA-F]+|[oO][0-7]+|[bB][01]+)\b/
}, {
token: "constant.numeric", // decimal integers and floats
regex: /(?:\d\d*(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+\b)?/
regex: numRe
}, {
token: "comment.block",
token: "comment.block.documentation",
regex: "#!.*"
}, {
token: "comment.line",
token: "comment.line.number-sign",
regex: "#.*"
}, {
token: "keyword.operator",
Expand Down Expand Up @@ -122,7 +126,7 @@ var PrqlHighlightRules = function() {
token: "invalid.illegal",
regex: bidi
}, {
defaultToken: "string"
defaultToken: "string.double"
}],
stringGap: [{
token: "text",
Expand Down

0 comments on commit 8b9175b

Please sign in to comment.