cue: don't print definitions in concrete mode

it is especially important to omit them when
printing data.

Issue #40

Change-Id: Ib6ce21cbaf4987d43036605b0e2fa3a62ec2ef63
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2873
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/testdata/export/export.cue b/cmd/cue/cmd/testdata/export/export.cue
index 7155601..5110493 100644
--- a/cmd/cue/cmd/testdata/export/export.cue
+++ b/cmd/cue/cmd/testdata/export/export.cue
@@ -1,6 +1,8 @@
 package export
 
-def: *1 | int
+One :: 1
+
+def: *One | int
 
 a: string
 a: "foo"
diff --git a/cmd/cue/cmd/testdata/hello/data.cue b/cmd/cue/cmd/testdata/hello/data.cue
index e226892..edbb1b6 100644
--- a/cmd/cue/cmd/testdata/hello/data.cue
+++ b/cmd/cue/cmd/testdata/hello/data.cue
@@ -1,3 +1,3 @@
 package hello
 
-who: "World"
\ No newline at end of file
+who :: "World"
diff --git a/cmd/cue/cmd/testdata/hello/eval.out b/cmd/cue/cmd/testdata/hello/eval.out
index 1ed63b3..f8492ce 100644
--- a/cmd/cue/cmd/testdata/hello/eval.out
+++ b/cmd/cue/cmd/testdata/hello/eval.out
@@ -1,2 +1,2 @@
-who:     "World"
+who ::   "World"
 message: "Hello World!"
diff --git a/cmd/cue/cmd/testdata/hello/eval_conc.out b/cmd/cue/cmd/testdata/hello/eval_conc.out
index 1ed63b3..df67acc 100644
--- a/cmd/cue/cmd/testdata/hello/eval_conc.out
+++ b/cmd/cue/cmd/testdata/hello/eval_conc.out
@@ -1,2 +1 @@
-who:     "World"
 message: "Hello World!"
diff --git a/cmd/cue/cmd/testdata/hello/export.out b/cmd/cue/cmd/testdata/hello/export.out
index ccd2471..cf38f26 100644
--- a/cmd/cue/cmd/testdata/hello/export.out
+++ b/cmd/cue/cmd/testdata/hello/export.out
@@ -1,4 +1,3 @@
 {
-    "who": "World",
     "message": "Hello World!"
 }
diff --git a/cue/export.go b/cue/export.go
index f834300..9ea6c8b 100644
--- a/cue/export.go
+++ b/cue/export.go
@@ -621,6 +621,9 @@
 			f.Optional = token.NoSpace.Pos()
 		}
 		if a.definition {
+			if p.mode.omitHidden || p.mode.concrete {
+				continue
+			}
 			f.Token = token.ISA
 		}
 		if a.feature&hidden != 0 && p.mode.concrete && p.mode.omitHidden {
diff --git a/cue/format/node.go b/cue/format/node.go
index 05bd943..e2bf474 100644
--- a/cue/format/node.go
+++ b/cue/format/node.go
@@ -173,7 +173,7 @@
 		if lastSize != len(f.labelBuf) {
 			f.print(formfeed)
 		}
-		if !regular && first.Pos().RelPos() < token.Newline {
+		if !regular && first.Pos().RelPos() < token.Newline && len(f.output) > 0 {
 			f.print(newline, nooverride)
 		}
 
diff --git a/cue/types.go b/cue/types.go
index dddef8e..c656759 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -1060,8 +1060,13 @@
 		f := label(0)
 		for _, a := range obj.arcs {
 			f |= a.feature
-			if o.omitOptional && a.optional {
+			if a.optional && o.omitOptional {
 				needFilter = true
+				break
+			}
+			if a.definition && (o.omitHidden || o.concrete) {
+				needFilter = true
+				break
 			}
 		}
 		needFilter = needFilter || f&hidden != 0
@@ -1071,10 +1076,17 @@
 		arcs := make([]arc, len(obj.arcs))
 		k := 0
 		for _, a := range obj.arcs {
-			if a.feature&hidden == 0 && !a.optional {
-				arcs[k] = a
-				k++
+			if a.definition && (o.omitHidden || o.concrete) {
+				continue
 			}
+			if a.feature&hidden != 0 && o.omitHidden {
+				continue
+			}
+			if o.omitOptional && a.optional {
+				continue
+			}
+			arcs[k] = a
+			k++
 		}
 		arcs = arcs[:k]
 		obj = &structLit{