From 574607f377e853796f7a49338ca7bc7a2954629e Mon Sep 17 00:00:00 2001 From: QuadnucYard <2380433991@qq.com> Date: Thu, 5 Dec 2024 10:26:56 +0800 Subject: [PATCH] feat: format chains with comments --- src/pretty/chain.rs | 162 ++++++++++++++---- src/pretty/code_chain.rs | 11 +- src/pretty/code_flow.rs | 8 +- .../unit/comment/comment-in-chain-binary.typ | 9 +- .../unit/comment/comment-in-chain-call.typ | 3 + .../assets__check_file@tablex.typ-0.snap | 8 +- .../assets__check_file@tablex.typ-120.snap | 4 +- .../assets__check_file@tablex.typ-40.snap | 8 +- .../assets__check_file@tablex.typ-80.snap | 4 +- ...comment-comment-in-chain-binary.typ-0.snap | 32 +++- ...mment-comment-in-chain-binary.typ-120.snap | 20 ++- ...omment-comment-in-chain-binary.typ-40.snap | 31 +++- ...omment-comment-in-chain-binary.typ-80.snap | 30 +++- ...t-comment-comment-in-chain-call.typ-0.snap | 19 +- ...comment-comment-in-chain-call.typ-120.snap | 19 +- ...-comment-comment-in-chain-call.typ-40.snap | 19 +- ...-comment-comment-in-chain-call.typ-80.snap | 19 +- ...le@unit-comment-comment-in-code.typ-0.snap | 22 ++- ...@unit-comment-comment-in-code.typ-120.snap | 4 +- ...e@unit-comment-comment-in-code.typ-40.snap | 22 ++- ...e@unit-comment-comment-in-code.typ-80.snap | 11 +- 21 files changed, 335 insertions(+), 130 deletions(-) diff --git a/src/pretty/chain.rs b/src/pretty/chain.rs index 78d85547..e89655b4 100644 --- a/src/pretty/chain.rs +++ b/src/pretty/chain.rs @@ -1,25 +1,37 @@ use itertools::Itertools; use pretty::DocAllocator; use std::iter; -use typst_syntax::SyntaxNode; +use typst_syntax::{SyntaxKind, SyntaxNode}; -use super::{ArenaDoc, PrettyPrinter}; +use crate::ext::StrExt; +use super::{util::is_comment_node, ArenaDoc, PrettyPrinter}; + +/// Intermediate representation in chain formatting. enum ChainItem<'a> { - Commented { body: ArenaDoc<'a> }, + Body(ArenaDoc<'a>), + Op(ArenaDoc<'a>), + Comment(ArenaDoc<'a>), + Attached(ArenaDoc<'a>), + Linebreak, } +/// A stylist that can format items as chains. pub struct ChainStylist<'a> { printer: &'a PrettyPrinter<'a>, items: Vec>, - chain_len: usize, - op_space: bool, + /// The number of chain operators in the chain. + chain_op_num: usize, + /// Whether the chain contains any line or block comment. + has_comment: bool, } #[derive(Default)] pub struct ChainStyle { /// Do not break line if the chain consists of only one operator. pub no_break_single: bool, + /// Add space before and after operators. + pub space_around_op: bool, } impl<'a> ChainStylist<'a> { @@ -27,16 +39,19 @@ impl<'a> ChainStylist<'a> { Self { printer, items: Default::default(), - chain_len: 0, - op_space: false, + chain_op_num: 0, + has_comment: false, } } - pub fn space_around_op(mut self) -> Self { - self.op_space = true; - self - } - + /// Processes a collection of syntax nodes directly from depth-first resolution. + /// + /// This method takes an iterator of `SyntaxNode`s, which are then processed in reverse order. + /// + /// # Parameters + /// + /// - `nodes`: An iterator over references to `SyntaxNode`s that have been resolved. + /// - Others: See [`Self::process`]. pub fn process_resolved( self, nodes: impl Iterator, @@ -56,6 +71,17 @@ impl<'a> ChainStylist<'a> { ) } + /// Processes a vector of syntax nodes with the provided predicates and converters + /// to create a structured representation. + /// + /// # Parameters + /// + /// - `nodes`: A vector of `SyntaxNode`s to be processed. + /// - `operand_pred`: A predicate that checks if a node is an operand. + /// - `op_pred`: A predicate that checks if a node is an operator. + /// - `rhs_converter`: A function that converts right-hand side nodes into an `Option>`. + /// - `fallback_converter`: A function that provides a fallback conversion for nodes that + /// do not match the primary criteria. Used for sticky args and innermost expressions. pub fn process( mut self, nodes: Vec<&'a SyntaxNode>, @@ -65,57 +91,129 @@ impl<'a> ChainStylist<'a> { fallback_converter: impl Fn(&'a SyntaxNode) -> Option>, ) -> Self { let arena = &self.printer.arena; - - let mut doc = arena.nil(); + let mut can_attach = false; for node in nodes { if operand_pred(node) { - self.chain_len += 1; + self.chain_op_num += 1; let mut seen_op = false; for child in node.children() { if op_pred(child) { seen_op = true; - self.items.push(ChainItem::Commented { body: doc }); - doc = if self.op_space { - arena.text(child.text().as_str()) + " " + self.items + .push(ChainItem::Op(arena.text(child.text().as_str()))); + } else if is_comment_node(child) { + let doc = self.printer.convert_comment(child); + self.items.push(if can_attach { + ChainItem::Attached(doc) } else { - arena.text(child.text().as_str()) - }; + ChainItem::Comment(doc) + }); + self.has_comment = true; + } else if child.kind() == SyntaxKind::Space { + if child.text().has_linebreak() { + if self.items.last().is_some_and(|last| { + matches!(*last, ChainItem::Attached(_) | ChainItem::Comment(_)) + }) { + self.items.push(ChainItem::Linebreak); + } + can_attach = false; + } } else if seen_op { if let Some(rhs) = rhs_converter(child) { - doc += rhs; + self.items.push(ChainItem::Body(rhs)); + can_attach = true; } } } } else if let Some(fallback) = fallback_converter(node) { - doc += fallback; + // We must use this to handle args. + if let Some(ChainItem::Body(body)) = self.items.last_mut() { + *body += fallback; + } else { + self.items.push(ChainItem::Body(fallback)); + } } } - self.items.push(ChainItem::Commented { body: doc }); self } + /// Create a Doc from IR and given styles. pub fn print_doc(self, sty: ChainStyle) -> ArenaDoc<'a> { let arena = &self.printer.arena; + let op_sep = if sty.space_around_op { + arena.line() + } else { + arena.line_() + }; + + let use_simple_layout = self.chain_op_num == 1 && sty.no_break_single && !self.has_comment; + let mut docs = vec![]; + let mut has_break = false; + let mut leading = true; + let mut space_after = true; for item in self.items { match item { - ChainItem::Commented { body } => docs.push(body), + ChainItem::Body(body) => { + if leading { + docs.push(body); + } else if let Some(last) = docs.last_mut() { + *last += body; + } + leading = false; + space_after = true; + } + ChainItem::Op(op) => { + if !(has_break && leading || use_simple_layout) { + docs.push(op_sep.clone()); + } + has_break = false; + if sty.space_around_op { + docs.push(op + " "); + } else { + docs.push(op); + } + leading = false; + space_after = false; + } + ChainItem::Comment(cmt) => { + if leading { + docs.push(cmt); + } else if let Some(last) = docs.last_mut() { + *last += if space_after { + arena.space() + cmt + } else { + cmt + } + } + leading = false; + space_after = true; + } + ChainItem::Attached(cmt) => { + if let Some(last) = docs.last_mut() { + *last += if space_after { + arena.space() + cmt + } else { + cmt + } + } + } + ChainItem::Linebreak => { + has_break = true; + leading = true; + docs.push(arena.hardline()); + } } } - let op_sep = if self.op_space { - arena.line() - } else { - arena.line_() - }; let first_doc = docs.remove(0); - let follow_docs = arena.intersperse(docs, op_sep.clone()); - if self.chain_len == 1 && sty.no_break_single { + let follow_docs = arena.concat(docs); + if use_simple_layout { (first_doc + follow_docs).group() } else { - (first_doc + (op_sep + follow_docs).nest(2)).group() + (first_doc + (follow_docs).nest(2)).group() } } } diff --git a/src/pretty/code_chain.rs b/src/pretty/code_chain.rs index 96b23e7f..1d795da3 100644 --- a/src/pretty/code_chain.rs +++ b/src/pretty/code_chain.rs @@ -5,15 +5,11 @@ use crate::PrettyPrinter; use super::{ chain::{iterate_deep_nodes, ChainStyle, ChainStylist}, - util::has_comment_children, ArenaDoc, }; impl<'a> PrettyPrinter<'a> { pub(super) fn convert_field_access(&'a self, field_access: FieldAccess<'a>) -> ArenaDoc<'a> { - if let Some(res) = self.check_unformattable(field_access.to_untyped()) { - return res; - } if self.current_mode().is_code() { return self.convert_dot_chain(field_access.to_untyped()); } @@ -23,10 +19,6 @@ impl<'a> PrettyPrinter<'a> { } pub(super) fn convert_dot_chain(&'a self, node: &'a SyntaxNode) -> ArenaDoc<'a> { - if resolve_dot_chain(node).any(has_comment_children) { - return self.format_disabled(node); - } - ChainStylist::new(self) .process_resolved( resolve_dot_chain(node), @@ -44,13 +36,13 @@ impl<'a> PrettyPrinter<'a> { ) .print_doc(ChainStyle { no_break_single: true, + ..Default::default() }) } pub(super) fn convert_binary_chain(&'a self, binary: Binary<'a>) -> ArenaDoc<'a> { let prec = binary.op().precedence(); ChainStylist::new(self) - .space_around_op() .process_resolved( resolve_binary_chain(binary), |node| { @@ -62,6 +54,7 @@ impl<'a> PrettyPrinter<'a> { |node| node.cast().map(|expr| self.convert_expr(expr)), ) .print_doc(ChainStyle { + space_around_op: true, ..Default::default() }) } diff --git a/src/pretty/code_flow.rs b/src/pretty/code_flow.rs index 76ddbf74..5bd86fba 100644 --- a/src/pretty/code_flow.rs +++ b/src/pretty/code_flow.rs @@ -3,10 +3,7 @@ use typst_syntax::{ast::*, SyntaxKind}; use crate::ext::BoolExt; -use super::{ - code_chain::resolve_binary_chain, flow::FlowItem, util::has_comment_children, ArenaDoc, - PrettyPrinter, -}; +use super::{flow::FlowItem, ArenaDoc, PrettyPrinter}; impl<'a> PrettyPrinter<'a> { pub(super) fn convert_named(&'a self, named: Named<'a>) -> ArenaDoc<'a> { @@ -77,8 +74,7 @@ impl<'a> PrettyPrinter<'a> { if matches!( binary.op(), BinOp::Add | BinOp::Sub | BinOp::Mul | BinOp::Div | BinOp::And | BinOp::Or - ) && !resolve_binary_chain(binary).any(has_comment_children) - { + ) { return self.parenthesize_if_necessary(|| self.convert_binary_chain(binary)); } self.convert_flow_like(binary.to_untyped(), |child| { diff --git a/tests/assets/unit/comment/comment-in-chain-binary.typ b/tests/assets/unit/comment/comment-in-chain-binary.typ index f6849512..7812eb89 100644 --- a/tests/assets/unit/comment/comment-in-chain-binary.typ +++ b/tests/assets/unit/comment/comment-in-chain-binary.typ @@ -1,8 +1,7 @@ -#{ let a = (1111111111111 // 1 - + 2222222222222/* 2 */ - +/* 3 */ 3333333333333 / 2 - /* 4 */+ 4444444444444 + 5555555555555 -/* 5 */ + 444444444 +#{ let a = (1111111111111 // - + + 2222222222222/* 0 */ /* 1 */ + +/* 2 */ 3333333333333 / 2 /* 3 */ /* 4 */ + /* 5 */+ 4444444444444 + 5555555555555 - 6666666/* 6 */ + /* 7 */7777777 - 9999999 / /* 8 */ 10000000 // 9 diff --git a/tests/assets/unit/comment/comment-in-chain-call.typ b/tests/assets/unit/comment/comment-in-chain-call.typ index b0dd4d91..b3a69f39 100644 --- a/tests/assets/unit/comment/comment-in-chain-call.typ +++ b/tests/assets/unit/comment/comment-in-chain-call.typ @@ -3,12 +3,15 @@ .b(1)(2) .c .d(3) + a // 1 .b(1)(2) // 2 // 3 /* 4 */ ./* 5 */c /* 6 *//* 7 */ .d(3) // 8 + /* 0 */ a/* 1 */ /* 2 */ .b(1)(2) /* 3 */ .c // 4 + /* 5 */ ./* 6 */d(3) // 7 } diff --git a/tests/snapshots/assets__check_file@tablex.typ-0.snap b/tests/snapshots/assets__check_file@tablex.typ-0.snap index da315cf4..12524796 100644 --- a/tests/snapshots/assets__check_file@tablex.typ-0.snap +++ b/tests/snapshots/assets__check_file@tablex.typ-0.snap @@ -3253,8 +3253,8 @@ snapshot_kind: text auto, none, ) // always goes towards the right - or h.end >= cell.x - + cell.colspan // ends at or after this cell + or h.end >= cell.x + + cell.colspan // ends at or after this cell ) ( @@ -3303,8 +3303,8 @@ snapshot_kind: text auto, none, ) // always goes towards the bottom - or v.end >= cell.y - + cell.rowspan // ends at or after this cell + or v.end >= cell.y + + cell.rowspan // ends at or after this cell ) ( diff --git a/tests/snapshots/assets__check_file@tablex.typ-120.snap b/tests/snapshots/assets__check_file@tablex.typ-120.snap index b70c3757..b44ed994 100644 --- a/tests/snapshots/assets__check_file@tablex.typ-120.snap +++ b/tests/snapshots/assets__check_file@tablex.typ-120.snap @@ -1923,7 +1923,7 @@ snapshot_kind: text let hline_hasnt_already_ended = ( h.end in (auto, none) // always goes towards the right - or h.end >= cell.x + cell.colspan // ends at or after this cell + or h.end >= cell.x + cell.colspan // ends at or after this cell ) (in_top_or_bottom and hline_hasnt_already_ended) @@ -1949,7 +1949,7 @@ snapshot_kind: text let vline_hasnt_already_ended = ( v.end in (auto, none) // always goes towards the bottom - or v.end >= cell.y + cell.rowspan // ends at or after this cell + or v.end >= cell.y + cell.rowspan // ends at or after this cell ) (at_left_or_right and vline_hasnt_already_ended) diff --git a/tests/snapshots/assets__check_file@tablex.typ-40.snap b/tests/snapshots/assets__check_file@tablex.typ-40.snap index 1bf81bd5..78e19178 100644 --- a/tests/snapshots/assets__check_file@tablex.typ-40.snap +++ b/tests/snapshots/assets__check_file@tablex.typ-40.snap @@ -2711,8 +2711,8 @@ snapshot_kind: text auto, none, ) // always goes towards the right - or h.end >= cell.x - + cell.colspan // ends at or after this cell + or h.end >= cell.x + + cell.colspan // ends at or after this cell ) ( @@ -2757,8 +2757,8 @@ snapshot_kind: text auto, none, ) // always goes towards the bottom - or v.end >= cell.y - + cell.rowspan // ends at or after this cell + or v.end >= cell.y + + cell.rowspan // ends at or after this cell ) ( diff --git a/tests/snapshots/assets__check_file@tablex.typ-80.snap b/tests/snapshots/assets__check_file@tablex.typ-80.snap index 6c9fcd60..bbfde066 100644 --- a/tests/snapshots/assets__check_file@tablex.typ-80.snap +++ b/tests/snapshots/assets__check_file@tablex.typ-80.snap @@ -2065,7 +2065,7 @@ snapshot_kind: text let hline_hasnt_already_ended = ( h.end in (auto, none) // always goes towards the right - or h.end >= cell.x + cell.colspan // ends at or after this cell + or h.end >= cell.x + cell.colspan // ends at or after this cell ) (in_top_or_bottom and hline_hasnt_already_ended) @@ -2097,7 +2097,7 @@ snapshot_kind: text let vline_hasnt_already_ended = ( v.end in (auto, none) // always goes towards the bottom - or v.end >= cell.y + cell.rowspan // ends at or after this cell + or v.end >= cell.y + cell.rowspan // ends at or after this cell ) (at_left_or_right and vline_hasnt_already_ended) diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-0.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-0.snap index 36e5dab3..12fd9bf2 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-0.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-0.snap @@ -6,11 +6,31 @@ snapshot_kind: text --- #{ let a = ( - 1111111111111 // 1 - + 2222222222222 /* 2 */ + /* 3 */ 3333333333333 - / 2 /* 4 */ + 4444444444444 + 5555555555555 /* 5 */ + 444444444 - 6666666 /* 6 */ + /* 7 */ 7777777 - 9999999 / /* 8 */ 10000000 // 9 - + 111111111111 - * 333 /* 10 */ / 222 /* 11 */ * 44444 / 999 * 1111 / 44444 * 1111 / 44444 * 1111 / 44444 - /* 12 */ 222222222222 /* 13 */ + /* 14 */ 333333333333 - 444444444444 // 15 - + 555555555555 /* 16 */ + 1111111111111 // - + + 2222222222222 /* 0 */ /* 1 */ + + /* 2 */3333333333333 + / 2 /* 3 */ /* 4 */ + /* 5 */ + + 4444444444444 + + 5555555555555 + - 6666666 /* 6 */ + + /* 7 */7777777 + - 9999999 + / /* 8 */10000000 // 9 + + 111111111111 + * 333 /* 10 */ + / 222 /* 11 */ + * 44444 + / 999 + * 1111 + / 44444 + * 1111 + / 44444 + * 1111 + / 44444 + - /* 12 */222222222222 /* 13 */ + + /* 14 */333333333333 + - 444444444444 // 15 + + 555555555555 /* 16 */ ) } diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-120.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-120.snap index 36e5dab3..56747ad2 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-120.snap @@ -6,11 +6,19 @@ snapshot_kind: text --- #{ let a = ( - 1111111111111 // 1 - + 2222222222222 /* 2 */ + /* 3 */ 3333333333333 - / 2 /* 4 */ + 4444444444444 + 5555555555555 /* 5 */ + 444444444 - 6666666 /* 6 */ + /* 7 */ 7777777 - 9999999 / /* 8 */ 10000000 // 9 - + 111111111111 - * 333 /* 10 */ / 222 /* 11 */ * 44444 / 999 * 1111 / 44444 * 1111 / 44444 * 1111 / 44444 - /* 12 */ 222222222222 /* 13 */ + /* 14 */ 333333333333 - 444444444444 // 15 - + 555555555555 /* 16 */ + 1111111111111 // - + + 2222222222222 /* 0 */ /* 1 */ + + /* 2 */3333333333333 / 2 /* 3 */ /* 4 */ + /* 5 */ + + 4444444444444 + + 5555555555555 + - 6666666 /* 6 */ + + /* 7 */7777777 + - 9999999 / /* 8 */10000000 // 9 + + 111111111111 * 333 /* 10 */ / 222 /* 11 */ * 44444 / 999 * 1111 / 44444 * 1111 / 44444 * 1111 / 44444 + - /* 12 */222222222222 /* 13 */ + + /* 14 */333333333333 + - 444444444444 // 15 + + 555555555555 /* 16 */ ) } diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-40.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-40.snap index 36e5dab3..21f1ed7a 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-40.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-40.snap @@ -6,11 +6,30 @@ snapshot_kind: text --- #{ let a = ( - 1111111111111 // 1 - + 2222222222222 /* 2 */ + /* 3 */ 3333333333333 - / 2 /* 4 */ + 4444444444444 + 5555555555555 /* 5 */ + 444444444 - 6666666 /* 6 */ + /* 7 */ 7777777 - 9999999 / /* 8 */ 10000000 // 9 - + 111111111111 - * 333 /* 10 */ / 222 /* 11 */ * 44444 / 999 * 1111 / 44444 * 1111 / 44444 * 1111 / 44444 - /* 12 */ 222222222222 /* 13 */ + /* 14 */ 333333333333 - 444444444444 // 15 - + 555555555555 /* 16 */ + 1111111111111 // - + + 2222222222222 /* 0 */ /* 1 */ + + /* 2 */3333333333333 + / 2 /* 3 */ /* 4 */ + /* 5 */ + + 4444444444444 + + 5555555555555 + - 6666666 /* 6 */ + + /* 7 */7777777 + - 9999999 / /* 8 */10000000 // 9 + + 111111111111 + * 333 /* 10 */ + / 222 /* 11 */ + * 44444 + / 999 + * 1111 + / 44444 + * 1111 + / 44444 + * 1111 + / 44444 + - /* 12 */222222222222 /* 13 */ + + /* 14 */333333333333 + - 444444444444 // 15 + + 555555555555 /* 16 */ ) } diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-80.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-80.snap index 36e5dab3..eb4a7929 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-binary.typ-80.snap @@ -6,11 +6,29 @@ snapshot_kind: text --- #{ let a = ( - 1111111111111 // 1 - + 2222222222222 /* 2 */ + /* 3 */ 3333333333333 - / 2 /* 4 */ + 4444444444444 + 5555555555555 /* 5 */ + 444444444 - 6666666 /* 6 */ + /* 7 */ 7777777 - 9999999 / /* 8 */ 10000000 // 9 - + 111111111111 - * 333 /* 10 */ / 222 /* 11 */ * 44444 / 999 * 1111 / 44444 * 1111 / 44444 * 1111 / 44444 - /* 12 */ 222222222222 /* 13 */ + /* 14 */ 333333333333 - 444444444444 // 15 - + 555555555555 /* 16 */ + 1111111111111 // - + + 2222222222222 /* 0 */ /* 1 */ + + /* 2 */3333333333333 / 2 /* 3 */ /* 4 */ + /* 5 */ + + 4444444444444 + + 5555555555555 + - 6666666 /* 6 */ + + /* 7 */7777777 + - 9999999 / /* 8 */10000000 // 9 + + 111111111111 + * 333 /* 10 */ + / 222 /* 11 */ + * 44444 + / 999 + * 1111 + / 44444 + * 1111 + / 44444 + * 1111 + / 44444 + - /* 12 */222222222222 /* 13 */ + + /* 14 */333333333333 + - 444444444444 // 15 + + 555555555555 /* 16 */ ) } diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-0.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-0.snap index ef2ce7f3..87ba66c2 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-0.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-0.snap @@ -10,13 +10,20 @@ snapshot_kind: text .c .d(3) + a // 1 - .b(1)(2) // 2 - // 3 -/* 4 */ ./* 5 */c /* 6 *//* 7 */ .d(3) // 8 + .b(1)(2) // 2 + // 3 + /* 4 */ + ./* 5 */c /* 6 */ /* 7 */ + .d(3) // 8 + /* 0 */ - a/* 1 */ -/* 2 */ .b(1)(2) /* 3 */ .c // 4 -/* 5 */ ./* 6 */d(3) // 7 + a /* 1 */ + /* 2 */ + .b(1)(2) /* 3 */ + .c // 4 + /* 5 */ + ./* 6 */d(3) // 7 } diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-120.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-120.snap index f1268e18..32e0e155 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-120.snap @@ -7,13 +7,20 @@ snapshot_kind: text #{ a.b(1)(2).c.d(3) + a // 1 - .b(1)(2) // 2 - // 3 -/* 4 */ ./* 5 */c /* 6 *//* 7 */ .d(3) // 8 + .b(1)(2) // 2 + // 3 + /* 4 */ + ./* 5 */c /* 6 */ /* 7 */ + .d(3) // 8 + /* 0 */ - a/* 1 */ -/* 2 */ .b(1)(2) /* 3 */ .c // 4 -/* 5 */ ./* 6 */d(3) // 7 + a /* 1 */ + /* 2 */ + .b(1)(2) /* 3 */ + .c // 4 + /* 5 */ + ./* 6 */d(3) // 7 } diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-40.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-40.snap index f1268e18..32e0e155 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-40.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-40.snap @@ -7,13 +7,20 @@ snapshot_kind: text #{ a.b(1)(2).c.d(3) + a // 1 - .b(1)(2) // 2 - // 3 -/* 4 */ ./* 5 */c /* 6 *//* 7 */ .d(3) // 8 + .b(1)(2) // 2 + // 3 + /* 4 */ + ./* 5 */c /* 6 */ /* 7 */ + .d(3) // 8 + /* 0 */ - a/* 1 */ -/* 2 */ .b(1)(2) /* 3 */ .c // 4 -/* 5 */ ./* 6 */d(3) // 7 + a /* 1 */ + /* 2 */ + .b(1)(2) /* 3 */ + .c // 4 + /* 5 */ + ./* 6 */d(3) // 7 } diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-80.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-80.snap index f1268e18..32e0e155 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-chain-call.typ-80.snap @@ -7,13 +7,20 @@ snapshot_kind: text #{ a.b(1)(2).c.d(3) + a // 1 - .b(1)(2) // 2 - // 3 -/* 4 */ ./* 5 */c /* 6 *//* 7 */ .d(3) // 8 + .b(1)(2) // 2 + // 3 + /* 4 */ + ./* 5 */c /* 6 */ /* 7 */ + .d(3) // 8 + /* 0 */ - a/* 1 */ -/* 2 */ .b(1)(2) /* 3 */ .c // 4 -/* 5 */ ./* 6 */d(3) // 7 + a /* 1 */ + /* 2 */ + .b(1)(2) /* 3 */ + .c // 4 + /* 5 */ + ./* 6 */d(3) // 7 } diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-0.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-0.snap index 23ebfeb7..5c84d217 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-0.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-0.snap @@ -46,9 +46,15 @@ snapshot_kind: text ) } #{ - -1 /* 2 */ - /* 1 */ +/* 0 */7 /* 1 */ + /* 2 */ ( - /* 3 */ - +/* 4 */7 /* 5 */ * /* 6 */ -3 /* 7 */ - 6 /* 8 */ + ( + -1 /* 2 */ + - /* 1 */+/* 0 */7 /* 1 */ + + /* 2 */( + /* 3 */ + +/* 4 */7 /* 5 */ + * /* 6 */-3 /* 7 */ + - 6 /* 8 */ + ) ) } #{ @@ -71,9 +77,13 @@ snapshot_kind: text } #{ /* 0 */ - not /* 1 */ true /* 2 */ and /* 3 */ ( - /* 4 */ - false /* 5 */ or /* 6 */ true /* 7 */ + ( + not /* 1 */ true /* 2 */ + and /* 3 */( + /* 4 */ + false /* 5 */ + or /* 6 */true /* 7 */ + ) ) } diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-120.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-120.snap index 35abbc83..23e784e8 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-120.snap @@ -19,7 +19,7 @@ snapshot_kind: text -1 - +7 + (+7 * -3 - 6) } #{ - -1 /* 2 */ - /* 1 */ +/* 0 */7 /* 1 */ + /* 2 */ (/* 3 */ +/* 4 */7 /* 5 */ * /* 6 */ -3 /* 7 */ - 6 /* 8 */) + -1 /* 2 */ - /* 1 */+/* 0 */7 /* 1 */ + /* 2 */(/* 3 */ +/* 4 */7 /* 5 */ * /* 6 */-3 /* 7 */ - 6 /* 8 */) } #{ not a and (b or c) @@ -29,7 +29,7 @@ snapshot_kind: text } #{ /* 0 */ - not /* 1 */ true /* 2 */ and /* 3 */ (/* 4 */ false /* 5 */ or /* 6 */ true /* 7 */) + not /* 1 */ true /* 2 */ and /* 3 */(/* 4 */ false /* 5 */ or /* 6 */true /* 7 */) } #let /* 0 */ (/* 1 */ (/* 2 */ (a) /* 3 */,)) = /* 4 */ (/* 5 */ (/* 6 */ (1,) /* 7 */)) diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-40.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-40.snap index 29d2bc08..c99ebe7f 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-40.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-40.snap @@ -27,9 +27,15 @@ snapshot_kind: text -1 - +7 + (+7 * -3 - 6) } #{ - -1 /* 2 */ - /* 1 */ +/* 0 */7 /* 1 */ + /* 2 */ ( - /* 3 */ - +/* 4 */7 /* 5 */ * /* 6 */ -3 /* 7 */ - 6 /* 8 */ + ( + -1 /* 2 */ + - /* 1 */+/* 0 */7 /* 1 */ + + /* 2 */( + /* 3 */ + +/* 4 */7 /* 5 */ + * /* 6 */-3 /* 7 */ + - 6 /* 8 */ + ) ) } #{ @@ -40,9 +46,13 @@ snapshot_kind: text } #{ /* 0 */ - not /* 1 */ true /* 2 */ and /* 3 */ ( - /* 4 */ - false /* 5 */ or /* 6 */ true /* 7 */ + ( + not /* 1 */ true /* 2 */ + and /* 3 */( + /* 4 */ + false /* 5 */ + or /* 6 */true /* 7 */ + ) ) } diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-80.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-80.snap index ca4ad027..61e263bb 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-code.typ-80.snap @@ -19,8 +19,10 @@ snapshot_kind: text -1 - +7 + (+7 * -3 - 6) } #{ - -1 /* 2 */ - /* 1 */ +/* 0 */7 /* 1 */ + /* 2 */ ( - /* 3 */ +/* 4 */7 /* 5 */ * /* 6 */ -3 /* 7 */ - 6 /* 8 */ + ( + -1 /* 2 */ + - /* 1 */+/* 0 */7 /* 1 */ + + /* 2 */(/* 3 */ +/* 4 */7 /* 5 */ * /* 6 */-3 /* 7 */ - 6 /* 8 */) ) } #{ @@ -31,8 +33,9 @@ snapshot_kind: text } #{ /* 0 */ - not /* 1 */ true /* 2 */ and /* 3 */ ( - /* 4 */ false /* 5 */ or /* 6 */ true /* 7 */ + ( + not /* 1 */ true /* 2 */ + and /* 3 */(/* 4 */ false /* 5 */ or /* 6 */true /* 7 */) ) }