Pretty print field accesses and assignments
This commit is contained in:
parent
81e2a28b06
commit
5bd43ee37a
3 changed files with 66 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
mod basic;
|
||||
mod call;
|
||||
mod expr;
|
||||
mod field;
|
||||
mod lit;
|
||||
mod program;
|
||||
mod table_constr;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Expr {
|
|||
match self {
|
||||
Self::Lit(lit) => lit.pretty(allocator),
|
||||
Self::Call(call) => call.pretty(allocator),
|
||||
Self::Field(field) => allocator.text("<field>"),
|
||||
Self::Field(field) => field.pretty(allocator),
|
||||
Self::Var(var) => allocator.text("<var>"),
|
||||
Self::TableConstr(constr) => constr.pretty(allocator),
|
||||
Self::TableDestr(destr) => allocator.text("<destr>"),
|
||||
|
|
|
|||
64
src/pretty/field.rs
Normal file
64
src/pretty/field.rs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
use pretty::{DocAllocator, DocBuilder, Pretty};
|
||||
|
||||
use crate::ast::Field;
|
||||
|
||||
impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Field {
|
||||
fn pretty(self, allocator: &'a D) -> DocBuilder<'a, D> {
|
||||
match self {
|
||||
Self::Access {
|
||||
expr,
|
||||
s0,
|
||||
s1,
|
||||
index,
|
||||
s2,
|
||||
span: _,
|
||||
} => expr
|
||||
.pretty(allocator)
|
||||
.append(index.pretty(allocator).brackets()),
|
||||
Self::Assign {
|
||||
expr,
|
||||
s0,
|
||||
s1,
|
||||
index,
|
||||
s2,
|
||||
s3,
|
||||
s4,
|
||||
value,
|
||||
span: _,
|
||||
} => expr
|
||||
.pretty(allocator)
|
||||
.append(index.pretty(allocator).brackets())
|
||||
.append(allocator.text(" = "))
|
||||
.append(value.pretty(allocator)),
|
||||
Self::AccessIdent {
|
||||
expr,
|
||||
s0,
|
||||
s1,
|
||||
ident,
|
||||
span: _,
|
||||
} => expr
|
||||
.pretty(allocator)
|
||||
.append(allocator.line_())
|
||||
.append(allocator.text("."))
|
||||
.append(ident.pretty(allocator))
|
||||
.group(),
|
||||
Self::AssignIdent {
|
||||
expr,
|
||||
s0,
|
||||
s1,
|
||||
ident,
|
||||
s2,
|
||||
s3,
|
||||
value,
|
||||
span: _,
|
||||
} => expr
|
||||
.pretty(allocator)
|
||||
.append(allocator.line_())
|
||||
.append(allocator.text("."))
|
||||
.append(ident.pretty(allocator))
|
||||
.append(allocator.text(" = "))
|
||||
.append(value.pretty(allocator))
|
||||
.group(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue