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

11 statements  

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

1""" 

2 pygments.lexers.wren 

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

4 

5 Lexer for Wren. 

6 

7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11import re 

12 

13from pygments.lexer import include, RegexLexer, words 

14from pygments.token import Whitespace, Punctuation, Keyword, Name, Comment, \ 

15 Operator, Number, String, Error 

16 

17__all__ = ['WrenLexer'] 

18 

19class WrenLexer(RegexLexer): 

20 """ 

21 For Wren source code, version 0.4.0. 

22 

23 .. versionadded:: 2.14.0 

24 """ 

25 name = 'Wren' 

26 url = 'https://wren.io' 

27 aliases = ['wren'] 

28 filenames = ['*.wren'] 

29 

30 flags = re.MULTILINE | re.DOTALL 

31 

32 tokens = { 

33 'root': [ 

34 # Whitespace. 

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

36 (r'[,\\\[\]{}]', Punctuation), 

37 

38 # Really 'root', not '#push': in 'interpolation', 

39 # parentheses inside the interpolation expression are 

40 # Punctuation, not String.Interpol. 

41 (r'\(', Punctuation, 'root'), 

42 (r'\)', Punctuation, '#pop'), 

43 

44 # Keywords. 

45 (words(( 

46 'as', 'break', 'class', 'construct', 'continue', 'else', 

47 'for', 'foreign', 'if', 'import', 'return', 'static', 'super', 

48 'this', 'var', 'while'), prefix = r'(?<!\.)', 

49 suffix = r'\b'), Keyword), 

50 

51 (words(( 

52 'true', 'false', 'null'), prefix = r'(?<!\.)', 

53 suffix = r'\b'), Keyword.Constant), 

54 

55 (words(( 

56 'in', 'is'), prefix = r'(?<!\.)', 

57 suffix = r'\b'), Operator.Word), 

58 

59 # Comments. 

60 (r'/\*', Comment.Multiline, 'comment'), # Multiline, can nest. 

61 (r'//.*?$', Comment.Single), # Single line. 

62 (r'#.*?(\(.*?\))?$', Comment.Special), # Attribute or shebang. 

63 

64 # Names and operators. 

65 (r'[!%&*+\-./:<=>?\\^|~]+', Operator), 

66 (r'[a-z][a-zA-Z_0-9]*', Name), 

67 (r'[A-Z][a-zA-Z_0-9]*', Name.Class), 

68 (r'__[a-zA-Z_0-9]*', Name.Variable.Class), 

69 (r'_[a-zA-Z_0-9]*', Name.Variable.Instance), 

70 

71 # Numbers. 

72 (r'0x[0-9a-fA-F]+', Number.Hex), 

73 (r'\d+(\.\d+)?([eE][-+]?\d+)?', Number.Float), 

74 

75 # Strings. 

76 (r'""".*?"""', String), # Raw string 

77 (r'"', String, 'string'), # Other string 

78 ], 

79 'comment': [ 

80 (r'/\*', Comment.Multiline, '#push'), 

81 (r'\*/', Comment.Multiline, '#pop'), 

82 (r'([^*/]|\*(?!/)|/(?!\*))+', Comment.Multiline), 

83 ], 

84 'string': [ 

85 (r'"', String, '#pop'), 

86 (r'\\[\\%"0abefnrtv]', String.Escape), # Escape. 

87 (r'\\x[a-fA-F0-9]{2}', String.Escape), # Byte escape. 

88 (r'\\u[a-fA-F0-9]{4}', String.Escape), # Unicode escape. 

89 (r'\\U[a-fA-F0-9]{8}', String.Escape), # Long Unicode escape. 

90 

91 (r'%\(', String.Interpol, 'interpolation'), 

92 (r'[^\\"%]+', String), # All remaining characters. 

93 ], 

94 'interpolation': [ 

95 # redefine closing paren to be String.Interpol 

96 (r'\)', String.Interpol, '#pop'), 

97 include('root'), 

98 ], 

99 }