Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/spice.py: 100%
10 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
1"""
2 pygments.lexers.spice
3 ~~~~~~~~~~~~~~~~~~~~~
5 Lexers for the Spice programming language.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11from pygments.lexer import RegexLexer, bygroups, words
12from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
13 Number, Punctuation, Whitespace
15__all__ = ['SpiceLexer']
18class SpiceLexer(RegexLexer):
19 """
20 For Spice source.
22 .. versionadded:: 2.11
23 """
24 name = 'Spice'
25 url = 'https://www.spicelang.com'
26 filenames = ['*.spice']
27 aliases = ['spice', 'spicelang']
28 mimetypes = ['text/x-spice']
30 tokens = {
31 'root': [
32 (r'\n', Whitespace),
33 (r'\s+', Whitespace),
34 (r'\\\n', Text),
35 # comments
36 (r'//(.*?)\n', Comment.Single),
37 (r'/(\\\n)?[*]{2}(.|\n)*?[*](\\\n)?/', String.Doc),
38 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
39 # keywords
40 (r'(import|as)\b', Keyword.Namespace),
41 (r'(f|p|type|struct|interface|enum|alias|operator)\b', Keyword.Declaration),
42 (words(('if', 'else', 'for', 'foreach', 'do', 'while', 'break',
43 'continue', 'return', 'assert', 'thread', 'unsafe', 'ext',
44 'dll'), suffix=r'\b'), Keyword),
45 (words(('const', 'signed', 'unsigned', 'inline', 'public', 'heap'),
46 suffix=r'\b'), Keyword.Pseudo),
47 (words(('new', 'switch', 'case', 'yield', 'stash', 'pick', 'sync',
48 'class'), suffix=r'\b'), Keyword.Reserved),
49 (r'(true|false|nil)\b', Keyword.Constant),
50 (words(('double', 'int', 'short', 'long', 'byte', 'char', 'string',
51 'bool', 'dyn'), suffix=r'\b'), Keyword.Type),
52 (words(('printf', 'sizeof', 'len', 'tid', 'join'), suffix=r'\b(\()'),
53 bygroups(Name.Builtin, Punctuation)),
54 # numeric literals
55 (r'[0-9]*[.][0-9]+', Number.Double),
56 (r'0[bB][01]+[sl]?', Number.Bin),
57 (r'0[oO][0-7]+[sl]?', Number.Oct),
58 (r'0[xXhH][0-9a-fA-F]+[sl]?', Number.Hex),
59 (r'(0[dD])?[0-9]+[sl]?', Number.Integer),
60 # string literal
61 (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
62 # char literal
63 (r'\'(\\\\|\\[^\\]|[^\'\\])\'', String.Char),
64 # tokens
65 (r'<<=|>>=|<<|>>|<=|>=|\+=|-=|\*=|/=|\%=|\|=|&=|\^=|&&|\|\||&|\||'
66 r'\+\+|--|\%|\^|\~|==|!=|::|[.]{3}|[+\-*/&]', Operator),
67 (r'[|<>=!()\[\]{}.,;:\?]', Punctuation),
68 # identifiers
69 (r'[^\W\d]\w*', Name.Other),
70 ]
71 }