From b261c99d53b6949dfb3ac74d580ce016c6e30f3b Mon Sep 17 00:00:00 2001 From: Matt Masson Date: Tue, 10 Jul 2018 15:04:43 -0400 Subject: [PATCH] Separate constructors and constants from keywords --- src/powerquery/powerquery.test.ts | 38 ++++++++++++++++++++++++++++--- src/powerquery/powerquery.ts | 27 +++++++++++++++++----- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/powerquery/powerquery.test.ts b/src/powerquery/powerquery.test.ts index a8c5a064..5a202e87 100644 --- a/src/powerquery/powerquery.test.ts +++ b/src/powerquery/powerquery.test.ts @@ -185,7 +185,7 @@ testTokenization('powerquery', [ ] }], - // keywords and identifiers + // built-in keywords/identifiers [{ line: 'And as Each each _', tokens: [ @@ -205,7 +205,7 @@ testTokenization('powerquery', [ line: ' #table({})', tokens: [ { startIndex: 0, type: 'white.pq' }, - { startIndex: 2, type: 'keyword.pq' }, + { startIndex: 2, type: 'constructor.pq' }, { startIndex: 8, type: "delimiter.parenthesis.pq" }, { startIndex: 9, type: "delimiter.brackets.pq" }, { startIndex: 11, type: "delimiter.parenthesis.pq" } @@ -219,7 +219,39 @@ testTokenization('powerquery', [ { startIndex: 5, type: 'white.pq' }, { startIndex: 6, type: 'keyword.pq' }, { startIndex: 8, type: 'white.pq' }, - { startIndex: 9, type: 'keyword.type.pq' } + { startIndex: 9, type: 'type.pq' } + ] + }], + + [{ + line: 'type table', + tokens: [ + { startIndex: 0, type: 'keyword.pq' }, + { startIndex: 4, type: 'white.pq' }, + { startIndex: 5, type: 'type.pq' } + ] + }], + + [{ + line: 'if (a = #nan) then null else a', + tokens: [ + { startIndex: 0, type: "keyword.pq" }, + { startIndex: 2, type: "white.pq" }, + { startIndex: 3, type: "delimiter.parenthesis.pq"}, + { startIndex: 4, type: "identifier.pq" }, + { startIndex: 5, type: "white.pq" }, + { startIndex: 6, type: "operator.pq" }, + { startIndex: 7, type: "white.pq" }, + { startIndex: 8, type: "constant.pq" }, + { startIndex: 12, type: "delimiter.parenthesis.pq"}, + { startIndex: 13, type: "white.pq" }, + { startIndex: 14, type: "keyword.pq" }, + { startIndex: 18, type: "white.pq" }, + { startIndex: 19, type: "type.pq" }, + { startIndex: 23, type: "white.pq" }, + { startIndex: 24, type: "keyword.pq" }, + { startIndex: 28, type: "white.pq" }, + { startIndex: 29, type: "identifier.pq" }, ] }], ]); diff --git a/src/powerquery/powerquery.ts b/src/powerquery/powerquery.ts index 48579d6f..86187d76 100644 --- a/src/powerquery/powerquery.ts +++ b/src/powerquery/powerquery.ts @@ -39,11 +39,24 @@ export const language = { "is", "let", "meta", "not", "otherwise", "or", "section", "shared", "then", "true", - "try", "type", "#binary", - "#date", "#datetime", - "#datetimezone", "#duration", - "#infinity", "#nan", "#sections", - "#shared", "#table", "#time" + "try", "type" + ], + + constructors: [ + "#binary", + "#date", + "#datetime", + "#datetimezone", + "#duration", + "#table", + "#time" + ], + + constants: [ + "#infinity", + "#nan", + "#sections", + "#shared" ], typeKeywords: [ @@ -81,8 +94,10 @@ export const language = { [/(#?[a-z]+)/, { cases: { - "@typeKeywords": "keyword.type", + "@typeKeywords": "type", "@keywords": "keyword", + "@constants": "constant", + "@constructors": "constructor", "@default": "identifier" } }