From 530f45f7a474e7ead101971d52babe754bc2d51f Mon Sep 17 00:00:00 2001 From: HalidOdat Date: Mon, 27 Jul 2020 09:56:13 +0200 Subject: [PATCH] Added syntax highlighting for strings --- boa_cli/src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/boa_cli/src/main.rs b/boa_cli/src/main.rs index a666dc4a10d..a40290f42f9 100644 --- a/boa_cli/src/main.rs +++ b/boa_cli/src/main.rs @@ -345,9 +345,11 @@ impl Highlighter for LineHighlighter { let mut coloured = line.to_string(); let reg = Regex::new( - r"(?x) + r#"(?x) (?P[$A-z_]+[$A-z_0-9]*) | - (?P[+\-/*%~^!&|=<>,.;:])", + (?P"([^"\\]|\\.)*") | + (?P'([^'\\]|\\.)*') | + (?P[+\-/*%~^!&|=<>;:])"#, ) .unwrap(); @@ -362,8 +364,12 @@ impl Highlighter for LineHighlighter { } _ => cap.as_str().to_string(), } - } else if let Some(cap) = caps.name("op") { + } else if let Some(cap) = caps.name("string_double_quote") { + cap.as_str().green().to_string() + } else if let Some(cap) = caps.name("string_single_quote") { cap.as_str().green().to_string() + } else if let Some(cap) = caps.name("op") { + cap.as_str().truecolor(214, 95, 26).to_string() } else { caps[0].to_string() }