From 09424bd295058c956afc034d3c39500ec3fa3efc Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sat, 9 Sep 2023 19:30:08 +0200 Subject: [PATCH 1/7] Update modelist.js --- src/ext/modelist.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ext/modelist.js b/src/ext/modelist.js index 95540ad5404..26617f81d49 100644 --- a/src/ext/modelist.js +++ b/src/ext/modelist.js @@ -170,6 +170,7 @@ var supportedModes = { Prolog: ["plg|prolog"], Properties: ["properties"], Protobuf: ["proto"], + PRQL: ["prql"], Puppet: ["epp|pp"], Python: ["py"], QML: ["qml"], From c15bb9d90b7ec6ac17333a1a4cf7a4406f86d437 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sat, 9 Sep 2023 19:31:29 +0200 Subject: [PATCH 2/7] Add files via upload --- src/mode/prql.js | 21 +++++++ src/mode/prql_highlight_rules.js | 104 +++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 src/mode/prql.js create mode 100644 src/mode/prql_highlight_rules.js diff --git a/src/mode/prql.js b/src/mode/prql.js new file mode 100644 index 00000000000..2de2433676c --- /dev/null +++ b/src/mode/prql.js @@ -0,0 +1,21 @@ +"use strict"; + +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var HighlightRules = require("./prql_highlight_rules").PrqlHighlightRules; +var FoldMode = require("./folding/cstyle").FoldMode; + +var Mode = function() { + this.HighlightRules = HighlightRules; + this.foldingRules = new FoldMode(); + this.$behaviour = this.$defaultBehaviour; +}; +oop.inherits(Mode, TextMode); + +(function() { + this.lineCommentStart = "#"; + // Extra logic goes here. + this.$id = "ace/mode/prql"; +}).call(Mode.prototype); + +exports.Mode = Mode; diff --git a/src/mode/prql_highlight_rules.js b/src/mode/prql_highlight_rules.js new file mode 100644 index 00000000000..2199de2ea25 --- /dev/null +++ b/src/mode/prql_highlight_rules.js @@ -0,0 +1,104 @@ +// https://github.com/PRQL/prql + +"use strict"; + +var oop = require("../lib/oop"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var PrqlHighlightRules = function() { + var builtinFunctions = "min|max|sum|average|stddev|every|any|concat_array|count|" + + "lag|lead|first|last|rank|rank_dense|row_number|" + + "round|as|in|" + + "tuple_every|tuple_map|tuple_zip|_eq|_is_null|" + + "from_text|" + + "lower|upper|" + + "read_parquet|read_csv"; + + var builtinTypes = [ + "bool", + "int", + "int8", + "int16", + "int32", + "int64", + "float", + "text", + "set"].join("|"); + + var keywordMapper = this.createKeywordMapper({ + "support.function": builtinFunctions, + "support.type": builtinTypes, + "constant.language": "true|false|null", + "keyword": "let|into|case|prql|type|module|internal" + }, "identifier"); + + var escapeRe = /\\(\d+|['"\\&trnbvf]|u[0-9a-fA-F]{4})/; + var identifierRe = /[A-Za-z_][a-z_A-Z0-9]/.source; + + this.$rules = { + start: [{ + token: "string.start", + regex: '"', + next: "string" + }, { + token: "string.character", + regex: "'(?:" + escapeRe.source + "|.)'?" + }, { + regex: /0(?:[xX][0-9A-Fa-f]+|[oO][0-7]+)|\d+(\.\d+)?([eE][-+]?\d*)?/, + token: "constant.numeric" + }, { + token: "comment", + regex: "#.*" + }, { + token : "keyword", + regex : /\.\.|\||:|=|\\|"|->|<-/ + }, { + token : "keyword.operator", + regex : /[-!#$%&*+.\/<=>?@\\^|~:]+/ + }, { + token : "operator.punctuation", + regex : /[,`]/ + }, { + token : "constant.language", + regex : "^" + identifierRe + "*", + }, { + token : keywordMapper, + regex : "[\\w\\xff-\\u218e\\u2455-\\uffff]+\\b" + }, { + token: "paren.lparen", + regex: /[\[({]/ + }, { + token: "paren.rparen", + regex: /[\])}]/ + } ], + string: [{ + token: "constant.language.escape", + regex: escapeRe + }, { + token: "text", + regex: /\\(\s|$)/, + next: "stringGap" + }, { + token: "string.end", + regex: '"', + next: "start" + }, { + defaultToken: "string" + }], + stringGap: [{ + token: "text", + regex: /\\/, + next: "string" + }, { + token: "error", + regex: "", + next: "start" + }] + }; + + this.normalizeRules(); +}; + +oop.inherits(PrqlHighlightRules, TextHighlightRules); + +exports.PrqlHighlightRules = PrqlHighlightRules; From 2c57ef8802eda5c4e7ee81ca8f8d4efb782661ee Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sat, 9 Sep 2023 19:32:36 +0200 Subject: [PATCH 3/7] Create prql.prql --- demo/kitchen-sink/docs/prql.prql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 demo/kitchen-sink/docs/prql.prql diff --git a/demo/kitchen-sink/docs/prql.prql b/demo/kitchen-sink/docs/prql.prql new file mode 100644 index 00000000000..5387d697b6f --- /dev/null +++ b/demo/kitchen-sink/docs/prql.prql @@ -0,0 +1,22 @@ +from invoices +filter invoice_date >= @1970-01-16 +derive { + transaction_fees = 0.8, + income = total - transaction_fees +} +filter income > 1 +group customer_id ( + aggregate { + average total, + sum_income = sum income, + ct = count total, + } +) +sort {-sum_income} +take 10 +join c=customers (==customer_id) +derive name = f"{c.last_name}, {c.first_name}" +select { + c.customer_id, name, sum_income +} +derive db_version = s"version()" From 07bc1e87520b081261ba98ae327af6dc85bbca4e Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sat, 9 Sep 2023 19:39:51 +0200 Subject: [PATCH 4/7] Update prql_highlight_rules.js --- src/mode/prql_highlight_rules.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mode/prql_highlight_rules.js b/src/mode/prql_highlight_rules.js index 2199de2ea25..a606ca6c894 100644 --- a/src/mode/prql_highlight_rules.js +++ b/src/mode/prql_highlight_rules.js @@ -6,7 +6,7 @@ var oop = require("../lib/oop"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var PrqlHighlightRules = function() { - var builtinFunctions = "min|max|sum|average|stddev|every|any|concat_array|count|" + + const builtinFunctions = "min|max|sum|average|stddev|every|any|concat_array|count|" + "lag|lead|first|last|rank|rank_dense|row_number|" + "round|as|in|" + "tuple_every|tuple_map|tuple_zip|_eq|_is_null|" + @@ -14,7 +14,7 @@ var PrqlHighlightRules = function() { "lower|upper|" + "read_parquet|read_csv"; - var builtinTypes = [ + const builtinTypes = [ "bool", "int", "int8", @@ -60,7 +60,7 @@ var PrqlHighlightRules = function() { regex : /[,`]/ }, { token : "constant.language", - regex : "^" + identifierRe + "*", + regex : "^" + identifierRe + "*" }, { token : keywordMapper, regex : "[\\w\\xff-\\u218e\\u2455-\\uffff]+\\b" From 341b848fd0027c265f61e4d18581ed2d68c1df4f Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sat, 9 Sep 2023 19:40:38 +0200 Subject: [PATCH 5/7] Update prql_highlight_rules.js --- src/mode/prql_highlight_rules.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mode/prql_highlight_rules.js b/src/mode/prql_highlight_rules.js index a606ca6c894..c5d7632e0c8 100644 --- a/src/mode/prql_highlight_rules.js +++ b/src/mode/prql_highlight_rules.js @@ -6,7 +6,7 @@ var oop = require("../lib/oop"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var PrqlHighlightRules = function() { - const builtinFunctions = "min|max|sum|average|stddev|every|any|concat_array|count|" + + var builtinFunctions = "min|max|sum|average|stddev|every|any|concat_array|count|" + "lag|lead|first|last|rank|rank_dense|row_number|" + "round|as|in|" + "tuple_every|tuple_map|tuple_zip|_eq|_is_null|" + @@ -14,7 +14,7 @@ var PrqlHighlightRules = function() { "lower|upper|" + "read_parquet|read_csv"; - const builtinTypes = [ + var builtinTypes = [ "bool", "int", "int8", From 9b25e3a671917cf453c7d021c7ba26a82f885aca Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sun, 10 Sep 2023 19:11:07 +0200 Subject: [PATCH 6/7] Update prql_highlight_rules.js --- src/mode/prql_highlight_rules.js | 39 ++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/mode/prql_highlight_rules.js b/src/mode/prql_highlight_rules.js index c5d7632e0c8..f58e592f616 100644 --- a/src/mode/prql_highlight_rules.js +++ b/src/mode/prql_highlight_rules.js @@ -1,3 +1,4 @@ +// https://prql-lang.org/ // https://github.com/PRQL/prql "use strict"; @@ -26,13 +27,15 @@ var PrqlHighlightRules = function() { "set"].join("|"); var keywordMapper = this.createKeywordMapper({ + "constant.language": "null", + "constant.language.boolean": "true|false", + "keyword": "let|into|case|prql|type|module|internal", + "storage.type": "let|func", "support.function": builtinFunctions, "support.type": builtinTypes, - "constant.language": "true|false|null", - "keyword": "let|into|case|prql|type|module|internal" }, "identifier"); - var escapeRe = /\\(\d+|['"\\&trnbvf]|u[0-9a-fA-F]{4})/; + var escapeRe = /\\(\d+|['"\\&bfnrt]|u[0-9a-fA-F]{4})/; var identifierRe = /[A-Za-z_][a-z_A-Z0-9]/.source; this.$rules = { @@ -44,23 +47,26 @@ var PrqlHighlightRules = function() { token: "string.character", regex: "'(?:" + escapeRe.source + "|.)'?" }, { - regex: /0(?:[xX][0-9A-Fa-f]+|[oO][0-7]+)|\d+(\.\d+)?([eE][-+]?\d*)?/, - token: "constant.numeric" + token : "constant.language", + regex : "^" + identifierRe + "*" }, { - token: "comment", - regex: "#.*" + token : "constant.numeric", // hexadecimal, octal and binary + regex : /0(?:[xX][0-9a-fA-F]+|[oO][0-7]+|[bB][01]+)\b/ }, { - token : "keyword", - regex : /\.\.|\||:|=|\\|"|->|<-/ + 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 : /[-!#$%&*+.\/<=>?@\\^|~:]+/ + regex : /->|=>|==|!=|>=|<=|~=|&&|\|\||\?\?|\/\/|@/ }, { - token : "operator.punctuation", + token : "punctuation.operator", regex : /[,`]/ - }, { - token : "constant.language", - regex : "^" + identifierRe + "*" }, { token : keywordMapper, regex : "[\\w\\xff-\\u218e\\u2455-\\uffff]+\\b" @@ -72,7 +78,7 @@ var PrqlHighlightRules = function() { regex: /[\])}]/ } ], string: [{ - token: "constant.language.escape", + token: "constant.character.escape", regex: escapeRe }, { token: "text", @@ -83,6 +89,9 @@ var PrqlHighlightRules = function() { regex: '"', next: "start" }, { + token: "invalid.illegal", + regex: "[\\u202A\\u202B\\u202D\\u202E\\u2066\\u2067\\u2068\\u202C\\u2069]" + }, { defaultToken: "string" }], stringGap: [{ From cf0755fbba1c481054b04365977c4d77b0ab2c8e Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sun, 10 Sep 2023 19:25:54 +0200 Subject: [PATCH 7/7] Update prql_highlight_rules.js --- src/mode/prql_highlight_rules.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mode/prql_highlight_rules.js b/src/mode/prql_highlight_rules.js index f58e592f616..fb9df57dc10 100644 --- a/src/mode/prql_highlight_rules.js +++ b/src/mode/prql_highlight_rules.js @@ -32,11 +32,12 @@ var PrqlHighlightRules = function() { "keyword": "let|into|case|prql|type|module|internal", "storage.type": "let|func", "support.function": builtinFunctions, - "support.type": builtinTypes, + "support.type": builtinTypes }, "identifier"); var escapeRe = /\\(\d+|['"\\&bfnrt]|u[0-9a-fA-F]{4})/; var identifierRe = /[A-Za-z_][a-z_A-Z0-9]/.source; + var bidi = "[\\u202A\\u202B\\u202D\\u202E\\u2066\\u2067\\u2068\\u202C\\u2069]"; this.$rules = { start: [{ @@ -64,6 +65,9 @@ var PrqlHighlightRules = function() { }, { token : "keyword.operator", regex : /->|=>|==|!=|>=|<=|~=|&&|\|\||\?\?|\/\/|@/ + }, { + token: "invalid.illegal", + regex: bidi }, { token : "punctuation.operator", regex : /[,`]/ @@ -90,8 +94,8 @@ var PrqlHighlightRules = function() { next: "start" }, { token: "invalid.illegal", - regex: "[\\u202A\\u202B\\u202D\\u202E\\u2066\\u2067\\u2068\\u202C\\u2069]" - }, { + regex: bidi + }, { defaultToken: "string" }], stringGap: [{