Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/berry.py: 100%
10 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1"""
2 pygments.lexers.berry
3 ~~~~~~~~~~~~~~~~~~~~~
5 Lexer for Berry.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11from pygments.lexer import RegexLexer, words, include, bygroups
12from pygments.token import Comment, Whitespace, Operator, Keyword, Name, \
13 String, Number, Punctuation
15__all__ = ['BerryLexer']
18class BerryLexer(RegexLexer):
19 """
20 For `berry <http://github.com/berry-lang/berry>`_ source code.
22 .. versionadded:: 2.12.0
23 """
24 name = 'Berry'
25 aliases = ['berry', 'be']
26 filenames = ['*.be']
27 mimetypes = ['text/x-berry', 'application/x-berry']
29 _name = r'\b[^\W\d]\w*'
31 tokens = {
32 'root': [
33 include('whitespace'),
34 include('numbers'),
35 include('keywords'),
36 (rf'(def)(\s+)({_name})',
37 bygroups(Keyword.Declaration, Whitespace, Name.Function)),
38 (rf'\b(class)(\s+)({_name})',
39 bygroups(Keyword.Declaration, Whitespace, Name.Class)),
40 (rf'\b(import)(\s+)({_name})',
41 bygroups(Keyword.Namespace, Whitespace, Name.Namespace)),
42 include('expr')
43 ],
44 'expr': [
45 (r'[^\S\n]+', Whitespace),
46 (r'\.\.|[~!%^&*+=|?:<>/-]', Operator),
47 (r'[(){}\[\],.;]', Punctuation),
48 include('controls'),
49 include('builtins'),
50 include('funccall'),
51 include('member'),
52 include('name'),
53 include('strings')
54 ],
55 'whitespace': [
56 (r'\s+', Whitespace),
57 (r'#-(.|\n)*?-#', Comment.Multiline),
58 (r'#.*?$', Comment.Single)
59 ],
60 'keywords': [
61 (words((
62 'as', 'break', 'continue', 'import', 'static', 'self', 'super'),
63 suffix=r'\b'), Keyword.Reserved),
64 (r'(true|false|nil)\b', Keyword.Constant),
65 (r'(var|def)\b', Keyword.Declaration)
66 ],
67 'controls': [
68 (words((
69 'if', 'elif', 'else', 'for', 'while', 'do', 'end', 'break',
70 'continue', 'return', 'try', 'except', 'raise'),
71 suffix=r'\b'), Keyword)
72 ],
73 'builtins': [
74 (words((
75 'assert', 'bool', 'input', 'classname', 'classof', 'number', 'real',
76 'bytes', 'compile', 'map', 'list', 'int', 'isinstance', 'print',
77 'range', 'str', 'super', 'module', 'size', 'issubclass', 'open',
78 'file', 'type', 'call'),
79 suffix=r'\b'), Name.Builtin)
80 ],
81 'numbers': [
82 (r'0[xX][a-fA-F0-9]+', Number.Hex),
83 (r'-?\d+', Number.Integer),
84 (r'(-?\d+\.?|\.\d)\d*([eE][+-]?\d+)?', Number.Float)
85 ],
86 'name': [
87 (_name, Name)
88 ],
89 'funccall': [
90 (rf'{_name}(?=\s*\()', Name.Function, '#pop')
91 ],
92 'member': [
93 (rf'(?<=\.){_name}\b(?!\()', Name.Attribute, '#pop')
94 ],
95 'strings': [
96 (r'"([^\\]|\\.)*?"', String.Double, '#pop'),
97 (r'\'([^\\]|\\.)*?\'', String.Single, '#pop')
98 ]
99 }