From 885d100fbf3e067aa6fe04eec6c17ce7cc7ca271 Mon Sep 17 00:00:00 2001 From: mappu Date: Wed, 8 Apr 2020 20:02:30 +1200 Subject: [PATCH] node: implement stmt.ConstList --- node.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/node.go b/node.go index a88f698..90bc2d3 100644 --- a/node.go +++ b/node.go @@ -621,6 +621,32 @@ func (this *conversionState) convertNoFreeFloating(n_ node.Node) (string, error) return "fmt.Print(" + quoted + ")\n", nil // newline - standalone statement + case *stmt.ConstList: + consts := make([]string, 0, len(n.Consts)) + for _, c_ := range n.Consts { + c, ok := c_.(*stmt.Constant) + if !ok { + return "", parseErr{c_, fmt.Errorf("expected stmt.Constant")} + } + + // TODO c.PhpDocComment + + constName := c.ConstantName.(*node.Identifier).Value + + rvalue, err := this.convert(c.Expr) + if err != nil { + return "", parseErr{c, err} + } + + consts = append(consts, constName+" = "+rvalue) + } + + if len(n.Consts) == 1 { + return "const " + consts[0] + "\n", nil + } else { + return "const (\n" + strings.Join(consts, "\n") + ")\n", nil + } + case *stmt.If: hasCondAssign, err := hasInteriorAssignment(n.Cond)