Objective C: Improved `string` token (#3235)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
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'"]
]