Tuple field access #59
This commit is contained in:
@@ -153,6 +153,14 @@ impl GenRust for Vec<Prefix> {
|
||||
impl GenRust for Postfix {
|
||||
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||
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!(
|
||||
".{}{}",
|
||||
field.get_rust(),
|
||||
|
||||
@@ -50,6 +50,7 @@ pub enum MacroDelimiter {
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum Postfix {
|
||||
FieldAccess(Identifier, Option<Generics>),
|
||||
TupleFieldAccess(u8, Option<Generics>),
|
||||
Call(Vec<Expression>),
|
||||
MacroCall {
|
||||
inner: String,
|
||||
|
||||
@@ -486,7 +486,7 @@ macro_inner_v = @{
|
||||
// ------------------------------------------------------
|
||||
|
||||
expr_path_segment = {
|
||||
identifier ~ ("::" ~ generics)?
|
||||
identifier ~ generics?
|
||||
}
|
||||
|
||||
expr_path = {
|
||||
@@ -507,7 +507,11 @@ primary = {
|
||||
// ------------------------------------------------------
|
||||
|
||||
field_px = {
|
||||
"." ~ identifier ~ ("::" ~ generics)?
|
||||
"." ~ identifier ~ generics?
|
||||
}
|
||||
|
||||
tuple_field_px = {
|
||||
"." ~ integer ~ generics?
|
||||
}
|
||||
|
||||
call_px = {
|
||||
@@ -548,6 +552,7 @@ decrement = {
|
||||
|
||||
postfix = {
|
||||
field_px
|
||||
| tuple_field_px
|
||||
| call_px
|
||||
| macro_call_paren
|
||||
| macro_call_bracket
|
||||
|
||||
@@ -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::struct_px => ast_expr!(Postfix::StructCall(collect_recovered_map(inner, |p| {
|
||||
|
||||
Reference in New Issue
Block a user