-
Notifications
You must be signed in to change notification settings - Fork 597
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
feat: return with no expression. #3034
Comments
I'll look into it |
Can the same be done for |
If @spapinistarkware confirms it is the same complexity, I'll try |
I think it's actualy easier to change both :) |
You're welcome @gaetbout 😁 |
Hey @spapinistarkware I'm struggling a bit (just doing return atm): .add_struct(StructBuilder::new("StatementReturn")
.node("return_kw", "TerminalReturn")
.node("expr", "Expr")
.node("semicolon", "TerminalSemicolon")
) to .add_struct(StructBuilder::new("StatementReturn")
.node("return_kw", "TerminalReturn")
**.node("optinal_expr", "OptionExpr")**
.node("semicolon", "TerminalSemicolon")
) then running the command Then I go to SyntaxKind::TerminalReturn => {
let return_kw = self.take::<TerminalReturn>();
let expr = self.parse_expr();
let semicolon = self.parse_token::<TerminalSemicolon>();
Some(StatementReturn::new_green(self.db, return_kw, expr, semicolon).into())
} To update it to something like: SyntaxKind::TerminalReturn => {
let return_kw = self.take::<TerminalReturn>();
let optional_expr = if self.peek().kind == SyntaxKind::**???** { // Should it be StatementExpr?
self.parse_expr();
} else {
**???**
};
let semicolon = self.parse_token::<TerminalSemicolon>();
Some(StatementReturn::new_green(self.db, return_kw, expr, semicolon).into())
} I tried a bunch of stuff but can't figure out what to do 🙁 ... |
Try to check if the next token is semicolon. If not, parse expr. |
Look at how let stmt parsing works, it should be similar.
When u introduce an optional expr node, u should get these nodes:
OptionExpr OptionExprSome and OptionExprNone.
The latter have .into() to the former.
So, in the parser, at each branch of then if u create one of these and
use.into()
…On Fri, May 5, 2023, 22:35 gaetbout ***@***.***> wrote:
I'm at this:
main...gaetbout:cairo:feat/returnEmpty
<main...gaetbout:cairo:feat/returnEmpty>
Could you let me know if I'm on the right path?
—
Reply to this email directly, view it on GitHub
<#3034 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKOAMHOVMGRIMUPHRQNLUYLXEVI7BANCNFSM6AAAAAAXVNX4ZA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
That's the thing I don't have any of those two being generated. |
Status update: fn some_fn(){
let mut a = 12;
loop {
if a == 14 {
break;
}
a = a + 1;
}
error: Variable not dropped. Trait has no implementation in context: core::traits::Drop::<core::never>. Trait has no implementation in context: core::traits::Destruct::<core::never>.
--> bool_test.cairo:25:5
loop {
^****^ Looking into it. |
This is a lowering error. Assuming you didn't change anything in the lowering phase, this is unrelated. |
if I break with (); it does work. |
"return;" should be equivalent to "return ():".
Add syntax to cairo_spec.rs and parser.rs.
Fix what breaks.
The text was updated successfully, but these errors were encountered: