Browse Source

Fix yaml string tokenization

Grzegorz Wcisło 6 years ago
parent
commit
4b0d5c54d2
2 changed files with 38 additions and 15 deletions
  1. 29 0
      src/yaml/yaml.test.ts
  2. 9 15
      src/yaml/yaml.ts

+ 29 - 0
src/yaml/yaml.test.ts

@@ -241,6 +241,35 @@ testTokenization('yaml', [
 		},]
 	}],
 
+    // Flow Scalars
+    [{
+        line: '\'this is a single quote string\'',
+        tokens: [{
+            startIndex: 0,
+            type: 'string.yaml'
+        }]
+    }],
+
+    [{
+        line: "\"this is a double \\quote string\\n\"",
+        tokens: [{
+            startIndex: 0,
+            type: 'string.yaml'
+        }, {
+            startIndex: 18,
+            type: 'string.escape.invalid.yaml'
+        }, {
+            startIndex: 20,
+            type: 'string.yaml'
+        }, {
+            startIndex: 31,
+            type: 'string.escape.yaml'
+        }, {
+            startIndex: 33,
+            type: 'string.yaml'
+        }]
+    }],
+
 	// Flow Sequence - Data types
 	[{
 		line: '[string,"double",\'single\',1,1.1,2002-04-28]',

+ 9 - 15
src/yaml/yaml.ts

@@ -156,19 +156,6 @@ export const language = <ILanguage>{
 			}]
 		],
 
-		// Flow Scalars (quoted strings)
-		string: [
-			[/[^\\"']+/, 'string'],
-			[/@escapes/, 'string.escape'],
-			[/\\./, 'string.escape.invalid'],
-			[/["']/, {
-				cases: {
-					'$#==$S2': { token: 'string', next: '@pop' },
-					'@default': 'string'
-				}
-			}]
-		],
-
 		// First line of a Block Style
 		multiString: [
 			[/^( +).+$/, 'string', '@multiStringContinued.$1']
@@ -202,8 +189,15 @@ export const language = <ILanguage>{
 
 		// Start Flow Scalars (quoted strings)
 		flowScalars: [
-			[/"/, 'string', '@string."'],
-			[/'/, 'string', '@string.\'']
+			[/'[^']*'/, 'string'],
+			[/"/, 'string', '@doubleQuotedString']
+		],
+
+		doubleQuotedString: [
+			[/[^\\"]+/, 'string'],
+			[/@escapes/, 'string.escape'],
+			[/\\./, 'string.escape.invalid'],
+            [/"/, 'string', '@pop']
 		],
 
 		// Start Block Scalar