Pretty print variable accesses and assignments
This commit is contained in:
parent
5bd43ee37a
commit
c7fc8584ff
3 changed files with 47 additions and 1 deletions
45
src/pretty/var.rs
Normal file
45
src/pretty/var.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use pretty::{DocAllocator, DocBuilder, Pretty};
|
||||
|
||||
use crate::ast::Var;
|
||||
|
||||
impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Var {
|
||||
fn pretty(self, allocator: &'a D) -> DocBuilder<'a, D> {
|
||||
match self {
|
||||
Self::Access {
|
||||
s0,
|
||||
index,
|
||||
s1,
|
||||
span: _,
|
||||
} => index.pretty(allocator).brackets(),
|
||||
Self::Assign {
|
||||
local,
|
||||
s0,
|
||||
index,
|
||||
s1,
|
||||
s2,
|
||||
s3,
|
||||
value,
|
||||
span: _,
|
||||
} => local
|
||||
.map(|s| allocator.text("local "))
|
||||
.unwrap_or_else(|| allocator.nil())
|
||||
.append(index.pretty(allocator).brackets())
|
||||
.append(allocator.text(" = "))
|
||||
.append(value.pretty(allocator)),
|
||||
Self::AccessIdent(ident) => ident.pretty(allocator),
|
||||
Self::AssignIdent {
|
||||
local,
|
||||
name,
|
||||
s0,
|
||||
s1,
|
||||
value,
|
||||
span: _,
|
||||
} => local
|
||||
.map(|s| allocator.text("local "))
|
||||
.unwrap_or_else(|| allocator.nil())
|
||||
.append(name.pretty(allocator))
|
||||
.append(allocator.text(" = "))
|
||||
.append(value.pretty(allocator)),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue