Skip to content

Commit

Permalink
New quirk: imports.sequencedlist
Browse files Browse the repository at this point in the history
Closes #80
  • Loading branch information
tliron committed Jul 29, 2021
1 parent 6eca57e commit 71daaaf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tosca/QUIRKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ These are activated via the `--quirk/-x` switch for
* **imports.topology_template.ignore**: Allows imported units to contain a `topology_template`
section, which is ignored.

* **imports.sequencedlist**: Allows the "import" syntax to be a sequenced list, in which the
name is ignored.

* **data_types.string.permissive**: By default Puccini is strict about "string"-typed values
and will consider integers, floats, and boolean values to be problems. This quirk will accept
such values and convert them as sensibly as possible to strings. This includes accepting floats
Expand Down Expand Up @@ -45,4 +48,3 @@ These are activated via the `--quirk/-x` switch for

* **annotations.ignore**: Ignores the "annotation_types" keyword in service templates and the
"annotations" keyword in parameter definitions.

12 changes: 12 additions & 0 deletions tosca/grammars/tosca_v1_3/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ func ReadImport(context *tosca.Context) tosca.EntityPtr {
self := tosca_v2_0.NewImport(context)

if context.Is(ard.TypeMap) {
if context.HasQuirk(tosca.QuirkImportsSequencedList) {
map_ := context.Data.(ard.Map)
if len(map_) == 1 {
for _, data := range map_ {
if data_, ok := data.(ard.Map); ok {
context.Data = data_
}
break
}
}
}

// Long notation
context.ValidateUnsupportedFields(context.ReadFields(self))
} else if context.ValidateType(ard.TypeMap, ard.TypeString) {
Expand Down
12 changes: 12 additions & 0 deletions tosca/grammars/tosca_v2_0/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ func ReadImport(context *tosca.Context) tosca.EntityPtr {
self := NewImport(context)

if context.Is(ard.TypeMap) {
if context.HasQuirk(tosca.QuirkImportsSequencedList) {
map_ := context.Data.(ard.Map)
if len(map_) == 1 {
for _, data := range map_ {
if data_, ok := data.(ard.Map); ok {
context.Data = data_
}
break
}
}
}

// Long notation
context.ValidateUnsupportedFields(context.ReadFields(self))
} else if context.ValidateType(ard.TypeMap, ard.TypeString) {
Expand Down
4 changes: 4 additions & 0 deletions tosca/quirk.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const QuirkImportsTopologyTemplateIgnore Quirk = "imports.topology_template.igno
// another unit with an incompatible grammar. This quirk will disable the check.
const QuirkImportsVersionPermissive Quirk = "imports.version.permissive"

// Allows the "import" syntax to be a sequenced list, in which the
// name is ignored.
const QuirkImportsSequencedList Quirk = "imports.sequencedlist"

// By default Puccini is strict about "string"-typed values
// and will consider integers, floats, and boolean values to be problems. This quirk will accept
// such values and convert them as sensibly as possible to strings. This includes accepting floats
Expand Down

0 comments on commit 71daaaf

Please sign in to comment.