]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_vendor/pygments/token.py
5 Basic token types and the standard tokens.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
12 class _TokenType(tuple):
18 while node
is not None:
24 def __init__(self
, *args
):
25 # no need to call super.__init__
28 def __contains__(self
, val
):
29 return self
is val
or (
30 type(val
) is self
.__class
__ and
31 val
[:len(self
)] == self
34 def __getattr__(self
, val
):
35 if not val
or not val
[0].isupper():
36 return tuple.__getattribute
__(self
, val
)
37 new
= _TokenType(self
+ (val
,))
38 setattr(self
, val
, new
)
39 self
.subtypes
.add(new
)
44 return 'Token' + (self
and '.' or '') + '.'.join(self
)
47 # These instances are supposed to be singletons
50 def __deepcopy__(self
, memo
):
51 # These instances are supposed to be singletons
59 Whitespace
= Text
.Whitespace
62 # Text that doesn't belong to this lexer (e.g. HTML in PHP)
65 # Common token types for source code
66 Keyword
= Token
.Keyword
68 Literal
= Token
.Literal
69 String
= Literal
.String
70 Number
= Literal
.Number
71 Punctuation
= Token
.Punctuation
72 Operator
= Token
.Operator
73 Comment
= Token
.Comment
75 # Generic types for non-source code
76 Generic
= Token
.Generic
78 # String and some others are not direct children of Token.
85 def is_token_subtype(ttype
, other
):
87 Return True if ``ttype`` is a subtype of ``other``.
89 exists for backwards compatibility. use ``ttype in other`` now.
94 def string_to_tokentype(s
):
96 Convert a string into a token type::
98 >>> string_to_token('String.Double')
99 Token.Literal.String.Double
100 >>> string_to_token('Token.Literal.Number')
102 >>> string_to_token('')
105 Tokens that are already tokens are returned unchanged:
107 >>> string_to_token(String)
110 if isinstance(s
, _TokenType
):
115 for item
in s
.split('.'):
116 node
= getattr(node
, item
)
120 # Map standard token types to short names, used in CSS class naming.
121 # If you add a new item, please be sure to run this file to perform
122 # a consistency check for duplicate values.
133 Keyword
.Constant
: 'kc',
134 Keyword
.Declaration
: 'kd',
135 Keyword
.Namespace
: 'kn',
136 Keyword
.Pseudo
: 'kp',
137 Keyword
.Reserved
: 'kr',
141 Name
.Attribute
: 'na',
143 Name
.Builtin
.Pseudo
: 'bp',
146 Name
.Decorator
: 'nd',
148 Name
.Exception: 'ne',
150 Name
.Function
.Magic
: 'fm',
153 Name
.Namespace
: 'nn',
157 Name
.Variable
.Class
: 'vc',
158 Name
.Variable
.Global
: 'vg',
159 Name
.Variable
.Instance
: 'vi',
160 Name
.Variable
.Magic
: 'vm',
167 String
.Backtick
: 'sb',
169 String
.Delimiter
: 'dl',
173 String
.Heredoc
: 'sh',
174 String
.Interpol
: 'si',
184 Number
.Integer
: 'mi',
185 Number
.Integer
.Long
: 'il',
192 Punctuation
.Marker
: 'pm',
195 Comment
.Hashbang
: 'ch',
196 Comment
.Multiline
: 'cm',
197 Comment
.Preproc
: 'cp',
198 Comment
.PreprocFile
: 'cpf',
199 Comment
.Single
: 'c1',
200 Comment
.Special
: 'cs',
203 Generic
.Deleted
: 'gd',
206 Generic
.Heading
: 'gh',
207 Generic
.Inserted
: 'gi',
208 Generic
.Output
: 'go',
209 Generic
.Prompt
: 'gp',
210 Generic
.Strong
: 'gs',
211 Generic
.Subheading
: 'gu',
212 Generic
.Traceback
: 'gt',