typstyle_core/pretty/
code_misc.rs1use typst_syntax::ast::*;
2
3use super::{prelude::*, Context, PrettyPrinter};
4
5impl<'a> PrettyPrinter<'a> {
6 pub(super) fn convert_ident(&'a self, ident: Ident<'a>) -> ArenaDoc<'a> {
7 self.convert_trivia(ident)
8 }
9
10 pub(super) fn convert_array_item(
11 &'a self,
12 ctx: Context,
13 array_item: ArrayItem<'a>,
14 ) -> ArenaDoc<'a> {
15 if let Some(res) = self.check_disabled(array_item.to_untyped()) {
16 return res;
17 }
18 match array_item {
19 ArrayItem::Pos(p) => self.convert_expr(ctx, p),
20 ArrayItem::Spread(s) => self.convert_spread(ctx, s),
21 }
22 }
23
24 pub(super) fn convert_dict_item(
25 &'a self,
26 ctx: Context,
27 dict_item: DictItem<'a>,
28 ) -> ArenaDoc<'a> {
29 if let Some(res) = self.check_disabled(dict_item.to_untyped()) {
30 return res;
31 }
32 match dict_item {
33 DictItem::Named(n) => self.convert_named(ctx, n),
34 DictItem::Keyed(k) => self.convert_keyed(ctx, k),
35 DictItem::Spread(s) => self.convert_spread(ctx, s),
36 }
37 }
38
39 pub(super) fn convert_arg(&'a self, ctx: Context, arg: Arg<'a>) -> ArenaDoc<'a> {
40 if let Some(res) = self.check_disabled(arg.to_untyped()) {
41 return res;
42 }
43 match arg {
44 Arg::Pos(p) => self.convert_expr(ctx, p),
45 Arg::Named(n) => self.convert_named(ctx, n),
46 Arg::Spread(s) => self.convert_spread(ctx, s),
47 }
48 }
49
50 pub(super) fn convert_param(&'a self, ctx: Context, param: Param<'a>) -> ArenaDoc<'a> {
51 if let Some(res) = self.check_disabled(param.to_untyped()) {
52 return res;
53 }
54 match param {
55 Param::Pos(p) => self.convert_pattern(ctx, p),
56 Param::Named(n) => self.convert_named(ctx, n),
57 Param::Spread(s) => self.convert_spread(ctx, s),
58 }
59 }
60
61 pub fn convert_pattern(&'a self, ctx: Context, pattern: Pattern<'a>) -> ArenaDoc<'a> {
62 if let Some(res) = self.check_disabled(pattern.to_untyped()) {
63 return res;
64 }
65 match pattern {
66 Pattern::Normal(n) => self.convert_expr(ctx, n),
67 Pattern::Placeholder(_) => self.convert_literal("_"),
68 Pattern::Destructuring(d) => self.convert_destructuring(ctx, d),
69 Pattern::Parenthesized(p) => self.convert_parenthesized(ctx, p),
70 }
71 }
72
73 pub(super) fn convert_destructuring_item(
74 &'a self,
75 ctx: Context,
76 destructuring_item: DestructuringItem<'a>,
77 ) -> ArenaDoc<'a> {
78 if let Some(res) = self.check_disabled(destructuring_item.to_untyped()) {
79 return res;
80 }
81 match destructuring_item {
82 DestructuringItem::Spread(s) => self.convert_spread(ctx, s),
83 DestructuringItem::Named(n) => self.convert_named(ctx, n),
84 DestructuringItem::Pattern(p) => self.convert_pattern(ctx, p),
85 }
86 }
87}