Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/func.py: 100%
9 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.func
3 ~~~~~~~~~~~~~~~~~~~~
5 Lexers for FunC.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11from pygments.lexer import RegexLexer, include, words
12from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
13 Number, Whitespace, Punctuation
15__all__ = ['FuncLexer']
18class FuncLexer(RegexLexer):
19 """
20 For FunC source code.
21 """
23 name = 'FunC'
24 aliases = ['func', 'fc']
25 filenames = ['*.fc', '*.func']
27 # 1. Does not start from "
28 # 2. Can start from ` and end with `, containing any character
29 # 3. Starts with underscore or { or } and have more than 1 character after it
30 # 4. Starts with letter, contains letters, numbers and underscores
31 identifier = r'(?!")(`([^`]+)`|((?=_)_|(?=\{)\{|(?=\})\}|(?![_`{}]))([^;,\[\]\(\)\s~.]+))'
33 tokens = {
34 'root': [
35 (r'\n', Whitespace),
36 (r'\s+', Whitespace),
38 include('keywords'),
39 include('strings'),
40 include('directives'),
41 include('numeric'),
42 include('comments'),
43 include('storage'),
44 include('functions'),
45 include('variables'),
47 (r'[.;(),\[\]~{}]', Punctuation)
48 ],
49 'keywords': [
50 (words((
51 '<=>', '>=', '<=', '!=', '==', '^>>', '~>>',
52 '>>', '<<', '/%', '^%', '~%', '^/', '~/', '+=',
53 '-=', '*=', '/=', '~/=', '^/=', '%=', '^%=', '<<=',
54 '>>=', '~>>=', '^>>=', '&=', '|=', '^=', '^', '=',
55 '~', '/', '%', '-', '*', '+','>',
56 '<', '&', '|', ':', '?'), prefix=r'(?<=\s)', suffix=r'(?=\s)'),
57 Operator),
58 (words((
59 'if', 'ifnot',
60 'else', 'elseif', 'elseifnot',
61 'while', 'do', 'until', 'repeat',
62 'return', 'impure', 'method_id',
63 'forall', 'asm', 'inline', 'inline_ref'), prefix=r'\b', suffix=r'\b'),
64 Keyword),
65 (words(('true', 'false'), prefix=r'\b', suffix=r'\b'), Keyword.Constant),
66 ],
67 'directives': [
68 (r'#include|#pragma', Keyword, 'directive'),
69 ],
70 'directive': [
71 include('strings'),
72 (r'\s+', Whitespace),
73 (r'version|not-version', Keyword),
74 (r'(>=|<=|=|>|<|\^)?([0-9]+)(.[0-9]+)?(.[0-9]+)?', Number), # version
75 (r';', Text, '#pop')
76 ],
77 'strings': [
78 (r'\"([^\n\"]+)\"[Hhcusa]?', String),
79 ],
80 'numeric': [
81 (r'\b(-?(?!_)([\d_]+|0x[\d_a-fA-F]+)|0b[1_0]+)(?<!_)(?=[\s\)\],;])', Number)
82 ],
83 'comments': [
84 (r';;([^\n]*)', Comment.Singleline),
85 (r'\{-', Comment.Multiline, 'comment'),
86 ],
87 'comment': [
88 (r'[^-}{]+', Comment.Multiline),
89 (r'\{-', Comment.Multiline, '#push'),
90 (r'-\}', Comment.Multiline, '#pop'),
91 (r'[-}{]', Comment.Multiline),
92 ],
93 'storage': [
94 (words((
95 'var', 'int', 'slice', 'tuple',
96 'cell', 'builder', 'cont', '_'),
97 prefix=r'\b', suffix=r'(?=[\s\(\),\[\]])'),
98 Keyword.Type),
99 (words(('global', 'const'), prefix=r'\b', suffix=r'\b'), Keyword.Constant),
100 ],
101 'variables': [
102 (identifier, Name.Variable),
103 ],
104 'functions': [
105 # identifier followed by (
106 (identifier + r'(?=[\(])', Name.Function),
107 ]
108 }