From 8b9175bc780fade64bed1570fa1cd34d022b337b Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 9 Oct 2023 17:28:50 +0200 Subject: [PATCH] feat: Add support for time units in PRQL (#5324) * Update prql_highlight_rules.js * Update prql_highlight_rules.js --- src/mode/prql_highlight_rules.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/mode/prql_highlight_rules.js b/src/mode/prql_highlight_rules.js index 9d7d387bfed..a30d1ae6717 100644 --- a/src/mode/prql_highlight_rules.js +++ b/src/mode/prql_highlight_rules.js @@ -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 = { @@ -54,7 +55,7 @@ var PrqlHighlightRules = function() { regex: 'r"', next: "rstring" }, { - token: "string", + token: "string.single", start: "'", end: "'" }, { @@ -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", @@ -122,7 +126,7 @@ var PrqlHighlightRules = function() { token: "invalid.illegal", regex: bidi }, { - defaultToken: "string" + defaultToken: "string.double" }], stringGap: [{ token: "text",