Skip to content

Commit

Permalink
Added support for Power Query (#2250)
Browse files Browse the repository at this point in the history
This adds support for Power Query.
https://docs.microsoft.com/en-us/powerquery-m/
  • Loading branch information
peterbud committed Mar 16, 2020
1 parent 2d5082a commit 8119e57
Show file tree
Hide file tree
Showing 19 changed files with 555 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,11 @@
"require": "sql",
"owner": "Golmote"
},
"powerquery": {
"title": "PowerQuery",
"alias": ["pq", "mscript"],
"owner": "peterbud"
},
"powershell": {
"title": "PowerShell",
"owner": "nauzilus"
Expand Down
55 changes: 55 additions & 0 deletions components/prism-powerquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// https://docs.microsoft.com/en-us/powerquery-m/power-query-m-language-specification

Prism.languages.powerquery = {
'comment': {
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:\/\/).*)/,
lookbehind: true
},
'quoted-identifier': {
pattern: /#"(?:[^"\r\n]|"")*"(?!")/,
greedy: true,
alias: 'variable'
},
'string': {
pattern: /"(?:[^"\r\n]|"")*"(?!")/,
greedy: true
},
'constant': [
/\bDay\.(?:Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)\b/,
/\bTraceLevel\.(?:Critical|Error|Information|Verbose|Warning)\b/,
/\bOccurrence\.(?:First|Last|All)\b/,
/\bOrder\.(?:Ascending|Descending)\b/,
/\bRoundingMode\.(?:AwayFromZero|Down|ToEven|TowardZero|Up)\b/,
/\bMissingField\.(?:Error|Ignore|UseNull)\b/,
/\bQuoteStyle\.(?:Csv|None)\b/,
/\bJoinKind\.(?:Inner|LeftOuter|RightOuter|FullOuter|LeftAnti|RightAnti)\b/,
/\bGroupKind\.(?:Global|Local)\b/,
/\bExtraValues\.(?:List|Ignore|Error)\b/,
/\bJoinAlgorithm\.(?:Dynamic|PairwiseHash|SortMerge|LeftHash|RightHash|LeftIndex|RightIndex)\b/,
/\bJoinSide\.(?:Left|Right)\b/,
/\bPrecision\.(?:Double|Decimal)\b/,
/\bRelativePosition\.From(?:End|Start)\b/,
/\bTextEncoding\.(?:Ascii|BigEndianUnicode|Unicode|Utf8|Utf16|Windows)\b/,
/\b(?:Any|Binary|Date|DateTime|DateTimeZone|Duration|Int8|Int16|Int32|Int64|Function|List|Logical|None|Number|Record|Table|Text|Time)\.Type\b/,
/\bnull\b/
],
'boolean': /\b(?:true|false)\b/,
'keyword': /\b(?:and|as|each|else|error|if|in|is|let|meta|not|nullable|optional|or|otherwise|section|shared|then|try|type)\b|#(?:binary|date|datetime|datetimezone|duration|infinity|nan|sections|shared|table|time)\b/,
'function': {
pattern: /(^|[^#\w.])(?!\d)[\w.]+(?=\s*\()/,
lookbehind: true
},
'data-type': {
pattern: /\b(?:any|anynonnull|binary|date|datetime|datetimezone|duration|function|list|logical|none|number|record|table|text|time|type)\b/,
alias: 'variable'
},
'number': {
pattern: /\b0x[\da-f]+\b|(?:[+-]?(?:\b\d+\.)?\b\d+|[+-]\.\d+|(^|[^.])\B\.\d+)(?:e[+-]?\d+)?\b/i,
lookbehind: true
},
'operator': /[-+*\/&?@^]|<(?:=>?|>)?|>=?|=>?|\.\.\.?/,
'punctuation': /[,;\[\](){}]/
};

Prism.languages.pq = Prism.languages['powerquery'];
Prism.languages.mscript = Prism.languages['powerquery']
1 change: 1 addition & 0 deletions components/prism-powerquery.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions examples/prism-powerquery.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<h2>Comments</h2>
<pre><code>// This is a comment</code></pre>
<h2>Simple example</h2>
<pre><code>
let
x = 1 + 1,
y = 2 + 2,
z = y + 1
in
x + y + z
</code></pre>
<h2>Another example</h2>
<pre><code>
let Orders = Table.FromRecords({
[OrderID = 1, CustomerID = 1, Item = "fishing rod", Price = 100.0],
[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5.0],
[OrderID = 3, CustomerID = 2, Item = "fishing net", Price = 25.0]}),
#"Capitalized Each Word" = Table.TransformColumns(Orders, {"Item", Text.Proper})
in
#"Capitalized Each Word"
</code></pre>
<h2>Full example</h2>
<pre><code>
let
Source = Sales,
LookupTable = #table(
type table
[
#"FROM"=text,
#"TO"=text
],
{
{"CEE","Central & Eastern Europe"},
{"WE","Western Europe"}
}
),

JT = Table.NestedJoin(
Source,
{"Area"},
LookupTable,
{"FROM"},
"Map",
JoinKind.LeftOuter
),

#"Expanded Map" = Table.ExpandTableColumn(
JT,
"Map",
{"TO"},
{"TO"}
),

#"Replace non-matches with original value" = Table.AddColumn(
#"Expanded Map",
"Replaced",
each
if [TO] = null then [Area]
else [TO]
),

#"Remove original column" = Table.RemoveColumns(
#"Replace non-matches with original value",
{"Area", "TO"}
),

#"Renamed replace column to original name" = Table.RenameColumns(
#"Remove original column",
{{"Replaced", "Area"}}
)

in
#"Renamed replace column to original name"
</code></pre>
2 changes: 2 additions & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
"n4jsd": "n4js",
"objectpascal": "pascal",
"px": "pcaxis",
"pq": "powerquery",
"mscript": "powerquery",
"py": "python",
"robot": "robotframework",
"rb": "ruby",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
"phpdoc": "PHPDoc",
"php-extras": "PHP Extras",
"plsql": "PL/SQL",
"powerquery": "PowerQuery",
"pq": "PowerQuery",
"mscript": "PowerQuery",
"powershell": "PowerShell",
"properties": ".properties",
"protobuf": "Protocol Buffers",
Expand Down
Loading

0 comments on commit 8119e57

Please sign in to comment.