Skip to content

Commit

Permalink
enh(objc) add scopes type and variable.language (#3499)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel authored Mar 3, 2022
1 parent f2c6652 commit 50d3a1e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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][]
Expand Down
37 changes: 22 additions & 15 deletions src/languages/objectivec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,51 @@ 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",
"const",
"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",
Expand All @@ -61,8 +66,6 @@ export default function(hljs) {
"id",
"typeof",
"nonatomic",
"super",
"unichar",
"IBOutlet",
"IBAction",
"strong",
Expand Down Expand Up @@ -153,18 +156,22 @@ export default function(hljs) {
"NULL"
];
const BUILT_INS = [
"BOOL",
"dispatch_once_t",
"dispatch_queue_t",
"dispatch_sync",
"dispatch_async",
"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,
Expand Down
6 changes: 3 additions & 3 deletions test/markup/objectivec/preprocessor.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<span class="hljs-meta">#<span class="hljs-keyword">define</span> foo 1&lt;&lt;16</span>

<span class="hljs-meta">#<span class="hljs-keyword">ifdef</span> DEBUG</span>
TYPE1 foo(<span class="hljs-keyword">void</span>)
TYPE1 foo(<span class="hljs-type">void</span>)
<span class="hljs-meta">#<span class="hljs-keyword">else</span></span>
<span class="hljs-keyword">int</span> foo(<span class="hljs-keyword">void</span>)
<span class="hljs-type">int</span> foo(<span class="hljs-type">void</span>)
<span class="hljs-meta">#<span class="hljs-keyword">endif</span></span>
{ }

Expand All @@ -15,5 +15,5 @@ TYPE1 foo(<span class="hljs-keyword">void</span>)
<span class="hljs-meta">#<span class="hljs-keyword">if</span> MACRO_WITH_STRING_ARG(<span class="hljs-string">&quot;hello \&quot;world\&quot;&quot;</span>)</span>
<span class="hljs-meta">#<span class="hljs-keyword">elif</span> MULTI_LINE <span class="hljs-comment">/* comment */</span> &lt; \
EXPRESSION</span>
<span class="hljs-keyword">int</span> bar;
<span class="hljs-type">int</span> bar;
<span class="hljs-meta">#<span class="hljs-keyword">endif</span> <span class="hljs-comment">// comment</span></span>
12 changes: 6 additions & 6 deletions test/markup/objectivec/string-literals.expect.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<span class="hljs-keyword">const</span> <span class="hljs-keyword">char</span> *str = <span class="hljs-string">&quot;Regular \&quot;quoted\&quot; string\n&quot;</span>;
<span class="hljs-keyword">const</span> <span class="hljs-type">char</span> *str = <span class="hljs-string">&quot;Regular \&quot;quoted\&quot; string\n&quot;</span>;
<span class="hljs-built_in">NSString</span> *nsstr = <span class="hljs-string">@&quot;Obj-C \&quot;quoted\&quot; string\n&quot;</span>;
<span class="hljs-keyword">char</span> c = <span class="hljs-string">&#x27;c&#x27;</span>;
<span class="hljs-keyword">char</span> c2 = <span class="hljs-string">&#x27;&quot;&#x27;</span>;
<span class="hljs-keyword">char</span> c3 = <span class="hljs-string">&#x27;\&#x27;&#x27;</span>;
<span class="hljs-keyword">char</span> c4 = <span class="hljs-string">&#x27;\n&#x27;</span>;
<span class="hljs-keyword">int</span> multibyte_char = <span class="hljs-string">&#x27;abcd&#x27;</span>;
<span class="hljs-type">char</span> c = <span class="hljs-string">&#x27;c&#x27;</span>;
<span class="hljs-type">char</span> c2 = <span class="hljs-string">&#x27;&quot;&#x27;</span>;
<span class="hljs-type">char</span> c3 = <span class="hljs-string">&#x27;\&#x27;&#x27;</span>;
<span class="hljs-type">char</span> c4 = <span class="hljs-string">&#x27;\n&#x27;</span>;
<span class="hljs-type">int</span> multibyte_char = <span class="hljs-string">&#x27;abcd&#x27;</span>;

0 comments on commit 50d3a1e

Please sign in to comment.