Details

    • Type: New Feature
    • Status: Closed
    • Priority: Normal
    • Resolution: Won't Do
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Language
    • Labels:
      None
    • Template:
    • QA Risk Assessment:
      Needs Assessment

      Description

      I'd like to be able to match context-free languages using the type system. Most of the pieces are there, but it needs a Concat or Combinator type. Here's how I see it working.

      The Concat type would take multiple Scalars and all of its sub-types (converted to match strings), other Concat types, Undef and Optional where Undef matches the empty string, plus Variant types containing all these types (or maybe a new type of restricted Variant). The type would concatenate its parameter types to create a recognizer for larger strings. For example the following would match the strings 'foo bar' and 'foobar'.

      Concat[
        Enum['foo'],
        Optional[
          Pattern[/\s/]
        ],
        Enum['bar']
      ]
      

      This could also be used to match complete contex-free languages. Take the textbook example of balanced parentheses.

      S → SS
      S → (S)
      S → ε

      Or in BNF

      <empty-string> ::= ""
      <BP> ::= <empty-string>
          | ( <BP> )
          | <BP> <BP>
      

      This could be expressed using Puppet type aliases as follows.

      type BP = Variant[Enum[''], Concat[Enum['('], BP, Enum[')']], Concat[BP, BP]]
      

      This alone could match some really complex things, like a user-defined subset of JSON, however it would be very difficult and ugly without PUP-7033.

        Attachments

          Issue Links

            Activity

              jsd-sla-details-panel

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  lamawithonel Lucas Yamanishi
                • Votes:
                  1 Vote for this issue
                  Watchers:
                  6 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: