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

30 statements  

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

1""" 

2 pygments.lexers.arturo 

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

4 

5 Lexer for the Arturo language. 

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, 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 .. versionadded:: 2.14.0 

29 """ 

30 

31 name = 'Arturo' 

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

33 filenames = ['*.art'] 

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

35 

36 def __init__(self, **options): 

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

38 True) 

39 RegexLexer.__init__(self, **options) 

40 

41 def handle_annotated_strings(self, match): 

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

43 

44 match args: 

45 1:open_string, 

46 2:exclamation_mark, 

47 3:lang_name, 

48 4:space_or_newline, 

49 5:code, 

50 6:close_string 

51 """ 

52 from pygments.lexers import get_lexer_by_name 

53 

54 # Header's section 

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

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

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

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

59 

60 lexer = None 

61 if self.handle_annotateds: 

62 try: 

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

64 except ClassNotFound: 

65 pass 

66 code = match.group(5) 

67 

68 if lexer is None: 

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

70 else: 

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

72 

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

74 

75 tokens = { 

76 'root': [ 

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

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

79 

80 # Constants 

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

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

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

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

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

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

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

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

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

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

91 # Note: Literals can be labeled too 

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

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

94 # Note: Attributes can be labeled too 

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

96 

97 # Switch structure 

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

99 bygroups(Punctuation, using(this), Punctuation)), 

100 

101 # Single Line Strings 

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

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

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

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

106 

107 # Multi Line Strings 

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

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

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

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

112 

113 include('builtin-functions'), 

114 

115 # Operators 

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

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

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

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

120 'ø', '∞', 

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

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

123 '=>>', '<<=>>', '<<==>>', 

124 '-->', '<->', '<-->', 

125 '=|', '|=', '-:', ':-', 

126 '_', '.', '..', '\\')), Operator), 

127 

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

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

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

131 ], 

132 

133 'inside-interpol': [ 

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

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

136 ], 

137 'inside-template': [ 

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

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

140 ], 

141 'string-escape': [ 

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

143 ], 

144 

145 'inside-simple-string': [ 

146 include('string-escape'), 

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

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

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

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

151 ], 

152 'inside-smart-string': [ 

153 include('string-escape'), 

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

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

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

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

158 ], 

159 'inside-safe-string': [ 

160 include('string-escape'), 

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

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

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

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

165 ], 

166 'inside-regex-string': [ 

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

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

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

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

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

172 ], 

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

174 include('string-escape'), 

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

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

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

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

179 ], 

180 'inside-curly-string': [ 

181 include('string-escape'), 

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

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

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

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

186 ], 

187 'inside-eof-string': [ 

188 include('string-escape'), 

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

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

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

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

193 ], 

194 

195 'builtin-functions': [ 

196 (words(( 

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

198 'attributeLabel', 'binary', 'block' 'char', 'contains', 

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

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

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

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

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

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

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

206 'sorted', 'standalone', 'string', 'subset', 'suffix', 

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

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

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

210 (words(( 

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

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

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

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

215 'before', 'benchmark', 'blend', 'break', 'builtins1', 

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

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

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

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

220 'decouple', 'define', 'delete', 'desaturate', 'deviation', 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

246 'write', 'xnor', 'xor', 'zip' 

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

248 ], 

249 

250 }