From 63b4bb1e95ae1e436dd5d7886c32b0d7a1377b9b Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 27 Mar 2012 11:00:35 +0200
Subject: [PATCH] Fix escaping of percent signs in the shell lexer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Of course, we do have cases where we want to escape the percent signs,
and our regexes were not fully correct for this case.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 lib/build/shell_example_lexer.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/build/shell_example_lexer.py b/lib/build/shell_example_lexer.py
index c2506156b..401ad65f2 100644
--- a/lib/build/shell_example_lexer.py
+++ b/lib/build/shell_example_lexer.py
@@ -46,12 +46,13 @@ class ShellExampleLexer(RegexLexer):
       # switch to state input on '$ ' at the start of the line
       (r"^\$ ", Text, "input"),
       (r"\s+", Text),
-      (r"[^#%\s]+", Text),
+      (r"[^#%\s\\]+", Text),
+      (r"\\", Text),
       ],
     "input": [
       include("comments"),
       include("userinput"),
-      (r"[^%\\\s]+", Generic.Strong),
+      (r"[^#%\s\\]+", Generic.Strong),
       (r"\\\n", Generic.Strong),
       (r"\\", Generic.Strong),
       # switch to prev state at non-escaped new-line
@@ -62,7 +63,7 @@ class ShellExampleLexer(RegexLexer):
       (r"#.*\n", Comment.Single),
       ],
     "userinput": [
-      (r"\\%", Text),
+      (r"(\\)(%)", bygroups(None, Text)),
       (r"(%)([^%]*)(%)", bygroups(None, Name.Variable, None)),
       ],
     }
-- 
GitLab