1#![allow(clippy::match_same_arms, clippy::too_many_lines)]
4#![allow(missing_docs)]
7
8use num_derive::FromPrimitive;
11
12#[derive(Clone, Debug, PartialEq, Eq, FromPrimitive)]
13pub enum Python {
14 End = 0,
15 Identifier = 1,
16 SEMI = 2,
17 Import = 3,
18 DOT = 4,
19 From = 5,
20 Future = 6,
21 LPAREN = 7,
22 RPAREN = 8,
23 COMMA = 9,
24 As = 10,
25 STAR = 11,
26 Print = 12,
27 GTGT = 13,
28 Assert = 14,
29 COLONEQ = 15,
30 Return = 16,
31 Del = 17,
32 Raise = 18,
33 Pass = 19,
34 Break = 20,
35 Continue = 21,
36 If = 22,
37 COLON = 23,
38 Elif = 24,
39 Else = 25,
40 Match = 26,
41 Case = 27,
42 Async = 28,
43 For = 29,
44 In = 30,
45 While = 31,
46 Try = 32,
47 Except = 33,
48 STAR2 = 34,
49 Finally = 35,
50 With = 36,
51 Def = 37,
52 DASHGT = 38,
53 STARSTAR = 39,
54 Global = 40,
55 Nonlocal = 41,
56 Exec = 42,
57 Type2 = 43,
58 EQ = 44,
59 Class = 45,
60 LBRACK = 46,
61 RBRACK = 47,
62 AT = 48,
63 DASH = 49,
64 UNDERSCORE = 50,
65 PIPE = 51,
66 LBRACE = 52,
67 RBRACE = 53,
68 PLUS = 54,
69 Not = 55,
70 And = 56,
71 Or = 57,
72 SLASH = 58,
73 PERCENT = 59,
74 SLASHSLASH = 60,
75 AMP = 61,
76 CARET = 62,
77 LTLT = 63,
78 TILDE = 64,
79 Is = 65,
80 LT = 66,
81 LTEQ = 67,
82 EQEQ = 68,
83 BANGEQ = 69,
84 GTEQ = 70,
85 GT = 71,
86 LTGT = 72,
87 Lambda3 = 73,
88 PLUSEQ = 74,
89 DASHEQ = 75,
90 STAREQ = 76,
91 SLASHEQ = 77,
92 ATEQ = 78,
93 SLASHSLASHEQ = 79,
94 PERCENTEQ = 80,
95 STARSTAREQ = 81,
96 GTGTEQ = 82,
97 LTLTEQ = 83,
98 AMPEQ = 84,
99 CARETEQ = 85,
100 PIPEEQ = 86,
101 Yield2 = 87,
102 Ellipsis = 88,
103 EscapeSequence = 89,
104 BSLASH = 90,
105 FormatSpecifierToken1 = 91,
106 TypeConversion = 92,
107 Integer = 93,
108 Float = 94,
109 Await2 = 95,
110 True = 96,
111 False = 97,
112 None = 98,
113 Comment = 99,
114 LineContinuation = 100,
115 Newline = 101,
116 Indent = 102,
117 Dedent = 103,
118 StringStart = 104,
119 StringContent2 = 105,
120 EscapeInterpolation = 106,
121 StringEnd = 107,
122 Module = 108,
123 Statement = 109,
124 SimpleStatements = 110,
125 ImportStatement = 111,
126 ImportPrefix = 112,
127 RelativeImport = 113,
128 FutureImportStatement = 114,
129 ImportFromStatement = 115,
130 ImportList = 116,
131 AliasedImport = 117,
132 WildcardImport = 118,
133 PrintStatement = 119,
134 Chevron = 120,
135 AssertStatement = 121,
136 ExpressionStatement = 122,
137 NamedExpression = 123,
138 NamedExpressionLhs = 124,
139 ReturnStatement = 125,
140 DeleteStatement = 126,
141 RaiseStatement = 127,
142 PassStatement = 128,
143 BreakStatement = 129,
144 ContinueStatement = 130,
145 IfStatement = 131,
146 ElifClause = 132,
147 ElseClause = 133,
148 MatchStatement = 134,
149 Block = 135,
150 CaseClause = 136,
151 ForStatement = 137,
152 WhileStatement = 138,
153 TryStatement = 139,
154 ExceptClause = 140,
155 FinallyClause = 141,
156 WithStatement = 142,
157 WithClause = 143,
158 WithItem = 144,
159 FunctionDefinition = 145,
160 Parameters = 146,
161 LambdaParameters = 147,
162 ListSplat = 148,
163 DictionarySplat = 149,
164 GlobalStatement = 150,
165 NonlocalStatement = 151,
166 ExecStatement = 152,
167 TypeAliasStatement = 153,
168 ClassDefinition = 154,
169 TypeParameter = 155,
170 ParenthesizedListSplat = 156,
171 ArgumentList = 157,
172 DecoratedDefinition = 158,
173 Decorator = 159,
174 Block2 = 160,
175 ExpressionList = 161,
176 DottedName = 162,
177 CasePattern = 163,
178 SimplePattern = 164,
179 AsPattern = 165,
180 UnionPattern = 166,
181 ListPattern = 167,
182 TuplePattern = 168,
183 DictPattern = 169,
184 KeyValuePattern = 170,
185 KeywordPattern = 171,
186 SplatPattern = 172,
187 ClassPattern = 173,
188 ComplexPattern = 174,
189 Parameters2 = 175,
190 Patterns = 176,
191 Parameter = 177,
192 Pattern = 178,
193 TuplePattern2 = 179,
194 ListPattern2 = 180,
195 DefaultParameter = 181,
196 TypedDefaultParameter = 182,
197 ListSplatPattern = 183,
198 DictionarySplatPattern = 184,
199 AsPattern2 = 185,
200 ExpressionWithinForInClause = 186,
201 Expression = 187,
202 PrimaryExpression = 188,
203 NotOperator = 189,
204 BooleanOperator = 190,
205 BinaryOperator = 191,
206 UnaryOperator = 192,
207 Notin = 193,
208 Isnot = 194,
209 ComparisonOperator = 195,
210 Lambda = 196,
211 Lambda2 = 197,
212 Assignment = 198,
213 AugmentedAssignment = 199,
214 PatternList = 200,
215 RightHandSide = 201,
216 Yield = 202,
217 Attribute = 203,
218 Subscript = 204,
219 Slice = 205,
220 Call = 206,
221 TypedParameter = 207,
222 Type = 208,
223 SplatType = 209,
224 GenericType = 210,
225 UnionType = 211,
226 ConstrainedType = 212,
227 MemberType = 213,
228 KeywordArgument = 214,
229 List = 215,
230 Set = 216,
231 Tuple = 217,
232 Dictionary = 218,
233 Pair = 219,
234 ListComprehension = 220,
235 DictionaryComprehension = 221,
236 SetComprehension = 222,
237 GeneratorExpression = 223,
238 ComprehensionClauses = 224,
239 ParenthesizedExpression = 225,
240 CollectionElements = 226,
241 ForInClause = 227,
242 IfClause = 228,
243 ConditionalExpression = 229,
244 ConcatenatedString = 230,
245 String = 231,
246 StringContent = 232,
247 Interpolation = 233,
248 FExpression = 234,
249 NotEscapeSequence = 235,
250 FormatSpecifier = 236,
251 Await = 237,
252 PositionalSeparator = 238,
253 KeywordSeparator = 239,
254 ModuleRepeat1 = 240,
255 SimpleStatementsRepeat1 = 241,
256 ImportPrefixRepeat1 = 242,
257 ImportListRepeat1 = 243,
258 PrintStatementRepeat1 = 244,
259 AssertStatementRepeat1 = 245,
260 IfStatementRepeat1 = 246,
261 MatchStatementRepeat1 = 247,
262 MatchBlockRepeat1 = 248,
263 CaseClauseRepeat1 = 249,
264 TryStatementRepeat1 = 250,
265 ExceptClauseRepeat1 = 251,
266 WithClauseRepeat1 = 252,
267 GlobalStatementRepeat1 = 253,
268 TypeParameterRepeat1 = 254,
269 ArgumentListRepeat1 = 255,
270 DecoratedDefinitionRepeat1 = 256,
271 DottedNameRepeat1 = 257,
272 UnionPatternRepeat1 = 258,
273 DictPatternRepeat1 = 259,
274 ParametersRepeat1 = 260,
275 PatternsRepeat1 = 261,
276 ComparisonOperatorRepeat1 = 262,
277 SubscriptRepeat1 = 263,
278 DictionaryRepeat1 = 264,
279 ComprehensionClausesRepeat1 = 265,
280 CollectionElementsRepeat1 = 266,
281 ForInClauseRepeat1 = 267,
282 ConcatenatedStringRepeat1 = 268,
283 StringRepeat1 = 269,
284 StringContentRepeat1 = 270,
285 FormatSpecifierRepeat1 = 271,
286 AsPatternTarget = 272,
287 FormatExpression = 273,
288 Error = 274,
289}
290
291impl From<Python> for &'static str {
292 #[inline]
293 fn from(tok: Python) -> Self {
294 match tok {
295 Python::End => "end",
296 Python::Identifier => "identifier",
297 Python::SEMI => ";",
298 Python::Import => "import",
299 Python::DOT => ".",
300 Python::From => "from",
301 Python::Future => "__future__",
302 Python::LPAREN => "(",
303 Python::RPAREN => ")",
304 Python::COMMA => ",",
305 Python::As => "as",
306 Python::STAR => "*",
307 Python::Print => "print",
308 Python::GTGT => ">>",
309 Python::Assert => "assert",
310 Python::COLONEQ => ":=",
311 Python::Return => "return",
312 Python::Del => "del",
313 Python::Raise => "raise",
314 Python::Pass => "pass",
315 Python::Break => "break",
316 Python::Continue => "continue",
317 Python::If => "if",
318 Python::COLON => ":",
319 Python::Elif => "elif",
320 Python::Else => "else",
321 Python::Match => "match",
322 Python::Case => "case",
323 Python::Async => "async",
324 Python::For => "for",
325 Python::In => "in",
326 Python::While => "while",
327 Python::Try => "try",
328 Python::Except => "except",
329 Python::STAR2 => "*",
330 Python::Finally => "finally",
331 Python::With => "with",
332 Python::Def => "def",
333 Python::DASHGT => "->",
334 Python::STARSTAR => "**",
335 Python::Global => "global",
336 Python::Nonlocal => "nonlocal",
337 Python::Exec => "exec",
338 Python::Type2 => "type",
339 Python::EQ => "=",
340 Python::Class => "class",
341 Python::LBRACK => "[",
342 Python::RBRACK => "]",
343 Python::AT => "@",
344 Python::DASH => "-",
345 Python::UNDERSCORE => "_",
346 Python::PIPE => "|",
347 Python::LBRACE => "{",
348 Python::RBRACE => "}",
349 Python::PLUS => "+",
350 Python::Not => "not",
351 Python::And => "and",
352 Python::Or => "or",
353 Python::SLASH => "/",
354 Python::PERCENT => "%",
355 Python::SLASHSLASH => "//",
356 Python::AMP => "&",
357 Python::CARET => "^",
358 Python::LTLT => "<<",
359 Python::TILDE => "~",
360 Python::Is => "is",
361 Python::LT => "<",
362 Python::LTEQ => "<=",
363 Python::EQEQ => "==",
364 Python::BANGEQ => "!=",
365 Python::GTEQ => ">=",
366 Python::GT => ">",
367 Python::LTGT => "<>",
368 Python::Lambda3 => "lambda",
369 Python::PLUSEQ => "+=",
370 Python::DASHEQ => "-=",
371 Python::STAREQ => "*=",
372 Python::SLASHEQ => "/=",
373 Python::ATEQ => "@=",
374 Python::SLASHSLASHEQ => "//=",
375 Python::PERCENTEQ => "%=",
376 Python::STARSTAREQ => "**=",
377 Python::GTGTEQ => ">>=",
378 Python::LTLTEQ => "<<=",
379 Python::AMPEQ => "&=",
380 Python::CARETEQ => "^=",
381 Python::PIPEEQ => "|=",
382 Python::Yield2 => "yield",
383 Python::Ellipsis => "ellipsis",
384 Python::EscapeSequence => "escape_sequence",
385 Python::BSLASH => "\\",
386 Python::FormatSpecifierToken1 => "format_specifier_token1",
387 Python::TypeConversion => "type_conversion",
388 Python::Integer => "integer",
389 Python::Float => "float",
390 Python::Await2 => "await",
391 Python::True => "true",
392 Python::False => "false",
393 Python::None => "none",
394 Python::Comment => "comment",
395 Python::LineContinuation => "line_continuation",
396 Python::Newline => "_newline",
397 Python::Indent => "_indent",
398 Python::Dedent => "_dedent",
399 Python::StringStart => "string_start",
400 Python::StringContent2 => "_string_content",
401 Python::EscapeInterpolation => "escape_interpolation",
402 Python::StringEnd => "string_end",
403 Python::Module => "module",
404 Python::Statement => "_statement",
405 Python::SimpleStatements => "_simple_statements",
406 Python::ImportStatement => "import_statement",
407 Python::ImportPrefix => "import_prefix",
408 Python::RelativeImport => "relative_import",
409 Python::FutureImportStatement => "future_import_statement",
410 Python::ImportFromStatement => "import_from_statement",
411 Python::ImportList => "_import_list",
412 Python::AliasedImport => "aliased_import",
413 Python::WildcardImport => "wildcard_import",
414 Python::PrintStatement => "print_statement",
415 Python::Chevron => "chevron",
416 Python::AssertStatement => "assert_statement",
417 Python::ExpressionStatement => "expression_statement",
418 Python::NamedExpression => "named_expression",
419 Python::NamedExpressionLhs => "_named_expression_lhs",
420 Python::ReturnStatement => "return_statement",
421 Python::DeleteStatement => "delete_statement",
422 Python::RaiseStatement => "raise_statement",
423 Python::PassStatement => "pass_statement",
424 Python::BreakStatement => "break_statement",
425 Python::ContinueStatement => "continue_statement",
426 Python::IfStatement => "if_statement",
427 Python::ElifClause => "elif_clause",
428 Python::ElseClause => "else_clause",
429 Python::MatchStatement => "match_statement",
430 Python::Block => "block",
431 Python::CaseClause => "case_clause",
432 Python::ForStatement => "for_statement",
433 Python::WhileStatement => "while_statement",
434 Python::TryStatement => "try_statement",
435 Python::ExceptClause => "except_clause",
436 Python::FinallyClause => "finally_clause",
437 Python::WithStatement => "with_statement",
438 Python::WithClause => "with_clause",
439 Python::WithItem => "with_item",
440 Python::FunctionDefinition => "function_definition",
441 Python::Parameters => "parameters",
442 Python::LambdaParameters => "lambda_parameters",
443 Python::ListSplat => "list_splat",
444 Python::DictionarySplat => "dictionary_splat",
445 Python::GlobalStatement => "global_statement",
446 Python::NonlocalStatement => "nonlocal_statement",
447 Python::ExecStatement => "exec_statement",
448 Python::TypeAliasStatement => "type_alias_statement",
449 Python::ClassDefinition => "class_definition",
450 Python::TypeParameter => "type_parameter",
451 Python::ParenthesizedListSplat => "parenthesized_list_splat",
452 Python::ArgumentList => "argument_list",
453 Python::DecoratedDefinition => "decorated_definition",
454 Python::Decorator => "decorator",
455 Python::Block2 => "block",
456 Python::ExpressionList => "expression_list",
457 Python::DottedName => "dotted_name",
458 Python::CasePattern => "case_pattern",
459 Python::SimplePattern => "_simple_pattern",
460 Python::AsPattern => "as_pattern",
461 Python::UnionPattern => "union_pattern",
462 Python::ListPattern => "list_pattern",
463 Python::TuplePattern => "tuple_pattern",
464 Python::DictPattern => "dict_pattern",
465 Python::KeyValuePattern => "_key_value_pattern",
466 Python::KeywordPattern => "keyword_pattern",
467 Python::SplatPattern => "splat_pattern",
468 Python::ClassPattern => "class_pattern",
469 Python::ComplexPattern => "complex_pattern",
470 Python::Parameters2 => "_parameters",
471 Python::Patterns => "_patterns",
472 Python::Parameter => "parameter",
473 Python::Pattern => "pattern",
474 Python::TuplePattern2 => "tuple_pattern",
475 Python::ListPattern2 => "list_pattern",
476 Python::DefaultParameter => "default_parameter",
477 Python::TypedDefaultParameter => "typed_default_parameter",
478 Python::ListSplatPattern => "list_splat_pattern",
479 Python::DictionarySplatPattern => "dictionary_splat_pattern",
480 Python::AsPattern2 => "as_pattern",
481 Python::ExpressionWithinForInClause => "_expression_within_for_in_clause",
482 Python::Expression => "expression",
483 Python::PrimaryExpression => "primary_expression",
484 Python::NotOperator => "not_operator",
485 Python::BooleanOperator => "boolean_operator",
486 Python::BinaryOperator => "binary_operator",
487 Python::UnaryOperator => "unary_operator",
488 Python::Notin => "not in",
489 Python::Isnot => "is not",
490 Python::ComparisonOperator => "comparison_operator",
491 Python::Lambda => "lambda",
492 Python::Lambda2 => "lambda",
493 Python::Assignment => "assignment",
494 Python::AugmentedAssignment => "augmented_assignment",
495 Python::PatternList => "pattern_list",
496 Python::RightHandSide => "_right_hand_side",
497 Python::Yield => "yield",
498 Python::Attribute => "attribute",
499 Python::Subscript => "subscript",
500 Python::Slice => "slice",
501 Python::Call => "call",
502 Python::TypedParameter => "typed_parameter",
503 Python::Type => "type",
504 Python::SplatType => "splat_type",
505 Python::GenericType => "generic_type",
506 Python::UnionType => "union_type",
507 Python::ConstrainedType => "constrained_type",
508 Python::MemberType => "member_type",
509 Python::KeywordArgument => "keyword_argument",
510 Python::List => "list",
511 Python::Set => "set",
512 Python::Tuple => "tuple",
513 Python::Dictionary => "dictionary",
514 Python::Pair => "pair",
515 Python::ListComprehension => "list_comprehension",
516 Python::DictionaryComprehension => "dictionary_comprehension",
517 Python::SetComprehension => "set_comprehension",
518 Python::GeneratorExpression => "generator_expression",
519 Python::ComprehensionClauses => "_comprehension_clauses",
520 Python::ParenthesizedExpression => "parenthesized_expression",
521 Python::CollectionElements => "_collection_elements",
522 Python::ForInClause => "for_in_clause",
523 Python::IfClause => "if_clause",
524 Python::ConditionalExpression => "conditional_expression",
525 Python::ConcatenatedString => "concatenated_string",
526 Python::String => "string",
527 Python::StringContent => "string_content",
528 Python::Interpolation => "interpolation",
529 Python::FExpression => "_f_expression",
530 Python::NotEscapeSequence => "_not_escape_sequence",
531 Python::FormatSpecifier => "format_specifier",
532 Python::Await => "await",
533 Python::PositionalSeparator => "positional_separator",
534 Python::KeywordSeparator => "keyword_separator",
535 Python::ModuleRepeat1 => "module_repeat1",
536 Python::SimpleStatementsRepeat1 => "_simple_statements_repeat1",
537 Python::ImportPrefixRepeat1 => "import_prefix_repeat1",
538 Python::ImportListRepeat1 => "_import_list_repeat1",
539 Python::PrintStatementRepeat1 => "print_statement_repeat1",
540 Python::AssertStatementRepeat1 => "assert_statement_repeat1",
541 Python::IfStatementRepeat1 => "if_statement_repeat1",
542 Python::MatchStatementRepeat1 => "match_statement_repeat1",
543 Python::MatchBlockRepeat1 => "_match_block_repeat1",
544 Python::CaseClauseRepeat1 => "case_clause_repeat1",
545 Python::TryStatementRepeat1 => "try_statement_repeat1",
546 Python::ExceptClauseRepeat1 => "except_clause_repeat1",
547 Python::WithClauseRepeat1 => "with_clause_repeat1",
548 Python::GlobalStatementRepeat1 => "global_statement_repeat1",
549 Python::TypeParameterRepeat1 => "type_parameter_repeat1",
550 Python::ArgumentListRepeat1 => "argument_list_repeat1",
551 Python::DecoratedDefinitionRepeat1 => "decorated_definition_repeat1",
552 Python::DottedNameRepeat1 => "dotted_name_repeat1",
553 Python::UnionPatternRepeat1 => "union_pattern_repeat1",
554 Python::DictPatternRepeat1 => "dict_pattern_repeat1",
555 Python::ParametersRepeat1 => "_parameters_repeat1",
556 Python::PatternsRepeat1 => "_patterns_repeat1",
557 Python::ComparisonOperatorRepeat1 => "comparison_operator_repeat1",
558 Python::SubscriptRepeat1 => "subscript_repeat1",
559 Python::DictionaryRepeat1 => "dictionary_repeat1",
560 Python::ComprehensionClausesRepeat1 => "_comprehension_clauses_repeat1",
561 Python::CollectionElementsRepeat1 => "_collection_elements_repeat1",
562 Python::ForInClauseRepeat1 => "for_in_clause_repeat1",
563 Python::ConcatenatedStringRepeat1 => "concatenated_string_repeat1",
564 Python::StringRepeat1 => "string_repeat1",
565 Python::StringContentRepeat1 => "string_content_repeat1",
566 Python::FormatSpecifierRepeat1 => "format_specifier_repeat1",
567 Python::AsPatternTarget => "as_pattern_target",
568 Python::FormatExpression => "format_expression",
569 Python::Error => "ERROR",
570 }
571 }
572}
573
574impl From<u16> for Python {
575 #[inline]
576 fn from(x: u16) -> Self {
577 num_traits::FromPrimitive::from_u16(x).unwrap_or(Self::Error)
578 }
579}
580
581impl PartialEq<u16> for Python {
583 #[inline]
584 fn eq(&self, x: &u16) -> bool {
585 *self == Into::<Self>::into(*x)
586 }
587}
588
589impl PartialEq<Python> for u16 {
591 #[inline]
592 fn eq(&self, x: &Python) -> bool {
593 *x == *self
594 }
595}