From 250f5d42d82044002acb91c47277b54faf9be4ec Mon Sep 17 00:00:00 2001 From: Matt Masson Date: Tue, 10 Jul 2018 15:25:10 -0400 Subject: [PATCH] Split operator keywords and fix "operators" typo --- src/powerquery/powerquery.test.ts | 50 +++++++++++++++++++++++-------- src/powerquery/powerquery.ts | 15 +++++++--- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/powerquery/powerquery.test.ts b/src/powerquery/powerquery.test.ts index 5a202e87..4fe0f2bc 100644 --- a/src/powerquery/powerquery.test.ts +++ b/src/powerquery/powerquery.test.ts @@ -70,7 +70,7 @@ testTokenization('powerquery', [ tokens: [ { startIndex: 0, type: 'number.pq' }, { startIndex: 1, type: 'white.pq' }, - { startIndex: 2, type: 'operator.pq' }, + { startIndex: 2, type: 'operators.pq' }, { startIndex: 3, type: 'white.pq' }, { startIndex: 4, type: 'number.pq' }, { startIndex: 5, type: 'delimiter.pq' }, @@ -92,10 +92,10 @@ testTokenization('powerquery', [ tokens: [ { startIndex: 0, type: 'identifier.quote.pq' }, { startIndex: 7, type: 'white.pq' }, - { startIndex: 8, type: 'operator.pq' }, + { startIndex: 8, type: 'operators.pq' }, { startIndex: 9, type: 'white.pq' }, { startIndex: 10, type: 'number.pq' }, - { startIndex: 11, type: 'operator.pq' }, + { startIndex: 11, type: 'operators.pq' }, { startIndex: 12, type: 'number.pq' }, { startIndex: 13, type: 'delimiter.pq' }, ] @@ -106,10 +106,10 @@ testTokenization('powerquery', [ tokens: [ { startIndex: 0, type: 'identifier.pq' }, { startIndex: 1, type: 'white.pq' }, - { startIndex: 2, type: 'operator.pq' }, + { startIndex: 2, type: 'operators.pq' }, { startIndex: 3, type: 'white.pq' }, { startIndex: 4, type: 'identifier.quote.pq' }, - { startIndex: 15, type: 'operator.pq' }, + { startIndex: 15, type: 'operators.pq' }, { startIndex: 16, type: 'white.pq' }, { startIndex: 17, type: 'number.pq' } ] @@ -121,11 +121,11 @@ testTokenization('powerquery', [ tokens: [ { startIndex: 0, type: 'number.pq' }, { startIndex: 1, type: 'white.pq' }, - { startIndex: 2, type: 'operator.pq' }, + { startIndex: 2, type: 'operators.pq' }, { startIndex: 3, type: 'white.pq' }, { startIndex: 4, type: 'number.float.pq' }, { startIndex: 10, type: 'white.pq' }, - { startIndex: 11, type: 'operator.pq' }, + { startIndex: 11, type: 'operators.pq' }, { startIndex: 12, type: 'white.pq'}, { startIndex: 13, type: 'number.hex.pq'} ] @@ -136,7 +136,7 @@ testTokenization('powerquery', [ tokens: [ { startIndex: 0, type: 'number.hex.pq' }, { startIndex: 3, type: 'white.pq' }, - { startIndex: 4, type: 'operator.pq' }, + { startIndex: 4, type: 'operators.pq' }, { startIndex: 5, type: 'delimiter.parenthesis.pq' }, { startIndex: 6, type: 'number.float.pq' }, { startIndex: 8, type: 'delimiter.parenthesis.pq' } @@ -147,9 +147,9 @@ testTokenization('powerquery', [ line: '1.23e34+1.2e-2-.3e2', tokens: [ { startIndex: 0, type: 'number.float.pq' }, - { startIndex: 7, type: 'operator.pq' }, + { startIndex: 7, type: 'operators.pq' }, { startIndex: 8, type: 'number.float.pq' }, - { startIndex: 14, type: 'operator.pq' }, + { startIndex: 14, type: 'operators.pq' }, { startIndex: 15, type: 'number.float.pq' } ] }], @@ -168,7 +168,7 @@ testTokenization('powerquery', [ tokens: [ { startIndex: 0, type: 'string.pq' }, { startIndex: 8, type: 'white.pq' }, - { startIndex: 9, type: 'operator.pq' }, + { startIndex: 9, type: 'operators.pq' }, { startIndex: 10, type: 'white.pq' }, { startIndex: 11, type: 'string.pq' } ] @@ -240,7 +240,7 @@ testTokenization('powerquery', [ { startIndex: 3, type: "delimiter.parenthesis.pq"}, { startIndex: 4, type: "identifier.pq" }, { startIndex: 5, type: "white.pq" }, - { startIndex: 6, type: "operator.pq" }, + { startIndex: 6, type: "operators.pq" }, { startIndex: 7, type: "white.pq" }, { startIndex: 8, type: "constant.pq" }, { startIndex: 12, type: "delimiter.parenthesis.pq"}, @@ -254,4 +254,30 @@ testTokenization('powerquery', [ { startIndex: 29, type: "identifier.pq" }, ] }], + + // statements + [{ + line: '[version="1.0.0.1"] section Foo; shared Member.Name = 1;', + tokens: [ + { startIndex: 0, type: "delimiter.square.pq" }, + { startIndex: 1, type: "identifier.pq" }, + { startIndex: 8, type: "operators.pq" }, + { startIndex: 9, type: "string.pq" }, + { startIndex: 18, type: "delimiter.square.pq" }, + { startIndex: 19, type: "white.pq" }, + { startIndex: 20, type: "keyword.pq" }, + { startIndex: 27, type: "white.pq" }, + { startIndex: 28, type: "identifier.pq" }, + { startIndex: 31, type: "delimiter.pq" }, + { startIndex: 32, type: "white.pq" }, + { startIndex: 33, type: "keyword.pq" }, + { startIndex: 39, type: "white.pq" }, + { startIndex: 40, type: "identifier.pq" }, + { startIndex: 51, type: "white.pq" }, + { startIndex: 52, type: "operators.pq" }, + { startIndex: 53, type: "white.pq" }, + { startIndex: 54, type: "number.pq" }, + { startIndex: 55, type: "delimiter.pq" } + ] + }], ]); diff --git a/src/powerquery/powerquery.ts b/src/powerquery/powerquery.ts index 86187d76..d72fea34 100644 --- a/src/powerquery/powerquery.ts +++ b/src/powerquery/powerquery.ts @@ -33,11 +33,17 @@ export const language = { { open: '(', close: ')', token: 'delimiter.parenthesis' } ], + operatorKeywords: [ + "and", + "not", + "or" + ], + keywords: [ - "and", "as", "each", "else", + "as", "each", "else", "error", "false", "if", "in", - "is", "let", "meta", "not", - "otherwise", "or", "section", + "is", "let", "meta", + "otherwise", "section", "shared", "then", "true", "try", "type" ], @@ -98,6 +104,7 @@ export const language = { "@keywords": "keyword", "@constants": "constant", "@constructors": "constructor", + "@operatorKeywords": "operators", "@default": "identifier" } } @@ -111,7 +118,7 @@ export const language = { { include: "@strings" }, [/[{}()\[\]]/, "@brackets"], - [/([=\+<>\-\*&@\?\/!])|([<>]=)|(<>)|(=>)|(\.\.\.)|(\.\.)/, "operator"], + [/([=\+<>\-\*&@\?\/!])|([<>]=)|(<>)|(=>)|(\.\.\.)|(\.\.)/, "operators"], [/[,;]/, "delimiter"], ],