From 50d3a1e9b9b4ce6a72efb6952e7a5142f6468d3f Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Wed, 2 Mar 2022 20:05:05 -0500 Subject: [PATCH] enh(objc) add scopes `type` and `variable.language` (#3499) --- CHANGES.md | 1 + src/languages/objectivec.js | 37 +++++++++++-------- .../markup/objectivec/preprocessor.expect.txt | 6 +-- .../objectivec/string-literals.expect.txt | 12 +++--- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e46b22fe81..2ad4fc51f6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ New Grammars: Grammars: +- enh(objectivec) add `type` and `variable.language` scopes [Josh Goebel][] - enh(xml) support processing instructions (#3492) [Josh Goebel][] - enh(ruby ) better support multi-line IRB prompts - enh(bash) improved keyword `$pattern` (numbers allowed in command names) [Martin Mattel][] diff --git a/src/languages/objectivec.js b/src/languages/objectivec.js index 72167648fa..0f9f67beeb 100644 --- a/src/languages/objectivec.js +++ b/src/languages/objectivec.js @@ -12,11 +12,25 @@ export default function(hljs) { begin: '\\b(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)\\w+' }; const IDENTIFIER_RE = /[a-zA-Z@][a-zA-Z0-9_]*/; - const KWS = [ + const TYPES = [ "int", "float", - "while", "char", + "unsigned", + "signed", + "short", + "long", + "double", + "wchar_t", + "unichar", + "void", + "bool", + "BOOL", + "id|0", + "_Bool" + ]; + const KWS = [ + "while", "export", "sizeof", "typedef", @@ -24,34 +38,25 @@ export default function(hljs) { "struct", "for", "union", - "unsigned", - "long", "volatile", "static", - "bool", "mutable", "if", "do", "return", "goto", - "void", "enum", "else", "break", "extern", "asm", "case", - "short", "default", - "double", "register", "explicit", - "signed", "typename", - "this", "switch", "continue", - "wchar_t", "inline", "readonly", "assign", @@ -61,8 +66,6 @@ export default function(hljs) { "id", "typeof", "nonatomic", - "super", - "unichar", "IBOutlet", "IBAction", "strong", @@ -153,7 +156,6 @@ export default function(hljs) { "NULL" ]; const BUILT_INS = [ - "BOOL", "dispatch_once_t", "dispatch_queue_t", "dispatch_sync", @@ -161,10 +163,15 @@ export default function(hljs) { "dispatch_once" ]; const KEYWORDS = { + "variable.language": [ + "this", + "super" + ], $pattern: IDENTIFIER_RE, keyword: KWS, literal: LITERALS, - built_in: BUILT_INS + built_in: BUILT_INS, + type: TYPES }; const CLASS_KEYWORDS = { $pattern: IDENTIFIER_RE, diff --git a/test/markup/objectivec/preprocessor.expect.txt b/test/markup/objectivec/preprocessor.expect.txt index b69e9b5aa0..09bf75aefa 100644 --- a/test/markup/objectivec/preprocessor.expect.txt +++ b/test/markup/objectivec/preprocessor.expect.txt @@ -2,9 +2,9 @@ #define foo 1<<16 #ifdef DEBUG -TYPE1 foo(void) +TYPE1 foo(void) #else -int foo(void) +int foo(void) #endif { } @@ -15,5 +15,5 @@ TYPE1 foo(void) #if MACRO_WITH_STRING_ARG("hello \"world\"") #elif MULTI_LINE /* comment */ < \ EXPRESSION -int bar; +int bar; #endif // comment diff --git a/test/markup/objectivec/string-literals.expect.txt b/test/markup/objectivec/string-literals.expect.txt index a59d6c08c1..4446ce05c5 100644 --- a/test/markup/objectivec/string-literals.expect.txt +++ b/test/markup/objectivec/string-literals.expect.txt @@ -1,7 +1,7 @@ -const char *str = "Regular \"quoted\" string\n"; +const char *str = "Regular \"quoted\" string\n"; NSString *nsstr = @"Obj-C \"quoted\" string\n"; -char c = 'c'; -char c2 = '"'; -char c3 = '\''; -char c4 = '\n'; -int multibyte_char = 'abcd'; +char c = 'c'; +char c2 = '"'; +char c3 = '\''; +char c4 = '\n'; +int multibyte_char = 'abcd';