Commit 8e0e95f305c43e7a4bf38a1053c0d52ce8f4db91

Michael Schmidt 2021-12-07T13:01:13

Objective C: Improved `string` token (#3235)

diff --git a/components/prism-objectivec.js b/components/prism-objectivec.js
index 412ab7f..e17fc4e 100644
--- a/components/prism-objectivec.js
+++ b/components/prism-objectivec.js
@@ -1,5 +1,8 @@
 Prism.languages.objectivec = Prism.languages.extend('c', {
-	'string': /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|@"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,
+	'string': {
+		pattern: /@?"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,
+		greedy: true
+	},
 	'keyword': /\b(?:asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|in|inline|int|long|register|return|self|short|signed|sizeof|static|struct|super|switch|typedef|typeof|union|unsigned|void|volatile|while)\b|(?:@interface|@end|@implementation|@protocol|@class|@public|@protected|@private|@property|@try|@catch|@finally|@throw|@synthesize|@dynamic|@selector)\b/,
 	'operator': /-[->]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|\|?|[~^%?*\/@]/
 });
diff --git a/components/prism-objectivec.min.js b/components/prism-objectivec.min.js
index 75763b2..f893297 100644
--- a/components/prism-objectivec.min.js
+++ b/components/prism-objectivec.min.js
@@ -1 +1 @@
-Prism.languages.objectivec=Prism.languages.extend("c",{string:/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|@"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,keyword:/\b(?:asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|in|inline|int|long|register|return|self|short|signed|sizeof|static|struct|super|switch|typedef|typeof|union|unsigned|void|volatile|while)\b|(?:@interface|@end|@implementation|@protocol|@class|@public|@protected|@private|@property|@try|@catch|@finally|@throw|@synthesize|@dynamic|@selector)\b/,operator:/-[->]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|\|?|[~^%?*\/@]/}),delete Prism.languages.objectivec["class-name"],Prism.languages.objc=Prism.languages.objectivec;
\ No newline at end of file
+Prism.languages.objectivec=Prism.languages.extend("c",{string:{pattern:/@?"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,greedy:!0},keyword:/\b(?:asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|in|inline|int|long|register|return|self|short|signed|sizeof|static|struct|super|switch|typedef|typeof|union|unsigned|void|volatile|while)\b|(?:@interface|@end|@implementation|@protocol|@class|@public|@protected|@private|@property|@try|@catch|@finally|@throw|@synthesize|@dynamic|@selector)\b/,operator:/-[->]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|\|?|[~^%?*\/@]/}),delete Prism.languages.objectivec["class-name"],Prism.languages.objc=Prism.languages.objectivec;
\ No newline at end of file
diff --git a/tests/languages/objectivec/char_feature.test b/tests/languages/objectivec/char_feature.test
index cf11705..a97fc67 100644
--- a/tests/languages/objectivec/char_feature.test
+++ b/tests/languages/objectivec/char_feature.test
@@ -1,12 +1,15 @@
-''
-'fo\'o'
-'foo\
-bar'
+'a'
+'\n'
+'\000'
+'\x00'
+'\u0000'
 
 ----------------------------------------------------
 
 [
-	["char", "''"],
-	["char", "'fo\\'o'"],
-	["char", "'foo\\\r\nbar'"]
+	["char", "'a'"],
+	["char", "'\\n'"],
+	["char", "'\\000'"],
+	["char", "'\\x00'"],
+	["char", "'\\u0000'"]
 ]