Unverified Commit d2b0df05 authored by bryanl's avatar bryanl
Browse files

update ksonnet lib printer with array comprehensions


Signed-off-by: default avatarbryanl <bryanliles@gmail.com>
parent 7692a499
......@@ -276,8 +276,8 @@
"ksonnet-gen/nodemaker",
"ksonnet-gen/printer"
]
revision = "6f85269d8cc77d49df665ea240f57dc0de1e7abc"
version = "v0.1.0"
revision = "cd6bc29c939b79f8e3acdd289356b8fbebf09c50"
version = "v0.1.1"
[[projects]]
name = "github.com/magiconair/properties"
......@@ -683,6 +683,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "f761dfa7c14879995a07e46c07d35dd95db79cc363e6b7be4310076b7d6d2077"
inputs-digest = "52b150f1b6dc5cb0b070e3161194ab302ed6a524834e6dd5177a4c40b64c63bb"
solver-name = "gps-cdcl"
solver-version = 1
......@@ -50,7 +50,7 @@
[[constraint]]
name = "github.com/ksonnet/ksonnet-lib"
version = "v0.1.0"
version = "v0.1.1"
[[constraint]]
name = "github.com/mattn/go-isatty"
......
......@@ -18,6 +18,7 @@ package pipeline
import (
"bytes"
"encoding/json"
"fmt"
"io"
"path/filepath"
"regexp"
......@@ -221,6 +222,7 @@ func (p *Pipeline) moduleObjects(module component.Module, filter []string) ([]*u
uns, _, err := unstructured.UnstructuredJSONScheme.Decode([]byte(patched), nil, nil)
if err != nil {
fmt.Println(patched)
return nil, errors.Wrap(err, "decode unstructured")
}
ret = append(ret, uns)
......
......@@ -146,6 +146,8 @@ func (p *printer) print(n interface{}) {
}
}
p.writeString("]")
case *ast.ArrayComp:
p.handleArrayComp(t)
case *ast.Binary:
p.print(t.Left)
p.writeByte(space, 1)
......@@ -157,7 +159,10 @@ func (p *printer) print(n interface{}) {
case *ast.Conditional:
p.handleConditional(t)
case *ast.Function:
p.writeString("function")
p.addMethodSignature(t)
p.writeString(" ")
p.print(t.Body)
case *ast.Import:
p.writeString("import ")
p.print(t.File)
......@@ -336,7 +341,7 @@ func (p *printer) handleLocal(l *ast.Local) {
p.print(bind.Body)
p.writeString(";")
case *ast.Function:
p.print(bind.Body)
p.addMethodSignature(bodyType)
p.handleLocalFunction(bodyType)
}
c := 1
......@@ -389,6 +394,23 @@ func (p *printer) handleObjectComp(oc *ast.ObjectComp) {
p.handleObjectField(oc)
}
func (p *printer) handleArrayComp(ac *ast.ArrayComp) {
p.writeString("[")
p.indentLevel++
p.writeByte(newline, 1)
p.print(ac.Body)
p.writeByte(newline, 1)
p.forSpec(ac.Spec)
p.indentLevel--
p.writeByte(newline, 1)
p.writeString("]")
}
func (p *printer) forSpec(spec ast.ForSpec) {
p.writeString(fmt.Sprintf("for %s in ", string(spec.VarName)))
p.print(spec.Expr)
}
func (p *printer) handleObjectField(n interface{}) {
var ofHide ast.ObjectFieldHide
var ofKind ast.ObjectFieldKind
......@@ -451,7 +473,7 @@ func (p *printer) handleObjectField(n interface{}) {
switch ofKind {
default:
p.err = errors.Errorf("unknown Kind type %#v", ofKind)
p.err = errors.Errorf("unknown Kind type (%T) %#v", ofKind, ofKind)
return
case ast.ObjectFieldID:
p.writeString(ofID)
......@@ -499,8 +521,7 @@ func (p *printer) handleObjectField(n interface{}) {
p.print(ofExpr2)
p.writeByte(comma, 1)
p.writeByte(space, 1)
p.writeString(fmt.Sprintf("for %s in ", string(forSpec.VarName)))
p.print(forSpec.Expr)
p.forSpec(forSpec)
p.indentLevel--
p.writeByte(newline, 1)
p.writeString("}")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment