Skip to content

Implement tagged literals for IDL 2.1#3047

Draft
sugmanue wants to merge 1 commit into
smithy-lang:mainfrom
sugmanue:sugmanue/tagged-string-literals2
Draft

Implement tagged literals for IDL 2.1#3047
sugmanue wants to merge 1 commit into
smithy-lang:mainfrom
sugmanue:sugmanue/tagged-string-literals2

Conversation

@sugmanue
Copy link
Copy Markdown
Contributor

@sugmanue sugmanue commented Apr 14, 2026

Background

These changes are expected to be part of the IDL 2.1 changes planed. For now, it adds support for "tagged literals" which allows a literal to be prefixed with a tag that will modify the way the literal is parsed and the resulting token. This change implements:

  • #b <string> Similar to b-strings in Python signals that the string contains binary data that can be composed by hex or octal escapes or literal values. The resulting token will be the string base64 encoded.
  • #hex <string> Similar to a hex dump string that contains hexadecimal values, spaces are ignored and strings starting with # are consider comments and ignored until the end of line.
  • #timestamp <string> This tag converts that given ISO encoded date to Smithy's epoch second with millis precision.
  • #re <string> Takes backslashes as literal chars instead of escape sequences allowing writing regular expressions with character classes without having to escape the slashes.

A model that uses all of that is shown below:

$version: "2.1"

structure Example {

    @default(#timestamp "1994-07-05T00:00:00Z")
    startDate: Timestamp

    @pattern(#re "^\d{3}-\d{2}-\d{4}$")
    founderSsn: String

    @default(#b ".PNG\x0D\x0A\x1A\x0A")
    avatar: Blob

    @default(#hex """
          # The first 4 hex values are the literal .PNG, the magic value for PNG images
          89 50 4E 47 0D 0A 1A 0A
          """)
    bigAvatar: Blob
}
    

* What do these changes do? 
* Why are they important?

#### Testing
* How did you test these changes?

#### Links
* Links to additional context, if necessary
* Issue #, if applicable (see [here](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) for a list of keywords to use for linking issues)

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request does not contain a staged changelog entry. To create one, use the ./.changes/new-change command. For example:

./.changes/new-change --pull-requests "#3047" --type feature --description "Implement tagged literals for IDL 2.1"

Make sure that the description is appropriate for a changelog entry and that the proper feature type is used. See ./.changes/README or run ./.changes/new-change -h for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant