summaryrefslogtreecommitdiff
path: root/cli/repl.rs
diff options
context:
space:
mode:
authorali ahmed <48116123+AliBasicCoder@users.noreply.github.com>2020-11-05 05:08:01 +0200
committerGitHub <noreply@github.com>2020-11-05 14:08:01 +1100
commite7cfd90b0f72874aa1535a382df32dce28bd587a (patch)
tree9ea82e87c782309495b9da1426c96d3d3712fcf8 /cli/repl.rs
parent6dd76332619c917e0d00766fe84e9205b8311e79 (diff)
fix(cli/repl): Fixing syntax highlighting (#8202)
Fixes #8240
Diffstat (limited to 'cli/repl.rs')
-rw-r--r--cli/repl.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/cli/repl.rs b/cli/repl.rs
index b2ea32670..b5f89ec51 100644
--- a/cli/repl.rs
+++ b/cli/repl.rs
@@ -222,11 +222,15 @@ impl LineHighlighter {
(?P<comment>(?:/\*[\s\S]*?\*/|//[^\n]*)) |
(?P<string>(?:"([^"\\]|\\.)*"|'([^'\\]|\\.)*'|`([^`\\]|\\.)*`)) |
(?P<regexp>/(?:(?:\\/|[^\n/]))*?/[gimsuy]*) |
- (?P<number>\d+(?:\.\d+)*(?:e[+-]?\d+)*n?) |
+ (?P<number>\b\d+(?:\.\d+)?(?:e[+-]?\d+)*n?\b) |
+ (?P<infinity>\b(?:Infinity|NaN)\b) |
+ (?P<hexnumber>\b0x[a-fA-F0-9]+\b) |
+ (?P<octalnumber>\b0o[0-7]+\b) |
+ (?P<binarynumber>\b0b[01]+\b) |
(?P<boolean>\b(?:true|false)\b) |
(?P<null>\b(?:null)\b) |
(?P<undefined>\b(?:undefined)\b) |
- (?P<keyword>\b(?:await|async|var|let|for|if|else|in|of|class|const|function|yield|return|with|case|break|switch|import|export|new|while|do|throw|catch)\b) |
+ (?P<keyword>\b(?:await|async|var|let|for|if|else|in|of|class|const|function|yield|return|with|case|break|switch|import|export|new|while|do|throw|catch|this)\b) |
"#,
)
.unwrap();
@@ -256,6 +260,16 @@ impl Highlighter for LineHighlighter {
format!("{}", colors::gray(cap.as_str()))
} else if let Some(cap) = caps.name("keyword") {
format!("{}", colors::cyan(cap.as_str()))
+ } else if let Some(cap) = caps.name("infinity") {
+ format!("{}", colors::yellow(cap.as_str()))
+ } else if let Some(cap) = caps.name("classes") {
+ format!("{}", colors::green_bold(cap.as_str()))
+ } else if let Some(cap) = caps.name("hexnumber") {
+ format!("{}", colors::yellow(cap.as_str()))
+ } else if let Some(cap) = caps.name("octalnumber") {
+ format!("{}", colors::yellow(cap.as_str()))
+ } else if let Some(cap) = caps.name("binarynumber") {
+ format!("{}", colors::yellow(cap.as_str()))
} else {
caps[0].to_string()
}