]> granicus.if.org Git - clang/commitdiff
lit: Don't treat '\' as an escape in unquoted strings, on Win32. This turns out
authorDaniel Dunbar <daniel@zuster.org>
Mon, 3 Aug 2009 05:29:22 +0000 (05:29 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 3 Aug 2009 05:29:22 +0000 (05:29 +0000)
to not be a very good idea.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77957 91177308-0d34-0410-b5e6-96231b3b80d8

utils/test/ShUtil.py
utils/test/TestRunner.py

index bf56a11413a11957421063b092e07add92527c2b..dd4b584ac00b616d1ad5fc943652ccbeb4e432fb 100644 (file)
@@ -2,14 +2,12 @@ import itertools
 
 import Util
 
-# FIXME: It would be nice to at least match a few other things like `...`, $(
-# ... ), $VAR, etc., if only so we can nicely say "we don't support this".
-
 class ShLexer:
-    def __init__(self, data):
+    def __init__(self, data, win32Escapes = False):
         self.data = data
         self.pos = 0
         self.end = len(data)
+        self.win32Escapes = win32Escapes
 
     def eat(self):
         c = self.data[self.pos]
@@ -67,8 +65,8 @@ class ShLexer:
                 return (tok[0], num)                    
             elif c == '"':
                 self.eat()
-                str += self.lex_arg_quoted('"')
-            elif c == '\\':
+                str += self.lex_arg_quoted('"')\r
+            elif not self.win32Escapes and c == '\\':
                 # Outside of a string, '\\' escapes everything.
                 self.eat()
                 if self.pos == self.end:
@@ -211,9 +209,9 @@ class Seq:
                    (other.lhs, other.op, other.rhs))
 
 class ShParser:
-    def __init__(self, data):
+    def __init__(self, data, win32Escapes = False):
         self.data = data
-        self.tokens = ShLexer(data).lex()
+        self.tokens = ShLexer(data, win32Escapes = win32Escapes).lex()
     
     def lex(self):
         try:
@@ -294,8 +292,8 @@ class ShParser:
 import unittest
 
 class TestShLexer(unittest.TestCase):
-    def lex(self, str):
-        return list(ShLexer(str).lex())
+    def lex(self, str, *args, **kwargs):
+        return list(ShLexer(str, *args, **kwargs).lex())
 
     def test_basic(self):
         self.assertEqual(self.lex('a|b>c&d<e'),
@@ -323,6 +321,8 @@ class TestShLexer(unittest.TestCase):
                          ["a b", "a\\b"])
         self.assertEqual(self.lex(""" "" "" """),
                          ["", ""])
+        self.assertEqual(self.lex(""" a\\ b """, win32Escapes = True),
+                         ['a\\', 'b'])
 
 class TestShParse(unittest.TestCase):
     def parse(self, str):
index 42799093d195929cf24ef7ae854c7a1701e8e9a5..3c0c8072c21b5bf2975cddd384c16a520caeb7cc 100755 (executable)
@@ -110,7 +110,8 @@ def executeShCmd(cmd, cfg, cwd, results):
     return exitCode
         
 def executeScriptInternal(cfg, commands, cwd):
-    cmd = ShUtil.ShParser(' &&\n'.join(commands)).parse()
+    cmd = ShUtil.ShParser(' &&\n'.join(commands), 
+                          kSystemName == 'Windows').parse()
 
     results = []
     try: