1"""
2 pygments.lexers.smithy
3 ~~~~~~~~~~~~~~~~~~~~~~
4
5 Lexers for the Smithy IDL.
6
7 :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
10
11from pygments.lexer import RegexLexer, bygroups, words
12from pygments.token import Text, Comment, Keyword, Name, String, \
13 Number, Whitespace, Punctuation
14
15__all__ = ['SmithyLexer']
16
17
18class SmithyLexer(RegexLexer):
19 """
20 For Smithy IDL
21 """
22 name = 'Smithy'
23 url = 'https://awslabs.github.io/smithy/'
24 filenames = ['*.smithy']
25 aliases = ['smithy']
26 version_added = '2.10'
27
28 unquoted = r'[A-Za-z0-9_\.#$-]+'
29 identifier = r"[A-Za-z0-9_\.#$-]+"
30
31 simple_shapes = (
32 'use', 'byte', 'short', 'integer', 'long', 'float', 'document',
33 'double', 'bigInteger', 'bigDecimal', 'boolean', 'blob', 'string',
34 'timestamp',
35 )
36
37 aggregate_shapes = (
38 'apply', 'list', 'map', 'set', 'structure', 'union', 'resource',
39 'operation', 'service', 'trait'
40 )
41
42 tokens = {
43 'root': [
44 (r'///.*$', Comment.Multiline),
45 (r'//.*$', Comment),
46 (r'@[0-9a-zA-Z\.#-]*', Name.Decorator),
47 (r'(=)', Name.Decorator),
48 (r'^(\$version)(:)(.+)',
49 bygroups(Keyword.Declaration, Name.Decorator, Name.Class)),
50 (r'^(namespace)(\s+' + identifier + r')\b',
51 bygroups(Keyword.Declaration, Name.Class)),
52 (words(simple_shapes,
53 prefix=r'^', suffix=r'(\s+' + identifier + r')\b'),
54 bygroups(Keyword.Declaration, Name.Class)),
55 (words(aggregate_shapes,
56 prefix=r'^', suffix=r'(\s+' + identifier + r')'),
57 bygroups(Keyword.Declaration, Name.Class)),
58 (r'^(metadata)(\s+)((?:\S+)|(?:\"[^"]+\"))(\s*)(=)',
59 bygroups(Keyword.Declaration, Whitespace, Name.Class,
60 Whitespace, Name.Decorator)),
61 (r"(true|false|null)", Keyword.Constant),
62 (r"(-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)", Number),
63 (identifier + ":", Name.Label),
64 (identifier, Name.Variable.Class),
65 (r'\[', Text, "#push"),
66 (r'\]', Text, "#pop"),
67 (r'\(', Text, "#push"),
68 (r'\)', Text, "#pop"),
69 (r'\{', Text, "#push"),
70 (r'\}', Text, "#pop"),
71 (r'"{3}(\\\\|\n|\\")*"{3}', String.Doc),
72 (r'"(\\\\|\n|\\"|[^"])*"', String.Double),
73 (r"'(\\\\|\n|\\'|[^'])*'", String.Single),
74 (r'[:,]+', Punctuation),
75 (r'\s+', Whitespace),
76 ]
77 }