Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pygments/lexers/arturo.py: 50%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

32 statements  

1""" 

2 pygments.lexers.arturo 

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

4 

5 Lexer for the Arturo language. 

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

12 this, using, words 

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

14 Punctuation, String, Text 

15 

16from pygments.util import ClassNotFound, get_bool_opt 

17 

18__all__ = ['ArturoLexer'] 

19 

20 

21class ArturoLexer(RegexLexer): 

22 """ 

23 For Arturo source code. 

24 

25 See `Arturo's Github <https://github.com/arturo-lang/arturo>`_ 

26 and `Arturo's Website <https://arturo-lang.io/>`_. 

27 """ 

28 

29 name = 'Arturo' 

30 aliases = ['arturo', 'art'] 

31 filenames = ['*.art'] 

32 url = 'https://arturo-lang.io/' 

33 version_added = '2.14' 

34 

35 def __init__(self, **options): 

36 self.handle_annotateds = get_bool_opt(options, 'handle_annotateds', 

37 True) 

38 RegexLexer.__init__(self, **options) 

39 

40 def handle_annotated_strings(self, match): 

41 """Adds syntax from another languages inside annotated strings 

42 

43 match args: 

44 1:open_string, 

45 2:exclamation_mark, 

46 3:lang_name, 

47 4:space_or_newline, 

48 5:code, 

49 6:close_string 

50 """ 

51 from pygments.lexers import get_lexer_by_name 

52 

53 # Header's section 

54 yield match.start(1), String.Double, match.group(1) 

55 yield match.start(2), String.Interpol, match.group(2) 

56 yield match.start(3), String.Interpol, match.group(3) 

57 yield match.start(4), Text.Whitespace, match.group(4) 

58 

59 lexer = None 

60 if self.handle_annotateds: 

61 try: 

62 lexer = get_lexer_by_name(match.group(3).strip()) 

63 except ClassNotFound: 

64 pass 

65 code = match.group(5) 

66 

67 if lexer is None: 

68 yield match.group(5), String, code 

69 else: 

70 yield from do_insertions([], lexer.get_tokens_unprocessed(code)) 

71 

72 yield match.start(6), String.Double, match.group(6) 

73 

74 tokens = { 

75 'root': [ 

76 (r';.*?$', Comment.Single), 

77 (r'^((\s#!)|(#!)).*?$', Comment.Hashbang), 

78 

79 # Constants 

80 (words(('false', 'true', 'maybe'), # boolean 

81 suffix=r'\b'), Name.Constant), 

82 (words(('this', 'init'), # class related keywords 

83 prefix=r'\b', suffix=r'\b\??:?'), Name.Builtin.Pseudo), 

84 (r'`.`', String.Char), # character 

85 (r'\\\w+\b\??:?', Name.Property), # array index 

86 (r'#\w+', Name.Constant), # color 

87 (r'\b[0-9]+\.[0-9]+', Number.Float), # float 

88 (r'\b[0-9]+', Number.Integer), # integer 

89 (r'\w+\b\??:', Name.Label), # label 

90 # Note: Literals can be labeled too 

91 (r'\'(?:\w+\b\??:?)', Keyword.Declaration), # literal 

92 (r'\:\w+', Keyword.Type), # type 

93 # Note: Attributes can be labeled too 

94 (r'\.\w+\??:?', Name.Attribute), # attributes 

95 

96 # Switch structure 

97 (r'(\()(.*?)(\)\?)', 

98 bygroups(Punctuation, using(this), Punctuation)), 

99 

100 # Single Line Strings 

101 (r'"', String.Double, 'inside-simple-string'), 

102 (r'»', String.Single, 'inside-smart-string'), 

103 (r'«««', String.Double, 'inside-safe-string'), 

104 (r'\{\/', String.Single, 'inside-regex-string'), 

105 

106 # Multi Line Strings 

107 (r'\{\:', String.Double, 'inside-curly-verb-string'), 

108 (r'(\{)(\!)(\w+)(\s|\n)([\w\W]*?)(^\})', handle_annotated_strings), 

109 (r'\{', String.Single, 'inside-curly-string'), 

110 (r'\-{3,}', String.Single, 'inside-eof-string'), 

111 

112 include('builtin-functions'), 

113 

114 # Operators 

115 (r'[()[\],]', Punctuation), 

116 (words(('->', '==>', '|', '::', '@', '#', # sugar syntax 

117 '$', '&', '!', '!!', './')), Name.Decorator), 

118 (words(('<:', ':>', ':<', '>:', '<\\', '<>', '<', '>', 

119 'ø', '∞', 

120 '+', '-', '*', '~', '=', '^', '%', '/', '//', 

121 '==>', '<=>', '<==>', 

122 '=>>', '<<=>>', '<<==>>', 

123 '-->', '<->', '<-->', 

124 '=|', '|=', '-:', ':-', 

125 '_', '.', '..', '\\')), Operator), 

126 

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

128 (r'\s+', Text.Whitespace), 

129 (r'.+$', Error), 

130 ], 

131 

132 'inside-interpol': [ 

133 (r'\|', String.Interpol, '#pop'), 

134 (r'[^|]+', using(this)), 

135 ], 

136 'inside-template': [ 

137 (r'\|\|\>', String.Interpol, '#pop'), 

138 (r'[^|]+', using(this)), 

139 ], 

140 'string-escape': [ 

141 (words(('\\\\', '\\n', '\\t', '\\"')), String.Escape), 

142 ], 

143 

144 'inside-simple-string': [ 

145 include('string-escape'), 

146 (r'\|', String.Interpol, 'inside-interpol'), # Interpolation 

147 (r'\<\|\|', String.Interpol, 'inside-template'), # Templates 

148 (r'"', String.Double, '#pop'), # Closing Quote 

149 (r'[^|"]+', String) # String Content 

150 ], 

151 'inside-smart-string': [ 

152 include('string-escape'), 

153 (r'\|', String.Interpol, 'inside-interpol'), # Interpolation 

154 (r'\<\|\|', String.Interpol, 'inside-template'), # Templates 

155 (r'\n', String.Single, '#pop'), # Closing Quote 

156 (r'[^|\n]+', String) # String Content 

157 ], 

158 'inside-safe-string': [ 

159 include('string-escape'), 

160 (r'\|', String.Interpol, 'inside-interpol'), # Interpolation 

161 (r'\<\|\|', String.Interpol, 'inside-template'), # Templates 

162 (r'»»»', String.Double, '#pop'), # Closing Quote 

163 (r'[^|»]+', String) # String Content 

164 ], 

165 'inside-regex-string': [ 

166 (r'\\[sSwWdDbBZApPxucItnvfr0]+', String.Escape), 

167 (r'\|', String.Interpol, 'inside-interpol'), # Interpolation 

168 (r'\<\|\|', String.Interpol, 'inside-template'), # Templates 

169 (r'\/\}', String.Single, '#pop'), # Closing Quote 

170 (r'[^|\/]+', String.Regex), # String Content 

171 ], 

172 'inside-curly-verb-string': [ 

173 include('string-escape'), 

174 (r'\|', String.Interpol, 'inside-interpol'), # Interpolation 

175 (r'\<\|\|', String.Interpol, 'inside-template'), # Templates 

176 (r'\:\}', String.Double, '#pop'), # Closing Quote 

177 (r'[^|<:]+', String), # String Content 

178 ], 

179 'inside-curly-string': [ 

180 include('string-escape'), 

181 (r'\|', String.Interpol, 'inside-interpol'), # Interpolation 

182 (r'\<\|\|', String.Interpol, 'inside-template'), # Templates 

183 (r'\}', String.Single, '#pop'), # Closing Quote 

184 (r'[^|<}]+', String), # String Content 

185 ], 

186 'inside-eof-string': [ 

187 include('string-escape'), 

188 (r'\|', String.Interpol, 'inside-interpol'), # Interpolation 

189 (r'\<\|\|', String.Interpol, 'inside-template'), # Templates 

190 (r'\Z', String.Single, '#pop'), # Closing Quote 

191 (r'[^|<]+', String), # String Content 

192 ], 

193 

194 'builtin-functions': [ 

195 (words(( 

196 'all', 'and', 'any', 'ascii', 'attr', 'attribute', 

197 'attributeLabel', 'binary', 'block' 'char', 'contains', 

198 'database', 'date', 'dictionary', 'empty', 'equal', 'even', 

199 'every', 'exists', 'false', 'floatin', 'function', 'greater', 

200 'greaterOrEqual', 'if', 'in', 'inline', 'integer', 'is', 

201 'key', 'label', 'leap', 'less', 'lessOrEqual', 'literal', 

202 'logical', 'lower', 'nand', 'negative', 'nor', 'not', 

203 'notEqual', 'null', 'numeric', 'odd', 'or', 'path', 

204 'pathLabel', 'positive', 'prefix', 'prime', 'set', 'some', 

205 'sorted', 'standalone', 'string', 'subset', 'suffix', 

206 'superset', 'ymbol', 'true', 'try', 'type', 'unless', 'upper', 

207 'when', 'whitespace', 'word', 'xnor', 'xor', 'zero', 

208 ), prefix=r'\b', suffix=r'\b\?'), Name.Builtin), 

209 (words(( 

210 'abs', 'acos', 'acosh', 'acsec', 'acsech', 'actan', 'actanh', 

211 'add', 'after', 'alphabet', 'and', 'angle', 'append', 'arg', 

212 'args', 'arity', 'array', 'as', 'asec', 'asech', 'asin', 

213 'asinh', 'atan', 'atan2', 'atanh', 'attr', 'attrs', 'average', 

214 'before', 'benchmark', 'blend', 'break', 'builtins1', 

215 'builtins2', 'call', 'capitalize', 'case', 'ceil', 'chop', 

216 'chunk', 'clear', 'close', 'cluster', 'color', 'combine', 

217 'conj', 'continue', 'copy', 'cos', 'cosh', 'couple', 'csec', 

218 'csech', 'ctan', 'ctanh', 'cursor', 'darken', 'dec', 'decode', 

219 'decouple', 'define', 'delete', 'desaturate', 'deviation', 

220 'dictionary', 'difference', 'digest', 'digits', 'div', 'do', 

221 'download', 'drop', 'dup', 'e', 'else', 'empty', 'encode', 

222 'ensure', 'env', 'epsilon', 'escape', 'execute', 'exit', 'exp', 

223 'extend', 'extract', 'factors', 'false', 'fdiv', 'filter', 

224 'first', 'flatten', 'floor', 'fold', 'from', 'function', 

225 'gamma', 'gcd', 'get', 'goto', 'hash', 'help', 'hypot', 'if', 

226 'in', 'inc', 'indent', 'index', 'infinity', 'info', 'input', 

227 'insert', 'inspect', 'intersection', 'invert', 'join', 'keys', 

228 'kurtosis', 'last', 'let', 'levenshtein', 'lighten', 'list', 

229 'ln', 'log', 'loop', 'lower', 'mail', 'map', 'match', 'max', 

230 'maybe', 'median', 'min', 'mod', 'module', 'mul', 'nand', 

231 'neg', 'new', 'nor', 'normalize', 'not', 'now', 'null', 'open', 

232 'or', 'outdent', 'pad', 'panic', 'path', 'pause', 

233 'permissions', 'permutate', 'pi', 'pop', 'pow', 'powerset', 

234 'powmod', 'prefix', 'print', 'prints', 'process', 'product', 

235 'query', 'random', 'range', 'read', 'relative', 'remove', 

236 'rename', 'render', 'repeat', 'replace', 'request', 'return', 

237 'reverse', 'round', 'sample', 'saturate', 'script', 'sec', 

238 'sech', 'select', 'serve', 'set', 'shl', 'shr', 'shuffle', 

239 'sin', 'sinh', 'size', 'skewness', 'slice', 'sort', 'split', 

240 'sqrt', 'squeeze', 'stack', 'strip', 'sub', 'suffix', 'sum', 

241 'switch', 'symbols', 'symlink', 'sys', 'take', 'tan', 'tanh', 

242 'terminal', 'to', 'true', 'truncate', 'try', 'type', 'union', 

243 'unique', 'unless', 'until', 'unzip', 'upper', 'values', 'var', 

244 'variance', 'volume', 'webview', 'while', 'with', 'wordwrap', 

245 'write', 'xnor', 'xor', 'zip' 

246 ), prefix=r'\b', suffix=r'\b'), Name.Builtin) 

247 ], 

248 

249 }