node: implement stmt.ConstList

This commit is contained in:
mappu 2020-04-08 20:02:30 +12:00
parent 51ca4ecd77
commit 885d100fbf

26
node.go
View File

@ -621,6 +621,32 @@ func (this *conversionState) convertNoFreeFloating(n_ node.Node) (string, error)
return "fmt.Print(" + quoted + ")\n", nil // newline - standalone statement 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: case *stmt.If:
hasCondAssign, err := hasInteriorAssignment(n.Cond) hasCondAssign, err := hasInteriorAssignment(n.Cond)