Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Added nagative look-ahead keywords for function invocations in the Rust Language #3883

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {}
Loading