-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Tree-sitter grammar: support if/else expressions #5343
Conversation
a559e27
to
6512afe
Compare
I wonder if we could write a function in our grammar.js that would abstract over this pattern
like
|
Some initial thoughts:
so, the function would probably be more like
Unrelated note: |
3b74d38
to
86d4295
Compare
repeat1(field("then_expression", $.expression)), | ||
$.dedent, | ||
), | ||
field("then_expression", $.paren_expression), |
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.
it's neat that you needed a paren_expression here, but not in the equivalent else_expression below. This tree-sitter conflict stuff continues to be a mystery to me.
("""if true then | ||
a | ||
else if false then | ||
c | ||
else if true then | ||
d""" | ||
|> roundtripCliScript) = """if true then | ||
a | ||
else | ||
if false then | ||
c | ||
else | ||
if true then | ||
d""" |
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.
Since this PR is just focused on the parser, this is good -- could we follow this PR up with one focused on the pretty-printing of EIfs?
such that:
if an if
has an else, whose root expression is an if
as well, we format like:
if cond then
expr
else if cond2 then
expr2
?
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.
(it might turn out that that code might need to 'track' indentation to do its job correctly)
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.
Yes, I tried to make it work within this PR, but encountered some issues with the indentations
Changelog:
#5321