Skip to main content

wdl_format/v1/
expr.rs

1//! Formatting of WDL v1.x expression elements.
2
3use wdl_ast::SyntaxKind;
4
5use crate::PreToken;
6use crate::TokenStream;
7use crate::Writable as _;
8use crate::element::FormatElement;
9
10/// Formats a [`SepOption`](wdl_ast::v1::SepOption).
11///
12/// # Panics
13///
14/// This will panic if the element does not have the expected children.
15pub fn format_sep_option(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
16    let mut children = element.children().expect("sep option children");
17
18    let sep_keyword = children.next().expect("sep keyword");
19    assert!(sep_keyword.element().kind() == SyntaxKind::Ident);
20    (&sep_keyword).write(stream);
21
22    let equals = children.next().expect("sep equals");
23    assert!(equals.element().kind() == SyntaxKind::Assignment);
24    (&equals).write(stream);
25
26    let sep_value = children.next().expect("sep value");
27    assert!(sep_value.element().kind() == SyntaxKind::LiteralStringNode);
28    (&sep_value).write(stream);
29    stream.end_word();
30}
31
32/// Formats a [`DefaultOption`](wdl_ast::v1::DefaultOption).
33///
34/// # Panics
35///
36/// This will panic if the element does not have the expected children.
37pub fn format_default_option(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
38    let mut children = element.children().expect("default option children");
39
40    let default_keyword = children.next().expect("default keyword");
41    assert!(default_keyword.element().kind() == SyntaxKind::Ident);
42    (&default_keyword).write(stream);
43
44    let equals = children.next().expect("default equals");
45    assert!(equals.element().kind() == SyntaxKind::Assignment);
46    (&equals).write(stream);
47
48    let default_value = children.next().expect("default value");
49    (&default_value).write(stream);
50    stream.end_word();
51}
52
53/// Formats a [`TrueFalseOption`](wdl_ast::v1::TrueFalseOption).
54///
55/// # Panics
56///
57/// This will panic if the element does not have the expected children.
58pub fn format_true_false_option(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
59    let mut children = element.children().expect("true false option children");
60
61    let first_keyword = children.next().expect("true false option first keyword");
62    let first_keyword_kind = first_keyword.element().kind();
63    assert!(
64        first_keyword_kind == SyntaxKind::TrueKeyword
65            || first_keyword_kind == SyntaxKind::FalseKeyword
66    );
67
68    let first_equals = children.next().expect("true false option first equals");
69    assert!(first_equals.element().kind() == SyntaxKind::Assignment);
70
71    let first_value = children.next().expect("true false option first value");
72
73    let second_keyword = children.next().expect("true false option second keyword");
74    let second_keyword_kind = second_keyword.element().kind();
75    assert!(
76        second_keyword_kind == SyntaxKind::TrueKeyword
77            || second_keyword_kind == SyntaxKind::FalseKeyword
78    );
79
80    let second_equals = children.next().expect("true false option second equals");
81    assert!(second_equals.element().kind() == SyntaxKind::Assignment);
82
83    let second_value = children.next().expect("true false option second value");
84
85    if first_keyword_kind == SyntaxKind::TrueKeyword {
86        assert!(second_keyword_kind == SyntaxKind::FalseKeyword);
87        (&first_keyword).write(stream);
88        (&first_equals).write(stream);
89        (&first_value).write(stream);
90        stream.end_word();
91        (&second_keyword).write(stream);
92        (&second_equals).write(stream);
93        (&second_value).write(stream);
94    } else {
95        assert!(second_keyword_kind == SyntaxKind::TrueKeyword);
96        (&second_keyword).write(stream);
97        (&second_equals).write(stream);
98        (&second_value).write(stream);
99        stream.end_word();
100        (&first_keyword).write(stream);
101        (&first_equals).write(stream);
102        (&first_value).write(stream);
103    }
104    stream.end_word();
105}
106
107/// Formats a [`Placeholder`](wdl_ast::v1::Placeholder).
108///
109/// # Panics
110///
111/// This will panic if the element does not have the expected children.
112pub fn format_placeholder(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
113    let mut children = element.children().expect("placeholder children");
114
115    let open = children.next().expect("placeholder open");
116    assert!(open.element().kind() == SyntaxKind::PlaceholderOpen);
117    let syntax = open.element().inner();
118    let text = syntax.as_token().expect("token").text();
119    match text {
120        "${" => {
121            stream.push_literal_in_place_of_token(
122                open.element().as_token().expect("token"),
123                "~{".to_owned(),
124            );
125        }
126        "~{" => {
127            (&open).write(stream);
128        }
129        _ => {
130            unreachable!("unexpected placeholder open: {:?}", text);
131        }
132    }
133
134    for child in children {
135        (&child).write(stream);
136    }
137}
138
139/// Formats a [`LiteralString`](wdl_ast::v1::LiteralString).
140///
141/// # Panics
142///
143/// This will panic if the element does not have the expected children.
144pub fn format_literal_string(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
145    for child in element.children().expect("literal string children") {
146        match child.element().kind() {
147            SyntaxKind::SingleQuote => {
148                stream.push_literal_in_place_of_token(
149                    child.element().as_token().expect("token"),
150                    "\"".to_owned(),
151                );
152            }
153            SyntaxKind::OpenHeredoc | SyntaxKind::CloseHeredoc | SyntaxKind::DoubleQuote => {
154                (&child).write(stream);
155            }
156            SyntaxKind::LiteralStringText => {
157                let mut replacement = String::new();
158                let syntax = child.element().inner();
159                let mut chars = syntax.as_token().expect("token").text().chars().peekable();
160                let mut prev_c = None;
161                while let Some(c) = chars.next() {
162                    match c {
163                        '\\' => {
164                            if let Some(next_c) = chars.peek()
165                                && *next_c == '\''
166                            {
167                                // Do not write this backslash as single quotes don't need
168                                // escaping in a double-quoted string (and we format all
169                                // LiteralStrings as double-quoted strings).
170                                prev_c = Some(c);
171                                continue;
172                            }
173                            replacement.push(c);
174                        }
175                        '"' => {
176                            if prev_c.is_none_or(|c| c != '\\') {
177                                // This double quote sign is not escaped, so we need to escape
178                                // it. This happens when a single quoted string is re-formatted
179                                // as a double quoted string.
180                                replacement.push('\\');
181                            }
182                            replacement.push(c);
183                        }
184                        _ => {
185                            replacement.push(c);
186                        }
187                    }
188                    prev_c = Some(c);
189                }
190
191                stream.push_literal_in_place_of_token(
192                    child.element().as_token().expect("token"),
193                    replacement,
194                );
195            }
196            SyntaxKind::PlaceholderNode => {
197                (&child).write(stream);
198            }
199            _ => {
200                unreachable!(
201                    "unexpected child in literal string: {:?}",
202                    child.element().kind()
203                );
204            }
205        }
206    }
207}
208
209/// Formats a [`LiteralNone`](wdl_ast::v1::LiteralNone).
210///
211/// # Panics
212///
213/// This will panic if the element does not have the expected children.
214pub fn format_literal_none(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
215    let mut children = element.children().expect("literal none children");
216    let none = children.next().expect("literal none token");
217    assert!(none.element().kind() == SyntaxKind::NoneKeyword);
218    (&none).write(stream);
219}
220
221/// Formats a [`LiteralPair`](wdl_ast::v1::LiteralPair).
222///
223/// # Panics
224///
225/// This will panic if the element does not have the expected children.
226pub fn format_literal_pair(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
227    let mut children = element.children().expect("literal pair children");
228
229    let open_paren = children.next().expect("literal pair open paren");
230    assert!(open_paren.element().kind() == SyntaxKind::OpenParen);
231    (&open_paren).write(stream);
232
233    let left = children.next().expect("literal pair left");
234    (&left).write(stream);
235
236    let comma = children.next().expect("literal pair comma");
237    assert!(comma.element().kind() == SyntaxKind::Comma);
238    (&comma).write(stream);
239    stream.end_word();
240
241    let right = children.next().expect("literal pair right");
242    (&right).write(stream);
243
244    let close_paren = children.next().expect("literal pair close paren");
245    assert!(close_paren.element().kind() == SyntaxKind::CloseParen);
246    (&close_paren).write(stream);
247}
248
249/// Formats a [`LiteralBoolean`](wdl_ast::v1::LiteralBoolean).
250///
251/// # Panics
252///
253/// This will panic if the element does not have the expected children.
254pub fn format_literal_boolean(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
255    let mut children = element.children().expect("literal boolean children");
256    let bool = children.next().expect("literal boolean token");
257    (&bool).write(stream);
258}
259
260/// Formats a [`NegationExpr`](wdl_ast::v1::NegationExpr).
261///
262/// # Panics
263///
264/// This will panic if the element does not have the expected children.
265pub fn format_negation_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
266    let mut children = element.children().expect("negation expr children");
267    let minus = children.next().expect("negation expr minus");
268    assert!(minus.element().kind() == SyntaxKind::Minus);
269    (&minus).write(stream);
270
271    let expr = children.next().expect("negation expr expr");
272    (&expr).write(stream);
273}
274
275/// Formats a [`LiteralInteger`](wdl_ast::v1::LiteralInteger).
276///
277/// # Panics
278///
279/// This will panic if the element does not have the expected children.
280pub fn format_literal_integer(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
281    for child in element.children().expect("literal integer children") {
282        (&child).write(stream);
283    }
284}
285
286/// Formats a [`LiteralFloat`](wdl_ast::v1::LiteralFloat).
287///
288/// # Panics
289///
290/// This will panic if the element does not have the expected children.
291pub fn format_literal_float(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
292    for child in element.children().expect("literal float children") {
293        (&child).write(stream);
294    }
295}
296
297/// Formats a [`NameRefExpr`](wdl_ast::v1::NameRefExpr).
298///
299/// # Panics
300///
301/// This will panic if the element does not have the expected children.
302pub fn format_name_ref_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
303    let mut children = element.children().expect("name ref children");
304    let name = children.next().expect("name ref name");
305    (&name).write(stream);
306}
307
308/// Formats a [`LiteralArray`](wdl_ast::v1::LiteralArray).
309///
310/// # Panics
311///
312/// This will panic if the element does not have the expected children.
313pub fn format_literal_array(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
314    let mut children = element.children().expect("literal array children");
315
316    let open_bracket = children.next().expect("literal array open bracket");
317    assert!(open_bracket.element().kind() == SyntaxKind::OpenBracket);
318    (&open_bracket).write(stream);
319
320    let mut items = Vec::new();
321    let mut commas = Vec::new();
322    let mut close_bracket = None;
323
324    for child in children {
325        match child.element().kind() {
326            SyntaxKind::CloseBracket => {
327                close_bracket = Some(child.to_owned());
328            }
329            SyntaxKind::Comma => {
330                commas.push(child.to_owned());
331            }
332            _ => {
333                items.push(child.to_owned());
334            }
335        }
336    }
337
338    let empty = items.is_empty();
339    if !empty {
340        stream.increment_indent();
341    }
342    let mut commas = commas.iter();
343    for item in items {
344        (&item).write(stream);
345        if let Some(comma) = commas.next() {
346            (comma).write(stream);
347        } else {
348            stream.push_literal(",".to_string(), SyntaxKind::Comma);
349        }
350        stream.end_line();
351    }
352
353    if !empty {
354        stream.decrement_indent();
355    }
356    (&close_bracket.expect("literal array close bracket")).write(stream);
357}
358
359/// Formats a [`LiteralMapItem`](wdl_ast::v1::LiteralMapItem).
360///
361/// # Panics
362///
363/// This will panic if the element does not have the expected children.
364pub fn format_literal_map_item(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
365    let mut children = element.children().expect("literal map item children");
366
367    let key = children.next().expect("literal map item key");
368    (&key).write(stream);
369
370    let colon = children.next().expect("literal map item colon");
371    assert!(colon.element().kind() == SyntaxKind::Colon);
372    (&colon).write(stream);
373    stream.end_word();
374
375    let value = children.next().expect("literal map item value");
376    (&value).write(stream);
377}
378
379/// Formats a [`LiteralMap`](wdl_ast::v1::LiteralMap).
380///
381/// # Panics
382///
383/// This will panic if the element does not have the expected children.
384pub fn format_literal_map(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
385    let mut children = element.children().expect("literal map children");
386
387    let open_brace = children.next().expect("literal map open brace");
388    assert!(open_brace.element().kind() == SyntaxKind::OpenBrace);
389    (&open_brace).write(stream);
390    stream.increment_indent();
391
392    let mut items = Vec::new();
393    let mut commas = Vec::new();
394    let mut close_brace = None;
395
396    for child in children {
397        match child.element().kind() {
398            SyntaxKind::CloseBrace => {
399                close_brace = Some(child.to_owned());
400            }
401            SyntaxKind::Comma => {
402                commas.push(child.to_owned());
403            }
404            _ => {
405                items.push(child.to_owned());
406            }
407        }
408    }
409
410    let mut commas = commas.iter();
411    for item in items {
412        (&item).write(stream);
413        if let Some(comma) = commas.next() {
414            (comma).write(stream);
415        } else {
416            stream.push_literal(",".to_string(), SyntaxKind::Comma);
417        }
418        stream.end_line();
419    }
420
421    stream.decrement_indent();
422    (&close_brace.expect("literal map close brace")).write(stream);
423}
424
425/// Formats a [`LiteralObjectItem`](wdl_ast::v1::LiteralObjectItem).
426///
427/// # Panics
428///
429/// This will panic if the element does not have the expected children.
430pub fn format_literal_object_item(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
431    let mut children = element.children().expect("literal object item children");
432
433    let key = children.next().expect("literal object item key");
434    assert!(key.element().kind() == SyntaxKind::Ident);
435    (&key).write(stream);
436
437    let colon = children.next().expect("literal object item colon");
438    assert!(colon.element().kind() == SyntaxKind::Colon);
439    (&colon).write(stream);
440    stream.end_word();
441
442    let value = children.next().expect("literal object item value");
443    (&value).write(stream);
444    assert!(children.next().is_none());
445}
446
447/// Formats a [`LiteralObject`](wdl_ast::v1::LiteralObject).
448///
449/// # Panics
450///
451/// This will panic if the element does not have the expected children.
452pub fn format_literal_object(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
453    let mut children = element.children().expect("literal object children");
454
455    let object_keyword = children.next().expect("literal object keyword");
456    assert!(object_keyword.element().kind() == SyntaxKind::ObjectKeyword);
457    (&object_keyword).write(stream);
458    stream.end_word();
459
460    let open_brace = children.next().expect("literal object open brace");
461    assert!(open_brace.element().kind() == SyntaxKind::OpenBrace);
462    (&open_brace).write(stream);
463    stream.increment_indent();
464
465    let mut members = Vec::new();
466    let mut commas = Vec::new();
467    let mut close_brace = None;
468
469    for child in children {
470        match child.element().kind() {
471            SyntaxKind::CloseBrace => {
472                close_brace = Some(child.to_owned());
473            }
474            SyntaxKind::Comma => {
475                commas.push(child.to_owned());
476            }
477            _ => {
478                members.push(child.to_owned());
479            }
480        }
481    }
482
483    let mut commas = commas.iter();
484    for member in members {
485        (&member).write(stream);
486        if let Some(comma) = commas.next() {
487            (comma).write(stream);
488        } else {
489            stream.push_literal(",".to_string(), SyntaxKind::Comma);
490        }
491        stream.end_line();
492    }
493
494    stream.decrement_indent();
495    (&close_brace.expect("literal object close brace")).write(stream);
496}
497
498/// Formats a [`AccessExpr`](wdl_ast::v1::AccessExpr).
499///
500/// # Panics
501///
502/// This will panic if the element does not have the expected children.
503pub fn format_access_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
504    for child in element.children().expect("access expr children") {
505        (&child).write(stream);
506    }
507}
508
509/// Formats a [`CallExpr`](wdl_ast::v1::CallExpr).
510///
511/// # Panics
512///
513/// This will panic if the element does not have the expected children.
514pub fn format_call_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
515    for child in element.children().expect("call expr children") {
516        (&child).write(stream);
517        if child.element().kind() == SyntaxKind::Comma {
518            stream.end_word();
519        }
520    }
521}
522
523/// Formats an [`IndexExpr`](wdl_ast::v1::IndexExpr).
524///
525/// # Panics
526///
527/// This will panic if the element does not have the expected children.
528pub fn format_index_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
529    for child in element.children().expect("index expr children") {
530        (&child).write(stream);
531    }
532}
533
534/// Formats an [`AdditionExpr`](wdl_ast::v1::AdditionExpr).
535///
536/// # Panics
537///
538/// This will panic if the element does not have the expected children.
539pub fn format_addition_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
540    for child in element.children().expect("addition expr children") {
541        let whitespace_wrapped = child.element().kind() == SyntaxKind::Plus;
542        if whitespace_wrapped {
543            stream.end_word();
544        }
545        (&child).write(stream);
546        if whitespace_wrapped {
547            stream.end_word();
548        }
549    }
550}
551
552/// Formats a [`SubtractionExpr`](wdl_ast::v1::SubtractionExpr).
553///
554/// # Panics
555///
556/// This will panic if the element does not have the expected children.
557pub fn format_subtraction_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
558    for child in element.children().expect("subtraction expr children") {
559        let whitespace_wrapped = child.element().kind() == SyntaxKind::Minus;
560        if whitespace_wrapped {
561            stream.end_word();
562        }
563        (&child).write(stream);
564        if whitespace_wrapped {
565            stream.end_word();
566        }
567    }
568}
569
570/// Formats a [`MultiplicationExpr`](wdl_ast::v1::MultiplicationExpr).
571///
572/// # Panics
573///
574/// This will panic if the element does not have the expected children.
575pub fn format_multiplication_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
576    for child in element.children().expect("multiplication expr children") {
577        let whitespace_wrapped = child.element().kind() == SyntaxKind::Asterisk;
578        if whitespace_wrapped {
579            stream.end_word();
580        }
581        (&child).write(stream);
582        if whitespace_wrapped {
583            stream.end_word();
584        }
585    }
586}
587
588/// Formats a [`DivisionExpr`](wdl_ast::v1::DivisionExpr).
589///
590/// # Panics
591///
592/// This will panic if the element does not have the expected children.
593pub fn format_division_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
594    for child in element.children().expect("division expr children") {
595        let whitespace_wrapped = child.element().kind() == SyntaxKind::Slash;
596        if whitespace_wrapped {
597            stream.end_word();
598        }
599        (&child).write(stream);
600        if whitespace_wrapped {
601            stream.end_word();
602        }
603    }
604}
605
606/// Formats a [`ModuloExpr`](wdl_ast::v1::ModuloExpr).
607///
608/// # Panics
609///
610/// This will panic if the element does not have the expected children.
611pub fn format_modulo_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
612    for child in element.children().expect("modulo expr children") {
613        let whitespace_wrapped = child.element().kind() == SyntaxKind::Percent;
614        if whitespace_wrapped {
615            stream.end_word();
616        }
617        (&child).write(stream);
618        if whitespace_wrapped {
619            stream.end_word();
620        }
621    }
622}
623
624/// Formats an [`ExponentiationExpr`](wdl_ast::v1::ExponentiationExpr).
625///
626/// # Panics
627///
628/// This will panic if the element does not have the expected children.
629pub fn format_exponentiation_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
630    for child in element.children().expect("exponentiation expr children") {
631        let whitespace_wrapped = child.element().kind() == SyntaxKind::Exponentiation;
632        if whitespace_wrapped {
633            stream.end_word();
634        }
635        (&child).write(stream);
636        if whitespace_wrapped {
637            stream.end_word();
638        }
639    }
640}
641
642/// Formats a [`LogicalAndExpr`](wdl_ast::v1::LogicalAndExpr).
643///
644/// # Panics
645///
646/// This will panic if the element does not have the expected children.
647pub fn format_logical_and_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
648    for child in element.children().expect("logical and expr children") {
649        let whitespace_wrapped = child.element().kind() == SyntaxKind::LogicalAnd;
650        if whitespace_wrapped {
651            stream.end_word();
652        }
653        (&child).write(stream);
654        if whitespace_wrapped {
655            stream.end_word();
656        }
657    }
658}
659
660/// Formats a [`LogicalNotExpr`](wdl_ast::v1::LogicalNotExpr).
661///
662/// # Panics
663///
664/// This will panic if the element does not have the expected children.
665pub fn format_logical_not_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
666    let mut children = element.children().expect("logical not expr children");
667    let not = children.next().expect("logical not expr not");
668    assert!(not.element().kind() == SyntaxKind::Exclamation);
669    (&not).write(stream);
670
671    let expr = children.next().expect("logical not expr expr");
672    (&expr).write(stream);
673}
674
675/// Formats a [`LogicalOrExpr`](wdl_ast::v1::LogicalOrExpr).
676///
677/// # Panics
678///
679/// This will panic if the element does not have the expected children.
680pub fn format_logical_or_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
681    for child in element.children().expect("logical or expr children") {
682        let whitespace_wrapped = child.element().kind() == SyntaxKind::LogicalOr;
683        if whitespace_wrapped {
684            stream.end_word();
685        }
686        (&child).write(stream);
687        if whitespace_wrapped {
688            stream.end_word();
689        }
690    }
691}
692
693/// Formats an [`EqualityExpr`](wdl_ast::v1::EqualityExpr).
694///
695/// # Panics
696///
697/// This will panic if the element does not have the expected children.
698pub fn format_equality_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
699    for child in element.children().expect("equality expr children") {
700        let whitespace_wrapped = child.element().kind() == SyntaxKind::Equal;
701        if whitespace_wrapped {
702            stream.end_word();
703        }
704        (&child).write(stream);
705        if whitespace_wrapped {
706            stream.end_word();
707        }
708    }
709}
710
711/// Formats a [`InequalityExpr`](wdl_ast::v1::InequalityExpr).
712///
713/// # Panics
714///
715/// This will panic if the element does not have the expected children.
716pub fn format_inequality_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
717    for child in element.children().expect("inequality expr children") {
718        let whitespace_wrapped = child.element().kind() == SyntaxKind::NotEqual;
719        if whitespace_wrapped {
720            stream.end_word();
721        }
722        (&child).write(stream);
723        if whitespace_wrapped {
724            stream.end_word();
725        }
726    }
727}
728
729/// Formats a [`LessExpr`](wdl_ast::v1::LessExpr).
730///
731/// # Panics
732///
733/// This will panic if the element does not have the expected children.
734pub fn format_less_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
735    for child in element.children().expect("less expr children") {
736        let whitespace_wrapped = child.element().kind() == SyntaxKind::Less;
737        if whitespace_wrapped {
738            stream.end_word();
739        }
740        (&child).write(stream);
741        if whitespace_wrapped {
742            stream.end_word();
743        }
744    }
745}
746
747/// Formats a [`LessEqualExpr`](wdl_ast::v1::LessEqualExpr).
748///
749/// # Panics
750///
751/// This will panic if the element does not have the expected children.
752pub fn format_less_equal_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
753    for child in element.children().expect("less equal expr children") {
754        let whitespace_wrapped = child.element().kind() == SyntaxKind::LessEqual;
755        if whitespace_wrapped {
756            stream.end_word();
757        }
758        (&child).write(stream);
759        if whitespace_wrapped {
760            stream.end_word();
761        }
762    }
763}
764
765/// Formats a [`GreaterExpr`](wdl_ast::v1::GreaterExpr).
766///
767/// # Panics
768///
769/// This will panic if the element does not have the expected children.
770pub fn format_greater_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
771    for child in element.children().expect("greater expr children") {
772        let whitespace_wrapped = child.element().kind() == SyntaxKind::Greater;
773        if whitespace_wrapped {
774            stream.end_word();
775        }
776        (&child).write(stream);
777        if whitespace_wrapped {
778            stream.end_word();
779        }
780    }
781}
782
783/// Formats a [`GreaterEqualExpr`](wdl_ast::v1::GreaterEqualExpr).
784///
785/// # Panics
786///
787/// This will panic if the element does not have the expected children.
788pub fn format_greater_equal_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
789    for child in element.children().expect("greater equal expr children") {
790        let whitespace_wrapped = child.element().kind() == SyntaxKind::GreaterEqual;
791        if whitespace_wrapped {
792            stream.end_word();
793        }
794        (&child).write(stream);
795        if whitespace_wrapped {
796            stream.end_word();
797        }
798    }
799}
800
801/// Formats a [`ParenthesizedExpr`](wdl_ast::v1::ParenthesizedExpr).
802///
803/// # Panics
804///
805/// This will panic if the element does not have the expected children.
806pub fn format_parenthesized_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
807    for child in element.children().expect("parenthesized expr children") {
808        (&child).write(stream);
809    }
810}
811
812/// Formats an [`IfExpr`](wdl_ast::v1::IfExpr).
813///
814/// # Panics
815///
816/// This will panic if the element does not have the expected children.
817pub fn format_if_expr(element: &FormatElement, stream: &mut TokenStream<PreToken>) {
818    for child in element.children().expect("if expr children") {
819        (&child).write(stream);
820        stream.end_word();
821    }
822    stream.trim_end(&PreToken::WordEnd);
823}