Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

connieyzhu
Copy link
Contributor

This patch implements parsing and execution of a series of commands grouped in curly braces in lit's internal shell. This addresses goals mentioned in this RFC: https://discourse.llvm.org/t/rfc-enabling-the-lit-internal-shell-by-default/80179.

Fixes #102382

This is a draft of the parsing implementation to support curly brace
syntax in lit's internal shell.
Copy link

⚠️ Python code formatter, darker found issues in your code. ⚠️

You can test this locally with the following command:
darker --check --diff -r b7c7dbd473c0857d0d86b228e45ce5a0a68a1a1b...01e06397c138a42516f65e16782eb069651b29fa llvm/utils/lit/lit/ShCommands.py llvm/utils/lit/lit/ShUtil.py llvm/utils/lit/lit/TestRunner.py
View the diff from darker here.
--- 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

@connieyzhu connieyzhu closed this Aug 11, 2024
@connieyzhu connieyzhu deleted the grouped-commands branch August 11, 2024 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[llvm-lit] lit internal shell failing to parse and execute curly brace syntax
1 participant