Added expr? syntax

This commit is contained in:
2026-05-17 06:08:53 +02:00
parent e270ec727e
commit 5fa3e77b8f
4 changed files with 10 additions and 0 deletions
+1
View File
@@ -71,6 +71,7 @@ pub enum Postfix {
StructCall(Vec<(Identifier, Expression)>), StructCall(Vec<(Identifier, Expression)>),
Index(Expression), Index(Expression),
As(TypeExpr), As(TypeExpr),
Try,
} }
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
+5
View File
@@ -500,6 +500,10 @@ as_px = {
"as" ~ type_expr "as" ~ type_expr
} }
try_px = {
"?"
}
postfix = { postfix = {
field_px field_px
| call_px | call_px
@@ -507,6 +511,7 @@ postfix = {
| struct_px | struct_px
| index_px | index_px
| as_px | as_px
| try_px
} }
// ------------------------------------------------------ // ------------------------------------------------------
+2
View File
@@ -183,6 +183,8 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Postfix {
ast_expr!(Postfix::As(inner.next().unwrap().try_into())) ast_expr!(Postfix::As(inner.next().unwrap().try_into()))
} }
Rule::try_px => Ok(Postfix::Try),
_ => AstError::bug_unimplemented(pair), _ => AstError::bug_unimplemented(pair),
} }
} }
+2
View File
@@ -302,6 +302,8 @@ impl GetRust for Postfix {
} }
Postfix::As(ty) => format!(" as {}", ty.get_rust()), Postfix::As(ty) => format!(" as {}", ty.get_rust()),
Postfix::Try => String::from("?"),
} }
} }
} }