Skip to content

Commit 06b6b45

Browse files
committed
parser: function idempotency
1 parent d078568 commit 06b6b45

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

parser/src/idempotency.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::{Debug, Display, Formatter, Result, Write};
22

33
use crate::{
4-
Ast,
4+
Ast, Function,
55
ast::{
66
Atom, BinaryOperator, BindingPower, Body, Command, Expr, ExprNode, PlaceOperator, Rule,
77
RulePattern, Statement, Ternary, UnaryOperator,
@@ -47,6 +47,14 @@ impl Display for Ast<'_> {
4747
write_body_ln(f, body, 0)?;
4848
writeln!(f)?;
4949
}
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+
}
5058
Ok(())
5159
}
5260
}
@@ -336,7 +344,7 @@ impl Display for Command {
336344
}
337345
}
338346

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 {
340348
let ew = encode(indent, 0);
341349
for (i, arg) in args.iter().enumerate() {
342350
if i != 0 {

0 commit comments

Comments
 (0)