Skip to content

Commit

Permalink
Improve the Smithy metadata matcher.
Browse files Browse the repository at this point in the history
Previously, metadata foo bar baz = 23 was accepted, but according to
the definition https://smithy.io/2.0/spec/idl.html#grammar-token-smithy-MetadataSection
it should be "metadata"<whitespace>Identifier/String<optional whitespace>.
  • Loading branch information
Anteru committed Dec 31, 2022
1 parent 92b77b2 commit dd52102
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pygments/lexers/smithy.py
Expand Up @@ -56,8 +56,9 @@ class SmithyLexer(RegexLexer):
(words(aggregate_shapes,
prefix=r'^', suffix=r'(\s+' + identifier + r')'),
bygroups(Keyword.Declaration, Name.Class)),
(r'^(metadata)(\s+.+)(\s*)(=)',
bygroups(Keyword.Declaration, Name.Class, Whitespace, Name.Decorator)),
(r'^(metadata)(\s+)((?:\S+)|(?:\"[^"]+\"))(\s*)(=)',
bygroups(Keyword.Declaration, Whitespace, Name.Class,
Whitespace, Name.Decorator)),
(r"(true|false|null)", Keyword.Constant),
(r"(-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)", Number),
(identifier + ":", Name.Label),
Expand Down
12 changes: 12 additions & 0 deletions tests/examplefiles/smithy/test.smithy
Expand Up @@ -2,6 +2,18 @@ $version: "1.0"

namespace test

metadata "foo" = ["bar", "baz"]
metadata validators = [
{
name: "ValidatorName"
id: "ValidatorId"
message: "Some string"
configuration: {
selector: "operation"
}
}
]

/// Define how an HTTP request is serialized given a specific protocol,
/// authentication scheme, and set of input parameters.
@trait(selector: "operation")
Expand Down
52 changes: 52 additions & 0 deletions tests/examplefiles/smithy/test.smithy.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dd52102

Please sign in to comment.