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

9 statements  

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

1""" 

2 pygments.lexers.savi 

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

4 

5 Lexer for Savi. 

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, include 

12from pygments.token import Whitespace, Keyword, Name, String, Number, \ 

13 Operator, Punctuation, Comment, Generic, Error 

14 

15__all__ = ['SaviLexer'] 

16 

17 

18# The canonical version of this file can be found in the following repository, 

19# where it is kept in sync with any language changes, as well as the other 

20# pygments-like lexers that are maintained for use with other tools: 

21# - https://github.com/savi-lang/savi/blob/main/tooling/pygments/lexers/savi.py 

22# 

23# If you're changing this file in the pygments repository, please ensure that 

24# any changes you make are also propagated to the official Savi repository, 

25# in order to avoid accidental clobbering of your changes later when an update 

26# from the Savi repository flows forward into the pygments repository. 

27# 

28# If you're changing this file in the Savi repository, please ensure that 

29# any changes you make are also reflected in the other pygments-like lexers 

30# (rouge, vscode, etc) so that all of the lexers can be kept cleanly in sync. 

31 

32class SaviLexer(RegexLexer): 

33 """ 

34 For Savi source code. 

35 

36 .. versionadded: 2.10 

37 """ 

38 

39 name = 'Savi' 

40 url = 'https://github.com/savi-lang/savi' 

41 aliases = ['savi'] 

42 filenames = ['*.savi'] 

43 

44 tokens = { 

45 "root": [ 

46 # Line Comment 

47 (r'//.*?$', Comment.Single), 

48 

49 # Doc Comment 

50 (r'::.*?$', Comment.Single), 

51 

52 # Capability Operator 

53 (r'(\')(\w+)(?=[^\'])', bygroups(Operator, Name)), 

54 

55 # Double-Quote String 

56 (r'\w?"', String.Double, "string.double"), 

57 

58 # Single-Char String 

59 (r"'", String.Char, "string.char"), 

60 

61 # Type Name 

62 (r'(_?[A-Z]\w*)', Name.Class), 

63 

64 # Nested Type Name 

65 (r'(\.)(\s*)(_?[A-Z]\w*)', bygroups(Punctuation, Whitespace, Name.Class)), 

66 

67 # Declare 

68 (r'^([ \t]*)(:\w+)', 

69 bygroups(Whitespace, Name.Tag), 

70 "decl"), 

71 

72 # Error-Raising Calls/Names 

73 (r'((\w+|\+|\-|\*)\!)', Generic.Deleted), 

74 

75 # Numeric Values 

76 (r'\b\d([\d_]*(\.[\d_]+)?)\b', Number), 

77 

78 # Hex Numeric Values 

79 (r'\b0x([0-9a-fA-F_]+)\b', Number.Hex), 

80 

81 # Binary Numeric Values 

82 (r'\b0b([01_]+)\b', Number.Bin), 

83 

84 # Function Call (with braces) 

85 (r'\w+(?=\()', Name.Function), 

86 

87 # Function Call (with receiver) 

88 (r'(\.)(\s*)(\w+)', bygroups(Punctuation, Whitespace, Name.Function)), 

89 

90 # Function Call (with self receiver) 

91 (r'(@)(\w+)', bygroups(Punctuation, Name.Function)), 

92 

93 # Parenthesis 

94 (r'\(', Punctuation, "root"), 

95 (r'\)', Punctuation, "#pop"), 

96 

97 # Brace 

98 (r'\{', Punctuation, "root"), 

99 (r'\}', Punctuation, "#pop"), 

100 

101 # Bracket 

102 (r'\[', Punctuation, "root"), 

103 (r'(\])(\!)', bygroups(Punctuation, Generic.Deleted), "#pop"), 

104 (r'\]', Punctuation, "#pop"), 

105 

106 # Punctuation 

107 (r'[,;:\.@]', Punctuation), 

108 

109 # Piping Operators 

110 (r'(\|\>)', Operator), 

111 

112 # Branching Operators 

113 (r'(\&\&|\|\||\?\?|\&\?|\|\?|\.\?)', Operator), 

114 

115 # Comparison Operators 

116 (r'(\<\=\>|\=\~|\=\=|\<\=|\>\=|\<|\>)', Operator), 

117 

118 # Arithmetic Operators 

119 (r'(\+|\-|\/|\*|\%)', Operator), 

120 

121 # Assignment Operators 

122 (r'(\=)', Operator), 

123 

124 # Other Operators 

125 (r'(\!|\<\<|\<|\&|\|)', Operator), 

126 

127 # Identifiers 

128 (r'\b\w+\b', Name), 

129 

130 # Whitespace 

131 (r'[ \t\r]+\n*|\n+', Whitespace), 

132 ], 

133 

134 # Declare (nested rules) 

135 "decl": [ 

136 (r'\b[a-z_]\w*\b(?!\!)', Keyword.Declaration), 

137 (r':', Punctuation, "#pop"), 

138 (r'\n', Whitespace, "#pop"), 

139 include("root"), 

140 ], 

141 

142 # Double-Quote String (nested rules) 

143 "string.double": [ 

144 (r'\\\(', String.Interpol, "string.interpolation"), 

145 (r'\\u[0-9a-fA-F]{4}', String.Escape), 

146 (r'\\x[0-9a-fA-F]{2}', String.Escape), 

147 (r'\\[bfnrt\\\']', String.Escape), 

148 (r'\\"', String.Escape), 

149 (r'"', String.Double, "#pop"), 

150 (r'[^\\"]+', String.Double), 

151 (r'.', Error), 

152 ], 

153 

154 # Single-Char String (nested rules) 

155 "string.char": [ 

156 (r'\\u[0-9a-fA-F]{4}', String.Escape), 

157 (r'\\x[0-9a-fA-F]{2}', String.Escape), 

158 (r'\\[bfnrt\\\']', String.Escape), 

159 (r"\\'", String.Escape), 

160 (r"'", String.Char, "#pop"), 

161 (r"[^\\']+", String.Char), 

162 (r'.', Error), 

163 ], 

164 

165 # Interpolation inside String (nested rules) 

166 "string.interpolation": [ 

167 (r"\)", String.Interpol, "#pop"), 

168 include("root"), 

169 ] 

170 }