Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/smithy.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:16 +0000

1""" 

2 pygments.lexers.smithy 

3 ~~~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexers for the Smithy IDL. 

6 

7 :copyright: Copyright 2006-2023 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 .. versionadded:: 2.10 

23 """ 

24 name = 'Smithy' 

25 url = 'https://awslabs.github.io/smithy/' 

26 filenames = ['*.smithy'] 

27 aliases = ['smithy'] 

28 

29 unquoted = r'[A-Za-z0-9_\.#$-]+' 

30 identifier = r"[A-Za-z0-9_\.#$-]+" 

31 

32 simple_shapes = ( 

33 'use', 'byte', 'short', 'integer', 'long', 'float', 'document', 

34 'double', 'bigInteger', 'bigDecimal', 'boolean', 'blob', 'string', 

35 'timestamp', 

36 ) 

37 

38 aggregate_shapes = ( 

39 'apply', 'list', 'map', 'set', 'structure', 'union', 'resource', 

40 'operation', 'service', 'trait' 

41 ) 

42 

43 tokens = { 

44 'root': [ 

45 (r'///.*$', Comment.Multiline), 

46 (r'//.*$', Comment), 

47 (r'@[0-9a-zA-Z\.#-]*', Name.Decorator), 

48 (r'(=)', Name.Decorator), 

49 (r'^(\$version)(:)(.+)', 

50 bygroups(Keyword.Declaration, Name.Decorator, Name.Class)), 

51 (r'^(namespace)(\s+' + identifier + r')\b', 

52 bygroups(Keyword.Declaration, Name.Class)), 

53 (words(simple_shapes, 

54 prefix=r'^', suffix=r'(\s+' + identifier + r')\b'), 

55 bygroups(Keyword.Declaration, Name.Class)), 

56 (words(aggregate_shapes, 

57 prefix=r'^', suffix=r'(\s+' + identifier + r')'), 

58 bygroups(Keyword.Declaration, Name.Class)), 

59 (r'^(metadata)(\s+)((?:\S+)|(?:\"[^"]+\"))(\s*)(=)', 

60 bygroups(Keyword.Declaration, Whitespace, Name.Class, 

61 Whitespace, Name.Decorator)), 

62 (r"(true|false|null)", Keyword.Constant), 

63 (r"(-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)", Number), 

64 (identifier + ":", Name.Label), 

65 (identifier, Name.Variable.Class), 

66 (r'\[', Text, "#push"), 

67 (r'\]', Text, "#pop"), 

68 (r'\(', Text, "#push"), 

69 (r'\)', Text, "#pop"), 

70 (r'\{', Text, "#push"), 

71 (r'\}', Text, "#pop"), 

72 (r'"{3}(\\\\|\n|\\")*"{3}', String.Doc), 

73 (r'"(\\\\|\n|\\"|[^"])*"', String.Double), 

74 (r"'(\\\\|\n|\\'|[^'])*'", String.Single), 

75 (r'[:,]+', Punctuation), 

76 (r'\s+', Whitespace), 

77 ] 

78 }