Skip to content

Commit

Permalink
Don't try to render attributes with no data type
Browse files Browse the repository at this point in the history
Also improve documentation for --stop/-s

Closes #83
  • Loading branch information
tliron committed Aug 18, 2021
1 parent 2494ff7 commit 723a254
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
8 changes: 4 additions & 4 deletions puccini-tosca/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ If you need more diagnostics for TOSCA parsing use the `parse` command. It works
`compile` but does not emit Clout. Instead, it provides you various flages for examining the
internal workings of Puccini's TOSCA parser.

Use `--stop/-s` to specify a [phase](../tosca/parser/) (1-5) at which you wish the parser to stop.
This could be useful if you're getting too many problems in your report and wish to minimize them
to a more manageable list. Note that `-s 0` will skip the TOSCA parser entirely and just check that
the YAML input is readable.
By default Puccini will attempt all [5 parser phases](../tosca/parser/). This is in order to give
users as complete a problem report as possible. However, if you're getting too many problems it
may be useful to specify `--stop/-s` with a phase number (1-5) at which you wish the to stop. Note
that `-s 0` will skip the TOSCA parser entirely and just check that the YAML input is readable.

`--dump/-d` is used to dump the internal data of phases. You may specify multiple phases to dump
using ",", e.g. `-d 2,3,4`. Per phase you will see:
Expand Down
2 changes: 1 addition & 1 deletion tosca/grammars/tosca_v2_0/attribute-definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (self *AttributeDefinition) Render() {

self.render()

if self.Default != nil {
if (self.Default != nil) && (self.DataType != nil) {
// The "default" value must be a valid value of the type
self.Default.RenderAttribute(self.DataType, self, false, false)
}
Expand Down
9 changes: 6 additions & 3 deletions tosca/grammars/tosca_v2_0/constraint-clause.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,16 @@ func (self *ConstraintClause) IsNativeArgument(index uint) bool {
type ConstraintClauses []*ConstraintClause

func (self ConstraintClauses) Append(constraints ConstraintClauses) ConstraintClauses {
var r ConstraintClauses
length := len(self)
if length > 0 {
r = make(ConstraintClauses, length)
r := make(ConstraintClauses, length)
copy(r, self)
return append(r, constraints...)
} else {
r := make(ConstraintClauses, len(constraints))
copy(r, constraints)
return r
}
return append(r, constraints...)
}

func (self ConstraintClauses) Render(dataType *DataType) {
Expand Down
13 changes: 9 additions & 4 deletions tosca/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,20 @@ func NewReadField(fieldName string, tag string, context *Context, entity reflect
}

func (self *ReadField) Read() {
field := self.Entity.FieldByName(self.FieldName)
fieldType := field.Type()

childData, ok := self.Context.Data.(ard.Map)[self.Key]
if !ok {
if reflection.IsSliceOfPtrToStruct(fieldType) {
// If we have no items, at least have an empty slice
// so that "require" will not see a nil here
field.Set(reflect.MakeSlice(fieldType, 0, 0))
}
return
}

field := self.Entity.FieldByName(self.FieldName)

if self.Reader != nil {
fieldType := field.Type()
if reflection.IsSliceOfPtrToStruct(fieldType) {
// Field is compatible with []*interface{}
slice := field
Expand Down Expand Up @@ -234,7 +239,7 @@ func (self *ReadField) Read() {
if slice.IsNil() {
// If we have no items, at least have an empty slice
// so that "require" will not see a nil here
slice = reflect.MakeSlice(slice.Type(), 0, 0)
slice = reflect.MakeSlice(fieldType, 0, 0)
}
field.Set(slice)
} else if reflection.IsMapOfStringToPtrToStruct(fieldType) {
Expand Down

0 comments on commit 723a254

Please sign in to comment.