Explorar el Código

Separate constructors and constants from keywords

Matt Masson hace 7 años
padre
commit
b261c99d53
Se han modificado 2 ficheros con 56 adiciones y 9 borrados
  1. 35 3
      src/powerquery/powerquery.test.ts
  2. 21 6
      src/powerquery/powerquery.ts

+ 35 - 3
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" },
 		]
 	}],
 ]);

+ 21 - 6
src/powerquery/powerquery.ts

@@ -39,11 +39,24 @@ export const language = <ILanguage>{
 		"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 = <ILanguage>{
 			[/(#?[a-z]+)/,
 				{
 					cases: {
-						"@typeKeywords": "keyword.type",
+						"@typeKeywords": "type",
 						"@keywords": "keyword",
+						"@constants": "constant",
+						"@constructors": "constructor",
 						"@default": "identifier"
 					}
 				}