Skip to content

Commit

Permalink
fix: Improve PRQL syntax highlightning (#5313)
Browse files Browse the repository at this point in the history
Update prql_highlight_rules.js
  • Loading branch information
vanillajonathan authored Sep 15, 2023
1 parent dccbcc2 commit 7d677f1
Showing 1 changed file with 79 additions and 15 deletions.
94 changes: 79 additions & 15 deletions src/mode/prql_highlight_rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,73 @@ var PrqlHighlightRules = function() {
var bidi = "[\\u202A\\u202B\\u202D\\u202E\\u2066\\u2067\\u2068\\u202C\\u2069]";

this.$rules = {
start: [{
start: [
{
token: "string.start",
regex: '"',
regex: 's?"',
next: "string"
}, {
token: "string.start",
regex: 'f"',
next: "fstring"
}, {
token: "string.start",
regex: 'r"',
next: "rstring"
}, {
token: "string",
start: "'",
end: "'"
}, {
token: "string.character",
regex: "'(?:" + escapeRe.source + "|.)'?"
}, {
token : "constant.language",
regex : "^" + identifierRe + "*"
token: "constant.language",
regex: "^" + identifierRe + "*"
}, {
token : "constant.numeric", // hexadecimal, octal and binary
regex : /0(?:[xX][0-9a-fA-F]+|[oO][0-7]+|[bB][01]+)\b/
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)?/
token: "constant.numeric", // decimal integers and floats
regex: /(?:\d\d*(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+\b)?/
}, {
token: "comment.block",
regex: "#!.*"
}, {
token: "comment.line",
regex: "#.*"
}, {
token : "keyword.operator",
regex : /->|=>|==|!=|>=|<=|~=|&&|\|\||\?\?|\/\/|@/
token: "keyword.operator",
regex: /\|\s*/,
next: "pipe"
}, {
token: "keyword.operator",
regex: /->|=>|==|!=|>=|<=|~=|&&|\|\||\?\?|\/\/|@/
}, {
token: "invalid.illegal",
regex: bidi
}, {
token : "punctuation.operator",
regex : /[,`]/
token: "punctuation.operator",
regex: /[,`]/
}, {
token : keywordMapper,
regex : "[\\w\\xff-\\u218e\\u2455-\\uffff]+\\b"
token: keywordMapper,
regex: "[\\w\\xff-\\u218e\\u2455-\\uffff]+\\b"
}, {
token: "paren.lparen",
regex: /[\[({]/
regex: /[\[({]/
}, {
token: "paren.rparen",
regex: /[\])}]/
} ],
pipe: [{
token: "constant.language",
regex: identifierRe + "*",
next: "pop"
},{
token: "error",
regex: "",
next: "pop"
}],
string: [{
token: "constant.character.escape",
regex: escapeRe
Expand All @@ -106,6 +132,44 @@ var PrqlHighlightRules = function() {
token: "error",
regex: "",
next: "start"
}],
fstring: [{
token: "constant.character.escape",
regex: escapeRe
}, {
token: "string.end",
regex: '"',
next: "start"
}, {
token: "invalid.illegal",
regex: bidi
}, {
token: "paren.lparen",
regex: "{",
push: "fstringParenRules"
}, {
token: "invalid.illegal",
regex: bidi
}, {
defaultToken: "string"
}],
fstringParenRules: [{
token: "constant.language",
regex: "^" + identifierRe + "*"
}, {
token: "paren.rparen",
regex: "}",
next: "pop"
}],
rstring: [{
token: "string.end",
regex: '"',
next: "start"
}, {
token: "invalid.illegal",
regex: bidi
}, {
defaultToken: "string"
}]
};

Expand Down

0 comments on commit 7d677f1

Please sign in to comment.