Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/savi.py: 100%
9 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.savi
3 ~~~~~~~~~~~~~~~~~~~~
5 Lexer for Savi.
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, include
12from pygments.token import Whitespace, Keyword, Name, String, Number, \
13 Operator, Punctuation, Comment, Generic, Error
15__all__ = ['SaviLexer']
18# The canonical version of this file can be found in the following repository,
19# where it is kept in sync with any language changes, as well as the other
20# pygments-like lexers that are maintained for use with other tools:
21# - https://github.com/savi-lang/savi/blob/main/tooling/pygments/lexers/savi.py
22#
23# If you're changing this file in the pygments repository, please ensure that
24# any changes you make are also propagated to the official Savi repository,
25# in order to avoid accidental clobbering of your changes later when an update
26# from the Savi repository flows forward into the pygments repository.
27#
28# If you're changing this file in the Savi repository, please ensure that
29# any changes you make are also reflected in the other pygments-like lexers
30# (rouge, vscode, etc) so that all of the lexers can be kept cleanly in sync.
32class SaviLexer(RegexLexer):
33 """
34 For Savi source code.
36 .. versionadded: 2.10
37 """
39 name = 'Savi'
40 url = 'https://github.com/savi-lang/savi'
41 aliases = ['savi']
42 filenames = ['*.savi']
44 tokens = {
45 "root": [
46 # Line Comment
47 (r'//.*?$', Comment.Single),
49 # Doc Comment
50 (r'::.*?$', Comment.Single),
52 # Capability Operator
53 (r'(\')(\w+)(?=[^\'])', bygroups(Operator, Name)),
55 # Double-Quote String
56 (r'\w?"', String.Double, "string.double"),
58 # Single-Char String
59 (r"'", String.Char, "string.char"),
61 # Type Name
62 (r'(_?[A-Z]\w*)', Name.Class),
64 # Nested Type Name
65 (r'(\.)(\s*)(_?[A-Z]\w*)', bygroups(Punctuation, Whitespace, Name.Class)),
67 # Declare
68 (r'^([ \t]*)(:\w+)',
69 bygroups(Whitespace, Name.Tag),
70 "decl"),
72 # Error-Raising Calls/Names
73 (r'((\w+|\+|\-|\*)\!)', Generic.Deleted),
75 # Numeric Values
76 (r'\b\d([\d_]*(\.[\d_]+)?)\b', Number),
78 # Hex Numeric Values
79 (r'\b0x([0-9a-fA-F_]+)\b', Number.Hex),
81 # Binary Numeric Values
82 (r'\b0b([01_]+)\b', Number.Bin),
84 # Function Call (with braces)
85 (r'\w+(?=\()', Name.Function),
87 # Function Call (with receiver)
88 (r'(\.)(\s*)(\w+)', bygroups(Punctuation, Whitespace, Name.Function)),
90 # Function Call (with self receiver)
91 (r'(@)(\w+)', bygroups(Punctuation, Name.Function)),
93 # Parenthesis
94 (r'\(', Punctuation, "root"),
95 (r'\)', Punctuation, "#pop"),
97 # Brace
98 (r'\{', Punctuation, "root"),
99 (r'\}', Punctuation, "#pop"),
101 # Bracket
102 (r'\[', Punctuation, "root"),
103 (r'(\])(\!)', bygroups(Punctuation, Generic.Deleted), "#pop"),
104 (r'\]', Punctuation, "#pop"),
106 # Punctuation
107 (r'[,;:\.@]', Punctuation),
109 # Piping Operators
110 (r'(\|\>)', Operator),
112 # Branching Operators
113 (r'(\&\&|\|\||\?\?|\&\?|\|\?|\.\?)', Operator),
115 # Comparison Operators
116 (r'(\<\=\>|\=\~|\=\=|\<\=|\>\=|\<|\>)', Operator),
118 # Arithmetic Operators
119 (r'(\+|\-|\/|\*|\%)', Operator),
121 # Assignment Operators
122 (r'(\=)', Operator),
124 # Other Operators
125 (r'(\!|\<\<|\<|\&|\|)', Operator),
127 # Identifiers
128 (r'\b\w+\b', Name),
130 # Whitespace
131 (r'[ \t\r]+\n*|\n+', Whitespace),
132 ],
134 # Declare (nested rules)
135 "decl": [
136 (r'\b[a-z_]\w*\b(?!\!)', Keyword.Declaration),
137 (r':', Punctuation, "#pop"),
138 (r'\n', Whitespace, "#pop"),
139 include("root"),
140 ],
142 # Double-Quote String (nested rules)
143 "string.double": [
144 (r'\\\(', String.Interpol, "string.interpolation"),
145 (r'\\u[0-9a-fA-F]{4}', String.Escape),
146 (r'\\x[0-9a-fA-F]{2}', String.Escape),
147 (r'\\[bfnrt\\\']', String.Escape),
148 (r'\\"', String.Escape),
149 (r'"', String.Double, "#pop"),
150 (r'[^\\"]+', String.Double),
151 (r'.', Error),
152 ],
154 # Single-Char String (nested rules)
155 "string.char": [
156 (r'\\u[0-9a-fA-F]{4}', String.Escape),
157 (r'\\x[0-9a-fA-F]{2}', String.Escape),
158 (r'\\[bfnrt\\\']', String.Escape),
159 (r"\\'", String.Escape),
160 (r"'", String.Char, "#pop"),
161 (r"[^\\']+", String.Char),
162 (r'.', Error),
163 ],
165 # Interpolation inside String (nested rules)
166 "string.interpolation": [
167 (r"\)", String.Interpol, "#pop"),
168 include("root"),
169 ]
170 }