-
Notifications
You must be signed in to change notification settings - Fork 28
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
parse parenthesized expressions #171
Conversation
✅ Deploy Preview for dada-lang ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
is causing this assert to fail: dada/components/dada-validate/src/validate/validator.rs Lines 205 to 207 in 0793cdf
I have fixed it by doing: syntax::ExprData::Parenthesized(parenthesized_expr) => {
let data = self
.validate_expr_in_mode(*parenthesized_expr, mode)
.data(self.tables)
.clone();
self.add(data, expr)
} in dada/components/dada-validate/src/validate/validator.rs Lines 400 to 402 in 0793cdf
but I don't know if that's the proper fix. |
Ok, I think I found the proper fix, by adding |
@@ -129,10 +129,10 @@ pub enum ExprData { | |||
/// `[shared|var|atomic] x = expr` | |||
Var(LocalVariableDecl, Expr), | |||
|
|||
/// `expr` | |||
/// `(expr)` | |||
Parenthesized(Expr), |
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.
We don't seem to have anything parsed as a Parenthsized
before 😅 .
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.
Nice! I think that the assertion is probably just wrong, though.
@@ -258,6 +258,9 @@ pub enum ExprData { | |||
/// `expr.give` | |||
Give(Place), | |||
|
|||
/// `(expr)` | |||
Parenthesized(Expr), |
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.
Hmm, I think we shouldn't have this in Validated
....
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 belongs in Syntax
, but Validated
is supposed to be kind of only the things that have meaning to the compiler
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.
If this is causing that assertion to fail, we should probably just remove the assertion.
@@ -398,7 +398,8 @@ impl<'me> Validator<'me> { | |||
} | |||
|
|||
syntax::ExprData::Parenthesized(parenthesized_expr) => { | |||
self.validate_expr_in_mode(*parenthesized_expr, mode) | |||
let validated_expr = self.validate_expr_in_mode(*parenthesized_expr, mode); | |||
self.add(validated::ExprData::Parenthesized(validated_expr), expr) |
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.
...in which case this diff is unnecessary, right?
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.
I had to change that because otherwise this assert was failing:
dada/components/dada-validate/src/validate/validator.rs
Lines 194 to 196 in 60986a3
// Check that the validated expression always has the same | |
// origin as the expression we started with. | |
assert_eq!(result.origin_in(self.origins).syntax_expr, expr); |
Before adding Parenthesized
to Validated
I did
dada/components/dada-validate/src/validate/validator.rs
Lines 400 to 406 in e4c5bdc
syntax::ExprData::Parenthesized(parenthesized_expr) => { | |
let data = self | |
.validate_expr_in_mode(*parenthesized_expr, mode) | |
.data(self.tables) | |
.clone(); | |
self.add(data, expr) | |
} |
but that felt wrong. ¿Maybe that is a better fix?
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.
Ah, you mean the assertion in validator.rs
, not the one from the #141, right?
There's another one in give_validated_expr
.
and use same commet as `validated::ExprData::Tuple` in `syntax::ExprData::Tuple`
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.
Looked it over, this seems better, did have one thought...
@@ -449,7 +449,15 @@ impl CodeParser<'_, '_> { | |||
} else if let Some((span, token_tree)) = self.delimited('(') { | |||
let expr = | |||
self.with_sub_parser(token_tree, |subparser| subparser.parse_only_expr_seq()); | |||
Some(self.add(ExprData::Tuple(expr), span)) | |||
|
|||
Some(self.add( |
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.
For better or worse, I think this change will mean that (a,)
also parses as a parenthesized expression. We should check that. Not sure if we want that or not!
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.
I will investigate the best way to emit an error for that case.
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.
Probably we want an error? It's not entirely clear to me.
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.
I'd be ok with just opening up an issue to follow-up on later.
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.
created #177
bors r+ |
Build succeeded: |
As per doc comments tuples are of
len != 1
dada/components/dada-ir/src/code/syntax.rs
Lines 135 to 136 in 0793cdf
so I fixed parsing to match that.
fixes #141