Skip to content

Commit

Permalink
fix(rust) Add negative-lookahead for fn like keywords (#3883)
Browse files Browse the repository at this point in the history
  • Loading branch information
omalk98 authored Oct 9, 2023
1 parent fa9a62c commit 1a531f5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ New Grammars:

Core Grammars:

- fix(rust) added negative-lookahead for callable keywords `if` `while` `for` [Omar Hussein][]
- enh(armasm) added `x0-x30` and `w0-w30` ARMv8 registers [Nicholas Thompson][]
- enh(haxe) added `final`, `is`, `macro` keywords and `$` identifiers [Robert Borghese][]
- enh(haxe) support numeric separators and suffixes [Robert Borghese][]
Expand Down
2 changes: 1 addition & 1 deletion src/languages/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function(hljs) {
relevance: 0,
begin: regex.concat(
/\b/,
/(?!let\b)/,
/(?!let|for|while|if|else|match\b)/,
hljs.IDENT_RE,
regex.lookahead(/\s*\(/))
};
Expand Down
7 changes: 7 additions & 0 deletions test/detect/rust/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@ impl From<&'a str> for State {
"closed" => State::Closed,
_ => unreachable!(),
}

if (str == "trans") {
State::Transient;
}
else if str == "start" {
State::Start;
}
}
}
9 changes: 9 additions & 0 deletions test/markup/rust/invoked-keywords.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {}
<span class="hljs-keyword">if</span> <span class="hljs-literal">true</span> {}
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {}
<span class="hljs-keyword">while</span> (<span class="hljs-literal">true</span>) {}
<span class="hljs-keyword">while</span> <span class="hljs-literal">true</span> {}
<span class="hljs-keyword">for</span> (a, b) <span class="hljs-title function_ invoke__">in</span> (<span class="hljs-number">0</span>..<span class="hljs-number">10</span>).<span class="hljs-title function_ invoke__">enumerate</span>() {}
<span class="hljs-keyword">for</span> <span class="hljs-variable">a</span> <span class="hljs-keyword">in</span> <span class="hljs-number">0</span>..<span class="hljs-number">10</span> {}
<span class="hljs-keyword">match</span> <span class="hljs-type">str</span> {}
<span class="hljs-keyword">match</span> (<span class="hljs-type">str</span>) {}
9 changes: 9 additions & 0 deletions test/markup/rust/invoked-keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if (true) {}
if true {}
else if (true) {}
while (true) {}
while true {}
for (a, b) in (0..10).enumerate() {}
for a in 0..10 {}
match str {}
match (str) {}

0 comments on commit 1a531f5

Please sign in to comment.