Skip to content

Commit 7d677f1

Browse files
authoredSep 15, 2023
fix: Improve PRQL syntax highlightning (#5313)
Update prql_highlight_rules.js
1 parent dccbcc2 commit 7d677f1

File tree

1 file changed

+79
-15
lines changed

1 file changed

+79
-15
lines changed
 

‎src/mode/prql_highlight_rules.js

+79-15
Original file line numberDiff line numberDiff line change
@@ -40,47 +40,73 @@ var PrqlHighlightRules = function() {
4040
var bidi = "[\\u202A\\u202B\\u202D\\u202E\\u2066\\u2067\\u2068\\u202C\\u2069]";
4141

4242
this.$rules = {
43-
start: [{
43+
start: [
44+
{
4445
token: "string.start",
45-
regex: '"',
46+
regex: 's?"',
4647
next: "string"
48+
}, {
49+
token: "string.start",
50+
regex: 'f"',
51+
next: "fstring"
52+
}, {
53+
token: "string.start",
54+
regex: 'r"',
55+
next: "rstring"
56+
}, {
57+
token: "string",
58+
start: "'",
59+
end: "'"
4760
}, {
4861
token: "string.character",
4962
regex: "'(?:" + escapeRe.source + "|.)'?"
5063
}, {
51-
token : "constant.language",
52-
regex : "^" + identifierRe + "*"
64+
token: "constant.language",
65+
regex: "^" + identifierRe + "*"
5366
}, {
54-
token : "constant.numeric", // hexadecimal, octal and binary
55-
regex : /0(?:[xX][0-9a-fA-F]+|[oO][0-7]+|[bB][01]+)\b/
67+
token: "constant.numeric", // hexadecimal, octal and binary
68+
regex: /0(?:[xX][0-9a-fA-F]+|[oO][0-7]+|[bB][01]+)\b/
5669
}, {
57-
token : "constant.numeric", // decimal integers and floats
58-
regex : /(?:\d\d*(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+\b)?/
70+
token: "constant.numeric", // decimal integers and floats
71+
regex: /(?:\d\d*(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+\b)?/
5972
}, {
6073
token: "comment.block",
6174
regex: "#!.*"
6275
}, {
6376
token: "comment.line",
6477
regex: "#.*"
6578
}, {
66-
token : "keyword.operator",
67-
regex : /->|=>|==|!=|>=|<=|~=|&&|\|\||\?\?|\/\/|@/
79+
token: "keyword.operator",
80+
regex: /\|\s*/,
81+
next: "pipe"
82+
}, {
83+
token: "keyword.operator",
84+
regex: /->|=>|==|!=|>=|<=|~=|&&|\|\||\?\?|\/\/|@/
6885
}, {
6986
token: "invalid.illegal",
7087
regex: bidi
7188
}, {
72-
token : "punctuation.operator",
73-
regex : /[,`]/
89+
token: "punctuation.operator",
90+
regex: /[,`]/
7491
}, {
75-
token : keywordMapper,
76-
regex : "[\\w\\xff-\\u218e\\u2455-\\uffff]+\\b"
92+
token: keywordMapper,
93+
regex: "[\\w\\xff-\\u218e\\u2455-\\uffff]+\\b"
7794
}, {
7895
token: "paren.lparen",
79-
regex: /[\[({]/
96+
regex: /[\[({]/
8097
}, {
8198
token: "paren.rparen",
8299
regex: /[\])}]/
83100
} ],
101+
pipe: [{
102+
token: "constant.language",
103+
regex: identifierRe + "*",
104+
next: "pop"
105+
},{
106+
token: "error",
107+
regex: "",
108+
next: "pop"
109+
}],
84110
string: [{
85111
token: "constant.character.escape",
86112
regex: escapeRe
@@ -106,6 +132,44 @@ var PrqlHighlightRules = function() {
106132
token: "error",
107133
regex: "",
108134
next: "start"
135+
}],
136+
fstring: [{
137+
token: "constant.character.escape",
138+
regex: escapeRe
139+
}, {
140+
token: "string.end",
141+
regex: '"',
142+
next: "start"
143+
}, {
144+
token: "invalid.illegal",
145+
regex: bidi
146+
}, {
147+
token: "paren.lparen",
148+
regex: "{",
149+
push: "fstringParenRules"
150+
}, {
151+
token: "invalid.illegal",
152+
regex: bidi
153+
}, {
154+
defaultToken: "string"
155+
}],
156+
fstringParenRules: [{
157+
token: "constant.language",
158+
regex: "^" + identifierRe + "*"
159+
}, {
160+
token: "paren.rparen",
161+
regex: "}",
162+
next: "pop"
163+
}],
164+
rstring: [{
165+
token: "string.end",
166+
regex: '"',
167+
next: "start"
168+
}, {
169+
token: "invalid.illegal",
170+
regex: bidi
171+
}, {
172+
defaultToken: "string"
109173
}]
110174
};
111175

0 commit comments

Comments
 (0)
Please sign in to comment.