Tuple field access #59

This commit is contained in:
2026-06-04 18:14:52 +02:00
parent d3b54b4114
commit d4dc1571b2
4 changed files with 24 additions and 2 deletions
+8
View File
@@ -153,6 +153,14 @@ impl GenRust for Vec<Prefix> {
impl GenRust for Postfix { impl GenRust for Postfix {
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) { fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
match self { match self {
Postfix::TupleFieldAccess(field, generics) => cg.add(&format!(
".{}{}",
field,
generics
.iter()
.map(|v| format!("::{}", v.get_rust()))
.collect::<String>()
)),
Postfix::FieldAccess(field, generics) => cg.add(&format!( Postfix::FieldAccess(field, generics) => cg.add(&format!(
".{}{}", ".{}{}",
field.get_rust(), field.get_rust(),
+1
View File
@@ -50,6 +50,7 @@ pub enum MacroDelimiter {
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
pub enum Postfix { pub enum Postfix {
FieldAccess(Identifier, Option<Generics>), FieldAccess(Identifier, Option<Generics>),
TupleFieldAccess(u8, Option<Generics>),
Call(Vec<Expression>), Call(Vec<Expression>),
MacroCall { MacroCall {
inner: String, inner: String,
+7 -2
View File
@@ -486,7 +486,7 @@ macro_inner_v = @{
// ------------------------------------------------------ // ------------------------------------------------------
expr_path_segment = { expr_path_segment = {
identifier ~ ("::" ~ generics)? identifier ~ generics?
} }
expr_path = { expr_path = {
@@ -507,7 +507,11 @@ primary = {
// ------------------------------------------------------ // ------------------------------------------------------
field_px = { field_px = {
"." ~ identifier ~ ("::" ~ generics)? "." ~ identifier ~ generics?
}
tuple_field_px = {
"." ~ integer ~ generics?
} }
call_px = { call_px = {
@@ -548,6 +552,7 @@ decrement = {
postfix = { postfix = {
field_px field_px
| tuple_field_px
| call_px | call_px
| macro_call_paren | macro_call_paren
| macro_call_bracket | macro_call_bracket
+8
View File
@@ -141,6 +141,14 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Postfix {
)) ))
} }
Rule::tuple_field_px => {
ast_expr!(Postfix::TupleFieldAccess(
Ok(inner.next().unwrap().as_str().parse().unwrap_or(255_u8))
as AstResult<'_, u8>,
inner.next().map(Generics::try_from).transpose(),
))
}
Rule::call_px => ast_expr!(Postfix::Call(collect_recovered(inner))), Rule::call_px => ast_expr!(Postfix::Call(collect_recovered(inner))),
Rule::struct_px => ast_expr!(Postfix::StructCall(collect_recovered_map(inner, |p| { Rule::struct_px => ast_expr!(Postfix::StructCall(collect_recovered_map(inner, |p| {