From e38278d2a53abfd9c400fb6ab83eace78a706264 Mon Sep 17 00:00:00 2001 From: Josh Crisp Date: Tue, 15 Feb 2022 16:52:08 -0800 Subject: [PATCH] Skip char and string literals when highlighting comments --- src/semantic_tokens.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/semantic_tokens.zig b/src/semantic_tokens.zig index beb448d..32811fb 100644 --- a/src/semantic_tokens.zig +++ b/src/semantic_tokens.zig @@ -138,6 +138,30 @@ const Builder = struct { var i: usize = from; while (i < to - 1) : (i += 1) { + // Skip multi-line string literals + if (source[i] == '\\' and source[i + 1] == '\\') { + while (i < to - 1 and source[i] != '\n') : (i += 1) {} + continue; + } + // Skip normal string literals + if (source[i] == '"') { + i += 1; + while (i < to - 1 and + source[i] != '\n' and + !(source[i] == '"' and source[i - 1] != '\\')) : (i += 1) + {} + continue; + } + // Skip char literals + if (source[i] == '\'') { + i += 1; + while (i < to - 1 and + source[i] != '\n' and + !(source[i] == '\'' and source[i - 1] != '\\')) : (i += 1) + {} + continue; + } + if (source[i] != '/' or source[i + 1] != '/') continue;