1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 00:29:09 -05:00

fix(cli/repl): Fixing syntax highlighting (#8202)

Fixes #8240
This commit is contained in:
ali ahmed 2020-11-05 05:08:01 +02:00 committed by GitHub
parent 6dd7633261
commit e7cfd90b0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -222,11 +222,15 @@ impl LineHighlighter {
(?P<comment>(?:/\*[\s\S]*?\*/|//[^\n]*)) | (?P<comment>(?:/\*[\s\S]*?\*/|//[^\n]*)) |
(?P<string>(?:"([^"\\]|\\.)*"|'([^'\\]|\\.)*'|`([^`\\]|\\.)*`)) | (?P<string>(?:"([^"\\]|\\.)*"|'([^'\\]|\\.)*'|`([^`\\]|\\.)*`)) |
(?P<regexp>/(?:(?:\\/|[^\n/]))*?/[gimsuy]*) | (?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<boolean>\b(?:true|false)\b) |
(?P<null>\b(?:null)\b) | (?P<null>\b(?:null)\b) |
(?P<undefined>\b(?:undefined)\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(); .unwrap();
@ -256,6 +260,16 @@ impl Highlighter for LineHighlighter {
format!("{}", colors::gray(cap.as_str())) format!("{}", colors::gray(cap.as_str()))
} else if let Some(cap) = caps.name("keyword") { } else if let Some(cap) = caps.name("keyword") {
format!("{}", colors::cyan(cap.as_str())) 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 { } else {
caps[0].to_string() caps[0].to_string()
} }