cue/ast: allow CommentGroup as declaration

This simplifies the construction of ASTs with
free-floating comments.

Also consecutive comment groups are now always
printed with a newline in between. To not do so,
one will have to merge two consecutive comment
groups manually. This more closely matches the
typical intention of comment groups.

Change-Id: Id4a601bd6d255aa6c6489f43df52534ac5303af9
Reviewed-by: Marcel van Lohuizen <>
diff --git a/cue/ast.go b/cue/ast.go
index 1db9ad8..1485a2a 100644
--- a/cue/ast.go
+++ b/cue/ast.go
@@ -512,6 +512,9 @@
+	case *ast.CommentGroup:
+		// Nothing to do for a free-floating comment group.
 	// nothing to do
 	// case *syntax.EmitDecl: