|
1 | 1 | use std::fmt::{Debug, Display, Formatter, Result, Write}; |
2 | 2 |
|
3 | 3 | use crate::{ |
4 | | - Ast, |
| 4 | + Ast, Function, |
5 | 5 | ast::{ |
6 | 6 | Atom, BinaryOperator, BindingPower, Body, Command, Expr, ExprNode, PlaceOperator, Rule, |
7 | 7 | RulePattern, Statement, Ternary, UnaryOperator, |
@@ -47,6 +47,14 @@ impl Display for Ast<'_> { |
47 | 47 | write_body_ln(f, body, 0)?; |
48 | 48 | writeln!(f)?; |
49 | 49 | } |
| 50 | + for (fun, Function { args, body }) in &self.functions { |
| 51 | + // GNU appears to place two newlines before functions. |
| 52 | + // I think it's a bug but we'll keep it. |
| 53 | + write!(f, "\nfunction {fun}(")?; |
| 54 | + write_args(f, args, 0)?; |
| 55 | + writeln!(f, ") ")?; |
| 56 | + write_body_ln(f, body, 0)?; |
| 57 | + } |
50 | 58 | Ok(()) |
51 | 59 | } |
52 | 60 | } |
@@ -336,7 +344,7 @@ impl Display for Command { |
336 | 344 | } |
337 | 345 | } |
338 | 346 |
|
339 | | -fn write_args(f: &mut Formatter<'_>, args: &[Expr<'_>], indent: u8) -> Result { |
| 347 | +fn write_args(f: &mut Formatter<'_>, args: &[impl Display], indent: u8) -> Result { |
340 | 348 | let ew = encode(indent, 0); |
341 | 349 | for (i, arg) in args.iter().enumerate() { |
342 | 350 | if i != 0 { |
|
0 commit comments