Jira (PUP-5942) Allow a Struct type to define keys using a pattern

2 views
Skip to first unread message

Henrik Lindberg (JIRA)

unread,
Feb 20, 2016, 11:19:03 PM2/20/16
to puppe...@googlegroups.com
Henrik Lindberg created an issue
 
Puppet / New Feature PUP-5942
Allow a Struct type to define keys using a pattern
Issue Type: New Feature New Feature
Assignee: Unassigned
Created: 2016/02/20 8:18 PM
Fix Versions: PUP 4.x
Priority: Normal Normal
Reporter: Henrik Lindberg

In order to support the behavior described in PUP-4669 and for general flexibility we should allow a Struct's key to be specified by a Pattern type.

type S1 = Struct{ regular => Integer, Pattern['prefix_.+'] => String}
type S2 = Struct{ regular => Integer, Optional[Pattern['prefix_.+']] => String}
type S3 = Struct{ regular => Integer, Array[Pattern['prefix_.+'], 2, 3] => String}

Where a Pattern key means 0 or infinite amount of occurrences,
an Optional around the key type means 0 or 1 occurrence, and an Array
specifies min, max occurrences.

Such that:

$a1 = { regular => 1, prefix_a = > 10}
$a1 =~ S1 == true
 
$a2 = { regular => 1}
$a2 =~ S1 == false
$a2 =~ S2 == true
 
$a3 = { regular => 1, prefix_a => 10, prefix_b = 20, prefix_c => 30}
$a4 = { regular => 1, prefix_a => 10, prefix_b = 20, prefix_c => 30, prefix_d => 40}
$a3 =~ S3 == true
$a3 =~ S3 == true
$a3 =~ S3 == true
 
$a4 =~ S3 == false # a4 has too many matching keys
$a1 =~ S3 == false  # a1 has one prefix, 2 is required

  • It is up to the user to construct the patterns so that they do not overlap. The struct type matches from left to right, the first pattern (if there are several) that accepts the key means that it is considered a match, and the count is associated with this struct entry. Thus, overlapping or keys with negative character set matches can cause ambiguities in the counts. This is the user's problem - it is impossible to issue a warning.
  • Type Algebra on Structs with patterns:
    • A struct is assignable to another if all after having matched all regular keys, regular keys in the RHS are matched by Pattern based keys on the LHS side, or if the set of Patterns are equal.
    • Two structs with non equal patterns are disjunct
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.12#64027-sha1:e3691cc)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
Feb 20, 2016, 11:23:03 PM2/20/16
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
In order to support the behavior described in PUP-4669 and for general flexibility we should allow a Struct's key to be specified by a Pattern type.

{code:puppet}

type S1 = Struct{ regular => Integer, Pattern['prefix_.+'] => String}
type S2 = Struct{ regular => Integer, Optional[Pattern['prefix_.+']] => String}
type S3 = Struct{ regular => Integer, Array[Pattern['prefix_.+'], 2, 3] => String}
{code}

Where a Pattern key means 0 or infinite amount of occurrences,
an Optional around the  key  pattern  type means 0 or 1 occurrence, and an Array

specifies min, max occurrences.

Such that:
{code:puppet}

$a1 = { regular => 1, prefix_a = > 10}
$a1 =~ S1 == true

$a2 = { regular => 1}
$a2 =~ S1 == false
$a2 =~ S2 == true

$a3 = { regular => 1, prefix_a => 10, prefix_b = 20, prefix_c => 30}
$a4 = { regular => 1, prefix_a => 10, prefix_b = 20, prefix_c => 30, prefix_d => 40}
$a3 =~ S3 == true
$a3 =~ S3 == true
$a3 =~ S3 == true

$a4 =~ S3 == false # a4 has too many matching keys
$a1 =~ S3 == false  # a1 has one prefix, 2 is required
{code}

* It is up to the user to construct the patterns so that they do not overlap. The struct type matches from left to right, the first pattern (if there are several) that accepts the key means that it is considered a match, and the count is associated with this struct entry. Thus, overlapping or keys with negative character set matches can cause ambiguities in the counts. This is the user's problem - it is impossible to issue a warning.
* Type Algebra on Structs with patterns:
** A struct is assignable to another if all after having matched all regular keys, regular keys in the RHS are matched by Pattern based keys on the LHS side, or if the set of Patterns are equal.
** Two structs with non equal patterns are disjunct

Henrik Lindberg (JIRA)

unread,
Feb 21, 2016, 12:01:02 AM2/21/16
to puppe...@googlegroups.com

Henrik Lindberg (JIRA)

unread,
Sep 7, 2016, 6:12:17 PM9/7/16
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Team: Puppet Developer Support
This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe)
Atlassian logo

Henrik Lindberg (JIRA)

unread,
Feb 24, 2017, 8:57:02 AM2/24/17
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Fix Version/s: PUP 4.y
Fix Version/s: PUP 5.y

Henrik Lindberg (JIRA)

unread,
May 15, 2017, 2:52:06 PM5/15/17
to puppe...@googlegroups.com
Henrik Lindberg updated an issue
Change By: Henrik Lindberg
Component/s: Type System

Henrik Lindberg (JIRA)

unread,
May 15, 2017, 2:53:05 PM5/15/17
to puppe...@googlegroups.com

Henrik Lindberg (JIRA)

unread,
Jun 5, 2017, 12:49:02 PM6/5/17
to puppe...@googlegroups.com
Henrik Lindberg commented on New Feature PUP-5942
 
Re: Allow a Struct type to define keys using a pattern

This could be written using hashes for better clarity when something other than 0:M multiplicity is wanted:

# simple case
type S1 = Struct[{ regular => Integer, Pattern['prefix_.+'] => String}]
# same as above, but in long form using a hash
type S1 = Struct[{ regular => Integer, { match => Pattern['prefix_.+']} => String}]
# variants with min and max occurs
type S2 = Struct[{ regular => Integer, { match => Pattern['prefix_.+'], min_occurs => 0, max_occurs => 1}  => String}]
type S3 = Struct[{ regular => Integer, { match => Pattern['prefix_.+'], min_occurs => 2, max_occurs => 3}  => String}]

Josh Cooper (Jira)

unread,
Jun 10, 2021, 1:13:03 PM6/10/21
to puppe...@googlegroups.com
Josh Cooper commented on New Feature PUP-5942

Based on Henrik Lindberg comment in https://tickets.puppetlabs.com/browse/PUP-4669?focusedCommentId=632368&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-632368, I'm going to close this as well. It sounds like adding a Like data type would be a better way of handling this.

This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages