all: handle optional args more gracefully

This commit is contained in:
2018-05-14 21:55:10 +02:00
parent ac880c26a6
commit 4be6927dc2
2 changed files with 12 additions and 4 deletions

View File

@@ -89,13 +89,21 @@ func (ast *AST) Pretty() string {
for _, elem := range val.Params {
agg = append(agg, elem)
}
opt := ""
rest := ""
if val.HasRest() {
opt = " . " + *val.Rest
rest = " . " + *val.Rest
}
// TODO: opt
opt := ""
iter := val.Opt.IterFunc()
for kv, ok := iter(); ok; kv, ok = iter() {
opt += "(o " + kv.Key.(string) + " " + kv.Value.(*AST).Pretty() + ")"
}
if val.HasOpt() && (val.HasRest() || len(agg) != 0) {
opt = " " + opt
}
body := val.Body.Pretty()
return "(fn (" + strings.Join(agg, " ") + opt + ") " + body + ")"
return "(fn (" + strings.Join(agg, " ") + rest + opt + ") " + body + ")"
} else if ast.Tag == Char {
return "#" + string(ast.Val.(rune))
} else if ast.Tag == Table {