-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[llvm-lit] Support curly brace syntax in lit internal shell #102830
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,7 +157,11 @@ def lex_one_token(self): | |
lex_one_token - Lex a single 'sh' token.""" | ||
|
||
c = self.eat() | ||
if c == "{" or c == "}": | ||
return (c,) | ||
if c == ";": | ||
if self.maybe_eat("}") or (self.maybe_eat(" ") and self.maybe_eat("}")): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we get a comment here about what's going on? |
||
return("}",) | ||
return (c,) | ||
if c == "|": | ||
if self.maybe_eat("|"): | ||
|
@@ -200,6 +204,8 @@ 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 = {'{': '}'} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you need a |
||
|
||
def lex(self): | ||
for item in self.tokens: | ||
|
@@ -255,18 +261,42 @@ def parse_pipeline(self): | |
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(('{', '}')) | ||
else: | ||
raise ValueError("syntax error near unexpected token %r" % brace[0]) | ||
|
||
def parse(self): | ||
lhs = self.parse_pipeline() | ||
else: | ||
lhs = self.parse_pipeline() | ||
|
||
while self.look(): | ||
operator = self.lex() | ||
assert isinstance(operator, tuple) and len(operator) == 1 | ||
|
||
if operator == self.brace_dict[self.brace_stack.peek()]: | ||
break | ||
|
||
if not self.look(): | ||
raise ValueError("missing argument to operator %r" % operator[0]) | ||
|
||
# FIXME: Operator precedence!! | ||
lhs = Seq(lhs, operator[0], self.parse_pipeline()) | ||
if isinstance(self.look(), tuple): | ||
lhs = self.parse(('{', '}')) | ||
else: | ||
lhs = Seq(lhs, operator[0], self.parse_pipeline(), seq_type) | ||
seq_type = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the |
||
|
||
if not stack.empty(): | ||
raise ValueError("missing token to %r" % stack.peek()) | ||
|
||
return lhs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the type of
seq_type
? What's it's purpose?