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

18 statements  

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

1""" 

2 pygments.lexers.monte 

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

4 

5 Lexer for the Monte programming language. 

6 

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

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.token import Comment, Error, Keyword, Name, Number, Operator, \ 

12 Punctuation, String, Whitespace 

13from pygments.lexer import RegexLexer, include, words 

14 

15__all__ = ['MonteLexer'] 

16 

17 

18# `var` handled separately 

19# `interface` handled separately 

20_declarations = ['bind', 'def', 'fn', 'object'] 

21_methods = ['method', 'to'] 

22_keywords = [ 

23 'as', 'break', 'catch', 'continue', 'else', 'escape', 'exit', 'exports', 

24 'extends', 'finally', 'for', 'guards', 'if', 'implements', 'import', 

25 'in', 'match', 'meta', 'pass', 'return', 'switch', 'try', 'via', 'when', 

26 'while', 

27] 

28_operators = [ 

29 # Unary 

30 '~', '!', 

31 # Binary 

32 '+', '-', '*', '/', '%', '**', '&', '|', '^', '<<', '>>', 

33 # Binary augmented 

34 '+=', '-=', '*=', '/=', '%=', '**=', '&=', '|=', '^=', '<<=', '>>=', 

35 # Comparison 

36 '==', '!=', '<', '<=', '>', '>=', '<=>', 

37 # Patterns and assignment 

38 ':=', '?', '=~', '!~', '=>', 

39 # Calls and sends 

40 '.', '<-', '->', 

41] 

42_escape_pattern = ( 

43 r'(?:\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|' 

44 r'\\["\'\\bftnr])') 

45# _char = _escape_chars + [('.', String.Char)] 

46_identifier = r'[_a-zA-Z]\w*' 

47 

48_constants = [ 

49 # Void constants 

50 'null', 

51 # Bool constants 

52 'false', 'true', 

53 # Double constants 

54 'Infinity', 'NaN', 

55 # Special objects 

56 'M', 'Ref', 'throw', 'traceln', 

57] 

58 

59_guards = [ 

60 'Any', 'Binding', 'Bool', 'Bytes', 'Char', 'DeepFrozen', 'Double', 

61 'Empty', 'Int', 'List', 'Map', 'Near', 'NullOk', 'Same', 'Selfless', 

62 'Set', 'Str', 'SubrangeGuard', 'Transparent', 'Void', 

63] 

64 

65_safeScope = [ 

66 '_accumulateList', '_accumulateMap', '_auditedBy', '_bind', 

67 '_booleanFlow', '_comparer', '_equalizer', '_iterForever', '_loop', 

68 '_makeBytes', '_makeDouble', '_makeFinalSlot', '_makeInt', '_makeList', 

69 '_makeMap', '_makeMessageDesc', '_makeOrderedSpace', '_makeParamDesc', 

70 '_makeProtocolDesc', '_makeSourceSpan', '_makeString', '_makeVarSlot', 

71 '_makeVerbFacet', '_mapExtract', '_matchSame', '_quasiMatcher', 

72 '_slotToBinding', '_splitList', '_suchThat', '_switchFailed', 

73 '_validateFor', 'b__quasiParser', 'eval', 'import', 'm__quasiParser', 

74 'makeBrandPair', 'makeLazySlot', 'safeScope', 'simple__quasiParser', 

75] 

76 

77 

78class MonteLexer(RegexLexer): 

79 """ 

80 Lexer for the Monte programming language. 

81 

82 .. versionadded:: 2.2 

83 """ 

84 name = 'Monte' 

85 url = 'https://monte.readthedocs.io/' 

86 aliases = ['monte'] 

87 filenames = ['*.mt'] 

88 

89 tokens = { 

90 'root': [ 

91 # Comments 

92 (r'#[^\n]*\n', Comment), 

93 

94 # Docstrings 

95 # Apologies for the non-greedy matcher here. 

96 (r'/\*\*.*?\*/', String.Doc), 

97 

98 # `var` declarations 

99 (r'\bvar\b', Keyword.Declaration, 'var'), 

100 

101 # `interface` declarations 

102 (r'\binterface\b', Keyword.Declaration, 'interface'), 

103 

104 # method declarations 

105 (words(_methods, prefix='\\b', suffix='\\b'), 

106 Keyword, 'method'), 

107 

108 # All other declarations 

109 (words(_declarations, prefix='\\b', suffix='\\b'), 

110 Keyword.Declaration), 

111 

112 # Keywords 

113 (words(_keywords, prefix='\\b', suffix='\\b'), Keyword), 

114 

115 # Literals 

116 ('[+-]?0x[_0-9a-fA-F]+', Number.Hex), 

117 (r'[+-]?[_0-9]+\.[_0-9]*([eE][+-]?[_0-9]+)?', Number.Float), 

118 ('[+-]?[_0-9]+', Number.Integer), 

119 ("'", String.Double, 'char'), 

120 ('"', String.Double, 'string'), 

121 

122 # Quasiliterals 

123 ('`', String.Backtick, 'ql'), 

124 

125 # Operators 

126 (words(_operators), Operator), 

127 

128 # Verb operators 

129 (_identifier + '=', Operator.Word), 

130 

131 # Safe scope constants 

132 (words(_constants, prefix='\\b', suffix='\\b'), 

133 Keyword.Pseudo), 

134 

135 # Safe scope guards 

136 (words(_guards, prefix='\\b', suffix='\\b'), Keyword.Type), 

137 

138 # All other safe scope names 

139 (words(_safeScope, prefix='\\b', suffix='\\b'), 

140 Name.Builtin), 

141 

142 # Identifiers 

143 (_identifier, Name), 

144 

145 # Punctuation 

146 (r'\(|\)|\{|\}|\[|\]|:|,', Punctuation), 

147 

148 # Whitespace 

149 (' +', Whitespace), 

150 

151 # Definite lexer errors 

152 ('=', Error), 

153 ], 

154 'char': [ 

155 # It is definitely an error to have a char of width == 0. 

156 ("'", Error, 'root'), 

157 (_escape_pattern, String.Escape, 'charEnd'), 

158 ('.', String.Char, 'charEnd'), 

159 ], 

160 'charEnd': [ 

161 ("'", String.Char, '#pop:2'), 

162 # It is definitely an error to have a char of width > 1. 

163 ('.', Error), 

164 ], 

165 # The state of things coming into an interface. 

166 'interface': [ 

167 (' +', Whitespace), 

168 (_identifier, Name.Class, '#pop'), 

169 include('root'), 

170 ], 

171 # The state of things coming into a method. 

172 'method': [ 

173 (' +', Whitespace), 

174 (_identifier, Name.Function, '#pop'), 

175 include('root'), 

176 ], 

177 'string': [ 

178 ('"', String.Double, 'root'), 

179 (_escape_pattern, String.Escape), 

180 (r'\n', String.Double), 

181 ('.', String.Double), 

182 ], 

183 'ql': [ 

184 ('`', String.Backtick, 'root'), 

185 (r'\$' + _escape_pattern, String.Escape), 

186 (r'\$\$', String.Escape), 

187 (r'@@', String.Escape), 

188 (r'\$\{', String.Interpol, 'qlNest'), 

189 (r'@\{', String.Interpol, 'qlNest'), 

190 (r'\$' + _identifier, Name), 

191 ('@' + _identifier, Name), 

192 ('.', String.Backtick), 

193 ], 

194 'qlNest': [ 

195 (r'\}', String.Interpol, '#pop'), 

196 include('root'), 

197 ], 

198 # The state of things immediately following `var`. 

199 'var': [ 

200 (' +', Whitespace), 

201 (_identifier, Name.Variable, '#pop'), 

202 include('root'), 

203 ], 

204 }