[llvm] [llvm-lit] Support curly brace syntax in lit internal shell (PR #102829)

via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 11 13:51:08 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r b7c7dbd473c0857d0d86b228e45ce5a0a68a1a1b...01e06397c138a42516f65e16782eb069651b29fa llvm/utils/lit/lit/ShCommands.py llvm/utils/lit/lit/ShUtil.py llvm/utils/lit/lit/TestRunner.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- ShUtil.py	2024-08-11 20:47:18.000000 +0000
+++ ShUtil.py	2024-08-11 20:50:42.446994 +0000
@@ -159,11 +159,11 @@
         c = self.eat()
         if c == "{" or c == "}":
             return (c,)
         if c == ";":
             if self.maybe_eat("}") or (self.maybe_eat(" ") and self.maybe_eat("}")):
-                return("}",)
+                return ("}",)
             return (c,)
         if c == "|":
             if self.maybe_eat("|"):
                 return ("||",)
             return (c,)
@@ -203,11 +203,11 @@
     def __init__(self, data, win32Escapes=False, pipefail=False):
         self.data = data
         self.pipefail = pipefail
         self.tokens = ShLexer(data, win32Escapes=win32Escapes).lex()
         self.brace_stack = []
-        self.brace_dict = {'{': '}'}
+        self.brace_dict = {"{": "}"}
 
     def lex(self):
         for item in self.tokens:
             return item
         return None
@@ -259,22 +259,21 @@
         commands = [self.parse_command()]
         while self.look() == ("|",):
             self.lex()
             commands.append(self.parse_command())
         return Pipeline(commands, negate, self.pipefail)
-            
-    
+
     # {echo foo; echo bar;} && echo hello
     # echo hello && {echo foo; echo bar}
-    
+
     def parse(self, seq_type):
         lhs = None
         if isinstance(self.look(), tuple):
             brace = self.lex()
             self.brace_stack.append(brace)
-            if brace[0] == '{':
-                lhs = self.parse(('{', '}'))
+            if brace[0] == "{":
+                lhs = self.parse(("{", "}"))
             else:
                 raise ValueError("syntax error near unexpected token %r" % brace[0])
 
         else:
             lhs = self.parse_pipeline()
@@ -289,14 +288,14 @@
             if not self.look():
                 raise ValueError("missing argument to operator %r" % operator[0])
 
             # FIXME: Operator precedence!!
             if isinstance(self.look(), tuple):
-                lhs = self.parse(('{', '}'))
-            else: 
+                lhs = self.parse(("{", "}"))
+            else:
                 lhs = Seq(lhs, operator[0], self.parse_pipeline(), seq_type)
             seq_type = None
-        
+
         if not stack.empty():
             raise ValueError("missing token to %r" % stack.peek())
 
         return lhs
--- TestRunner.py	2024-08-11 20:47:18.000000 +0000
+++ TestRunner.py	2024-08-11 20:50:43.120715 +0000
@@ -1054,11 +1054,13 @@
                 ln += "has no command after substitutions"
         else:
             ln = command
         try:
             cmds.append(
-                ShUtil.ShParser(ln, litConfig.isWindows, test.config.pipefail).parse(None)
+                ShUtil.ShParser(ln, litConfig.isWindows, test.config.pipefail).parse(
+                    None
+                )
             )
         except:
             raise ScriptFatal(
                 f"shell parser error on {dbg}: {command.lstrip()}\n"
             ) from None

``````````

</details>


https://github.com/llvm/llvm-project/pull/102829


More information about the llvm-commits mailing list