Browse Source

Merge pull request #3864 from yuri1969/yaml-fixes

Various YAML improvements
Henning Dieterichs 2 years ago
parent
commit
f3cac1faff
2 changed files with 195 additions and 2 deletions
  1. 193 0
      src/basic-languages/yaml/yaml.test.ts
  2. 2 2
      src/basic-languages/yaml/yaml.ts

+ 193 - 0
src/basic-languages/yaml/yaml.test.ts

@@ -458,6 +458,7 @@ testTokenization('yaml', [
 				{ startIndex: 4, type: 'operators.yaml' },
 				{ startIndex: 5, type: 'white.yaml' },
 				{ startIndex: 6, type: 'string.yaml' },
+				{ startIndex: 28, type: 'white.yaml' },
 				{ startIndex: 29, type: 'comment.yaml' }
 			]
 		}
@@ -470,8 +471,200 @@ testTokenization('yaml', [
 				{ startIndex: 6, type: 'operators.yaml' },
 				{ startIndex: 7, type: 'white.yaml' },
 				{ startIndex: 8, type: 'string.yaml' },
+				{ startIndex: 9, type: 'white.yaml' },
 				{ startIndex: 10, type: 'comment.yaml' }
 			]
 		}
+	],
+
+	// ': ' in double-quoted Value
+	[
+		{
+			line: 'key: "va: lue"',
+			tokens: [
+				{
+					startIndex: 0,
+					type: 'type.yaml'
+				},
+				{
+					startIndex: 3,
+					type: 'operators.yaml'
+				},
+				{
+					startIndex: 4,
+					type: 'white.yaml'
+				},
+				{
+					startIndex: 5,
+					type: 'string.yaml'
+				}
+			]
+		}
+	],
+
+	// ': ' in single-quoted Value
+	[
+		{
+			line: "key: 'va: lue'",
+			tokens: [
+				{
+					startIndex: 0,
+					type: 'type.yaml'
+				},
+				{
+					startIndex: 3,
+					type: 'operators.yaml'
+				},
+				{
+					startIndex: 4,
+					type: 'white.yaml'
+				},
+				{
+					startIndex: 5,
+					type: 'string.yaml'
+				}
+			]
+		}
+	],
+
+	// '#' in single-quoted Value
+	[
+		{
+			line: "key: 'va#lue'",
+			tokens: [
+				{
+					startIndex: 0,
+					type: 'type.yaml'
+				},
+				{
+					startIndex: 3,
+					type: 'operators.yaml'
+				},
+				{
+					startIndex: 4,
+					type: 'white.yaml'
+				},
+				{
+					startIndex: 5,
+					type: 'string.yaml'
+				}
+			]
+		}
+	],
+
+	// '#' in double-quoted Value
+	[
+		{
+			line: 'key: "va#lue"',
+			tokens: [
+				{
+					startIndex: 0,
+					type: 'type.yaml'
+				},
+				{
+					startIndex: 3,
+					type: 'operators.yaml'
+				},
+				{
+					startIndex: 4,
+					type: 'white.yaml'
+				},
+				{
+					startIndex: 5,
+					type: 'string.yaml'
+				}
+			]
+		}
+	],
+
+	// '#' in  Value
+	[
+		{
+			line: 'key: va#lue',
+			tokens: [
+				{
+					startIndex: 0,
+					type: 'type.yaml'
+				},
+				{
+					startIndex: 3,
+					type: 'operators.yaml'
+				},
+				{
+					startIndex: 4,
+					type: 'white.yaml'
+				},
+				{
+					startIndex: 5,
+					type: 'string.yaml'
+				}
+			]
+		}
+	],
+
+	// Comment following Value
+	[
+		{
+			line: 'key: value #comment',
+			tokens: [
+				{
+					startIndex: 0,
+					type: 'type.yaml'
+				},
+				{
+					startIndex: 3,
+					type: 'operators.yaml'
+				},
+				{
+					startIndex: 4,
+					type: 'white.yaml'
+				},
+				{
+					startIndex: 5,
+					type: 'string.yaml'
+				},
+				{
+					startIndex: 10,
+					type: 'white.yaml'
+				},
+				{
+					startIndex: 11,
+					type: 'comment.yaml'
+				}
+			]
+		}
+	],
+
+	// ': ' in Comment following Value
+	[
+		{
+			line: 'key: value #comment: also comment',
+			tokens: [
+				{
+					startIndex: 0,
+					type: 'type.yaml'
+				},
+				{
+					startIndex: 3,
+					type: 'operators.yaml'
+				},
+				{
+					startIndex: 4,
+					type: 'white.yaml'
+				},
+				{
+					startIndex: 5,
+					type: 'string.yaml'
+				},
+				{
+					startIndex: 10,
+					type: 'white.yaml'
+				},
+				{
+					startIndex: 11,
+					type: 'comment.yaml'
+				}
+			]
+		}
 	]
 ]);

+ 2 - 2
src/basic-languages/yaml/yaml.ts

@@ -86,13 +86,13 @@ export const language = <languages.IMonarchLanguage>{
 			[/@numberDate(?![ \t]*\S+)/, 'number.date'],
 
 			// Key:Value pair
-			[/(".*?"|'.*?'|.*?)([ \t]*)(:)( |$)/, ['type', 'white', 'operators', 'white']],
+			[/(".*?"|'.*?'|[^#'"]*?)([ \t]*)(:)( |$)/, ['type', 'white', 'operators', 'white']],
 
 			{ include: '@flowScalars' },
 
 			// String nodes
 			[
-				/[^#]+/,
+				/.+?(?=(\s+#|$))/,
 				{
 					cases: {
 						'@keywords': 'keyword',