diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 04a361904b..989f80eb3f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -73,4 +73,3 @@ jobs: 'core/**/*.rs' 'literal/**/*.rs' 'parser/**/*.rs' - 'ast/asdl_rs.py' diff --git a/ast/Python.asdl b/ast/Python.asdl deleted file mode 100644 index f8217eb5fe..0000000000 --- a/ast/Python.asdl +++ /dev/null @@ -1,147 +0,0 @@ --- ASDL's 4 builtin types are: --- identifier, int, string, constant, decorator - -module Python -{ - mod = Module(stmt* body, type_ignore* type_ignores) - | Interactive(stmt* body) - | Expression(expr body) - | FunctionType(expr* argtypes, expr returns) - - stmt = FunctionDef(identifier name, arguments args, - stmt* body, decorator* decorator_list, expr? returns, - string? type_comment) - | AsyncFunctionDef(identifier name, arguments args, - stmt* body, decorator* decorator_list, expr? returns, - string? type_comment) - - | ClassDef(identifier name, - expr* bases, - keyword* keywords, - stmt* body, - decorator* decorator_list) - | Return(expr? value) - - | Delete(expr* targets) - | Assign(expr* targets, expr value, string? type_comment) - | AugAssign(expr target, operator op, expr value) - -- 'simple' indicates that we annotate simple name without parens - | AnnAssign(expr target, expr annotation, expr? value, int simple) - - -- use 'orelse' because else is a keyword in target languages - | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment) - | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment) - | While(expr test, stmt* body, stmt* orelse) - | If(expr test, stmt* body, stmt* orelse) - | With(withitem* items, stmt* body, string? type_comment) - | AsyncWith(withitem* items, stmt* body, string? type_comment) - - | Match(expr subject, match_case* cases) - - | Raise(expr? exc, expr? cause) - | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody) - | TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody) - | Assert(expr test, expr? msg) - - | Import(alias* names) - | ImportFrom(identifier? module, alias* names, int? level) - - | Global(identifier* names) - | Nonlocal(identifier* names) - | Expr(expr value) - | Pass | Break | Continue - - -- col_offset is the byte offset in the utf8 string the parser uses - attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) - - -- BoolOp() can use left & right? - expr = BoolOp(boolop op, expr* values) - | NamedExpr(expr target, expr value) - | BinOp(expr left, operator op, expr right) - | UnaryOp(unaryop op, expr operand) - | Lambda(arguments args, expr body) - | IfExp(expr test, expr body, expr orelse) - | Dict(expr* keys, expr* values) - | Set(expr* elts) - | ListComp(expr elt, comprehension* generators) - | SetComp(expr elt, comprehension* generators) - | DictComp(expr key, expr value, comprehension* generators) - | GeneratorExp(expr elt, comprehension* generators) - -- the grammar constrains where yield expressions can occur - | Await(expr value) - | Yield(expr? value) - | YieldFrom(expr value) - -- need sequences for compare to distinguish between - -- x < 4 < 3 and (x < 4) < 3 - | Compare(expr left, cmpop* ops, expr* comparators) - | Call(expr func, expr* args, keyword* keywords) - | FormattedValue(expr value, int conversion, expr? format_spec) - | JoinedStr(expr* values) - | Constant(constant value, string? kind) - - -- the following expression can appear in assignment context - | Attribute(expr value, identifier attr, expr_context ctx) - | Subscript(expr value, expr slice, expr_context ctx) - | Starred(expr value, expr_context ctx) - | Name(identifier id, expr_context ctx) - | List(expr* elts, expr_context ctx) - | Tuple(expr* elts, expr_context ctx) - - -- can appear only in Subscript - | Slice(expr? lower, expr? upper, expr? step) - - -- col_offset is the byte offset in the utf8 string the parser uses - attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) - - expr_context = Load | Store | Del - - boolop = And | Or - - operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift - | RShift | BitOr | BitXor | BitAnd | FloorDiv - - unaryop = Invert | Not | UAdd | USub - - cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn - - comprehension = (expr target, expr iter, expr* ifs, int is_async) - - excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body) - attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) - - arguments = (arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, - expr* kw_defaults, arg? kwarg, expr* defaults) - - arg = (identifier arg, expr? annotation, string? type_comment) - attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) - - -- keyword arguments supplied to call (NULL identifier for **kwargs) - keyword = (identifier? arg, expr value) - attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) - - -- import name with optional 'as' alias. - alias = (identifier name, identifier? asname) - attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) - - withitem = (expr context_expr, expr? optional_vars) - - match_case = (pattern pattern, expr? guard, stmt* body) - - pattern = MatchValue(expr value) - | MatchSingleton(constant value) - | MatchSequence(pattern* patterns) - | MatchMapping(expr* keys, pattern* patterns, identifier? rest) - | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns) - - | MatchStar(identifier? name) - -- The optional "rest" MatchMapping parameter handles capturing extra mapping keys - - | MatchAs(pattern? pattern, identifier? name) - | MatchOr(pattern* patterns) - - attributes (int lineno, int col_offset, int end_lineno, int end_col_offset) - - type_ignore = TypeIgnore(int lineno, string tag) - - decorator = (expr expression) -} diff --git a/ast/asdl.py b/ast/asdl.py deleted file mode 100644 index 5c111b3e87..0000000000 --- a/ast/asdl.py +++ /dev/null @@ -1,385 +0,0 @@ -#------------------------------------------------------------------------------- -# Parser for ASDL [1] definition files. Reads in an ASDL description and parses -# it into an AST that describes it. -# -# The EBNF we're parsing here: Figure 1 of the paper [1]. Extended to support -# modules and attributes after a product. Words starting with Capital letters -# are terminals. Literal tokens are in "double quotes". Others are -# non-terminals. Id is either TokenId or ConstructorId. -# -# module ::= "module" Id "{" [definitions] "}" -# definitions ::= { TypeId "=" type } -# type ::= product | sum -# product ::= fields ["attributes" fields] -# fields ::= "(" { field, "," } field ")" -# field ::= TypeId ["?" | "*"] [Id] -# sum ::= constructor { "|" constructor } ["attributes" fields] -# constructor ::= ConstructorId [fields] -# -# [1] "The Zephyr Abstract Syntax Description Language" by Wang, et. al. See -# http://asdl.sourceforge.net/ -#------------------------------------------------------------------------------- -from collections import namedtuple -import re - -__all__ = [ - 'builtin_types', 'parse', 'AST', 'Module', 'Type', 'Constructor', - 'Field', 'Sum', 'Product', 'VisitorBase', 'Check', 'check'] - -# The following classes define nodes into which the ASDL description is parsed. -# Note: this is a "meta-AST". ASDL files (such as Python.asdl) describe the AST -# structure used by a programming language. But ASDL files themselves need to be -# parsed. This module parses ASDL files and uses a simple AST to represent them. -# See the EBNF at the top of the file to understand the logical connection -# between the various node types. - -builtin_types = {'identifier', 'string', 'int', 'constant'} - -class AST: - def __repr__(self): - raise NotImplementedError - -class Module(AST): - def __init__(self, name, dfns): - self.name = name - self.dfns = dfns - self.types = {type.name: type.value for type in dfns} - - def __repr__(self): - return 'Module({0.name}, {0.dfns})'.format(self) - -class Type(AST): - def __init__(self, name, value): - self.name = name - self.value = value - - def __repr__(self): - return 'Type({0.name}, {0.value})'.format(self) - -class Constructor(AST): - def __init__(self, name, fields=None): - self.name = name - self.fields = fields or [] - - def __repr__(self): - return 'Constructor({0.name}, {0.fields})'.format(self) - -class Field(AST): - def __init__(self, type, name=None, seq=False, opt=False): - self.type = type - self.name = name - self.seq = seq - self.opt = opt - - def __str__(self): - if self.seq: - extra = "*" - elif self.opt: - extra = "?" - else: - extra = "" - - return "{}{} {}".format(self.type, extra, self.name) - - def __repr__(self): - if self.seq: - extra = ", seq=True" - elif self.opt: - extra = ", opt=True" - else: - extra = "" - if self.name is None: - return 'Field({0.type}{1})'.format(self, extra) - else: - return 'Field({0.type}, {0.name}{1})'.format(self, extra) - -class Sum(AST): - def __init__(self, types, attributes=None): - self.types = types - self.attributes = attributes or [] - - def __repr__(self): - if self.attributes: - return 'Sum({0.types}, {0.attributes})'.format(self) - else: - return 'Sum({0.types})'.format(self) - -class Product(AST): - def __init__(self, fields, attributes=None): - self.fields = fields - self.attributes = attributes or [] - - def __repr__(self): - if self.attributes: - return 'Product({0.fields}, {0.attributes})'.format(self) - else: - return 'Product({0.fields})'.format(self) - -# A generic visitor for the meta-AST that describes ASDL. This can be used by -# emitters. Note that this visitor does not provide a generic visit method, so a -# subclass needs to define visit methods from visitModule to as deep as the -# interesting node. -# We also define a Check visitor that makes sure the parsed ASDL is well-formed. - -class VisitorBase(object): - """Generic tree visitor for ASTs.""" - def __init__(self): - self.cache = {} - - def visit(self, obj, *args): - klass = obj.__class__ - meth = self.cache.get(klass) - if meth is None: - methname = "visit" + klass.__name__ - meth = getattr(self, methname, None) - self.cache[klass] = meth - if meth: - try: - meth(obj, *args) - except Exception as e: - print("Error visiting %r: %s" % (obj, e)) - raise - -class Check(VisitorBase): - """A visitor that checks a parsed ASDL tree for correctness. - - Errors are printed and accumulated. - """ - def __init__(self): - super(Check, self).__init__() - self.cons = {} - self.errors = 0 - self.types = {} - - def visitModule(self, mod): - for dfn in mod.dfns: - self.visit(dfn) - - def visitType(self, type): - self.visit(type.value, str(type.name)) - - def visitSum(self, sum, name): - for t in sum.types: - self.visit(t, name) - - def visitConstructor(self, cons, name): - key = str(cons.name) - conflict = self.cons.get(key) - if conflict is None: - self.cons[key] = name - else: - print('Redefinition of constructor {}'.format(key)) - print('Defined in {} and {}'.format(conflict, name)) - self.errors += 1 - for f in cons.fields: - self.visit(f, key) - - def visitField(self, field, name): - key = str(field.type) - l = self.types.setdefault(key, []) # noqa - l.append(name) - - def visitProduct(self, prod, name): - for f in prod.fields: - self.visit(f, name) - -def check(mod): - """Check the parsed ASDL tree for correctness. - - Return True if success. For failure, the errors are printed out and False - is returned. - """ - v = Check() - v.visit(mod) - - for t in v.types: - if t not in mod.types and t not in builtin_types: - v.errors += 1 - uses = ", ".join(v.types[t]) - print('Undefined type {}, used in {}'.format(t, uses)) - return not v.errors - -# The ASDL parser itself comes next. The only interesting external interface -# here is the top-level parse function. - -def parse(filename): - """Parse ASDL from the given file and return a Module node describing it.""" - with open(filename, encoding="utf-8") as f: - parser = ASDLParser() - return parser.parse(f.read()) - -# Types for describing tokens in an ASDL specification. -class TokenKind: - """TokenKind is provides a scope for enumerated token kinds.""" - (ConstructorId, TypeId, Equals, Comma, Question, Pipe, Asterisk, - LParen, RParen, LBrace, RBrace) = range(11) - - operator_table = { - '=': Equals, ',': Comma, '?': Question, '|': Pipe, '(': LParen, - ')': RParen, '*': Asterisk, '{': LBrace, '}': RBrace} - -Token = namedtuple('Token', 'kind value lineno') - -class ASDLSyntaxError(Exception): - def __init__(self, msg, lineno=None): - self.msg = msg - self.lineno = lineno or '' - - def __str__(self): - return 'Syntax error on line {0.lineno}: {0.msg}'.format(self) - -def tokenize_asdl(buf): - """Tokenize the given buffer. Yield Token objects.""" - for lineno, line in enumerate(buf.splitlines(), 1): - for m in re.finditer(r'\s*(\w+|--.*|.)', line.strip()): - c = m.group(1) - if c[0].isalpha(): - # Some kind of identifier - if c[0].isupper(): - yield Token(TokenKind.ConstructorId, c, lineno) - else: - yield Token(TokenKind.TypeId, c, lineno) - elif c[:2] == '--': - # Comment - break - else: - # Operators - try: - op_kind = TokenKind.operator_table[c] - except KeyError: - raise ASDLSyntaxError('Invalid operator %s' % c, lineno) - yield Token(op_kind, c, lineno) - -class ASDLParser: - """Parser for ASDL files. - - Create, then call the parse method on a buffer containing ASDL. - This is a simple recursive descent parser that uses tokenize_asdl for the - lexing. - """ - def __init__(self): - self._tokenizer = None - self.cur_token = None - - def parse(self, buf): - """Parse the ASDL in the buffer and return an AST with a Module root. - """ - self._tokenizer = tokenize_asdl(buf) - self._advance() - return self._parse_module() - - def _parse_module(self): - if self._at_keyword('module'): - self._advance() - else: - raise ASDLSyntaxError( - 'Expected "module" (found {})'.format(self.cur_token.value), - self.cur_token.lineno) - name = self._match(self._id_kinds) - self._match(TokenKind.LBrace) - defs = self._parse_definitions() - self._match(TokenKind.RBrace) - return Module(name, defs) - - def _parse_definitions(self): - defs = [] - while self.cur_token.kind == TokenKind.TypeId: - typename = self._advance() - self._match(TokenKind.Equals) - type = self._parse_type() - defs.append(Type(typename, type)) - return defs - - def _parse_type(self): - if self.cur_token.kind == TokenKind.LParen: - # If we see a (, it's a product - return self._parse_product() - else: - # Otherwise it's a sum. Look for ConstructorId - sumlist = [Constructor(self._match(TokenKind.ConstructorId), - self._parse_optional_fields())] - while self.cur_token.kind == TokenKind.Pipe: - # More constructors - self._advance() - sumlist.append(Constructor( - self._match(TokenKind.ConstructorId), - self._parse_optional_fields())) - return Sum(sumlist, self._parse_optional_attributes()) - - def _parse_product(self): - return Product(self._parse_fields(), self._parse_optional_attributes()) - - def _parse_fields(self): - fields = [] - self._match(TokenKind.LParen) - while self.cur_token.kind == TokenKind.TypeId: - typename = self._advance() - is_seq, is_opt = self._parse_optional_field_quantifier() - id = (self._advance() if self.cur_token.kind in self._id_kinds - else None) - fields.append(Field(typename, id, seq=is_seq, opt=is_opt)) - if self.cur_token.kind == TokenKind.RParen: - break - elif self.cur_token.kind == TokenKind.Comma: - self._advance() - self._match(TokenKind.RParen) - return fields - - def _parse_optional_fields(self): - if self.cur_token.kind == TokenKind.LParen: - return self._parse_fields() - else: - return None - - def _parse_optional_attributes(self): - if self._at_keyword('attributes'): - self._advance() - return self._parse_fields() - else: - return None - - def _parse_optional_field_quantifier(self): - is_seq, is_opt = False, False - if self.cur_token.kind == TokenKind.Asterisk: - is_seq = True - self._advance() - elif self.cur_token.kind == TokenKind.Question: - is_opt = True - self._advance() - return is_seq, is_opt - - def _advance(self): - """ Return the value of the current token and read the next one into - self.cur_token. - """ - cur_val = None if self.cur_token is None else self.cur_token.value - try: - self.cur_token = next(self._tokenizer) - except StopIteration: - self.cur_token = None - return cur_val - - _id_kinds = (TokenKind.ConstructorId, TokenKind.TypeId) - - def _match(self, kind): - """The 'match' primitive of RD parsers. - - * Verifies that the current token is of the given kind (kind can - be a tuple, in which the kind must match one of its members). - * Returns the value of the current token - * Reads in the next token - """ - if (isinstance(kind, tuple) and self.cur_token.kind in kind or - self.cur_token.kind == kind - ): - value = self.cur_token.value - self._advance() - return value - else: - raise ASDLSyntaxError( - 'Unmatched {} (found {})'.format(kind, self.cur_token.kind), - self.cur_token.lineno) - - def _at_keyword(self, keyword): - return (self.cur_token.kind == TokenKind.TypeId and - self.cur_token.value == keyword) diff --git a/ast/asdl_rs.py b/ast/asdl_rs.py deleted file mode 100755 index 7d5c8bbbe8..0000000000 --- a/ast/asdl_rs.py +++ /dev/null @@ -1,817 +0,0 @@ -# spell-checker:words dfn dfns - -# ! /usr/bin/env python -"""Generate Rust code from an ASDL description.""" - -import re -import sys -import textwrap -from argparse import ArgumentParser -from pathlib import Path -from typing import Any, Dict, Optional - -import asdl - -TABSIZE = 4 -AUTO_GEN_MESSAGE = "// File automatically generated by {}.\n\n" - -BUILTIN_TYPE_NAMES = { - "identifier": "Identifier", - "string": "String", - "int": "Int", - "constant": "Constant", -} -assert BUILTIN_TYPE_NAMES.keys() == asdl.builtin_types - -BUILTIN_INT_NAMES = { - "simple": "bool", - "is_async": "bool", - "conversion": "ConversionFlag", -} - -RENAME_MAP = { - "cmpop": "cmp_op", - "unaryop": "unary_op", - "boolop": "bool_op", - "excepthandler": "except_handler", - "withitem": "with_item", -} - -RUST_KEYWORDS = { - "if", - "while", - "for", - "return", - "match", - "try", - "await", - "yield", - "in", - "mod", - "type", -} - -attributes = [ - asdl.Field("int", "lineno"), - asdl.Field("int", "col_offset"), - asdl.Field("int", "end_lineno"), - asdl.Field("int", "end_col_offset"), -] - -ORIGINAL_NODE_WARNING = "NOTE: This type is different from original Python AST." - -arg_with_default = asdl.Type( - "arg_with_default", - asdl.Product( - [ - asdl.Field("arg", "def"), - asdl.Field( - "expr", "default", opt=True - ), # order is important for cost-free borrow! - ], - ), -) -arg_with_default.doc = f""" -An alternative type of AST `arg`. This is used for each function argument that might have a default value. -Used by `Arguments` original type. - -{ORIGINAL_NODE_WARNING} -""".strip() - -alt_arguments = asdl.Type( - "alt:arguments", - asdl.Product( - [ - asdl.Field("arg_with_default", "posonlyargs", seq=True), - asdl.Field("arg_with_default", "args", seq=True), - asdl.Field("arg", "vararg", opt=True), - asdl.Field("arg_with_default", "kwonlyargs", seq=True), - asdl.Field("arg", "kwarg", opt=True), - ] - ), -) -alt_arguments.doc = f""" -An alternative type of AST `arguments`. This is parser-friendly and human-friendly definition of function arguments. -This form also has advantage to implement pre-order traverse. -`defaults` and `kw_defaults` fields are removed and the default values are placed under each `arg_with_default` typed argument. -`vararg` and `kwarg` are still typed as `arg` because they never can have a default value. - -The matching Python style AST type is [PythonArguments]. While [PythonArguments] has ordered `kwonlyargs` fields by -default existence, [Arguments] has location-ordered kwonlyargs fields. - -{ORIGINAL_NODE_WARNING} -""".strip() - -# Must be used only for rust types, not python types -CUSTOM_TYPES = [ - alt_arguments, - arg_with_default, -] - -CUSTOM_REPLACEMENTS = { - "arguments": alt_arguments, -} -CUSTOM_ATTACHMENTS = [ - arg_with_default, -] - - -def maybe_custom(type): - return CUSTOM_REPLACEMENTS.get(type.name, type) - - -def rust_field_name(name): - name = rust_type_name(name) - return re.sub(r"(?" - - @property - def name(self): - return self.type.name - - @property - def is_type(self): - return isinstance(self.type, asdl.Type) - - @property - def is_product(self): - return self.is_type and isinstance(self.type.value, asdl.Product) - - @property - def is_sum(self): - return self.is_type and isinstance(self.type.value, asdl.Sum) - - @property - def has_expr(self): - return self.is_product and any( - f.type != "identifier" for f in self.type.value.fields - ) - - @property - def is_custom(self): - return self.type.name in [t.name for t in CUSTOM_TYPES] - - @property - def is_custom_replaced(self): - return self.type.name in CUSTOM_REPLACEMENTS - - @property - def custom(self): - if self.type.name in CUSTOM_REPLACEMENTS: - return CUSTOM_REPLACEMENTS[self.type.name] - return self.type - - def no_cfg(self, typeinfo): - if self.is_product: - return self.has_attributes - elif self.enum_name: - return typeinfo[self.enum_name].has_attributes - else: - return self.has_attributes - - @property - def rust_name(self): - return rust_type_name(self.name) - - @property - def full_field_name(self): - name = self.name - if name.startswith("alt:"): - name = name[4:] - if self.enum_name is None: - return name - else: - return f"{self.enum_name}_{rust_field_name(name)}" - - @property - def full_type_name(self): - name = self.name - if name.startswith("alt:"): - name = name[4:] - rust_name = rust_type_name(name) - if self.enum_name is not None: - rust_name = rust_type_name(self.enum_name) + rust_name - if self.is_custom_replaced: - rust_name = "Python" + rust_name - return rust_name - - def determine_user_data(self, type_info, stack): - if self.name in stack: - return None - stack.add(self.name) - for child, child_seq in self.children: - if child in asdl.builtin_types: - continue - child_info = type_info[child] - child_has_user_data = child_info.determine_user_data(type_info, stack) - if self.has_user_data is None and child_has_user_data is True: - self.has_user_data = True - - stack.remove(self.name) - return self.has_user_data - - -class TypeInfoMixin: - type_info: Dict[str, TypeInfo] - - def customized_type_info(self, type_name): - info = self.type_info[type_name] - return self.type_info[info.custom.name] - - def has_user_data(self, typ): - return self.type_info[typ].has_user_data - - -class EmitVisitor(asdl.VisitorBase, TypeInfoMixin): - """Visit that emits lines""" - - def __init__(self, file, type_info): - self.file = file - self.type_info = type_info - self.identifiers = set() - super(EmitVisitor, self).__init__() - - def emit_identifier(self, name): - name = str(name) - if name in self.identifiers: - return - self.emit("_Py_IDENTIFIER(%s);" % name, 0) - self.identifiers.add(name) - - def emit(self, line, depth): - if line: - line = (" " * TABSIZE * depth) + textwrap.dedent(line) - self.file.write(line + "\n") - - -class FindUserDataTypesVisitor(asdl.VisitorBase): - def __init__(self, type_info): - self.type_info = type_info - super().__init__() - - def visitModule(self, mod): - for dfn in mod.dfns + CUSTOM_TYPES: - self.visit(dfn) - stack = set() - for info in self.type_info.values(): - info.determine_user_data(self.type_info, stack) - - def visitType(self, type): - key = type.name - info = self.type_info[key] = TypeInfo(type) - self.visit(type.value, info) - - def visitSum(self, sum, info): - type = info.type - info.is_simple = is_simple(sum) - for cons in sum.types: - self.visit(cons, type, info.is_simple) - - if info.is_simple: - info.has_user_data = False - return - - for t in sum.types: - self.add_children(t.name, t.fields) - - if len(sum.types) > 1: - info.boxed = True - if sum.attributes: - # attributes means located, which has the `range: R` field - info.has_user_data = True - info.has_attributes = True - - for variant in sum.types: - self.add_children(type.name, variant.fields) - - def visitConstructor(self, cons, type, simple): - info = self.type_info[cons.name] = TypeInfo(cons) - info.enum_name = type.name - info.is_simple = simple - - def visitProduct(self, product, info): - type = info.type - if product.attributes: - # attributes means located, which has the `range: R` field - info.has_user_data = True - info.has_attributes = True - if len(product.fields) > 2: - info.boxed = True - self.add_children(type.name, product.fields) - - def add_children(self, name, fields): - self.type_info[name].children.update( - (field.type, field.seq) for field in fields - ) - - -def rust_field(field_name): - if field_name in RUST_KEYWORDS: - field_name += "_" - return field_name - - -class StructVisitor(EmitVisitor): - """Visitor to generate type-defs for AST.""" - - def __init__(self, *args, **kw): - super().__init__(*args, **kw) - - def emit_attrs(self, depth): - self.emit("#[derive(Clone, Debug, PartialEq)]", depth) - - def emit_range(self, has_attributes, depth): - self.emit("pub range: TextRange,", depth + 1) - - def visitModule(self, mod): - self.emit_attrs(0) - self.emit( - """ - #[derive(is_macro::Is)] - pub enum Ast { - """, - 0, - ) - for dfn in mod.dfns: - info = self.customized_type_info(dfn.name) - dfn = info.custom - rust_name = info.full_type_name - if dfn.name == "mod": - # This is exceptional rule to other enums. - # Unlike other enums, this is justified because `Mod` is only used as - # the top node of parsing result and never a child node of other nodes. - # Because it will be very rarely used in very particular applications, - # "ast_" prefix to everywhere seems less useful. - self.emit('#[is(name = "module")]', 1) - self.emit(f"{rust_name}({rust_name}),", 1) - self.emit( - """ - } - impl Node for Ast { - const NAME: &'static str = "AST"; - const FIELD_NAMES: &'static [&'static str] = &[]; - } - """, - 0, - ) - for dfn in mod.dfns: - info = self.customized_type_info(dfn.name) - rust_name = info.full_type_name - self.emit( - f""" - impl From<{rust_name}> for Ast {{ - fn from(node: {rust_name}) -> Self {{ - Ast::{rust_name}(node) - }} - }} - """, - 0, - ) - - for dfn in mod.dfns + CUSTOM_TYPES: - self.visit(dfn) - - def visitType(self, type, depth=0): - if hasattr(type, "doc"): - doc = "/// " + type.doc.replace("\n", "\n/// ") + "\n" - else: - doc = f"/// See also [{type.name}](https://docs.python.org/3/library/ast.html#ast.{type.name})" - self.emit(doc, depth) - self.visit(type.value, type, depth) - - def visitSum(self, sum, type, depth): - if is_simple(sum): - self.simple_sum(sum, type, depth) - else: - self.sum_with_constructors(sum, type, depth) - - self.emit( - f""" - impl Node for {rust_type_name(type.name)} {{ - const NAME: &'static str = "{type.name}"; - const FIELD_NAMES: &'static [&'static str] = &[]; - }} - """, - depth, - ) - - def simple_sum(self, sum, type, depth): - rust_name = rust_type_name(type.name) - self.emit_attrs(depth) - self.emit("#[derive(is_macro::Is, Copy, Hash, Eq)]", depth) - self.emit(f"pub enum {rust_name} {{", depth) - for cons in sum.types: - self.emit(f"{cons.name},", depth + 1) - self.emit("}", depth) - self.emit(f"impl {rust_name} {{", depth) - needs_escape = any(rust_field_name(t.name) in RUST_KEYWORDS for t in sum.types) - if needs_escape: - prefix = rust_field_name(type.name) + "_" - else: - prefix = "" - for cons in sum.types: - self.emit( - f""" - #[inline] - pub const fn {prefix}{rust_field_name(cons.name)}(&self) -> Option<{rust_name}{cons.name}> {{ - match self {{ - {rust_name}::{cons.name} => Some({rust_name}{cons.name}), - _ => None, - }} - }} - """, - depth, - ) - self.emit("}", depth) - self.emit("", depth) - - for cons in sum.types: - self.emit( - f""" - pub struct {rust_name}{cons.name}; - impl From<{rust_name}{cons.name}> for {rust_name} {{ - fn from(_: {rust_name}{cons.name}) -> Self {{ - {rust_name}::{cons.name} - }} - }} - impl From<{rust_name}{cons.name}> for Ast {{ - fn from(_: {rust_name}{cons.name}) -> Self {{ - {rust_name}::{cons.name}.into() - }} - }} - impl Node for {rust_name}{cons.name} {{ - const NAME: &'static str = "{cons.name}"; - const FIELD_NAMES: &'static [&'static str] = &[]; - }} - impl std::cmp::PartialEq<{rust_name}> for {rust_name}{cons.name} {{ - #[inline] - fn eq(&self, other: &{rust_name}) -> bool {{ - matches!(other, {rust_name}::{cons.name}) - }} - }} - """, - 0, - ) - - def sum_with_constructors(self, sum, type, depth): - type_info = self.type_info[type.name] - rust_name = rust_type_name(type.name) - - self.emit_attrs(depth) - self.emit("#[derive(is_macro::Is)]", depth) - self.emit(f"pub enum {rust_name} {{", depth) - needs_escape = any(rust_field_name(t.name) in RUST_KEYWORDS for t in sum.types) - for t in sum.types: - if needs_escape: - self.emit( - f'#[is(name = "{rust_field_name(t.name)}_{rust_name.lower()}")]', - depth + 1, - ) - self.emit(f"{t.name}({rust_name}{t.name}),", depth + 1) - self.emit("}", depth) - self.emit("", depth) - - for t in sum.types: - self.sum_subtype_struct(type_info, t, rust_name, depth) - - def sum_subtype_struct(self, sum_type_info, t, rust_name, depth): - self.emit( - f"""/// See also [{t.name}](https://docs.python.org/3/library/ast.html#ast.{t.name})""", - depth, - ) - self.emit_attrs(depth) - payload_name = f"{rust_name}{t.name}" - self.emit(f"pub struct {payload_name} {{", depth) - self.emit_range(sum_type_info.has_attributes, depth) - for f in t.fields: - self.visit(f, sum_type_info, "pub ", depth + 1, t.name) - - assert sum_type_info.has_attributes == self.type_info[t.name].no_cfg( - self.type_info - ) - - self.emit("}", depth) - field_names = [f'"{f.name}"' for f in t.fields] - self.emit( - f""" - impl Node for {payload_name} {{ - const NAME: &'static str = "{t.name}"; - const FIELD_NAMES: &'static [&'static str] = &[{', '.join(field_names)}]; - }} - impl From<{payload_name}> for {rust_name} {{ - fn from(payload: {payload_name}) -> Self {{ - {rust_name}::{t.name}(payload) - }} - }} - impl From<{payload_name}> for Ast {{ - fn from(payload: {payload_name}) -> Self {{ - {rust_name}::from(payload).into() - }} - }} - """, - depth, - ) - - self.emit("", depth) - - def visitConstructor(self, cons, parent, depth): - if cons.fields: - self.emit(f"{cons.name} {{", depth) - for f in cons.fields: - self.visit(f, parent, "", depth + 1, cons.name) - self.emit("},", depth) - else: - self.emit(f"{cons.name},", depth) - - def visitField(self, field, parent, vis, depth, constructor=None): - try: - field_type = self.customized_type_info(field.type) - typ = field_type.full_type_name - except KeyError: - field_type = None - typ = rust_type_name(field.type) - if field_type and not field_type.is_simple: - typ = f"{typ}" - # don't box if we're doing Vec, but do box if we're doing Vec>> - if ( - field_type - and field_type.boxed - and (not (parent.is_product or field.seq) or field.opt) - ): - typ = f"Box<{typ}>" - if field.opt or ( - # When a dictionary literal contains dictionary unpacking (e.g., `{**d}`), - # the expression to be unpacked goes in `values` with a `None` at the corresponding - # position in `keys`. To handle this, the type of `keys` needs to be `Option>`. - constructor == "Dict" - and field.name == "keys" - ): - typ = f"Option<{typ}>" - if field.seq: - typ = f"Vec<{typ}>" - if typ == "Int": - typ = BUILTIN_INT_NAMES.get(field.name, typ) - name = rust_field(field.name) - - # Use a String, rather than an Identifier, for the `id` field of `Expr::Name`. - # Names already include a range, so there's no need to duplicate the span. - if name == "id": - typ = "String" - - self.emit(f"{vis}{name}: {typ},", depth) - - def visitProduct(self, product, type, depth): - type_info = self.type_info[type.name] - product_name = type_info.full_type_name - self.emit_attrs(depth) - self.emit(f"pub struct {product_name} {{", depth) - self.emit_range(product.attributes, depth + 1) - for f in product.fields: - self.visit(f, type_info, "pub ", depth + 1) - assert bool(product.attributes) == type_info.no_cfg(self.type_info) - self.emit("}", depth) - - field_names = [f'"{f.name}"' for f in product.fields] - self.emit( - f""" - impl Node for {product_name} {{ - const NAME: &'static str = "{type.name}"; - const FIELD_NAMES: &'static [&'static str] = &[ - {', '.join(field_names)} - ]; - }} - """, - depth, - ) - - -class RangedDefVisitor(EmitVisitor): - def visitModule(self, mod): - for dfn in mod.dfns + CUSTOM_TYPES: - self.visit(dfn) - - def visitType(self, type, depth=0): - self.visit(type.value, type.name, depth) - - def visitSum(self, sum, name, depth): - info = self.type_info[name] - - self.emit_type_alias(info) - - if info.is_simple: - for ty in sum.types: - variant_info = self.type_info[ty.name] - self.emit_type_alias(variant_info) - return - - sum_match_arms = "" - - for ty in sum.types: - variant_info = self.type_info[ty.name] - sum_match_arms += ( - f" Self::{variant_info.rust_name}(node) => node.range()," - ) - self.emit_type_alias(variant_info) - self.emit_ranged_impl(variant_info) - - - self.emit( - f""" - impl Ranged for crate::{info.full_type_name} {{ - fn range(&self) -> TextRange {{ - match self {{ - {sum_match_arms} - }} - }} - }} - """.lstrip(), - 0, - ) - - def visitProduct(self, product, name, depth): - info = self.type_info[name] - - self.emit_type_alias(info) - self.emit_ranged_impl(info) - - def emit_type_alias(self, info): - return # disable - self.emit( - f"pub type {info.full_type_name} = crate::generic::{info.full_type_name};", - 0, - ) - self.emit("", 0) - - def emit_ranged_impl(self, info): - self.file.write( - f""" - impl Ranged for crate::generic::{info.full_type_name} {{ - fn range(&self) -> TextRange {{ - self.range - }} - }} - """.strip() - ) - - -def write_ast_def(mod, type_info, f): - f.write("use crate::text_size::TextRange;") - StructVisitor(f, type_info).visit(mod) - - -def write_ranged_def(mod, type_info, f): - RangedDefVisitor(f, type_info).visit(mod) - - -def write_parse_def(mod, type_info, f): - for info in type_info.values(): - if info.enum_name not in ["expr", "stmt"]: - continue - - type_name = rust_type_name(info.enum_name) - cons_name = rust_type_name(info.name) - - f.write( - f""" - impl Parse for ast::{info.full_type_name} {{ - fn lex_starts_at( - source: &str, - offset: TextSize, - ) -> SoftKeywordTransformer> {{ - ast::{type_name}::lex_starts_at(source, offset) - }} - fn parse_tokens( - lxr: impl IntoIterator, - source_path: &str, - ) -> Result {{ - let node = ast::{type_name}::parse_tokens(lxr, source_path)?; - match node {{ - ast::{type_name}::{cons_name}(node) => Ok(node), - node => Err(ParseError {{ - error: ParseErrorType::InvalidToken, - offset: node.range().start(), - source_path: source_path.to_owned(), - }}), - }} - }} - }} - """ - ) - - -def main( - input_filename, - ast_dir, - parser_dir, - dump_module=False, -): - auto_gen_msg = AUTO_GEN_MESSAGE.format("/".join(Path(__file__).parts[-2:])) - mod = asdl.parse(input_filename) - if dump_module: - print("Parsed Module:") - print(mod) - if not asdl.check(mod): - sys.exit(1) - - type_info = {} - FindUserDataTypesVisitor(type_info).visit(mod) - - from functools import partial as p - - for filename, write in [ - ("generic", p(write_ast_def, mod, type_info)), - ("ranged", p(write_ranged_def, mod, type_info)), - ]: - with (ast_dir / f"{filename}.rs").open("w") as f: - f.write(auto_gen_msg) - write(f) - - for filename, write in [ - ("parse", p(write_parse_def, mod, type_info)), - ]: - with (parser_dir / f"{filename}.rs").open("w") as f: - f.write(auto_gen_msg) - write(f) - - print(f"{ast_dir} regenerated.") - - -if __name__ == "__main__": - parser = ArgumentParser() - parser.add_argument("input_file", type=Path) - parser.add_argument("-A", "--ast-dir", type=Path, required=True) - parser.add_argument("-P", "--parser-dir", type=Path, required=True) - parser.add_argument("-d", "--dump-module", action="store_true") - - args = parser.parse_args() - main( - args.input_file, - args.ast_dir, - args.parser_dir, - args.dump_module, - ) diff --git a/ast/src/builtin.rs b/ast/src/builtin.rs index dbca926af2..2a8f3f47ba 100644 --- a/ast/src/builtin.rs +++ b/ast/src/builtin.rs @@ -1,4 +1,4 @@ -//! `builtin_types` in asdl.py and Attributed +//! `builtin_types` in Attributed use rustpython_parser_core::text_size::TextRange; diff --git a/ast/src/gen/generic.rs b/ast/src/gen/generic.rs deleted file mode 100644 index 36f7955271..0000000000 --- a/ast/src/gen/generic.rs +++ /dev/null @@ -1,3137 +0,0 @@ -// File automatically generated by ast/asdl_rs.py. - -use crate::text_size::TextRange; -#[derive(Clone, Debug, PartialEq)] -#[derive(is_macro::Is)] -pub enum Ast { - #[is(name = "module")] - Mod(Mod), - Stmt(Stmt), - Expr(Expr), - ExprContext(ExprContext), - BoolOp(BoolOp), - Operator(Operator), - UnaryOp(UnaryOp), - CmpOp(CmpOp), - Comprehension(Comprehension), - ExceptHandler(ExceptHandler), - Arguments(Arguments), - Arg(Arg), - Keyword(Keyword), - Alias(Alias), - WithItem(WithItem), - MatchCase(MatchCase), - Pattern(Pattern), - TypeIgnore(TypeIgnore), - Decorator(Decorator), -} -impl Node for Ast { - const NAME: &'static str = "AST"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} - -impl From for Ast { - fn from(node: Mod) -> Self { - Ast::Mod(node) - } -} - -impl From for Ast { - fn from(node: Stmt) -> Self { - Ast::Stmt(node) - } -} - -impl From for Ast { - fn from(node: Expr) -> Self { - Ast::Expr(node) - } -} - -impl From for Ast { - fn from(node: ExprContext) -> Self { - Ast::ExprContext(node) - } -} - -impl From for Ast { - fn from(node: BoolOp) -> Self { - Ast::BoolOp(node) - } -} - -impl From for Ast { - fn from(node: Operator) -> Self { - Ast::Operator(node) - } -} - -impl From for Ast { - fn from(node: UnaryOp) -> Self { - Ast::UnaryOp(node) - } -} - -impl From for Ast { - fn from(node: CmpOp) -> Self { - Ast::CmpOp(node) - } -} - -impl From for Ast { - fn from(node: Comprehension) -> Self { - Ast::Comprehension(node) - } -} - -impl From for Ast { - fn from(node: ExceptHandler) -> Self { - Ast::ExceptHandler(node) - } -} - -impl From for Ast { - fn from(node: Arguments) -> Self { - Ast::Arguments(node) - } -} - -impl From for Ast { - fn from(node: Arg) -> Self { - Ast::Arg(node) - } -} - -impl From for Ast { - fn from(node: Keyword) -> Self { - Ast::Keyword(node) - } -} - -impl From for Ast { - fn from(node: Alias) -> Self { - Ast::Alias(node) - } -} - -impl From for Ast { - fn from(node: WithItem) -> Self { - Ast::WithItem(node) - } -} - -impl From for Ast { - fn from(node: MatchCase) -> Self { - Ast::MatchCase(node) - } -} - -impl From for Ast { - fn from(node: Pattern) -> Self { - Ast::Pattern(node) - } -} - -impl From for Ast { - fn from(node: TypeIgnore) -> Self { - Ast::TypeIgnore(node) - } -} - -impl From for Ast { - fn from(node: Decorator) -> Self { - Ast::Decorator(node) - } -} - -/// See also [mod](https://docs.python.org/3/library/ast.html#ast.mod) -#[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum Mod { - Module(ModModule), - Interactive(ModInteractive), - Expression(ModExpression), - FunctionType(ModFunctionType), -} - -/// See also [Module](https://docs.python.org/3/library/ast.html#ast.Module) -#[derive(Clone, Debug, PartialEq)] -pub struct ModModule { - pub range: TextRange, - pub body: Vec, - pub type_ignores: Vec, -} - -impl Node for ModModule { - const NAME: &'static str = "Module"; - const FIELD_NAMES: &'static [&'static str] = &["body", "type_ignores"]; -} -impl From for Mod { - fn from(payload: ModModule) -> Self { - Mod::Module(payload) - } -} -impl From for Ast { - fn from(payload: ModModule) -> Self { - Mod::from(payload).into() - } -} - -/// See also [Interactive](https://docs.python.org/3/library/ast.html#ast.Interactive) -#[derive(Clone, Debug, PartialEq)] -pub struct ModInteractive { - pub range: TextRange, - pub body: Vec, -} - -impl Node for ModInteractive { - const NAME: &'static str = "Interactive"; - const FIELD_NAMES: &'static [&'static str] = &["body"]; -} -impl From for Mod { - fn from(payload: ModInteractive) -> Self { - Mod::Interactive(payload) - } -} -impl From for Ast { - fn from(payload: ModInteractive) -> Self { - Mod::from(payload).into() - } -} - -/// See also [Expression](https://docs.python.org/3/library/ast.html#ast.Expression) -#[derive(Clone, Debug, PartialEq)] -pub struct ModExpression { - pub range: TextRange, - pub body: Box, -} - -impl Node for ModExpression { - const NAME: &'static str = "Expression"; - const FIELD_NAMES: &'static [&'static str] = &["body"]; -} -impl From for Mod { - fn from(payload: ModExpression) -> Self { - Mod::Expression(payload) - } -} -impl From for Ast { - fn from(payload: ModExpression) -> Self { - Mod::from(payload).into() - } -} - -/// See also [FunctionType](https://docs.python.org/3/library/ast.html#ast.FunctionType) -#[derive(Clone, Debug, PartialEq)] -pub struct ModFunctionType { - pub range: TextRange, - pub argtypes: Vec, - pub returns: Box, -} - -impl Node for ModFunctionType { - const NAME: &'static str = "FunctionType"; - const FIELD_NAMES: &'static [&'static str] = &["argtypes", "returns"]; -} -impl From for Mod { - fn from(payload: ModFunctionType) -> Self { - Mod::FunctionType(payload) - } -} -impl From for Ast { - fn from(payload: ModFunctionType) -> Self { - Mod::from(payload).into() - } -} - -impl Node for Mod { - const NAME: &'static str = "mod"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} - -/// See also [stmt](https://docs.python.org/3/library/ast.html#ast.stmt) -#[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum Stmt { - #[is(name = "function_def_stmt")] - FunctionDef(StmtFunctionDef), - #[is(name = "async_function_def_stmt")] - AsyncFunctionDef(StmtAsyncFunctionDef), - #[is(name = "class_def_stmt")] - ClassDef(StmtClassDef), - #[is(name = "return_stmt")] - Return(StmtReturn), - #[is(name = "delete_stmt")] - Delete(StmtDelete), - #[is(name = "assign_stmt")] - Assign(StmtAssign), - #[is(name = "aug_assign_stmt")] - AugAssign(StmtAugAssign), - #[is(name = "ann_assign_stmt")] - AnnAssign(StmtAnnAssign), - #[is(name = "for_stmt")] - For(StmtFor), - #[is(name = "async_for_stmt")] - AsyncFor(StmtAsyncFor), - #[is(name = "while_stmt")] - While(StmtWhile), - #[is(name = "if_stmt")] - If(StmtIf), - #[is(name = "with_stmt")] - With(StmtWith), - #[is(name = "async_with_stmt")] - AsyncWith(StmtAsyncWith), - #[is(name = "match_stmt")] - Match(StmtMatch), - #[is(name = "raise_stmt")] - Raise(StmtRaise), - #[is(name = "try_stmt")] - Try(StmtTry), - #[is(name = "try_star_stmt")] - TryStar(StmtTryStar), - #[is(name = "assert_stmt")] - Assert(StmtAssert), - #[is(name = "import_stmt")] - Import(StmtImport), - #[is(name = "import_from_stmt")] - ImportFrom(StmtImportFrom), - #[is(name = "global_stmt")] - Global(StmtGlobal), - #[is(name = "nonlocal_stmt")] - Nonlocal(StmtNonlocal), - #[is(name = "expr_stmt")] - Expr(StmtExpr), - #[is(name = "pass_stmt")] - Pass(StmtPass), - #[is(name = "break_stmt")] - Break(StmtBreak), - #[is(name = "continue_stmt")] - Continue(StmtContinue), -} - -/// See also [FunctionDef](https://docs.python.org/3/library/ast.html#ast.FunctionDef) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtFunctionDef { - pub range: TextRange, - pub name: Identifier, - pub args: Box, - pub body: Vec, - pub decorator_list: Vec, - pub returns: Option>, - pub type_comment: Option, -} - -impl Node for StmtFunctionDef { - const NAME: &'static str = "FunctionDef"; - const FIELD_NAMES: &'static [&'static str] = &[ - "name", - "args", - "body", - "decorator_list", - "returns", - "type_comment", - ]; -} -impl From for Stmt { - fn from(payload: StmtFunctionDef) -> Self { - Stmt::FunctionDef(payload) - } -} -impl From for Ast { - fn from(payload: StmtFunctionDef) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [AsyncFunctionDef](https://docs.python.org/3/library/ast.html#ast.AsyncFunctionDef) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtAsyncFunctionDef { - pub range: TextRange, - pub name: Identifier, - pub args: Box, - pub body: Vec, - pub decorator_list: Vec, - pub returns: Option>, - pub type_comment: Option, -} - -impl Node for StmtAsyncFunctionDef { - const NAME: &'static str = "AsyncFunctionDef"; - const FIELD_NAMES: &'static [&'static str] = &[ - "name", - "args", - "body", - "decorator_list", - "returns", - "type_comment", - ]; -} -impl From for Stmt { - fn from(payload: StmtAsyncFunctionDef) -> Self { - Stmt::AsyncFunctionDef(payload) - } -} -impl From for Ast { - fn from(payload: StmtAsyncFunctionDef) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [ClassDef](https://docs.python.org/3/library/ast.html#ast.ClassDef) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtClassDef { - pub range: TextRange, - pub name: Identifier, - pub bases: Vec, - pub keywords: Vec, - pub body: Vec, - pub decorator_list: Vec, -} - -impl Node for StmtClassDef { - const NAME: &'static str = "ClassDef"; - const FIELD_NAMES: &'static [&'static str] = - &["name", "bases", "keywords", "body", "decorator_list"]; -} -impl From for Stmt { - fn from(payload: StmtClassDef) -> Self { - Stmt::ClassDef(payload) - } -} -impl From for Ast { - fn from(payload: StmtClassDef) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Return](https://docs.python.org/3/library/ast.html#ast.Return) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtReturn { - pub range: TextRange, - pub value: Option>, -} - -impl Node for StmtReturn { - const NAME: &'static str = "Return"; - const FIELD_NAMES: &'static [&'static str] = &["value"]; -} -impl From for Stmt { - fn from(payload: StmtReturn) -> Self { - Stmt::Return(payload) - } -} -impl From for Ast { - fn from(payload: StmtReturn) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Delete](https://docs.python.org/3/library/ast.html#ast.Delete) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtDelete { - pub range: TextRange, - pub targets: Vec, -} - -impl Node for StmtDelete { - const NAME: &'static str = "Delete"; - const FIELD_NAMES: &'static [&'static str] = &["targets"]; -} -impl From for Stmt { - fn from(payload: StmtDelete) -> Self { - Stmt::Delete(payload) - } -} -impl From for Ast { - fn from(payload: StmtDelete) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Assign](https://docs.python.org/3/library/ast.html#ast.Assign) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtAssign { - pub range: TextRange, - pub targets: Vec, - pub value: Box, - pub type_comment: Option, -} - -impl Node for StmtAssign { - const NAME: &'static str = "Assign"; - const FIELD_NAMES: &'static [&'static str] = &["targets", "value", "type_comment"]; -} -impl From for Stmt { - fn from(payload: StmtAssign) -> Self { - Stmt::Assign(payload) - } -} -impl From for Ast { - fn from(payload: StmtAssign) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [AugAssign](https://docs.python.org/3/library/ast.html#ast.AugAssign) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtAugAssign { - pub range: TextRange, - pub target: Box, - pub op: Operator, - pub value: Box, -} - -impl Node for StmtAugAssign { - const NAME: &'static str = "AugAssign"; - const FIELD_NAMES: &'static [&'static str] = &["target", "op", "value"]; -} -impl From for Stmt { - fn from(payload: StmtAugAssign) -> Self { - Stmt::AugAssign(payload) - } -} -impl From for Ast { - fn from(payload: StmtAugAssign) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [AnnAssign](https://docs.python.org/3/library/ast.html#ast.AnnAssign) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtAnnAssign { - pub range: TextRange, - pub target: Box, - pub annotation: Box, - pub value: Option>, - pub simple: bool, -} - -impl Node for StmtAnnAssign { - const NAME: &'static str = "AnnAssign"; - const FIELD_NAMES: &'static [&'static str] = &["target", "annotation", "value", "simple"]; -} -impl From for Stmt { - fn from(payload: StmtAnnAssign) -> Self { - Stmt::AnnAssign(payload) - } -} -impl From for Ast { - fn from(payload: StmtAnnAssign) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [For](https://docs.python.org/3/library/ast.html#ast.For) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtFor { - pub range: TextRange, - pub target: Box, - pub iter: Box, - pub body: Vec, - pub orelse: Vec, - pub type_comment: Option, -} - -impl Node for StmtFor { - const NAME: &'static str = "For"; - const FIELD_NAMES: &'static [&'static str] = - &["target", "iter", "body", "orelse", "type_comment"]; -} -impl From for Stmt { - fn from(payload: StmtFor) -> Self { - Stmt::For(payload) - } -} -impl From for Ast { - fn from(payload: StmtFor) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [AsyncFor](https://docs.python.org/3/library/ast.html#ast.AsyncFor) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtAsyncFor { - pub range: TextRange, - pub target: Box, - pub iter: Box, - pub body: Vec, - pub orelse: Vec, - pub type_comment: Option, -} - -impl Node for StmtAsyncFor { - const NAME: &'static str = "AsyncFor"; - const FIELD_NAMES: &'static [&'static str] = - &["target", "iter", "body", "orelse", "type_comment"]; -} -impl From for Stmt { - fn from(payload: StmtAsyncFor) -> Self { - Stmt::AsyncFor(payload) - } -} -impl From for Ast { - fn from(payload: StmtAsyncFor) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [While](https://docs.python.org/3/library/ast.html#ast.While) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtWhile { - pub range: TextRange, - pub test: Box, - pub body: Vec, - pub orelse: Vec, -} - -impl Node for StmtWhile { - const NAME: &'static str = "While"; - const FIELD_NAMES: &'static [&'static str] = &["test", "body", "orelse"]; -} -impl From for Stmt { - fn from(payload: StmtWhile) -> Self { - Stmt::While(payload) - } -} -impl From for Ast { - fn from(payload: StmtWhile) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [If](https://docs.python.org/3/library/ast.html#ast.If) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtIf { - pub range: TextRange, - pub test: Box, - pub body: Vec, - pub orelse: Vec, -} - -impl Node for StmtIf { - const NAME: &'static str = "If"; - const FIELD_NAMES: &'static [&'static str] = &["test", "body", "orelse"]; -} -impl From for Stmt { - fn from(payload: StmtIf) -> Self { - Stmt::If(payload) - } -} -impl From for Ast { - fn from(payload: StmtIf) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [With](https://docs.python.org/3/library/ast.html#ast.With) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtWith { - pub range: TextRange, - pub items: Vec, - pub body: Vec, - pub type_comment: Option, -} - -impl Node for StmtWith { - const NAME: &'static str = "With"; - const FIELD_NAMES: &'static [&'static str] = &["items", "body", "type_comment"]; -} -impl From for Stmt { - fn from(payload: StmtWith) -> Self { - Stmt::With(payload) - } -} -impl From for Ast { - fn from(payload: StmtWith) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [AsyncWith](https://docs.python.org/3/library/ast.html#ast.AsyncWith) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtAsyncWith { - pub range: TextRange, - pub items: Vec, - pub body: Vec, - pub type_comment: Option, -} - -impl Node for StmtAsyncWith { - const NAME: &'static str = "AsyncWith"; - const FIELD_NAMES: &'static [&'static str] = &["items", "body", "type_comment"]; -} -impl From for Stmt { - fn from(payload: StmtAsyncWith) -> Self { - Stmt::AsyncWith(payload) - } -} -impl From for Ast { - fn from(payload: StmtAsyncWith) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Match](https://docs.python.org/3/library/ast.html#ast.Match) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtMatch { - pub range: TextRange, - pub subject: Box, - pub cases: Vec, -} - -impl Node for StmtMatch { - const NAME: &'static str = "Match"; - const FIELD_NAMES: &'static [&'static str] = &["subject", "cases"]; -} -impl From for Stmt { - fn from(payload: StmtMatch) -> Self { - Stmt::Match(payload) - } -} -impl From for Ast { - fn from(payload: StmtMatch) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Raise](https://docs.python.org/3/library/ast.html#ast.Raise) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtRaise { - pub range: TextRange, - pub exc: Option>, - pub cause: Option>, -} - -impl Node for StmtRaise { - const NAME: &'static str = "Raise"; - const FIELD_NAMES: &'static [&'static str] = &["exc", "cause"]; -} -impl From for Stmt { - fn from(payload: StmtRaise) -> Self { - Stmt::Raise(payload) - } -} -impl From for Ast { - fn from(payload: StmtRaise) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Try](https://docs.python.org/3/library/ast.html#ast.Try) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtTry { - pub range: TextRange, - pub body: Vec, - pub handlers: Vec, - pub orelse: Vec, - pub finalbody: Vec, -} - -impl Node for StmtTry { - const NAME: &'static str = "Try"; - const FIELD_NAMES: &'static [&'static str] = &["body", "handlers", "orelse", "finalbody"]; -} -impl From for Stmt { - fn from(payload: StmtTry) -> Self { - Stmt::Try(payload) - } -} -impl From for Ast { - fn from(payload: StmtTry) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [TryStar](https://docs.python.org/3/library/ast.html#ast.TryStar) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtTryStar { - pub range: TextRange, - pub body: Vec, - pub handlers: Vec, - pub orelse: Vec, - pub finalbody: Vec, -} - -impl Node for StmtTryStar { - const NAME: &'static str = "TryStar"; - const FIELD_NAMES: &'static [&'static str] = &["body", "handlers", "orelse", "finalbody"]; -} -impl From for Stmt { - fn from(payload: StmtTryStar) -> Self { - Stmt::TryStar(payload) - } -} -impl From for Ast { - fn from(payload: StmtTryStar) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Assert](https://docs.python.org/3/library/ast.html#ast.Assert) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtAssert { - pub range: TextRange, - pub test: Box, - pub msg: Option>, -} - -impl Node for StmtAssert { - const NAME: &'static str = "Assert"; - const FIELD_NAMES: &'static [&'static str] = &["test", "msg"]; -} -impl From for Stmt { - fn from(payload: StmtAssert) -> Self { - Stmt::Assert(payload) - } -} -impl From for Ast { - fn from(payload: StmtAssert) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Import](https://docs.python.org/3/library/ast.html#ast.Import) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtImport { - pub range: TextRange, - pub names: Vec, -} - -impl Node for StmtImport { - const NAME: &'static str = "Import"; - const FIELD_NAMES: &'static [&'static str] = &["names"]; -} -impl From for Stmt { - fn from(payload: StmtImport) -> Self { - Stmt::Import(payload) - } -} -impl From for Ast { - fn from(payload: StmtImport) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [ImportFrom](https://docs.python.org/3/library/ast.html#ast.ImportFrom) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtImportFrom { - pub range: TextRange, - pub module: Option, - pub names: Vec, - pub level: Option, -} - -impl Node for StmtImportFrom { - const NAME: &'static str = "ImportFrom"; - const FIELD_NAMES: &'static [&'static str] = &["module", "names", "level"]; -} -impl From for Stmt { - fn from(payload: StmtImportFrom) -> Self { - Stmt::ImportFrom(payload) - } -} -impl From for Ast { - fn from(payload: StmtImportFrom) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Global](https://docs.python.org/3/library/ast.html#ast.Global) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtGlobal { - pub range: TextRange, - pub names: Vec, -} - -impl Node for StmtGlobal { - const NAME: &'static str = "Global"; - const FIELD_NAMES: &'static [&'static str] = &["names"]; -} -impl From for Stmt { - fn from(payload: StmtGlobal) -> Self { - Stmt::Global(payload) - } -} -impl From for Ast { - fn from(payload: StmtGlobal) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Nonlocal](https://docs.python.org/3/library/ast.html#ast.Nonlocal) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtNonlocal { - pub range: TextRange, - pub names: Vec, -} - -impl Node for StmtNonlocal { - const NAME: &'static str = "Nonlocal"; - const FIELD_NAMES: &'static [&'static str] = &["names"]; -} -impl From for Stmt { - fn from(payload: StmtNonlocal) -> Self { - Stmt::Nonlocal(payload) - } -} -impl From for Ast { - fn from(payload: StmtNonlocal) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Expr](https://docs.python.org/3/library/ast.html#ast.Expr) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtExpr { - pub range: TextRange, - pub value: Box, -} - -impl Node for StmtExpr { - const NAME: &'static str = "Expr"; - const FIELD_NAMES: &'static [&'static str] = &["value"]; -} -impl From for Stmt { - fn from(payload: StmtExpr) -> Self { - Stmt::Expr(payload) - } -} -impl From for Ast { - fn from(payload: StmtExpr) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Pass](https://docs.python.org/3/library/ast.html#ast.Pass) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtPass { - pub range: TextRange, -} - -impl Node for StmtPass { - const NAME: &'static str = "Pass"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl From for Stmt { - fn from(payload: StmtPass) -> Self { - Stmt::Pass(payload) - } -} -impl From for Ast { - fn from(payload: StmtPass) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Break](https://docs.python.org/3/library/ast.html#ast.Break) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtBreak { - pub range: TextRange, -} - -impl Node for StmtBreak { - const NAME: &'static str = "Break"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl From for Stmt { - fn from(payload: StmtBreak) -> Self { - Stmt::Break(payload) - } -} -impl From for Ast { - fn from(payload: StmtBreak) -> Self { - Stmt::from(payload).into() - } -} - -/// See also [Continue](https://docs.python.org/3/library/ast.html#ast.Continue) -#[derive(Clone, Debug, PartialEq)] -pub struct StmtContinue { - pub range: TextRange, -} - -impl Node for StmtContinue { - const NAME: &'static str = "Continue"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl From for Stmt { - fn from(payload: StmtContinue) -> Self { - Stmt::Continue(payload) - } -} -impl From for Ast { - fn from(payload: StmtContinue) -> Self { - Stmt::from(payload).into() - } -} - -impl Node for Stmt { - const NAME: &'static str = "stmt"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} - -/// See also [expr](https://docs.python.org/3/library/ast.html#ast.expr) -#[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum Expr { - #[is(name = "bool_op_expr")] - BoolOp(ExprBoolOp), - #[is(name = "named_expr_expr")] - NamedExpr(ExprNamedExpr), - #[is(name = "bin_op_expr")] - BinOp(ExprBinOp), - #[is(name = "unary_op_expr")] - UnaryOp(ExprUnaryOp), - #[is(name = "lambda_expr")] - Lambda(ExprLambda), - #[is(name = "if_exp_expr")] - IfExp(ExprIfExp), - #[is(name = "dict_expr")] - Dict(ExprDict), - #[is(name = "set_expr")] - Set(ExprSet), - #[is(name = "list_comp_expr")] - ListComp(ExprListComp), - #[is(name = "set_comp_expr")] - SetComp(ExprSetComp), - #[is(name = "dict_comp_expr")] - DictComp(ExprDictComp), - #[is(name = "generator_exp_expr")] - GeneratorExp(ExprGeneratorExp), - #[is(name = "await_expr")] - Await(ExprAwait), - #[is(name = "yield_expr")] - Yield(ExprYield), - #[is(name = "yield_from_expr")] - YieldFrom(ExprYieldFrom), - #[is(name = "compare_expr")] - Compare(ExprCompare), - #[is(name = "call_expr")] - Call(ExprCall), - #[is(name = "formatted_value_expr")] - FormattedValue(ExprFormattedValue), - #[is(name = "joined_str_expr")] - JoinedStr(ExprJoinedStr), - #[is(name = "constant_expr")] - Constant(ExprConstant), - #[is(name = "attribute_expr")] - Attribute(ExprAttribute), - #[is(name = "subscript_expr")] - Subscript(ExprSubscript), - #[is(name = "starred_expr")] - Starred(ExprStarred), - #[is(name = "name_expr")] - Name(ExprName), - #[is(name = "list_expr")] - List(ExprList), - #[is(name = "tuple_expr")] - Tuple(ExprTuple), - #[is(name = "slice_expr")] - Slice(ExprSlice), -} - -/// See also [BoolOp](https://docs.python.org/3/library/ast.html#ast.BoolOp) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprBoolOp { - pub range: TextRange, - pub op: BoolOp, - pub values: Vec, -} - -impl Node for ExprBoolOp { - const NAME: &'static str = "BoolOp"; - const FIELD_NAMES: &'static [&'static str] = &["op", "values"]; -} -impl From for Expr { - fn from(payload: ExprBoolOp) -> Self { - Expr::BoolOp(payload) - } -} -impl From for Ast { - fn from(payload: ExprBoolOp) -> Self { - Expr::from(payload).into() - } -} - -/// See also [NamedExpr](https://docs.python.org/3/library/ast.html#ast.NamedExpr) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprNamedExpr { - pub range: TextRange, - pub target: Box, - pub value: Box, -} - -impl Node for ExprNamedExpr { - const NAME: &'static str = "NamedExpr"; - const FIELD_NAMES: &'static [&'static str] = &["target", "value"]; -} -impl From for Expr { - fn from(payload: ExprNamedExpr) -> Self { - Expr::NamedExpr(payload) - } -} -impl From for Ast { - fn from(payload: ExprNamedExpr) -> Self { - Expr::from(payload).into() - } -} - -/// See also [BinOp](https://docs.python.org/3/library/ast.html#ast.BinOp) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprBinOp { - pub range: TextRange, - pub left: Box, - pub op: Operator, - pub right: Box, -} - -impl Node for ExprBinOp { - const NAME: &'static str = "BinOp"; - const FIELD_NAMES: &'static [&'static str] = &["left", "op", "right"]; -} -impl From for Expr { - fn from(payload: ExprBinOp) -> Self { - Expr::BinOp(payload) - } -} -impl From for Ast { - fn from(payload: ExprBinOp) -> Self { - Expr::from(payload).into() - } -} - -/// See also [UnaryOp](https://docs.python.org/3/library/ast.html#ast.UnaryOp) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprUnaryOp { - pub range: TextRange, - pub op: UnaryOp, - pub operand: Box, -} - -impl Node for ExprUnaryOp { - const NAME: &'static str = "UnaryOp"; - const FIELD_NAMES: &'static [&'static str] = &["op", "operand"]; -} -impl From for Expr { - fn from(payload: ExprUnaryOp) -> Self { - Expr::UnaryOp(payload) - } -} -impl From for Ast { - fn from(payload: ExprUnaryOp) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Lambda](https://docs.python.org/3/library/ast.html#ast.Lambda) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprLambda { - pub range: TextRange, - pub args: Box, - pub body: Box, -} - -impl Node for ExprLambda { - const NAME: &'static str = "Lambda"; - const FIELD_NAMES: &'static [&'static str] = &["args", "body"]; -} -impl From for Expr { - fn from(payload: ExprLambda) -> Self { - Expr::Lambda(payload) - } -} -impl From for Ast { - fn from(payload: ExprLambda) -> Self { - Expr::from(payload).into() - } -} - -/// See also [IfExp](https://docs.python.org/3/library/ast.html#ast.IfExp) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprIfExp { - pub range: TextRange, - pub test: Box, - pub body: Box, - pub orelse: Box, -} - -impl Node for ExprIfExp { - const NAME: &'static str = "IfExp"; - const FIELD_NAMES: &'static [&'static str] = &["test", "body", "orelse"]; -} -impl From for Expr { - fn from(payload: ExprIfExp) -> Self { - Expr::IfExp(payload) - } -} -impl From for Ast { - fn from(payload: ExprIfExp) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Dict](https://docs.python.org/3/library/ast.html#ast.Dict) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprDict { - pub range: TextRange, - pub keys: Vec>, - pub values: Vec, -} - -impl Node for ExprDict { - const NAME: &'static str = "Dict"; - const FIELD_NAMES: &'static [&'static str] = &["keys", "values"]; -} -impl From for Expr { - fn from(payload: ExprDict) -> Self { - Expr::Dict(payload) - } -} -impl From for Ast { - fn from(payload: ExprDict) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Set](https://docs.python.org/3/library/ast.html#ast.Set) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprSet { - pub range: TextRange, - pub elts: Vec, -} - -impl Node for ExprSet { - const NAME: &'static str = "Set"; - const FIELD_NAMES: &'static [&'static str] = &["elts"]; -} -impl From for Expr { - fn from(payload: ExprSet) -> Self { - Expr::Set(payload) - } -} -impl From for Ast { - fn from(payload: ExprSet) -> Self { - Expr::from(payload).into() - } -} - -/// See also [ListComp](https://docs.python.org/3/library/ast.html#ast.ListComp) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprListComp { - pub range: TextRange, - pub elt: Box, - pub generators: Vec, -} - -impl Node for ExprListComp { - const NAME: &'static str = "ListComp"; - const FIELD_NAMES: &'static [&'static str] = &["elt", "generators"]; -} -impl From for Expr { - fn from(payload: ExprListComp) -> Self { - Expr::ListComp(payload) - } -} -impl From for Ast { - fn from(payload: ExprListComp) -> Self { - Expr::from(payload).into() - } -} - -/// See also [SetComp](https://docs.python.org/3/library/ast.html#ast.SetComp) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprSetComp { - pub range: TextRange, - pub elt: Box, - pub generators: Vec, -} - -impl Node for ExprSetComp { - const NAME: &'static str = "SetComp"; - const FIELD_NAMES: &'static [&'static str] = &["elt", "generators"]; -} -impl From for Expr { - fn from(payload: ExprSetComp) -> Self { - Expr::SetComp(payload) - } -} -impl From for Ast { - fn from(payload: ExprSetComp) -> Self { - Expr::from(payload).into() - } -} - -/// See also [DictComp](https://docs.python.org/3/library/ast.html#ast.DictComp) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprDictComp { - pub range: TextRange, - pub key: Box, - pub value: Box, - pub generators: Vec, -} - -impl Node for ExprDictComp { - const NAME: &'static str = "DictComp"; - const FIELD_NAMES: &'static [&'static str] = &["key", "value", "generators"]; -} -impl From for Expr { - fn from(payload: ExprDictComp) -> Self { - Expr::DictComp(payload) - } -} -impl From for Ast { - fn from(payload: ExprDictComp) -> Self { - Expr::from(payload).into() - } -} - -/// See also [GeneratorExp](https://docs.python.org/3/library/ast.html#ast.GeneratorExp) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprGeneratorExp { - pub range: TextRange, - pub elt: Box, - pub generators: Vec, -} - -impl Node for ExprGeneratorExp { - const NAME: &'static str = "GeneratorExp"; - const FIELD_NAMES: &'static [&'static str] = &["elt", "generators"]; -} -impl From for Expr { - fn from(payload: ExprGeneratorExp) -> Self { - Expr::GeneratorExp(payload) - } -} -impl From for Ast { - fn from(payload: ExprGeneratorExp) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Await](https://docs.python.org/3/library/ast.html#ast.Await) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprAwait { - pub range: TextRange, - pub value: Box, -} - -impl Node for ExprAwait { - const NAME: &'static str = "Await"; - const FIELD_NAMES: &'static [&'static str] = &["value"]; -} -impl From for Expr { - fn from(payload: ExprAwait) -> Self { - Expr::Await(payload) - } -} -impl From for Ast { - fn from(payload: ExprAwait) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Yield](https://docs.python.org/3/library/ast.html#ast.Yield) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprYield { - pub range: TextRange, - pub value: Option>, -} - -impl Node for ExprYield { - const NAME: &'static str = "Yield"; - const FIELD_NAMES: &'static [&'static str] = &["value"]; -} -impl From for Expr { - fn from(payload: ExprYield) -> Self { - Expr::Yield(payload) - } -} -impl From for Ast { - fn from(payload: ExprYield) -> Self { - Expr::from(payload).into() - } -} - -/// See also [YieldFrom](https://docs.python.org/3/library/ast.html#ast.YieldFrom) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprYieldFrom { - pub range: TextRange, - pub value: Box, -} - -impl Node for ExprYieldFrom { - const NAME: &'static str = "YieldFrom"; - const FIELD_NAMES: &'static [&'static str] = &["value"]; -} -impl From for Expr { - fn from(payload: ExprYieldFrom) -> Self { - Expr::YieldFrom(payload) - } -} -impl From for Ast { - fn from(payload: ExprYieldFrom) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Compare](https://docs.python.org/3/library/ast.html#ast.Compare) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprCompare { - pub range: TextRange, - pub left: Box, - pub ops: Vec, - pub comparators: Vec, -} - -impl Node for ExprCompare { - const NAME: &'static str = "Compare"; - const FIELD_NAMES: &'static [&'static str] = &["left", "ops", "comparators"]; -} -impl From for Expr { - fn from(payload: ExprCompare) -> Self { - Expr::Compare(payload) - } -} -impl From for Ast { - fn from(payload: ExprCompare) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Call](https://docs.python.org/3/library/ast.html#ast.Call) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprCall { - pub range: TextRange, - pub func: Box, - pub args: Vec, - pub keywords: Vec, -} - -impl Node for ExprCall { - const NAME: &'static str = "Call"; - const FIELD_NAMES: &'static [&'static str] = &["func", "args", "keywords"]; -} -impl From for Expr { - fn from(payload: ExprCall) -> Self { - Expr::Call(payload) - } -} -impl From for Ast { - fn from(payload: ExprCall) -> Self { - Expr::from(payload).into() - } -} - -/// See also [FormattedValue](https://docs.python.org/3/library/ast.html#ast.FormattedValue) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprFormattedValue { - pub range: TextRange, - pub value: Box, - pub conversion: ConversionFlag, - pub format_spec: Option>, -} - -impl Node for ExprFormattedValue { - const NAME: &'static str = "FormattedValue"; - const FIELD_NAMES: &'static [&'static str] = &["value", "conversion", "format_spec"]; -} -impl From for Expr { - fn from(payload: ExprFormattedValue) -> Self { - Expr::FormattedValue(payload) - } -} -impl From for Ast { - fn from(payload: ExprFormattedValue) -> Self { - Expr::from(payload).into() - } -} - -/// See also [JoinedStr](https://docs.python.org/3/library/ast.html#ast.JoinedStr) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprJoinedStr { - pub range: TextRange, - pub values: Vec, -} - -impl Node for ExprJoinedStr { - const NAME: &'static str = "JoinedStr"; - const FIELD_NAMES: &'static [&'static str] = &["values"]; -} -impl From for Expr { - fn from(payload: ExprJoinedStr) -> Self { - Expr::JoinedStr(payload) - } -} -impl From for Ast { - fn from(payload: ExprJoinedStr) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Constant](https://docs.python.org/3/library/ast.html#ast.Constant) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprConstant { - pub range: TextRange, - pub value: Constant, - pub kind: Option, -} - -impl Node for ExprConstant { - const NAME: &'static str = "Constant"; - const FIELD_NAMES: &'static [&'static str] = &["value", "kind"]; -} -impl From for Expr { - fn from(payload: ExprConstant) -> Self { - Expr::Constant(payload) - } -} -impl From for Ast { - fn from(payload: ExprConstant) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Attribute](https://docs.python.org/3/library/ast.html#ast.Attribute) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprAttribute { - pub range: TextRange, - pub value: Box, - pub attr: Identifier, - pub ctx: ExprContext, -} - -impl Node for ExprAttribute { - const NAME: &'static str = "Attribute"; - const FIELD_NAMES: &'static [&'static str] = &["value", "attr", "ctx"]; -} -impl From for Expr { - fn from(payload: ExprAttribute) -> Self { - Expr::Attribute(payload) - } -} -impl From for Ast { - fn from(payload: ExprAttribute) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Subscript](https://docs.python.org/3/library/ast.html#ast.Subscript) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprSubscript { - pub range: TextRange, - pub value: Box, - pub slice: Box, - pub ctx: ExprContext, -} - -impl Node for ExprSubscript { - const NAME: &'static str = "Subscript"; - const FIELD_NAMES: &'static [&'static str] = &["value", "slice", "ctx"]; -} -impl From for Expr { - fn from(payload: ExprSubscript) -> Self { - Expr::Subscript(payload) - } -} -impl From for Ast { - fn from(payload: ExprSubscript) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Starred](https://docs.python.org/3/library/ast.html#ast.Starred) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprStarred { - pub range: TextRange, - pub value: Box, - pub ctx: ExprContext, -} - -impl Node for ExprStarred { - const NAME: &'static str = "Starred"; - const FIELD_NAMES: &'static [&'static str] = &["value", "ctx"]; -} -impl From for Expr { - fn from(payload: ExprStarred) -> Self { - Expr::Starred(payload) - } -} -impl From for Ast { - fn from(payload: ExprStarred) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Name](https://docs.python.org/3/library/ast.html#ast.Name) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprName { - pub range: TextRange, - pub id: String, - pub ctx: ExprContext, -} - -impl Node for ExprName { - const NAME: &'static str = "Name"; - const FIELD_NAMES: &'static [&'static str] = &["id", "ctx"]; -} -impl From for Expr { - fn from(payload: ExprName) -> Self { - Expr::Name(payload) - } -} -impl From for Ast { - fn from(payload: ExprName) -> Self { - Expr::from(payload).into() - } -} - -/// See also [List](https://docs.python.org/3/library/ast.html#ast.List) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprList { - pub range: TextRange, - pub elts: Vec, - pub ctx: ExprContext, -} - -impl Node for ExprList { - const NAME: &'static str = "List"; - const FIELD_NAMES: &'static [&'static str] = &["elts", "ctx"]; -} -impl From for Expr { - fn from(payload: ExprList) -> Self { - Expr::List(payload) - } -} -impl From for Ast { - fn from(payload: ExprList) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Tuple](https://docs.python.org/3/library/ast.html#ast.Tuple) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprTuple { - pub range: TextRange, - pub elts: Vec, - pub ctx: ExprContext, -} - -impl Node for ExprTuple { - const NAME: &'static str = "Tuple"; - const FIELD_NAMES: &'static [&'static str] = &["elts", "ctx"]; -} -impl From for Expr { - fn from(payload: ExprTuple) -> Self { - Expr::Tuple(payload) - } -} -impl From for Ast { - fn from(payload: ExprTuple) -> Self { - Expr::from(payload).into() - } -} - -/// See also [Slice](https://docs.python.org/3/library/ast.html#ast.Slice) -#[derive(Clone, Debug, PartialEq)] -pub struct ExprSlice { - pub range: TextRange, - pub lower: Option>, - pub upper: Option>, - pub step: Option>, -} - -impl Node for ExprSlice { - const NAME: &'static str = "Slice"; - const FIELD_NAMES: &'static [&'static str] = &["lower", "upper", "step"]; -} -impl From for Expr { - fn from(payload: ExprSlice) -> Self { - Expr::Slice(payload) - } -} -impl From for Ast { - fn from(payload: ExprSlice) -> Self { - Expr::from(payload).into() - } -} - -impl Node for Expr { - const NAME: &'static str = "expr"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} - -/// See also [expr_context](https://docs.python.org/3/library/ast.html#ast.expr_context) -#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] -pub enum ExprContext { - Load, - Store, - Del, -} -impl ExprContext { - #[inline] - pub const fn load(&self) -> Option { - match self { - ExprContext::Load => Some(ExprContextLoad), - _ => None, - } - } - - #[inline] - pub const fn store(&self) -> Option { - match self { - ExprContext::Store => Some(ExprContextStore), - _ => None, - } - } - - #[inline] - pub const fn del(&self) -> Option { - match self { - ExprContext::Del => Some(ExprContextDel), - _ => None, - } - } -} - -pub struct ExprContextLoad; -impl From for ExprContext { - fn from(_: ExprContextLoad) -> Self { - ExprContext::Load - } -} -impl From for Ast { - fn from(_: ExprContextLoad) -> Self { - ExprContext::Load.into() - } -} -impl Node for ExprContextLoad { - const NAME: &'static str = "Load"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for ExprContextLoad { - #[inline] - fn eq(&self, other: &ExprContext) -> bool { - matches!(other, ExprContext::Load) - } -} - -pub struct ExprContextStore; -impl From for ExprContext { - fn from(_: ExprContextStore) -> Self { - ExprContext::Store - } -} -impl From for Ast { - fn from(_: ExprContextStore) -> Self { - ExprContext::Store.into() - } -} -impl Node for ExprContextStore { - const NAME: &'static str = "Store"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for ExprContextStore { - #[inline] - fn eq(&self, other: &ExprContext) -> bool { - matches!(other, ExprContext::Store) - } -} - -pub struct ExprContextDel; -impl From for ExprContext { - fn from(_: ExprContextDel) -> Self { - ExprContext::Del - } -} -impl From for Ast { - fn from(_: ExprContextDel) -> Self { - ExprContext::Del.into() - } -} -impl Node for ExprContextDel { - const NAME: &'static str = "Del"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for ExprContextDel { - #[inline] - fn eq(&self, other: &ExprContext) -> bool { - matches!(other, ExprContext::Del) - } -} - -impl Node for ExprContext { - const NAME: &'static str = "expr_context"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} - -/// See also [boolop](https://docs.python.org/3/library/ast.html#ast.boolop) -#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] -pub enum BoolOp { - And, - Or, -} -impl BoolOp { - #[inline] - pub const fn and(&self) -> Option { - match self { - BoolOp::And => Some(BoolOpAnd), - _ => None, - } - } - - #[inline] - pub const fn or(&self) -> Option { - match self { - BoolOp::Or => Some(BoolOpOr), - _ => None, - } - } -} - -pub struct BoolOpAnd; -impl From for BoolOp { - fn from(_: BoolOpAnd) -> Self { - BoolOp::And - } -} -impl From for Ast { - fn from(_: BoolOpAnd) -> Self { - BoolOp::And.into() - } -} -impl Node for BoolOpAnd { - const NAME: &'static str = "And"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for BoolOpAnd { - #[inline] - fn eq(&self, other: &BoolOp) -> bool { - matches!(other, BoolOp::And) - } -} - -pub struct BoolOpOr; -impl From for BoolOp { - fn from(_: BoolOpOr) -> Self { - BoolOp::Or - } -} -impl From for Ast { - fn from(_: BoolOpOr) -> Self { - BoolOp::Or.into() - } -} -impl Node for BoolOpOr { - const NAME: &'static str = "Or"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for BoolOpOr { - #[inline] - fn eq(&self, other: &BoolOp) -> bool { - matches!(other, BoolOp::Or) - } -} - -impl Node for BoolOp { - const NAME: &'static str = "boolop"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} - -/// See also [operator](https://docs.python.org/3/library/ast.html#ast.operator) -#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] -pub enum Operator { - Add, - Sub, - Mult, - MatMult, - Div, - Mod, - Pow, - LShift, - RShift, - BitOr, - BitXor, - BitAnd, - FloorDiv, -} -impl Operator { - #[inline] - pub const fn operator_add(&self) -> Option { - match self { - Operator::Add => Some(OperatorAdd), - _ => None, - } - } - - #[inline] - pub const fn operator_sub(&self) -> Option { - match self { - Operator::Sub => Some(OperatorSub), - _ => None, - } - } - - #[inline] - pub const fn operator_mult(&self) -> Option { - match self { - Operator::Mult => Some(OperatorMult), - _ => None, - } - } - - #[inline] - pub const fn operator_mat_mult(&self) -> Option { - match self { - Operator::MatMult => Some(OperatorMatMult), - _ => None, - } - } - - #[inline] - pub const fn operator_div(&self) -> Option { - match self { - Operator::Div => Some(OperatorDiv), - _ => None, - } - } - - #[inline] - pub const fn operator_mod(&self) -> Option { - match self { - Operator::Mod => Some(OperatorMod), - _ => None, - } - } - - #[inline] - pub const fn operator_pow(&self) -> Option { - match self { - Operator::Pow => Some(OperatorPow), - _ => None, - } - } - - #[inline] - pub const fn operator_l_shift(&self) -> Option { - match self { - Operator::LShift => Some(OperatorLShift), - _ => None, - } - } - - #[inline] - pub const fn operator_r_shift(&self) -> Option { - match self { - Operator::RShift => Some(OperatorRShift), - _ => None, - } - } - - #[inline] - pub const fn operator_bit_or(&self) -> Option { - match self { - Operator::BitOr => Some(OperatorBitOr), - _ => None, - } - } - - #[inline] - pub const fn operator_bit_xor(&self) -> Option { - match self { - Operator::BitXor => Some(OperatorBitXor), - _ => None, - } - } - - #[inline] - pub const fn operator_bit_and(&self) -> Option { - match self { - Operator::BitAnd => Some(OperatorBitAnd), - _ => None, - } - } - - #[inline] - pub const fn operator_floor_div(&self) -> Option { - match self { - Operator::FloorDiv => Some(OperatorFloorDiv), - _ => None, - } - } -} - -pub struct OperatorAdd; -impl From for Operator { - fn from(_: OperatorAdd) -> Self { - Operator::Add - } -} -impl From for Ast { - fn from(_: OperatorAdd) -> Self { - Operator::Add.into() - } -} -impl Node for OperatorAdd { - const NAME: &'static str = "Add"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorAdd { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::Add) - } -} - -pub struct OperatorSub; -impl From for Operator { - fn from(_: OperatorSub) -> Self { - Operator::Sub - } -} -impl From for Ast { - fn from(_: OperatorSub) -> Self { - Operator::Sub.into() - } -} -impl Node for OperatorSub { - const NAME: &'static str = "Sub"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorSub { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::Sub) - } -} - -pub struct OperatorMult; -impl From for Operator { - fn from(_: OperatorMult) -> Self { - Operator::Mult - } -} -impl From for Ast { - fn from(_: OperatorMult) -> Self { - Operator::Mult.into() - } -} -impl Node for OperatorMult { - const NAME: &'static str = "Mult"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorMult { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::Mult) - } -} - -pub struct OperatorMatMult; -impl From for Operator { - fn from(_: OperatorMatMult) -> Self { - Operator::MatMult - } -} -impl From for Ast { - fn from(_: OperatorMatMult) -> Self { - Operator::MatMult.into() - } -} -impl Node for OperatorMatMult { - const NAME: &'static str = "MatMult"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorMatMult { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::MatMult) - } -} - -pub struct OperatorDiv; -impl From for Operator { - fn from(_: OperatorDiv) -> Self { - Operator::Div - } -} -impl From for Ast { - fn from(_: OperatorDiv) -> Self { - Operator::Div.into() - } -} -impl Node for OperatorDiv { - const NAME: &'static str = "Div"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorDiv { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::Div) - } -} - -pub struct OperatorMod; -impl From for Operator { - fn from(_: OperatorMod) -> Self { - Operator::Mod - } -} -impl From for Ast { - fn from(_: OperatorMod) -> Self { - Operator::Mod.into() - } -} -impl Node for OperatorMod { - const NAME: &'static str = "Mod"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorMod { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::Mod) - } -} - -pub struct OperatorPow; -impl From for Operator { - fn from(_: OperatorPow) -> Self { - Operator::Pow - } -} -impl From for Ast { - fn from(_: OperatorPow) -> Self { - Operator::Pow.into() - } -} -impl Node for OperatorPow { - const NAME: &'static str = "Pow"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorPow { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::Pow) - } -} - -pub struct OperatorLShift; -impl From for Operator { - fn from(_: OperatorLShift) -> Self { - Operator::LShift - } -} -impl From for Ast { - fn from(_: OperatorLShift) -> Self { - Operator::LShift.into() - } -} -impl Node for OperatorLShift { - const NAME: &'static str = "LShift"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorLShift { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::LShift) - } -} - -pub struct OperatorRShift; -impl From for Operator { - fn from(_: OperatorRShift) -> Self { - Operator::RShift - } -} -impl From for Ast { - fn from(_: OperatorRShift) -> Self { - Operator::RShift.into() - } -} -impl Node for OperatorRShift { - const NAME: &'static str = "RShift"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorRShift { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::RShift) - } -} - -pub struct OperatorBitOr; -impl From for Operator { - fn from(_: OperatorBitOr) -> Self { - Operator::BitOr - } -} -impl From for Ast { - fn from(_: OperatorBitOr) -> Self { - Operator::BitOr.into() - } -} -impl Node for OperatorBitOr { - const NAME: &'static str = "BitOr"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorBitOr { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::BitOr) - } -} - -pub struct OperatorBitXor; -impl From for Operator { - fn from(_: OperatorBitXor) -> Self { - Operator::BitXor - } -} -impl From for Ast { - fn from(_: OperatorBitXor) -> Self { - Operator::BitXor.into() - } -} -impl Node for OperatorBitXor { - const NAME: &'static str = "BitXor"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorBitXor { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::BitXor) - } -} - -pub struct OperatorBitAnd; -impl From for Operator { - fn from(_: OperatorBitAnd) -> Self { - Operator::BitAnd - } -} -impl From for Ast { - fn from(_: OperatorBitAnd) -> Self { - Operator::BitAnd.into() - } -} -impl Node for OperatorBitAnd { - const NAME: &'static str = "BitAnd"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorBitAnd { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::BitAnd) - } -} - -pub struct OperatorFloorDiv; -impl From for Operator { - fn from(_: OperatorFloorDiv) -> Self { - Operator::FloorDiv - } -} -impl From for Ast { - fn from(_: OperatorFloorDiv) -> Self { - Operator::FloorDiv.into() - } -} -impl Node for OperatorFloorDiv { - const NAME: &'static str = "FloorDiv"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for OperatorFloorDiv { - #[inline] - fn eq(&self, other: &Operator) -> bool { - matches!(other, Operator::FloorDiv) - } -} - -impl Node for Operator { - const NAME: &'static str = "operator"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} - -/// See also [unaryop](https://docs.python.org/3/library/ast.html#ast.unaryop) -#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] -pub enum UnaryOp { - Invert, - Not, - UAdd, - USub, -} -impl UnaryOp { - #[inline] - pub const fn invert(&self) -> Option { - match self { - UnaryOp::Invert => Some(UnaryOpInvert), - _ => None, - } - } - - #[inline] - pub const fn not(&self) -> Option { - match self { - UnaryOp::Not => Some(UnaryOpNot), - _ => None, - } - } - - #[inline] - pub const fn u_add(&self) -> Option { - match self { - UnaryOp::UAdd => Some(UnaryOpUAdd), - _ => None, - } - } - - #[inline] - pub const fn u_sub(&self) -> Option { - match self { - UnaryOp::USub => Some(UnaryOpUSub), - _ => None, - } - } -} - -pub struct UnaryOpInvert; -impl From for UnaryOp { - fn from(_: UnaryOpInvert) -> Self { - UnaryOp::Invert - } -} -impl From for Ast { - fn from(_: UnaryOpInvert) -> Self { - UnaryOp::Invert.into() - } -} -impl Node for UnaryOpInvert { - const NAME: &'static str = "Invert"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for UnaryOpInvert { - #[inline] - fn eq(&self, other: &UnaryOp) -> bool { - matches!(other, UnaryOp::Invert) - } -} - -pub struct UnaryOpNot; -impl From for UnaryOp { - fn from(_: UnaryOpNot) -> Self { - UnaryOp::Not - } -} -impl From for Ast { - fn from(_: UnaryOpNot) -> Self { - UnaryOp::Not.into() - } -} -impl Node for UnaryOpNot { - const NAME: &'static str = "Not"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for UnaryOpNot { - #[inline] - fn eq(&self, other: &UnaryOp) -> bool { - matches!(other, UnaryOp::Not) - } -} - -pub struct UnaryOpUAdd; -impl From for UnaryOp { - fn from(_: UnaryOpUAdd) -> Self { - UnaryOp::UAdd - } -} -impl From for Ast { - fn from(_: UnaryOpUAdd) -> Self { - UnaryOp::UAdd.into() - } -} -impl Node for UnaryOpUAdd { - const NAME: &'static str = "UAdd"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for UnaryOpUAdd { - #[inline] - fn eq(&self, other: &UnaryOp) -> bool { - matches!(other, UnaryOp::UAdd) - } -} - -pub struct UnaryOpUSub; -impl From for UnaryOp { - fn from(_: UnaryOpUSub) -> Self { - UnaryOp::USub - } -} -impl From for Ast { - fn from(_: UnaryOpUSub) -> Self { - UnaryOp::USub.into() - } -} -impl Node for UnaryOpUSub { - const NAME: &'static str = "USub"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for UnaryOpUSub { - #[inline] - fn eq(&self, other: &UnaryOp) -> bool { - matches!(other, UnaryOp::USub) - } -} - -impl Node for UnaryOp { - const NAME: &'static str = "unaryop"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} - -/// See also [cmpop](https://docs.python.org/3/library/ast.html#ast.cmpop) -#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] -pub enum CmpOp { - Eq, - NotEq, - Lt, - LtE, - Gt, - GtE, - Is, - IsNot, - In, - NotIn, -} -impl CmpOp { - #[inline] - pub const fn cmp_op_eq(&self) -> Option { - match self { - CmpOp::Eq => Some(CmpOpEq), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_not_eq(&self) -> Option { - match self { - CmpOp::NotEq => Some(CmpOpNotEq), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_lt(&self) -> Option { - match self { - CmpOp::Lt => Some(CmpOpLt), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_lt_e(&self) -> Option { - match self { - CmpOp::LtE => Some(CmpOpLtE), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_gt(&self) -> Option { - match self { - CmpOp::Gt => Some(CmpOpGt), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_gt_e(&self) -> Option { - match self { - CmpOp::GtE => Some(CmpOpGtE), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_is(&self) -> Option { - match self { - CmpOp::Is => Some(CmpOpIs), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_is_not(&self) -> Option { - match self { - CmpOp::IsNot => Some(CmpOpIsNot), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_in(&self) -> Option { - match self { - CmpOp::In => Some(CmpOpIn), - _ => None, - } - } - - #[inline] - pub const fn cmp_op_not_in(&self) -> Option { - match self { - CmpOp::NotIn => Some(CmpOpNotIn), - _ => None, - } - } -} - -pub struct CmpOpEq; -impl From for CmpOp { - fn from(_: CmpOpEq) -> Self { - CmpOp::Eq - } -} -impl From for Ast { - fn from(_: CmpOpEq) -> Self { - CmpOp::Eq.into() - } -} -impl Node for CmpOpEq { - const NAME: &'static str = "Eq"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for CmpOpEq { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::Eq) - } -} - -pub struct CmpOpNotEq; -impl From for CmpOp { - fn from(_: CmpOpNotEq) -> Self { - CmpOp::NotEq - } -} -impl From for Ast { - fn from(_: CmpOpNotEq) -> Self { - CmpOp::NotEq.into() - } -} -impl Node for CmpOpNotEq { - const NAME: &'static str = "NotEq"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for CmpOpNotEq { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::NotEq) - } -} - -pub struct CmpOpLt; -impl From for CmpOp { - fn from(_: CmpOpLt) -> Self { - CmpOp::Lt - } -} -impl From for Ast { - fn from(_: CmpOpLt) -> Self { - CmpOp::Lt.into() - } -} -impl Node for CmpOpLt { - const NAME: &'static str = "Lt"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for CmpOpLt { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::Lt) - } -} - -pub struct CmpOpLtE; -impl From for CmpOp { - fn from(_: CmpOpLtE) -> Self { - CmpOp::LtE - } -} -impl From for Ast { - fn from(_: CmpOpLtE) -> Self { - CmpOp::LtE.into() - } -} -impl Node for CmpOpLtE { - const NAME: &'static str = "LtE"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for CmpOpLtE { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::LtE) - } -} - -pub struct CmpOpGt; -impl From for CmpOp { - fn from(_: CmpOpGt) -> Self { - CmpOp::Gt - } -} -impl From for Ast { - fn from(_: CmpOpGt) -> Self { - CmpOp::Gt.into() - } -} -impl Node for CmpOpGt { - const NAME: &'static str = "Gt"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for CmpOpGt { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::Gt) - } -} - -pub struct CmpOpGtE; -impl From for CmpOp { - fn from(_: CmpOpGtE) -> Self { - CmpOp::GtE - } -} -impl From for Ast { - fn from(_: CmpOpGtE) -> Self { - CmpOp::GtE.into() - } -} -impl Node for CmpOpGtE { - const NAME: &'static str = "GtE"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for CmpOpGtE { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::GtE) - } -} - -pub struct CmpOpIs; -impl From for CmpOp { - fn from(_: CmpOpIs) -> Self { - CmpOp::Is - } -} -impl From for Ast { - fn from(_: CmpOpIs) -> Self { - CmpOp::Is.into() - } -} -impl Node for CmpOpIs { - const NAME: &'static str = "Is"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for CmpOpIs { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::Is) - } -} - -pub struct CmpOpIsNot; -impl From for CmpOp { - fn from(_: CmpOpIsNot) -> Self { - CmpOp::IsNot - } -} -impl From for Ast { - fn from(_: CmpOpIsNot) -> Self { - CmpOp::IsNot.into() - } -} -impl Node for CmpOpIsNot { - const NAME: &'static str = "IsNot"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for CmpOpIsNot { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::IsNot) - } -} - -pub struct CmpOpIn; -impl From for CmpOp { - fn from(_: CmpOpIn) -> Self { - CmpOp::In - } -} -impl From for Ast { - fn from(_: CmpOpIn) -> Self { - CmpOp::In.into() - } -} -impl Node for CmpOpIn { - const NAME: &'static str = "In"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for CmpOpIn { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::In) - } -} - -pub struct CmpOpNotIn; -impl From for CmpOp { - fn from(_: CmpOpNotIn) -> Self { - CmpOp::NotIn - } -} -impl From for Ast { - fn from(_: CmpOpNotIn) -> Self { - CmpOp::NotIn.into() - } -} -impl Node for CmpOpNotIn { - const NAME: &'static str = "NotIn"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} -impl std::cmp::PartialEq for CmpOpNotIn { - #[inline] - fn eq(&self, other: &CmpOp) -> bool { - matches!(other, CmpOp::NotIn) - } -} - -impl Node for CmpOp { - const NAME: &'static str = "cmpop"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} - -/// See also [comprehension](https://docs.python.org/3/library/ast.html#ast.comprehension) -#[derive(Clone, Debug, PartialEq)] -pub struct Comprehension { - pub range: TextRange, - pub target: Expr, - pub iter: Expr, - pub ifs: Vec, - pub is_async: bool, -} - -impl Node for Comprehension { - const NAME: &'static str = "comprehension"; - const FIELD_NAMES: &'static [&'static str] = &["target", "iter", "ifs", "is_async"]; -} - -/// See also [excepthandler](https://docs.python.org/3/library/ast.html#ast.excepthandler) -#[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum ExceptHandler { - ExceptHandler(ExceptHandlerExceptHandler), -} - -/// See also [ExceptHandler](https://docs.python.org/3/library/ast.html#ast.ExceptHandler) -#[derive(Clone, Debug, PartialEq)] -pub struct ExceptHandlerExceptHandler { - pub range: TextRange, - pub type_: Option>, - pub name: Option, - pub body: Vec, -} - -impl Node for ExceptHandlerExceptHandler { - const NAME: &'static str = "ExceptHandler"; - const FIELD_NAMES: &'static [&'static str] = &["type", "name", "body"]; -} -impl From for ExceptHandler { - fn from(payload: ExceptHandlerExceptHandler) -> Self { - ExceptHandler::ExceptHandler(payload) - } -} -impl From for Ast { - fn from(payload: ExceptHandlerExceptHandler) -> Self { - ExceptHandler::from(payload).into() - } -} - -impl Node for ExceptHandler { - const NAME: &'static str = "excepthandler"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} - -/// See also [arguments](https://docs.python.org/3/library/ast.html#ast.arguments) -#[derive(Clone, Debug, PartialEq)] -pub struct PythonArguments { - pub range: TextRange, - pub posonlyargs: Vec, - pub args: Vec, - pub vararg: Option>, - pub kwonlyargs: Vec, - pub kw_defaults: Vec, - pub kwarg: Option>, - pub defaults: Vec, -} - -impl Node for PythonArguments { - const NAME: &'static str = "arguments"; - const FIELD_NAMES: &'static [&'static str] = &[ - "posonlyargs", - "args", - "vararg", - "kwonlyargs", - "kw_defaults", - "kwarg", - "defaults", - ]; -} - -/// See also [arg](https://docs.python.org/3/library/ast.html#ast.arg) -#[derive(Clone, Debug, PartialEq)] -pub struct Arg { - pub range: TextRange, - pub arg: Identifier, - pub annotation: Option>, - pub type_comment: Option, -} - -impl Node for Arg { - const NAME: &'static str = "arg"; - const FIELD_NAMES: &'static [&'static str] = &["arg", "annotation", "type_comment"]; -} - -/// See also [keyword](https://docs.python.org/3/library/ast.html#ast.keyword) -#[derive(Clone, Debug, PartialEq)] -pub struct Keyword { - pub range: TextRange, - pub arg: Option, - pub value: Expr, -} - -impl Node for Keyword { - const NAME: &'static str = "keyword"; - const FIELD_NAMES: &'static [&'static str] = &["arg", "value"]; -} - -/// See also [alias](https://docs.python.org/3/library/ast.html#ast.alias) -#[derive(Clone, Debug, PartialEq)] -pub struct Alias { - pub range: TextRange, - pub name: Identifier, - pub asname: Option, -} - -impl Node for Alias { - const NAME: &'static str = "alias"; - const FIELD_NAMES: &'static [&'static str] = &["name", "asname"]; -} - -/// See also [withitem](https://docs.python.org/3/library/ast.html#ast.withitem) -#[derive(Clone, Debug, PartialEq)] -pub struct WithItem { - pub range: TextRange, - pub context_expr: Expr, - pub optional_vars: Option>, -} - -impl Node for WithItem { - const NAME: &'static str = "withitem"; - const FIELD_NAMES: &'static [&'static str] = &["context_expr", "optional_vars"]; -} - -/// See also [match_case](https://docs.python.org/3/library/ast.html#ast.match_case) -#[derive(Clone, Debug, PartialEq)] -pub struct MatchCase { - pub range: TextRange, - pub pattern: Pattern, - pub guard: Option>, - pub body: Vec, -} - -impl Node for MatchCase { - const NAME: &'static str = "match_case"; - const FIELD_NAMES: &'static [&'static str] = &["pattern", "guard", "body"]; -} - -/// See also [pattern](https://docs.python.org/3/library/ast.html#ast.pattern) -#[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum Pattern { - MatchValue(PatternMatchValue), - MatchSingleton(PatternMatchSingleton), - MatchSequence(PatternMatchSequence), - MatchMapping(PatternMatchMapping), - MatchClass(PatternMatchClass), - MatchStar(PatternMatchStar), - MatchAs(PatternMatchAs), - MatchOr(PatternMatchOr), -} - -/// See also [MatchValue](https://docs.python.org/3/library/ast.html#ast.MatchValue) -#[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchValue { - pub range: TextRange, - pub value: Box, -} - -impl Node for PatternMatchValue { - const NAME: &'static str = "MatchValue"; - const FIELD_NAMES: &'static [&'static str] = &["value"]; -} -impl From for Pattern { - fn from(payload: PatternMatchValue) -> Self { - Pattern::MatchValue(payload) - } -} -impl From for Ast { - fn from(payload: PatternMatchValue) -> Self { - Pattern::from(payload).into() - } -} - -/// See also [MatchSingleton](https://docs.python.org/3/library/ast.html#ast.MatchSingleton) -#[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchSingleton { - pub range: TextRange, - pub value: Constant, -} - -impl Node for PatternMatchSingleton { - const NAME: &'static str = "MatchSingleton"; - const FIELD_NAMES: &'static [&'static str] = &["value"]; -} -impl From for Pattern { - fn from(payload: PatternMatchSingleton) -> Self { - Pattern::MatchSingleton(payload) - } -} -impl From for Ast { - fn from(payload: PatternMatchSingleton) -> Self { - Pattern::from(payload).into() - } -} - -/// See also [MatchSequence](https://docs.python.org/3/library/ast.html#ast.MatchSequence) -#[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchSequence { - pub range: TextRange, - pub patterns: Vec, -} - -impl Node for PatternMatchSequence { - const NAME: &'static str = "MatchSequence"; - const FIELD_NAMES: &'static [&'static str] = &["patterns"]; -} -impl From for Pattern { - fn from(payload: PatternMatchSequence) -> Self { - Pattern::MatchSequence(payload) - } -} -impl From for Ast { - fn from(payload: PatternMatchSequence) -> Self { - Pattern::from(payload).into() - } -} - -/// See also [MatchMapping](https://docs.python.org/3/library/ast.html#ast.MatchMapping) -#[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchMapping { - pub range: TextRange, - pub keys: Vec, - pub patterns: Vec, - pub rest: Option, -} - -impl Node for PatternMatchMapping { - const NAME: &'static str = "MatchMapping"; - const FIELD_NAMES: &'static [&'static str] = &["keys", "patterns", "rest"]; -} -impl From for Pattern { - fn from(payload: PatternMatchMapping) -> Self { - Pattern::MatchMapping(payload) - } -} -impl From for Ast { - fn from(payload: PatternMatchMapping) -> Self { - Pattern::from(payload).into() - } -} - -/// See also [MatchClass](https://docs.python.org/3/library/ast.html#ast.MatchClass) -#[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchClass { - pub range: TextRange, - pub cls: Box, - pub patterns: Vec, - pub kwd_attrs: Vec, - pub kwd_patterns: Vec, -} - -impl Node for PatternMatchClass { - const NAME: &'static str = "MatchClass"; - const FIELD_NAMES: &'static [&'static str] = &["cls", "patterns", "kwd_attrs", "kwd_patterns"]; -} -impl From for Pattern { - fn from(payload: PatternMatchClass) -> Self { - Pattern::MatchClass(payload) - } -} -impl From for Ast { - fn from(payload: PatternMatchClass) -> Self { - Pattern::from(payload).into() - } -} - -/// See also [MatchStar](https://docs.python.org/3/library/ast.html#ast.MatchStar) -#[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchStar { - pub range: TextRange, - pub name: Option, -} - -impl Node for PatternMatchStar { - const NAME: &'static str = "MatchStar"; - const FIELD_NAMES: &'static [&'static str] = &["name"]; -} -impl From for Pattern { - fn from(payload: PatternMatchStar) -> Self { - Pattern::MatchStar(payload) - } -} -impl From for Ast { - fn from(payload: PatternMatchStar) -> Self { - Pattern::from(payload).into() - } -} - -/// See also [MatchAs](https://docs.python.org/3/library/ast.html#ast.MatchAs) -#[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchAs { - pub range: TextRange, - pub pattern: Option>, - pub name: Option, -} - -impl Node for PatternMatchAs { - const NAME: &'static str = "MatchAs"; - const FIELD_NAMES: &'static [&'static str] = &["pattern", "name"]; -} -impl From for Pattern { - fn from(payload: PatternMatchAs) -> Self { - Pattern::MatchAs(payload) - } -} -impl From for Ast { - fn from(payload: PatternMatchAs) -> Self { - Pattern::from(payload).into() - } -} - -/// See also [MatchOr](https://docs.python.org/3/library/ast.html#ast.MatchOr) -#[derive(Clone, Debug, PartialEq)] -pub struct PatternMatchOr { - pub range: TextRange, - pub patterns: Vec, -} - -impl Node for PatternMatchOr { - const NAME: &'static str = "MatchOr"; - const FIELD_NAMES: &'static [&'static str] = &["patterns"]; -} -impl From for Pattern { - fn from(payload: PatternMatchOr) -> Self { - Pattern::MatchOr(payload) - } -} -impl From for Ast { - fn from(payload: PatternMatchOr) -> Self { - Pattern::from(payload).into() - } -} - -impl Node for Pattern { - const NAME: &'static str = "pattern"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} - -/// See also [type_ignore](https://docs.python.org/3/library/ast.html#ast.type_ignore) -#[derive(Clone, Debug, PartialEq, is_macro::Is)] -pub enum TypeIgnore { - TypeIgnore(TypeIgnoreTypeIgnore), -} - -/// See also [TypeIgnore](https://docs.python.org/3/library/ast.html#ast.TypeIgnore) -#[derive(Clone, Debug, PartialEq)] -pub struct TypeIgnoreTypeIgnore { - pub range: TextRange, - pub lineno: Int, - pub tag: String, -} - -impl Node for TypeIgnoreTypeIgnore { - const NAME: &'static str = "TypeIgnore"; - const FIELD_NAMES: &'static [&'static str] = &["lineno", "tag"]; -} -impl From for TypeIgnore { - fn from(payload: TypeIgnoreTypeIgnore) -> Self { - TypeIgnore::TypeIgnore(payload) - } -} -impl From for Ast { - fn from(payload: TypeIgnoreTypeIgnore) -> Self { - TypeIgnore::from(payload).into() - } -} - -impl Node for TypeIgnore { - const NAME: &'static str = "type_ignore"; - const FIELD_NAMES: &'static [&'static str] = &[]; -} - -/// See also [decorator](https://docs.python.org/3/library/ast.html#ast.decorator) -#[derive(Clone, Debug, PartialEq)] -pub struct Decorator { - pub range: TextRange, - pub expression: Expr, -} - -impl Node for Decorator { - const NAME: &'static str = "decorator"; - const FIELD_NAMES: &'static [&'static str] = &["expression"]; -} - -/// An alternative type of AST `arguments`. This is parser-friendly and human-friendly definition of function arguments. -/// This form also has advantage to implement pre-order traverse. -/// `defaults` and `kw_defaults` fields are removed and the default values are placed under each `arg_with_default` typed argument. -/// `vararg` and `kwarg` are still typed as `arg` because they never can have a default value. -/// -/// The matching Python style AST type is [PythonArguments]. While [PythonArguments] has ordered `kwonlyargs` fields by -/// default existence, [Arguments] has location-ordered kwonlyargs fields. -/// -/// NOTE: This type is different from original Python AST. - -#[derive(Clone, Debug, PartialEq)] -pub struct Arguments { - pub range: TextRange, - pub posonlyargs: Vec, - pub args: Vec, - pub vararg: Option>, - pub kwonlyargs: Vec, - pub kwarg: Option>, -} - -impl Node for Arguments { - const NAME: &'static str = "alt:arguments"; - const FIELD_NAMES: &'static [&'static str] = - &["posonlyargs", "args", "vararg", "kwonlyargs", "kwarg"]; -} - -/// An alternative type of AST `arg`. This is used for each function argument that might have a default value. -/// Used by `Arguments` original type. -/// -/// NOTE: This type is different from original Python AST. - -#[derive(Clone, Debug, PartialEq)] -pub struct ArgWithDefault { - pub range: TextRange, - pub def: Arg, - pub default: Option>, -} - -impl Node for ArgWithDefault { - const NAME: &'static str = "arg_with_default"; - const FIELD_NAMES: &'static [&'static str] = &["def", "default"]; -} diff --git a/ast/src/gen/ranged.rs b/ast/src/gen/ranged.rs deleted file mode 100644 index 26fe38a51f..0000000000 --- a/ast/src/gen/ranged.rs +++ /dev/null @@ -1,502 +0,0 @@ -// File automatically generated by ast/asdl_rs.py. - -impl Ranged for crate::generic::ModModule { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ModInteractive { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ModExpression { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ModFunctionType { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::Mod { - fn range(&self) -> TextRange { - match self { - Self::Module(node) => node.range(), - Self::Interactive(node) => node.range(), - Self::Expression(node) => node.range(), - Self::FunctionType(node) => node.range(), - } - } -} - -impl Ranged for crate::generic::StmtFunctionDef { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtAsyncFunctionDef { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtClassDef { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtReturn { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtDelete { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtAssign { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtAugAssign { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtAnnAssign { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtFor { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtAsyncFor { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtWhile { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtIf { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtWith { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtAsyncWith { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtMatch { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtRaise { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtTry { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtTryStar { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtAssert { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtImport { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtImportFrom { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtGlobal { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtNonlocal { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtExpr { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtPass { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtBreak { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::StmtContinue { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::Stmt { - fn range(&self) -> TextRange { - match self { - Self::FunctionDef(node) => node.range(), - Self::AsyncFunctionDef(node) => node.range(), - Self::ClassDef(node) => node.range(), - Self::Return(node) => node.range(), - Self::Delete(node) => node.range(), - Self::Assign(node) => node.range(), - Self::AugAssign(node) => node.range(), - Self::AnnAssign(node) => node.range(), - Self::For(node) => node.range(), - Self::AsyncFor(node) => node.range(), - Self::While(node) => node.range(), - Self::If(node) => node.range(), - Self::With(node) => node.range(), - Self::AsyncWith(node) => node.range(), - Self::Match(node) => node.range(), - Self::Raise(node) => node.range(), - Self::Try(node) => node.range(), - Self::TryStar(node) => node.range(), - Self::Assert(node) => node.range(), - Self::Import(node) => node.range(), - Self::ImportFrom(node) => node.range(), - Self::Global(node) => node.range(), - Self::Nonlocal(node) => node.range(), - Self::Expr(node) => node.range(), - Self::Pass(node) => node.range(), - Self::Break(node) => node.range(), - Self::Continue(node) => node.range(), - } - } -} - -impl Ranged for crate::generic::ExprBoolOp { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprNamedExpr { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprBinOp { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprUnaryOp { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprLambda { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprIfExp { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprDict { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprSet { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprListComp { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprSetComp { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprDictComp { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprGeneratorExp { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprAwait { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprYield { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprYieldFrom { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprCompare { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprCall { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprFormattedValue { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprJoinedStr { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprConstant { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprAttribute { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprSubscript { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprStarred { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprName { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprList { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprTuple { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExprSlice { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::Expr { - fn range(&self) -> TextRange { - match self { - Self::BoolOp(node) => node.range(), - Self::NamedExpr(node) => node.range(), - Self::BinOp(node) => node.range(), - Self::UnaryOp(node) => node.range(), - Self::Lambda(node) => node.range(), - Self::IfExp(node) => node.range(), - Self::Dict(node) => node.range(), - Self::Set(node) => node.range(), - Self::ListComp(node) => node.range(), - Self::SetComp(node) => node.range(), - Self::DictComp(node) => node.range(), - Self::GeneratorExp(node) => node.range(), - Self::Await(node) => node.range(), - Self::Yield(node) => node.range(), - Self::YieldFrom(node) => node.range(), - Self::Compare(node) => node.range(), - Self::Call(node) => node.range(), - Self::FormattedValue(node) => node.range(), - Self::JoinedStr(node) => node.range(), - Self::Constant(node) => node.range(), - Self::Attribute(node) => node.range(), - Self::Subscript(node) => node.range(), - Self::Starred(node) => node.range(), - Self::Name(node) => node.range(), - Self::List(node) => node.range(), - Self::Tuple(node) => node.range(), - Self::Slice(node) => node.range(), - } - } -} - -impl Ranged for crate::generic::Comprehension { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ExceptHandlerExceptHandler { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::ExceptHandler { - fn range(&self) -> TextRange { - match self { - Self::ExceptHandler(node) => node.range(), - } - } -} - -impl Ranged for crate::generic::PythonArguments { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::Arg { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::Keyword { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::Alias { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::WithItem { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::MatchCase { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::PatternMatchValue { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::PatternMatchSingleton { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::PatternMatchSequence { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::PatternMatchMapping { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::PatternMatchClass { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::PatternMatchStar { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::PatternMatchAs { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::PatternMatchOr { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::Pattern { - fn range(&self) -> TextRange { - match self { - Self::MatchValue(node) => node.range(), - Self::MatchSingleton(node) => node.range(), - Self::MatchSequence(node) => node.range(), - Self::MatchMapping(node) => node.range(), - Self::MatchClass(node) => node.range(), - Self::MatchStar(node) => node.range(), - Self::MatchAs(node) => node.range(), - Self::MatchOr(node) => node.range(), - } - } -} - -impl Ranged for crate::generic::TypeIgnoreTypeIgnore { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::TypeIgnore { - fn range(&self) -> TextRange { - match self { - Self::TypeIgnore(node) => node.range(), - } - } -} - -impl Ranged for crate::generic::Decorator { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::Arguments { - fn range(&self) -> TextRange { - self.range - } -} -impl Ranged for crate::generic::ArgWithDefault { - fn range(&self) -> TextRange { - self.range - } -} diff --git a/ast/src/generic.rs b/ast/src/generic.rs index 9c03891512..f30a240186 100644 --- a/ast/src/generic.rs +++ b/ast/src/generic.rs @@ -1,7 +1,3144 @@ #![allow(clippy::derive_partial_eq_without_eq)] +use crate::text_size::TextRange; pub use crate::{builtin::*, text_size::TextSize, ConversionFlag, Node}; use std::fmt::Debug; +// This file was originally generated from asdl by a python script, but we now edit it manually + +#[derive(Clone, Debug, PartialEq, is_macro::Is)] +pub enum Ast { + #[is(name = "module")] + Mod(Mod), + Stmt(Stmt), + Expr(Expr), + ExprContext(ExprContext), + BoolOp(BoolOp), + Operator(Operator), + UnaryOp(UnaryOp), + CmpOp(CmpOp), + Comprehension(Comprehension), + ExceptHandler(ExceptHandler), + Arguments(Arguments), + Arg(Arg), + Keyword(Keyword), + Alias(Alias), + WithItem(WithItem), + MatchCase(MatchCase), + Pattern(Pattern), + TypeIgnore(TypeIgnore), + Decorator(Decorator), +} +impl Node for Ast { + const NAME: &'static str = "AST"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} + +impl From for Ast { + fn from(node: Mod) -> Self { + Ast::Mod(node) + } +} + +impl From for Ast { + fn from(node: Stmt) -> Self { + Ast::Stmt(node) + } +} + +impl From for Ast { + fn from(node: Expr) -> Self { + Ast::Expr(node) + } +} + +impl From for Ast { + fn from(node: ExprContext) -> Self { + Ast::ExprContext(node) + } +} + +impl From for Ast { + fn from(node: BoolOp) -> Self { + Ast::BoolOp(node) + } +} + +impl From for Ast { + fn from(node: Operator) -> Self { + Ast::Operator(node) + } +} + +impl From for Ast { + fn from(node: UnaryOp) -> Self { + Ast::UnaryOp(node) + } +} + +impl From for Ast { + fn from(node: CmpOp) -> Self { + Ast::CmpOp(node) + } +} + +impl From for Ast { + fn from(node: Comprehension) -> Self { + Ast::Comprehension(node) + } +} + +impl From for Ast { + fn from(node: ExceptHandler) -> Self { + Ast::ExceptHandler(node) + } +} + +impl From for Ast { + fn from(node: Arguments) -> Self { + Ast::Arguments(node) + } +} + +impl From for Ast { + fn from(node: Arg) -> Self { + Ast::Arg(node) + } +} + +impl From for Ast { + fn from(node: Keyword) -> Self { + Ast::Keyword(node) + } +} + +impl From for Ast { + fn from(node: Alias) -> Self { + Ast::Alias(node) + } +} + +impl From for Ast { + fn from(node: WithItem) -> Self { + Ast::WithItem(node) + } +} + +impl From for Ast { + fn from(node: MatchCase) -> Self { + Ast::MatchCase(node) + } +} + +impl From for Ast { + fn from(node: Pattern) -> Self { + Ast::Pattern(node) + } +} + +impl From for Ast { + fn from(node: TypeIgnore) -> Self { + Ast::TypeIgnore(node) + } +} + +impl From for Ast { + fn from(node: Decorator) -> Self { + Ast::Decorator(node) + } +} + +/// See also [mod](https://docs.python.org/3/library/ast.html#ast.mod) +#[derive(Clone, Debug, PartialEq, is_macro::Is)] +pub enum Mod { + Module(ModModule), + Interactive(ModInteractive), + Expression(ModExpression), + FunctionType(ModFunctionType), +} + +/// See also [Module](https://docs.python.org/3/library/ast.html#ast.Module) +#[derive(Clone, Debug, PartialEq)] +pub struct ModModule { + pub range: TextRange, + pub body: Vec, + pub type_ignores: Vec, +} + +impl Node for ModModule { + const NAME: &'static str = "Module"; + const FIELD_NAMES: &'static [&'static str] = &["body", "type_ignores"]; +} +impl From for Mod { + fn from(payload: ModModule) -> Self { + Mod::Module(payload) + } +} +impl From for Ast { + fn from(payload: ModModule) -> Self { + Mod::from(payload).into() + } +} + +/// See also [Interactive](https://docs.python.org/3/library/ast.html#ast.Interactive) +#[derive(Clone, Debug, PartialEq)] +pub struct ModInteractive { + pub range: TextRange, + pub body: Vec, +} + +impl Node for ModInteractive { + const NAME: &'static str = "Interactive"; + const FIELD_NAMES: &'static [&'static str] = &["body"]; +} +impl From for Mod { + fn from(payload: ModInteractive) -> Self { + Mod::Interactive(payload) + } +} +impl From for Ast { + fn from(payload: ModInteractive) -> Self { + Mod::from(payload).into() + } +} + +/// See also [Expression](https://docs.python.org/3/library/ast.html#ast.Expression) +#[derive(Clone, Debug, PartialEq)] +pub struct ModExpression { + pub range: TextRange, + pub body: Box, +} + +impl Node for ModExpression { + const NAME: &'static str = "Expression"; + const FIELD_NAMES: &'static [&'static str] = &["body"]; +} +impl From for Mod { + fn from(payload: ModExpression) -> Self { + Mod::Expression(payload) + } +} +impl From for Ast { + fn from(payload: ModExpression) -> Self { + Mod::from(payload).into() + } +} + +/// See also [FunctionType](https://docs.python.org/3/library/ast.html#ast.FunctionType) +#[derive(Clone, Debug, PartialEq)] +pub struct ModFunctionType { + pub range: TextRange, + pub argtypes: Vec, + pub returns: Box, +} + +impl Node for ModFunctionType { + const NAME: &'static str = "FunctionType"; + const FIELD_NAMES: &'static [&'static str] = &["argtypes", "returns"]; +} +impl From for Mod { + fn from(payload: ModFunctionType) -> Self { + Mod::FunctionType(payload) + } +} +impl From for Ast { + fn from(payload: ModFunctionType) -> Self { + Mod::from(payload).into() + } +} + +impl Node for Mod { + const NAME: &'static str = "mod"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} + +/// See also [stmt](https://docs.python.org/3/library/ast.html#ast.stmt) +#[derive(Clone, Debug, PartialEq, is_macro::Is)] +pub enum Stmt { + #[is(name = "function_def_stmt")] + FunctionDef(StmtFunctionDef), + #[is(name = "async_function_def_stmt")] + AsyncFunctionDef(StmtAsyncFunctionDef), + #[is(name = "class_def_stmt")] + ClassDef(StmtClassDef), + #[is(name = "return_stmt")] + Return(StmtReturn), + #[is(name = "delete_stmt")] + Delete(StmtDelete), + #[is(name = "assign_stmt")] + Assign(StmtAssign), + #[is(name = "aug_assign_stmt")] + AugAssign(StmtAugAssign), + #[is(name = "ann_assign_stmt")] + AnnAssign(StmtAnnAssign), + #[is(name = "for_stmt")] + For(StmtFor), + #[is(name = "async_for_stmt")] + AsyncFor(StmtAsyncFor), + #[is(name = "while_stmt")] + While(StmtWhile), + #[is(name = "if_stmt")] + If(StmtIf), + #[is(name = "with_stmt")] + With(StmtWith), + #[is(name = "async_with_stmt")] + AsyncWith(StmtAsyncWith), + #[is(name = "match_stmt")] + Match(StmtMatch), + #[is(name = "raise_stmt")] + Raise(StmtRaise), + #[is(name = "try_stmt")] + Try(StmtTry), + #[is(name = "try_star_stmt")] + TryStar(StmtTryStar), + #[is(name = "assert_stmt")] + Assert(StmtAssert), + #[is(name = "import_stmt")] + Import(StmtImport), + #[is(name = "import_from_stmt")] + ImportFrom(StmtImportFrom), + #[is(name = "global_stmt")] + Global(StmtGlobal), + #[is(name = "nonlocal_stmt")] + Nonlocal(StmtNonlocal), + #[is(name = "expr_stmt")] + Expr(StmtExpr), + #[is(name = "pass_stmt")] + Pass(StmtPass), + #[is(name = "break_stmt")] + Break(StmtBreak), + #[is(name = "continue_stmt")] + Continue(StmtContinue), +} + +/// See also [FunctionDef](https://docs.python.org/3/library/ast.html#ast.FunctionDef) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtFunctionDef { + pub range: TextRange, + pub name: Identifier, + pub args: Box, + pub body: Vec, + pub decorator_list: Vec, + pub returns: Option>, + pub type_comment: Option, +} + +impl Node for StmtFunctionDef { + const NAME: &'static str = "FunctionDef"; + const FIELD_NAMES: &'static [&'static str] = &[ + "name", + "args", + "body", + "decorator_list", + "returns", + "type_comment", + ]; +} +impl From for Stmt { + fn from(payload: StmtFunctionDef) -> Self { + Stmt::FunctionDef(payload) + } +} +impl From for Ast { + fn from(payload: StmtFunctionDef) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [AsyncFunctionDef](https://docs.python.org/3/library/ast.html#ast.AsyncFunctionDef) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtAsyncFunctionDef { + pub range: TextRange, + pub name: Identifier, + pub args: Box, + pub body: Vec, + pub decorator_list: Vec, + pub returns: Option>, + pub type_comment: Option, +} + +impl Node for StmtAsyncFunctionDef { + const NAME: &'static str = "AsyncFunctionDef"; + const FIELD_NAMES: &'static [&'static str] = &[ + "name", + "args", + "body", + "decorator_list", + "returns", + "type_comment", + ]; +} +impl From for Stmt { + fn from(payload: StmtAsyncFunctionDef) -> Self { + Stmt::AsyncFunctionDef(payload) + } +} +impl From for Ast { + fn from(payload: StmtAsyncFunctionDef) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [ClassDef](https://docs.python.org/3/library/ast.html#ast.ClassDef) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtClassDef { + pub range: TextRange, + pub name: Identifier, + pub bases: Vec, + pub keywords: Vec, + pub body: Vec, + pub decorator_list: Vec, +} + +impl Node for StmtClassDef { + const NAME: &'static str = "ClassDef"; + const FIELD_NAMES: &'static [&'static str] = + &["name", "bases", "keywords", "body", "decorator_list"]; +} +impl From for Stmt { + fn from(payload: StmtClassDef) -> Self { + Stmt::ClassDef(payload) + } +} +impl From for Ast { + fn from(payload: StmtClassDef) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Return](https://docs.python.org/3/library/ast.html#ast.Return) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtReturn { + pub range: TextRange, + pub value: Option>, +} + +impl Node for StmtReturn { + const NAME: &'static str = "Return"; + const FIELD_NAMES: &'static [&'static str] = &["value"]; +} +impl From for Stmt { + fn from(payload: StmtReturn) -> Self { + Stmt::Return(payload) + } +} +impl From for Ast { + fn from(payload: StmtReturn) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Delete](https://docs.python.org/3/library/ast.html#ast.Delete) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtDelete { + pub range: TextRange, + pub targets: Vec, +} + +impl Node for StmtDelete { + const NAME: &'static str = "Delete"; + const FIELD_NAMES: &'static [&'static str] = &["targets"]; +} +impl From for Stmt { + fn from(payload: StmtDelete) -> Self { + Stmt::Delete(payload) + } +} +impl From for Ast { + fn from(payload: StmtDelete) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Assign](https://docs.python.org/3/library/ast.html#ast.Assign) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtAssign { + pub range: TextRange, + pub targets: Vec, + pub value: Box, + pub type_comment: Option, +} + +impl Node for StmtAssign { + const NAME: &'static str = "Assign"; + const FIELD_NAMES: &'static [&'static str] = &["targets", "value", "type_comment"]; +} +impl From for Stmt { + fn from(payload: StmtAssign) -> Self { + Stmt::Assign(payload) + } +} +impl From for Ast { + fn from(payload: StmtAssign) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [AugAssign](https://docs.python.org/3/library/ast.html#ast.AugAssign) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtAugAssign { + pub range: TextRange, + pub target: Box, + pub op: Operator, + pub value: Box, +} + +impl Node for StmtAugAssign { + const NAME: &'static str = "AugAssign"; + const FIELD_NAMES: &'static [&'static str] = &["target", "op", "value"]; +} +impl From for Stmt { + fn from(payload: StmtAugAssign) -> Self { + Stmt::AugAssign(payload) + } +} +impl From for Ast { + fn from(payload: StmtAugAssign) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [AnnAssign](https://docs.python.org/3/library/ast.html#ast.AnnAssign) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtAnnAssign { + pub range: TextRange, + pub target: Box, + pub annotation: Box, + pub value: Option>, + pub simple: bool, +} + +impl Node for StmtAnnAssign { + const NAME: &'static str = "AnnAssign"; + const FIELD_NAMES: &'static [&'static str] = &["target", "annotation", "value", "simple"]; +} +impl From for Stmt { + fn from(payload: StmtAnnAssign) -> Self { + Stmt::AnnAssign(payload) + } +} +impl From for Ast { + fn from(payload: StmtAnnAssign) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [For](https://docs.python.org/3/library/ast.html#ast.For) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtFor { + pub range: TextRange, + pub target: Box, + pub iter: Box, + pub body: Vec, + pub orelse: Vec, + pub type_comment: Option, +} + +impl Node for StmtFor { + const NAME: &'static str = "For"; + const FIELD_NAMES: &'static [&'static str] = + &["target", "iter", "body", "orelse", "type_comment"]; +} +impl From for Stmt { + fn from(payload: StmtFor) -> Self { + Stmt::For(payload) + } +} +impl From for Ast { + fn from(payload: StmtFor) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [AsyncFor](https://docs.python.org/3/library/ast.html#ast.AsyncFor) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtAsyncFor { + pub range: TextRange, + pub target: Box, + pub iter: Box, + pub body: Vec, + pub orelse: Vec, + pub type_comment: Option, +} + +impl Node for StmtAsyncFor { + const NAME: &'static str = "AsyncFor"; + const FIELD_NAMES: &'static [&'static str] = + &["target", "iter", "body", "orelse", "type_comment"]; +} +impl From for Stmt { + fn from(payload: StmtAsyncFor) -> Self { + Stmt::AsyncFor(payload) + } +} +impl From for Ast { + fn from(payload: StmtAsyncFor) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [While](https://docs.python.org/3/library/ast.html#ast.While) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtWhile { + pub range: TextRange, + pub test: Box, + pub body: Vec, + pub orelse: Vec, +} + +impl Node for StmtWhile { + const NAME: &'static str = "While"; + const FIELD_NAMES: &'static [&'static str] = &["test", "body", "orelse"]; +} +impl From for Stmt { + fn from(payload: StmtWhile) -> Self { + Stmt::While(payload) + } +} +impl From for Ast { + fn from(payload: StmtWhile) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [If](https://docs.python.org/3/library/ast.html#ast.If) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtIf { + pub range: TextRange, + pub test: Box, + pub body: Vec, + pub orelse: Vec, +} + +impl Node for StmtIf { + const NAME: &'static str = "If"; + const FIELD_NAMES: &'static [&'static str] = &["test", "body", "orelse"]; +} +impl From for Stmt { + fn from(payload: StmtIf) -> Self { + Stmt::If(payload) + } +} +impl From for Ast { + fn from(payload: StmtIf) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [With](https://docs.python.org/3/library/ast.html#ast.With) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtWith { + pub range: TextRange, + pub items: Vec, + pub body: Vec, + pub type_comment: Option, +} + +impl Node for StmtWith { + const NAME: &'static str = "With"; + const FIELD_NAMES: &'static [&'static str] = &["items", "body", "type_comment"]; +} +impl From for Stmt { + fn from(payload: StmtWith) -> Self { + Stmt::With(payload) + } +} +impl From for Ast { + fn from(payload: StmtWith) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [AsyncWith](https://docs.python.org/3/library/ast.html#ast.AsyncWith) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtAsyncWith { + pub range: TextRange, + pub items: Vec, + pub body: Vec, + pub type_comment: Option, +} + +impl Node for StmtAsyncWith { + const NAME: &'static str = "AsyncWith"; + const FIELD_NAMES: &'static [&'static str] = &["items", "body", "type_comment"]; +} +impl From for Stmt { + fn from(payload: StmtAsyncWith) -> Self { + Stmt::AsyncWith(payload) + } +} +impl From for Ast { + fn from(payload: StmtAsyncWith) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Match](https://docs.python.org/3/library/ast.html#ast.Match) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtMatch { + pub range: TextRange, + pub subject: Box, + pub cases: Vec, +} + +impl Node for StmtMatch { + const NAME: &'static str = "Match"; + const FIELD_NAMES: &'static [&'static str] = &["subject", "cases"]; +} +impl From for Stmt { + fn from(payload: StmtMatch) -> Self { + Stmt::Match(payload) + } +} +impl From for Ast { + fn from(payload: StmtMatch) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Raise](https://docs.python.org/3/library/ast.html#ast.Raise) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtRaise { + pub range: TextRange, + pub exc: Option>, + pub cause: Option>, +} + +impl Node for StmtRaise { + const NAME: &'static str = "Raise"; + const FIELD_NAMES: &'static [&'static str] = &["exc", "cause"]; +} +impl From for Stmt { + fn from(payload: StmtRaise) -> Self { + Stmt::Raise(payload) + } +} +impl From for Ast { + fn from(payload: StmtRaise) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Try](https://docs.python.org/3/library/ast.html#ast.Try) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtTry { + pub range: TextRange, + pub body: Vec, + pub handlers: Vec, + pub orelse: Vec, + pub finalbody: Vec, +} + +impl Node for StmtTry { + const NAME: &'static str = "Try"; + const FIELD_NAMES: &'static [&'static str] = &["body", "handlers", "orelse", "finalbody"]; +} +impl From for Stmt { + fn from(payload: StmtTry) -> Self { + Stmt::Try(payload) + } +} +impl From for Ast { + fn from(payload: StmtTry) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [TryStar](https://docs.python.org/3/library/ast.html#ast.TryStar) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtTryStar { + pub range: TextRange, + pub body: Vec, + pub handlers: Vec, + pub orelse: Vec, + pub finalbody: Vec, +} + +impl Node for StmtTryStar { + const NAME: &'static str = "TryStar"; + const FIELD_NAMES: &'static [&'static str] = &["body", "handlers", "orelse", "finalbody"]; +} +impl From for Stmt { + fn from(payload: StmtTryStar) -> Self { + Stmt::TryStar(payload) + } +} +impl From for Ast { + fn from(payload: StmtTryStar) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Assert](https://docs.python.org/3/library/ast.html#ast.Assert) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtAssert { + pub range: TextRange, + pub test: Box, + pub msg: Option>, +} + +impl Node for StmtAssert { + const NAME: &'static str = "Assert"; + const FIELD_NAMES: &'static [&'static str] = &["test", "msg"]; +} +impl From for Stmt { + fn from(payload: StmtAssert) -> Self { + Stmt::Assert(payload) + } +} +impl From for Ast { + fn from(payload: StmtAssert) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Import](https://docs.python.org/3/library/ast.html#ast.Import) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtImport { + pub range: TextRange, + pub names: Vec, +} + +impl Node for StmtImport { + const NAME: &'static str = "Import"; + const FIELD_NAMES: &'static [&'static str] = &["names"]; +} +impl From for Stmt { + fn from(payload: StmtImport) -> Self { + Stmt::Import(payload) + } +} +impl From for Ast { + fn from(payload: StmtImport) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [ImportFrom](https://docs.python.org/3/library/ast.html#ast.ImportFrom) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtImportFrom { + pub range: TextRange, + pub module: Option, + pub names: Vec, + pub level: Option, +} + +impl Node for StmtImportFrom { + const NAME: &'static str = "ImportFrom"; + const FIELD_NAMES: &'static [&'static str] = &["module", "names", "level"]; +} +impl From for Stmt { + fn from(payload: StmtImportFrom) -> Self { + Stmt::ImportFrom(payload) + } +} +impl From for Ast { + fn from(payload: StmtImportFrom) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Global](https://docs.python.org/3/library/ast.html#ast.Global) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtGlobal { + pub range: TextRange, + pub names: Vec, +} + +impl Node for StmtGlobal { + const NAME: &'static str = "Global"; + const FIELD_NAMES: &'static [&'static str] = &["names"]; +} +impl From for Stmt { + fn from(payload: StmtGlobal) -> Self { + Stmt::Global(payload) + } +} +impl From for Ast { + fn from(payload: StmtGlobal) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Nonlocal](https://docs.python.org/3/library/ast.html#ast.Nonlocal) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtNonlocal { + pub range: TextRange, + pub names: Vec, +} + +impl Node for StmtNonlocal { + const NAME: &'static str = "Nonlocal"; + const FIELD_NAMES: &'static [&'static str] = &["names"]; +} +impl From for Stmt { + fn from(payload: StmtNonlocal) -> Self { + Stmt::Nonlocal(payload) + } +} +impl From for Ast { + fn from(payload: StmtNonlocal) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Expr](https://docs.python.org/3/library/ast.html#ast.Expr) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtExpr { + pub range: TextRange, + pub value: Box, +} + +impl Node for StmtExpr { + const NAME: &'static str = "Expr"; + const FIELD_NAMES: &'static [&'static str] = &["value"]; +} +impl From for Stmt { + fn from(payload: StmtExpr) -> Self { + Stmt::Expr(payload) + } +} +impl From for Ast { + fn from(payload: StmtExpr) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Pass](https://docs.python.org/3/library/ast.html#ast.Pass) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtPass { + pub range: TextRange, +} + +impl Node for StmtPass { + const NAME: &'static str = "Pass"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl From for Stmt { + fn from(payload: StmtPass) -> Self { + Stmt::Pass(payload) + } +} +impl From for Ast { + fn from(payload: StmtPass) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Break](https://docs.python.org/3/library/ast.html#ast.Break) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtBreak { + pub range: TextRange, +} + +impl Node for StmtBreak { + const NAME: &'static str = "Break"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl From for Stmt { + fn from(payload: StmtBreak) -> Self { + Stmt::Break(payload) + } +} +impl From for Ast { + fn from(payload: StmtBreak) -> Self { + Stmt::from(payload).into() + } +} + +/// See also [Continue](https://docs.python.org/3/library/ast.html#ast.Continue) +#[derive(Clone, Debug, PartialEq)] +pub struct StmtContinue { + pub range: TextRange, +} + +impl Node for StmtContinue { + const NAME: &'static str = "Continue"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl From for Stmt { + fn from(payload: StmtContinue) -> Self { + Stmt::Continue(payload) + } +} +impl From for Ast { + fn from(payload: StmtContinue) -> Self { + Stmt::from(payload).into() + } +} + +impl Node for Stmt { + const NAME: &'static str = "stmt"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} + +/// See also [expr](https://docs.python.org/3/library/ast.html#ast.expr) +#[derive(Clone, Debug, PartialEq, is_macro::Is)] +pub enum Expr { + #[is(name = "bool_op_expr")] + BoolOp(ExprBoolOp), + #[is(name = "named_expr_expr")] + NamedExpr(ExprNamedExpr), + #[is(name = "bin_op_expr")] + BinOp(ExprBinOp), + #[is(name = "unary_op_expr")] + UnaryOp(ExprUnaryOp), + #[is(name = "lambda_expr")] + Lambda(ExprLambda), + #[is(name = "if_exp_expr")] + IfExp(ExprIfExp), + #[is(name = "dict_expr")] + Dict(ExprDict), + #[is(name = "set_expr")] + Set(ExprSet), + #[is(name = "list_comp_expr")] + ListComp(ExprListComp), + #[is(name = "set_comp_expr")] + SetComp(ExprSetComp), + #[is(name = "dict_comp_expr")] + DictComp(ExprDictComp), + #[is(name = "generator_exp_expr")] + GeneratorExp(ExprGeneratorExp), + #[is(name = "await_expr")] + Await(ExprAwait), + #[is(name = "yield_expr")] + Yield(ExprYield), + #[is(name = "yield_from_expr")] + YieldFrom(ExprYieldFrom), + #[is(name = "compare_expr")] + Compare(ExprCompare), + #[is(name = "call_expr")] + Call(ExprCall), + #[is(name = "formatted_value_expr")] + FormattedValue(ExprFormattedValue), + #[is(name = "joined_str_expr")] + JoinedStr(ExprJoinedStr), + #[is(name = "constant_expr")] + Constant(ExprConstant), + #[is(name = "attribute_expr")] + Attribute(ExprAttribute), + #[is(name = "subscript_expr")] + Subscript(ExprSubscript), + #[is(name = "starred_expr")] + Starred(ExprStarred), + #[is(name = "name_expr")] + Name(ExprName), + #[is(name = "list_expr")] + List(ExprList), + #[is(name = "tuple_expr")] + Tuple(ExprTuple), + #[is(name = "slice_expr")] + Slice(ExprSlice), +} + +/// See also [BoolOp](https://docs.python.org/3/library/ast.html#ast.BoolOp) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprBoolOp { + pub range: TextRange, + pub op: BoolOp, + pub values: Vec, +} + +impl Node for ExprBoolOp { + const NAME: &'static str = "BoolOp"; + const FIELD_NAMES: &'static [&'static str] = &["op", "values"]; +} +impl From for Expr { + fn from(payload: ExprBoolOp) -> Self { + Expr::BoolOp(payload) + } +} +impl From for Ast { + fn from(payload: ExprBoolOp) -> Self { + Expr::from(payload).into() + } +} + +/// See also [NamedExpr](https://docs.python.org/3/library/ast.html#ast.NamedExpr) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprNamedExpr { + pub range: TextRange, + pub target: Box, + pub value: Box, +} + +impl Node for ExprNamedExpr { + const NAME: &'static str = "NamedExpr"; + const FIELD_NAMES: &'static [&'static str] = &["target", "value"]; +} +impl From for Expr { + fn from(payload: ExprNamedExpr) -> Self { + Expr::NamedExpr(payload) + } +} +impl From for Ast { + fn from(payload: ExprNamedExpr) -> Self { + Expr::from(payload).into() + } +} + +/// See also [BinOp](https://docs.python.org/3/library/ast.html#ast.BinOp) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprBinOp { + pub range: TextRange, + pub left: Box, + pub op: Operator, + pub right: Box, +} + +impl Node for ExprBinOp { + const NAME: &'static str = "BinOp"; + const FIELD_NAMES: &'static [&'static str] = &["left", "op", "right"]; +} +impl From for Expr { + fn from(payload: ExprBinOp) -> Self { + Expr::BinOp(payload) + } +} +impl From for Ast { + fn from(payload: ExprBinOp) -> Self { + Expr::from(payload).into() + } +} + +/// See also [UnaryOp](https://docs.python.org/3/library/ast.html#ast.UnaryOp) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprUnaryOp { + pub range: TextRange, + pub op: UnaryOp, + pub operand: Box, +} + +impl Node for ExprUnaryOp { + const NAME: &'static str = "UnaryOp"; + const FIELD_NAMES: &'static [&'static str] = &["op", "operand"]; +} +impl From for Expr { + fn from(payload: ExprUnaryOp) -> Self { + Expr::UnaryOp(payload) + } +} +impl From for Ast { + fn from(payload: ExprUnaryOp) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Lambda](https://docs.python.org/3/library/ast.html#ast.Lambda) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprLambda { + pub range: TextRange, + pub args: Box, + pub body: Box, +} + +impl Node for ExprLambda { + const NAME: &'static str = "Lambda"; + const FIELD_NAMES: &'static [&'static str] = &["args", "body"]; +} +impl From for Expr { + fn from(payload: ExprLambda) -> Self { + Expr::Lambda(payload) + } +} +impl From for Ast { + fn from(payload: ExprLambda) -> Self { + Expr::from(payload).into() + } +} + +/// See also [IfExp](https://docs.python.org/3/library/ast.html#ast.IfExp) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprIfExp { + pub range: TextRange, + pub test: Box, + pub body: Box, + pub orelse: Box, +} + +impl Node for ExprIfExp { + const NAME: &'static str = "IfExp"; + const FIELD_NAMES: &'static [&'static str] = &["test", "body", "orelse"]; +} +impl From for Expr { + fn from(payload: ExprIfExp) -> Self { + Expr::IfExp(payload) + } +} +impl From for Ast { + fn from(payload: ExprIfExp) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Dict](https://docs.python.org/3/library/ast.html#ast.Dict) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprDict { + pub range: TextRange, + pub keys: Vec>, + pub values: Vec, +} + +impl Node for ExprDict { + const NAME: &'static str = "Dict"; + const FIELD_NAMES: &'static [&'static str] = &["keys", "values"]; +} +impl From for Expr { + fn from(payload: ExprDict) -> Self { + Expr::Dict(payload) + } +} +impl From for Ast { + fn from(payload: ExprDict) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Set](https://docs.python.org/3/library/ast.html#ast.Set) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprSet { + pub range: TextRange, + pub elts: Vec, +} + +impl Node for ExprSet { + const NAME: &'static str = "Set"; + const FIELD_NAMES: &'static [&'static str] = &["elts"]; +} +impl From for Expr { + fn from(payload: ExprSet) -> Self { + Expr::Set(payload) + } +} +impl From for Ast { + fn from(payload: ExprSet) -> Self { + Expr::from(payload).into() + } +} + +/// See also [ListComp](https://docs.python.org/3/library/ast.html#ast.ListComp) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprListComp { + pub range: TextRange, + pub elt: Box, + pub generators: Vec, +} + +impl Node for ExprListComp { + const NAME: &'static str = "ListComp"; + const FIELD_NAMES: &'static [&'static str] = &["elt", "generators"]; +} +impl From for Expr { + fn from(payload: ExprListComp) -> Self { + Expr::ListComp(payload) + } +} +impl From for Ast { + fn from(payload: ExprListComp) -> Self { + Expr::from(payload).into() + } +} + +/// See also [SetComp](https://docs.python.org/3/library/ast.html#ast.SetComp) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprSetComp { + pub range: TextRange, + pub elt: Box, + pub generators: Vec, +} + +impl Node for ExprSetComp { + const NAME: &'static str = "SetComp"; + const FIELD_NAMES: &'static [&'static str] = &["elt", "generators"]; +} +impl From for Expr { + fn from(payload: ExprSetComp) -> Self { + Expr::SetComp(payload) + } +} +impl From for Ast { + fn from(payload: ExprSetComp) -> Self { + Expr::from(payload).into() + } +} + +/// See also [DictComp](https://docs.python.org/3/library/ast.html#ast.DictComp) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprDictComp { + pub range: TextRange, + pub key: Box, + pub value: Box, + pub generators: Vec, +} + +impl Node for ExprDictComp { + const NAME: &'static str = "DictComp"; + const FIELD_NAMES: &'static [&'static str] = &["key", "value", "generators"]; +} +impl From for Expr { + fn from(payload: ExprDictComp) -> Self { + Expr::DictComp(payload) + } +} +impl From for Ast { + fn from(payload: ExprDictComp) -> Self { + Expr::from(payload).into() + } +} + +/// See also [GeneratorExp](https://docs.python.org/3/library/ast.html#ast.GeneratorExp) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprGeneratorExp { + pub range: TextRange, + pub elt: Box, + pub generators: Vec, +} + +impl Node for ExprGeneratorExp { + const NAME: &'static str = "GeneratorExp"; + const FIELD_NAMES: &'static [&'static str] = &["elt", "generators"]; +} +impl From for Expr { + fn from(payload: ExprGeneratorExp) -> Self { + Expr::GeneratorExp(payload) + } +} +impl From for Ast { + fn from(payload: ExprGeneratorExp) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Await](https://docs.python.org/3/library/ast.html#ast.Await) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprAwait { + pub range: TextRange, + pub value: Box, +} + +impl Node for ExprAwait { + const NAME: &'static str = "Await"; + const FIELD_NAMES: &'static [&'static str] = &["value"]; +} +impl From for Expr { + fn from(payload: ExprAwait) -> Self { + Expr::Await(payload) + } +} +impl From for Ast { + fn from(payload: ExprAwait) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Yield](https://docs.python.org/3/library/ast.html#ast.Yield) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprYield { + pub range: TextRange, + pub value: Option>, +} + +impl Node for ExprYield { + const NAME: &'static str = "Yield"; + const FIELD_NAMES: &'static [&'static str] = &["value"]; +} +impl From for Expr { + fn from(payload: ExprYield) -> Self { + Expr::Yield(payload) + } +} +impl From for Ast { + fn from(payload: ExprYield) -> Self { + Expr::from(payload).into() + } +} + +/// See also [YieldFrom](https://docs.python.org/3/library/ast.html#ast.YieldFrom) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprYieldFrom { + pub range: TextRange, + pub value: Box, +} + +impl Node for ExprYieldFrom { + const NAME: &'static str = "YieldFrom"; + const FIELD_NAMES: &'static [&'static str] = &["value"]; +} +impl From for Expr { + fn from(payload: ExprYieldFrom) -> Self { + Expr::YieldFrom(payload) + } +} +impl From for Ast { + fn from(payload: ExprYieldFrom) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Compare](https://docs.python.org/3/library/ast.html#ast.Compare) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprCompare { + pub range: TextRange, + pub left: Box, + pub ops: Vec, + pub comparators: Vec, +} + +impl Node for ExprCompare { + const NAME: &'static str = "Compare"; + const FIELD_NAMES: &'static [&'static str] = &["left", "ops", "comparators"]; +} +impl From for Expr { + fn from(payload: ExprCompare) -> Self { + Expr::Compare(payload) + } +} +impl From for Ast { + fn from(payload: ExprCompare) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Call](https://docs.python.org/3/library/ast.html#ast.Call) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprCall { + pub range: TextRange, + pub func: Box, + pub args: Vec, + pub keywords: Vec, +} + +impl Node for ExprCall { + const NAME: &'static str = "Call"; + const FIELD_NAMES: &'static [&'static str] = &["func", "args", "keywords"]; +} +impl From for Expr { + fn from(payload: ExprCall) -> Self { + Expr::Call(payload) + } +} +impl From for Ast { + fn from(payload: ExprCall) -> Self { + Expr::from(payload).into() + } +} + +/// See also [FormattedValue](https://docs.python.org/3/library/ast.html#ast.FormattedValue) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprFormattedValue { + pub range: TextRange, + pub value: Box, + pub conversion: ConversionFlag, + pub format_spec: Option>, +} + +impl Node for ExprFormattedValue { + const NAME: &'static str = "FormattedValue"; + const FIELD_NAMES: &'static [&'static str] = &["value", "conversion", "format_spec"]; +} +impl From for Expr { + fn from(payload: ExprFormattedValue) -> Self { + Expr::FormattedValue(payload) + } +} +impl From for Ast { + fn from(payload: ExprFormattedValue) -> Self { + Expr::from(payload).into() + } +} + +/// See also [JoinedStr](https://docs.python.org/3/library/ast.html#ast.JoinedStr) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprJoinedStr { + pub range: TextRange, + pub values: Vec, +} + +impl Node for ExprJoinedStr { + const NAME: &'static str = "JoinedStr"; + const FIELD_NAMES: &'static [&'static str] = &["values"]; +} +impl From for Expr { + fn from(payload: ExprJoinedStr) -> Self { + Expr::JoinedStr(payload) + } +} +impl From for Ast { + fn from(payload: ExprJoinedStr) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Constant](https://docs.python.org/3/library/ast.html#ast.Constant) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprConstant { + pub range: TextRange, + pub value: Constant, + pub kind: Option, +} + +impl Node for ExprConstant { + const NAME: &'static str = "Constant"; + const FIELD_NAMES: &'static [&'static str] = &["value", "kind"]; +} +impl From for Expr { + fn from(payload: ExprConstant) -> Self { + Expr::Constant(payload) + } +} +impl From for Ast { + fn from(payload: ExprConstant) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Attribute](https://docs.python.org/3/library/ast.html#ast.Attribute) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprAttribute { + pub range: TextRange, + pub value: Box, + pub attr: Identifier, + pub ctx: ExprContext, +} + +impl Node for ExprAttribute { + const NAME: &'static str = "Attribute"; + const FIELD_NAMES: &'static [&'static str] = &["value", "attr", "ctx"]; +} +impl From for Expr { + fn from(payload: ExprAttribute) -> Self { + Expr::Attribute(payload) + } +} +impl From for Ast { + fn from(payload: ExprAttribute) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Subscript](https://docs.python.org/3/library/ast.html#ast.Subscript) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprSubscript { + pub range: TextRange, + pub value: Box, + pub slice: Box, + pub ctx: ExprContext, +} + +impl Node for ExprSubscript { + const NAME: &'static str = "Subscript"; + const FIELD_NAMES: &'static [&'static str] = &["value", "slice", "ctx"]; +} +impl From for Expr { + fn from(payload: ExprSubscript) -> Self { + Expr::Subscript(payload) + } +} +impl From for Ast { + fn from(payload: ExprSubscript) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Starred](https://docs.python.org/3/library/ast.html#ast.Starred) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprStarred { + pub range: TextRange, + pub value: Box, + pub ctx: ExprContext, +} + +impl Node for ExprStarred { + const NAME: &'static str = "Starred"; + const FIELD_NAMES: &'static [&'static str] = &["value", "ctx"]; +} +impl From for Expr { + fn from(payload: ExprStarred) -> Self { + Expr::Starred(payload) + } +} +impl From for Ast { + fn from(payload: ExprStarred) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Name](https://docs.python.org/3/library/ast.html#ast.Name) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprName { + pub range: TextRange, + pub id: String, + pub ctx: ExprContext, +} + +impl Node for ExprName { + const NAME: &'static str = "Name"; + const FIELD_NAMES: &'static [&'static str] = &["id", "ctx"]; +} +impl From for Expr { + fn from(payload: ExprName) -> Self { + Expr::Name(payload) + } +} +impl From for Ast { + fn from(payload: ExprName) -> Self { + Expr::from(payload).into() + } +} + +/// See also [List](https://docs.python.org/3/library/ast.html#ast.List) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprList { + pub range: TextRange, + pub elts: Vec, + pub ctx: ExprContext, +} + +impl Node for ExprList { + const NAME: &'static str = "List"; + const FIELD_NAMES: &'static [&'static str] = &["elts", "ctx"]; +} +impl From for Expr { + fn from(payload: ExprList) -> Self { + Expr::List(payload) + } +} +impl From for Ast { + fn from(payload: ExprList) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Tuple](https://docs.python.org/3/library/ast.html#ast.Tuple) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprTuple { + pub range: TextRange, + pub elts: Vec, + pub ctx: ExprContext, +} + +impl Node for ExprTuple { + const NAME: &'static str = "Tuple"; + const FIELD_NAMES: &'static [&'static str] = &["elts", "ctx"]; +} +impl From for Expr { + fn from(payload: ExprTuple) -> Self { + Expr::Tuple(payload) + } +} +impl From for Ast { + fn from(payload: ExprTuple) -> Self { + Expr::from(payload).into() + } +} + +/// See also [Slice](https://docs.python.org/3/library/ast.html#ast.Slice) +#[derive(Clone, Debug, PartialEq)] +pub struct ExprSlice { + pub range: TextRange, + pub lower: Option>, + pub upper: Option>, + pub step: Option>, +} + +impl Node for ExprSlice { + const NAME: &'static str = "Slice"; + const FIELD_NAMES: &'static [&'static str] = &["lower", "upper", "step"]; +} +impl From for Expr { + fn from(payload: ExprSlice) -> Self { + Expr::Slice(payload) + } +} +impl From for Ast { + fn from(payload: ExprSlice) -> Self { + Expr::from(payload).into() + } +} + +impl Node for Expr { + const NAME: &'static str = "expr"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} + +/// See also [expr_context](https://docs.python.org/3/library/ast.html#ast.expr_context) +#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] +pub enum ExprContext { + Load, + Store, + Del, +} +impl ExprContext { + #[inline] + pub const fn load(&self) -> Option { + match self { + ExprContext::Load => Some(ExprContextLoad), + _ => None, + } + } + + #[inline] + pub const fn store(&self) -> Option { + match self { + ExprContext::Store => Some(ExprContextStore), + _ => None, + } + } + + #[inline] + pub const fn del(&self) -> Option { + match self { + ExprContext::Del => Some(ExprContextDel), + _ => None, + } + } +} + +pub struct ExprContextLoad; +impl From for ExprContext { + fn from(_: ExprContextLoad) -> Self { + ExprContext::Load + } +} +impl From for Ast { + fn from(_: ExprContextLoad) -> Self { + ExprContext::Load.into() + } +} +impl Node for ExprContextLoad { + const NAME: &'static str = "Load"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for ExprContextLoad { + #[inline] + fn eq(&self, other: &ExprContext) -> bool { + matches!(other, ExprContext::Load) + } +} + +pub struct ExprContextStore; +impl From for ExprContext { + fn from(_: ExprContextStore) -> Self { + ExprContext::Store + } +} +impl From for Ast { + fn from(_: ExprContextStore) -> Self { + ExprContext::Store.into() + } +} +impl Node for ExprContextStore { + const NAME: &'static str = "Store"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for ExprContextStore { + #[inline] + fn eq(&self, other: &ExprContext) -> bool { + matches!(other, ExprContext::Store) + } +} + +pub struct ExprContextDel; +impl From for ExprContext { + fn from(_: ExprContextDel) -> Self { + ExprContext::Del + } +} +impl From for Ast { + fn from(_: ExprContextDel) -> Self { + ExprContext::Del.into() + } +} +impl Node for ExprContextDel { + const NAME: &'static str = "Del"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for ExprContextDel { + #[inline] + fn eq(&self, other: &ExprContext) -> bool { + matches!(other, ExprContext::Del) + } +} + +impl Node for ExprContext { + const NAME: &'static str = "expr_context"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} + +/// See also [boolop](https://docs.python.org/3/library/ast.html#ast.boolop) +#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] +pub enum BoolOp { + And, + Or, +} +impl BoolOp { + #[inline] + pub const fn and(&self) -> Option { + match self { + BoolOp::And => Some(BoolOpAnd), + _ => None, + } + } + + #[inline] + pub const fn or(&self) -> Option { + match self { + BoolOp::Or => Some(BoolOpOr), + _ => None, + } + } +} + +pub struct BoolOpAnd; +impl From for BoolOp { + fn from(_: BoolOpAnd) -> Self { + BoolOp::And + } +} +impl From for Ast { + fn from(_: BoolOpAnd) -> Self { + BoolOp::And.into() + } +} +impl Node for BoolOpAnd { + const NAME: &'static str = "And"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for BoolOpAnd { + #[inline] + fn eq(&self, other: &BoolOp) -> bool { + matches!(other, BoolOp::And) + } +} + +pub struct BoolOpOr; +impl From for BoolOp { + fn from(_: BoolOpOr) -> Self { + BoolOp::Or + } +} +impl From for Ast { + fn from(_: BoolOpOr) -> Self { + BoolOp::Or.into() + } +} +impl Node for BoolOpOr { + const NAME: &'static str = "Or"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for BoolOpOr { + #[inline] + fn eq(&self, other: &BoolOp) -> bool { + matches!(other, BoolOp::Or) + } +} + +impl Node for BoolOp { + const NAME: &'static str = "boolop"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} + +/// See also [operator](https://docs.python.org/3/library/ast.html#ast.operator) +#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] +pub enum Operator { + Add, + Sub, + Mult, + MatMult, + Div, + Mod, + Pow, + LShift, + RShift, + BitOr, + BitXor, + BitAnd, + FloorDiv, +} +impl Operator { + #[inline] + pub const fn operator_add(&self) -> Option { + match self { + Operator::Add => Some(OperatorAdd), + _ => None, + } + } + + #[inline] + pub const fn operator_sub(&self) -> Option { + match self { + Operator::Sub => Some(OperatorSub), + _ => None, + } + } + + #[inline] + pub const fn operator_mult(&self) -> Option { + match self { + Operator::Mult => Some(OperatorMult), + _ => None, + } + } + + #[inline] + pub const fn operator_mat_mult(&self) -> Option { + match self { + Operator::MatMult => Some(OperatorMatMult), + _ => None, + } + } + + #[inline] + pub const fn operator_div(&self) -> Option { + match self { + Operator::Div => Some(OperatorDiv), + _ => None, + } + } + + #[inline] + pub const fn operator_mod(&self) -> Option { + match self { + Operator::Mod => Some(OperatorMod), + _ => None, + } + } + + #[inline] + pub const fn operator_pow(&self) -> Option { + match self { + Operator::Pow => Some(OperatorPow), + _ => None, + } + } + + #[inline] + pub const fn operator_l_shift(&self) -> Option { + match self { + Operator::LShift => Some(OperatorLShift), + _ => None, + } + } + + #[inline] + pub const fn operator_r_shift(&self) -> Option { + match self { + Operator::RShift => Some(OperatorRShift), + _ => None, + } + } + + #[inline] + pub const fn operator_bit_or(&self) -> Option { + match self { + Operator::BitOr => Some(OperatorBitOr), + _ => None, + } + } + + #[inline] + pub const fn operator_bit_xor(&self) -> Option { + match self { + Operator::BitXor => Some(OperatorBitXor), + _ => None, + } + } + + #[inline] + pub const fn operator_bit_and(&self) -> Option { + match self { + Operator::BitAnd => Some(OperatorBitAnd), + _ => None, + } + } + + #[inline] + pub const fn operator_floor_div(&self) -> Option { + match self { + Operator::FloorDiv => Some(OperatorFloorDiv), + _ => None, + } + } +} + +pub struct OperatorAdd; +impl From for Operator { + fn from(_: OperatorAdd) -> Self { + Operator::Add + } +} +impl From for Ast { + fn from(_: OperatorAdd) -> Self { + Operator::Add.into() + } +} +impl Node for OperatorAdd { + const NAME: &'static str = "Add"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorAdd { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::Add) + } +} + +pub struct OperatorSub; +impl From for Operator { + fn from(_: OperatorSub) -> Self { + Operator::Sub + } +} +impl From for Ast { + fn from(_: OperatorSub) -> Self { + Operator::Sub.into() + } +} +impl Node for OperatorSub { + const NAME: &'static str = "Sub"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorSub { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::Sub) + } +} + +pub struct OperatorMult; +impl From for Operator { + fn from(_: OperatorMult) -> Self { + Operator::Mult + } +} +impl From for Ast { + fn from(_: OperatorMult) -> Self { + Operator::Mult.into() + } +} +impl Node for OperatorMult { + const NAME: &'static str = "Mult"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorMult { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::Mult) + } +} + +pub struct OperatorMatMult; +impl From for Operator { + fn from(_: OperatorMatMult) -> Self { + Operator::MatMult + } +} +impl From for Ast { + fn from(_: OperatorMatMult) -> Self { + Operator::MatMult.into() + } +} +impl Node for OperatorMatMult { + const NAME: &'static str = "MatMult"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorMatMult { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::MatMult) + } +} + +pub struct OperatorDiv; +impl From for Operator { + fn from(_: OperatorDiv) -> Self { + Operator::Div + } +} +impl From for Ast { + fn from(_: OperatorDiv) -> Self { + Operator::Div.into() + } +} +impl Node for OperatorDiv { + const NAME: &'static str = "Div"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorDiv { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::Div) + } +} + +pub struct OperatorMod; +impl From for Operator { + fn from(_: OperatorMod) -> Self { + Operator::Mod + } +} +impl From for Ast { + fn from(_: OperatorMod) -> Self { + Operator::Mod.into() + } +} +impl Node for OperatorMod { + const NAME: &'static str = "Mod"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorMod { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::Mod) + } +} + +pub struct OperatorPow; +impl From for Operator { + fn from(_: OperatorPow) -> Self { + Operator::Pow + } +} +impl From for Ast { + fn from(_: OperatorPow) -> Self { + Operator::Pow.into() + } +} +impl Node for OperatorPow { + const NAME: &'static str = "Pow"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorPow { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::Pow) + } +} + +pub struct OperatorLShift; +impl From for Operator { + fn from(_: OperatorLShift) -> Self { + Operator::LShift + } +} +impl From for Ast { + fn from(_: OperatorLShift) -> Self { + Operator::LShift.into() + } +} +impl Node for OperatorLShift { + const NAME: &'static str = "LShift"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorLShift { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::LShift) + } +} + +pub struct OperatorRShift; +impl From for Operator { + fn from(_: OperatorRShift) -> Self { + Operator::RShift + } +} +impl From for Ast { + fn from(_: OperatorRShift) -> Self { + Operator::RShift.into() + } +} +impl Node for OperatorRShift { + const NAME: &'static str = "RShift"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorRShift { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::RShift) + } +} + +pub struct OperatorBitOr; +impl From for Operator { + fn from(_: OperatorBitOr) -> Self { + Operator::BitOr + } +} +impl From for Ast { + fn from(_: OperatorBitOr) -> Self { + Operator::BitOr.into() + } +} +impl Node for OperatorBitOr { + const NAME: &'static str = "BitOr"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorBitOr { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::BitOr) + } +} + +pub struct OperatorBitXor; +impl From for Operator { + fn from(_: OperatorBitXor) -> Self { + Operator::BitXor + } +} +impl From for Ast { + fn from(_: OperatorBitXor) -> Self { + Operator::BitXor.into() + } +} +impl Node for OperatorBitXor { + const NAME: &'static str = "BitXor"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorBitXor { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::BitXor) + } +} + +pub struct OperatorBitAnd; +impl From for Operator { + fn from(_: OperatorBitAnd) -> Self { + Operator::BitAnd + } +} +impl From for Ast { + fn from(_: OperatorBitAnd) -> Self { + Operator::BitAnd.into() + } +} +impl Node for OperatorBitAnd { + const NAME: &'static str = "BitAnd"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorBitAnd { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::BitAnd) + } +} + +pub struct OperatorFloorDiv; +impl From for Operator { + fn from(_: OperatorFloorDiv) -> Self { + Operator::FloorDiv + } +} +impl From for Ast { + fn from(_: OperatorFloorDiv) -> Self { + Operator::FloorDiv.into() + } +} +impl Node for OperatorFloorDiv { + const NAME: &'static str = "FloorDiv"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for OperatorFloorDiv { + #[inline] + fn eq(&self, other: &Operator) -> bool { + matches!(other, Operator::FloorDiv) + } +} + +impl Node for Operator { + const NAME: &'static str = "operator"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} + +/// See also [unaryop](https://docs.python.org/3/library/ast.html#ast.unaryop) +#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] +pub enum UnaryOp { + Invert, + Not, + UAdd, + USub, +} +impl UnaryOp { + #[inline] + pub const fn invert(&self) -> Option { + match self { + UnaryOp::Invert => Some(UnaryOpInvert), + _ => None, + } + } + + #[inline] + pub const fn not(&self) -> Option { + match self { + UnaryOp::Not => Some(UnaryOpNot), + _ => None, + } + } + + #[inline] + pub const fn u_add(&self) -> Option { + match self { + UnaryOp::UAdd => Some(UnaryOpUAdd), + _ => None, + } + } + + #[inline] + pub const fn u_sub(&self) -> Option { + match self { + UnaryOp::USub => Some(UnaryOpUSub), + _ => None, + } + } +} + +pub struct UnaryOpInvert; +impl From for UnaryOp { + fn from(_: UnaryOpInvert) -> Self { + UnaryOp::Invert + } +} +impl From for Ast { + fn from(_: UnaryOpInvert) -> Self { + UnaryOp::Invert.into() + } +} +impl Node for UnaryOpInvert { + const NAME: &'static str = "Invert"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for UnaryOpInvert { + #[inline] + fn eq(&self, other: &UnaryOp) -> bool { + matches!(other, UnaryOp::Invert) + } +} + +pub struct UnaryOpNot; +impl From for UnaryOp { + fn from(_: UnaryOpNot) -> Self { + UnaryOp::Not + } +} +impl From for Ast { + fn from(_: UnaryOpNot) -> Self { + UnaryOp::Not.into() + } +} +impl Node for UnaryOpNot { + const NAME: &'static str = "Not"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for UnaryOpNot { + #[inline] + fn eq(&self, other: &UnaryOp) -> bool { + matches!(other, UnaryOp::Not) + } +} + +pub struct UnaryOpUAdd; +impl From for UnaryOp { + fn from(_: UnaryOpUAdd) -> Self { + UnaryOp::UAdd + } +} +impl From for Ast { + fn from(_: UnaryOpUAdd) -> Self { + UnaryOp::UAdd.into() + } +} +impl Node for UnaryOpUAdd { + const NAME: &'static str = "UAdd"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for UnaryOpUAdd { + #[inline] + fn eq(&self, other: &UnaryOp) -> bool { + matches!(other, UnaryOp::UAdd) + } +} + +pub struct UnaryOpUSub; +impl From for UnaryOp { + fn from(_: UnaryOpUSub) -> Self { + UnaryOp::USub + } +} +impl From for Ast { + fn from(_: UnaryOpUSub) -> Self { + UnaryOp::USub.into() + } +} +impl Node for UnaryOpUSub { + const NAME: &'static str = "USub"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for UnaryOpUSub { + #[inline] + fn eq(&self, other: &UnaryOp) -> bool { + matches!(other, UnaryOp::USub) + } +} + +impl Node for UnaryOp { + const NAME: &'static str = "unaryop"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} + +/// See also [cmpop](https://docs.python.org/3/library/ast.html#ast.cmpop) +#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] +pub enum CmpOp { + Eq, + NotEq, + Lt, + LtE, + Gt, + GtE, + Is, + IsNot, + In, + NotIn, +} +impl CmpOp { + #[inline] + pub const fn cmp_op_eq(&self) -> Option { + match self { + CmpOp::Eq => Some(CmpOpEq), + _ => None, + } + } + + #[inline] + pub const fn cmp_op_not_eq(&self) -> Option { + match self { + CmpOp::NotEq => Some(CmpOpNotEq), + _ => None, + } + } + + #[inline] + pub const fn cmp_op_lt(&self) -> Option { + match self { + CmpOp::Lt => Some(CmpOpLt), + _ => None, + } + } + + #[inline] + pub const fn cmp_op_lt_e(&self) -> Option { + match self { + CmpOp::LtE => Some(CmpOpLtE), + _ => None, + } + } + + #[inline] + pub const fn cmp_op_gt(&self) -> Option { + match self { + CmpOp::Gt => Some(CmpOpGt), + _ => None, + } + } + + #[inline] + pub const fn cmp_op_gt_e(&self) -> Option { + match self { + CmpOp::GtE => Some(CmpOpGtE), + _ => None, + } + } + + #[inline] + pub const fn cmp_op_is(&self) -> Option { + match self { + CmpOp::Is => Some(CmpOpIs), + _ => None, + } + } + + #[inline] + pub const fn cmp_op_is_not(&self) -> Option { + match self { + CmpOp::IsNot => Some(CmpOpIsNot), + _ => None, + } + } + + #[inline] + pub const fn cmp_op_in(&self) -> Option { + match self { + CmpOp::In => Some(CmpOpIn), + _ => None, + } + } + + #[inline] + pub const fn cmp_op_not_in(&self) -> Option { + match self { + CmpOp::NotIn => Some(CmpOpNotIn), + _ => None, + } + } +} + +pub struct CmpOpEq; +impl From for CmpOp { + fn from(_: CmpOpEq) -> Self { + CmpOp::Eq + } +} +impl From for Ast { + fn from(_: CmpOpEq) -> Self { + CmpOp::Eq.into() + } +} +impl Node for CmpOpEq { + const NAME: &'static str = "Eq"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for CmpOpEq { + #[inline] + fn eq(&self, other: &CmpOp) -> bool { + matches!(other, CmpOp::Eq) + } +} + +pub struct CmpOpNotEq; +impl From for CmpOp { + fn from(_: CmpOpNotEq) -> Self { + CmpOp::NotEq + } +} +impl From for Ast { + fn from(_: CmpOpNotEq) -> Self { + CmpOp::NotEq.into() + } +} +impl Node for CmpOpNotEq { + const NAME: &'static str = "NotEq"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for CmpOpNotEq { + #[inline] + fn eq(&self, other: &CmpOp) -> bool { + matches!(other, CmpOp::NotEq) + } +} + +pub struct CmpOpLt; +impl From for CmpOp { + fn from(_: CmpOpLt) -> Self { + CmpOp::Lt + } +} +impl From for Ast { + fn from(_: CmpOpLt) -> Self { + CmpOp::Lt.into() + } +} +impl Node for CmpOpLt { + const NAME: &'static str = "Lt"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for CmpOpLt { + #[inline] + fn eq(&self, other: &CmpOp) -> bool { + matches!(other, CmpOp::Lt) + } +} + +pub struct CmpOpLtE; +impl From for CmpOp { + fn from(_: CmpOpLtE) -> Self { + CmpOp::LtE + } +} +impl From for Ast { + fn from(_: CmpOpLtE) -> Self { + CmpOp::LtE.into() + } +} +impl Node for CmpOpLtE { + const NAME: &'static str = "LtE"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for CmpOpLtE { + #[inline] + fn eq(&self, other: &CmpOp) -> bool { + matches!(other, CmpOp::LtE) + } +} + +pub struct CmpOpGt; +impl From for CmpOp { + fn from(_: CmpOpGt) -> Self { + CmpOp::Gt + } +} +impl From for Ast { + fn from(_: CmpOpGt) -> Self { + CmpOp::Gt.into() + } +} +impl Node for CmpOpGt { + const NAME: &'static str = "Gt"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for CmpOpGt { + #[inline] + fn eq(&self, other: &CmpOp) -> bool { + matches!(other, CmpOp::Gt) + } +} + +pub struct CmpOpGtE; +impl From for CmpOp { + fn from(_: CmpOpGtE) -> Self { + CmpOp::GtE + } +} +impl From for Ast { + fn from(_: CmpOpGtE) -> Self { + CmpOp::GtE.into() + } +} +impl Node for CmpOpGtE { + const NAME: &'static str = "GtE"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for CmpOpGtE { + #[inline] + fn eq(&self, other: &CmpOp) -> bool { + matches!(other, CmpOp::GtE) + } +} + +pub struct CmpOpIs; +impl From for CmpOp { + fn from(_: CmpOpIs) -> Self { + CmpOp::Is + } +} +impl From for Ast { + fn from(_: CmpOpIs) -> Self { + CmpOp::Is.into() + } +} +impl Node for CmpOpIs { + const NAME: &'static str = "Is"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for CmpOpIs { + #[inline] + fn eq(&self, other: &CmpOp) -> bool { + matches!(other, CmpOp::Is) + } +} + +pub struct CmpOpIsNot; +impl From for CmpOp { + fn from(_: CmpOpIsNot) -> Self { + CmpOp::IsNot + } +} +impl From for Ast { + fn from(_: CmpOpIsNot) -> Self { + CmpOp::IsNot.into() + } +} +impl Node for CmpOpIsNot { + const NAME: &'static str = "IsNot"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for CmpOpIsNot { + #[inline] + fn eq(&self, other: &CmpOp) -> bool { + matches!(other, CmpOp::IsNot) + } +} + +pub struct CmpOpIn; +impl From for CmpOp { + fn from(_: CmpOpIn) -> Self { + CmpOp::In + } +} +impl From for Ast { + fn from(_: CmpOpIn) -> Self { + CmpOp::In.into() + } +} +impl Node for CmpOpIn { + const NAME: &'static str = "In"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for CmpOpIn { + #[inline] + fn eq(&self, other: &CmpOp) -> bool { + matches!(other, CmpOp::In) + } +} + +pub struct CmpOpNotIn; +impl From for CmpOp { + fn from(_: CmpOpNotIn) -> Self { + CmpOp::NotIn + } +} +impl From for Ast { + fn from(_: CmpOpNotIn) -> Self { + CmpOp::NotIn.into() + } +} +impl Node for CmpOpNotIn { + const NAME: &'static str = "NotIn"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} +impl std::cmp::PartialEq for CmpOpNotIn { + #[inline] + fn eq(&self, other: &CmpOp) -> bool { + matches!(other, CmpOp::NotIn) + } +} + +impl Node for CmpOp { + const NAME: &'static str = "cmpop"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} + +/// See also [comprehension](https://docs.python.org/3/library/ast.html#ast.comprehension) +#[derive(Clone, Debug, PartialEq)] +pub struct Comprehension { + pub range: TextRange, + pub target: Expr, + pub iter: Expr, + pub ifs: Vec, + pub is_async: bool, +} + +impl Node for Comprehension { + const NAME: &'static str = "comprehension"; + const FIELD_NAMES: &'static [&'static str] = &["target", "iter", "ifs", "is_async"]; +} + +/// See also [excepthandler](https://docs.python.org/3/library/ast.html#ast.excepthandler) +#[derive(Clone, Debug, PartialEq, is_macro::Is)] +pub enum ExceptHandler { + ExceptHandler(ExceptHandlerExceptHandler), +} + +/// See also [ExceptHandler](https://docs.python.org/3/library/ast.html#ast.ExceptHandler) +#[derive(Clone, Debug, PartialEq)] +pub struct ExceptHandlerExceptHandler { + pub range: TextRange, + pub type_: Option>, + pub name: Option, + pub body: Vec, +} + +impl Node for ExceptHandlerExceptHandler { + const NAME: &'static str = "ExceptHandler"; + const FIELD_NAMES: &'static [&'static str] = &["type", "name", "body"]; +} +impl From for ExceptHandler { + fn from(payload: ExceptHandlerExceptHandler) -> Self { + ExceptHandler::ExceptHandler(payload) + } +} +impl From for Ast { + fn from(payload: ExceptHandlerExceptHandler) -> Self { + ExceptHandler::from(payload).into() + } +} + +impl Node for ExceptHandler { + const NAME: &'static str = "excepthandler"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} + +/// See also [arguments](https://docs.python.org/3/library/ast.html#ast.arguments) +#[derive(Clone, Debug, PartialEq)] +pub struct PythonArguments { + pub range: TextRange, + pub posonlyargs: Vec, + pub args: Vec, + pub vararg: Option>, + pub kwonlyargs: Vec, + pub kw_defaults: Vec, + pub kwarg: Option>, + pub defaults: Vec, +} + +impl Node for PythonArguments { + const NAME: &'static str = "arguments"; + const FIELD_NAMES: &'static [&'static str] = &[ + "posonlyargs", + "args", + "vararg", + "kwonlyargs", + "kw_defaults", + "kwarg", + "defaults", + ]; +} + +/// See also [arg](https://docs.python.org/3/library/ast.html#ast.arg) +#[derive(Clone, Debug, PartialEq)] +pub struct Arg { + pub range: TextRange, + pub arg: Identifier, + pub annotation: Option>, + pub type_comment: Option, +} + +impl Node for Arg { + const NAME: &'static str = "arg"; + const FIELD_NAMES: &'static [&'static str] = &["arg", "annotation", "type_comment"]; +} + +/// See also [keyword](https://docs.python.org/3/library/ast.html#ast.keyword) +#[derive(Clone, Debug, PartialEq)] +pub struct Keyword { + pub range: TextRange, + pub arg: Option, + pub value: Expr, +} + +impl Node for Keyword { + const NAME: &'static str = "keyword"; + const FIELD_NAMES: &'static [&'static str] = &["arg", "value"]; +} + +/// See also [alias](https://docs.python.org/3/library/ast.html#ast.alias) +#[derive(Clone, Debug, PartialEq)] +pub struct Alias { + pub range: TextRange, + pub name: Identifier, + pub asname: Option, +} + +impl Node for Alias { + const NAME: &'static str = "alias"; + const FIELD_NAMES: &'static [&'static str] = &["name", "asname"]; +} + +/// See also [withitem](https://docs.python.org/3/library/ast.html#ast.withitem) +#[derive(Clone, Debug, PartialEq)] +pub struct WithItem { + pub range: TextRange, + pub context_expr: Expr, + pub optional_vars: Option>, +} + +impl Node for WithItem { + const NAME: &'static str = "withitem"; + const FIELD_NAMES: &'static [&'static str] = &["context_expr", "optional_vars"]; +} + +/// See also [match_case](https://docs.python.org/3/library/ast.html#ast.match_case) +#[derive(Clone, Debug, PartialEq)] +pub struct MatchCase { + pub range: TextRange, + pub pattern: Pattern, + pub guard: Option>, + pub body: Vec, +} + +impl Node for MatchCase { + const NAME: &'static str = "match_case"; + const FIELD_NAMES: &'static [&'static str] = &["pattern", "guard", "body"]; +} + +/// See also [pattern](https://docs.python.org/3/library/ast.html#ast.pattern) +#[derive(Clone, Debug, PartialEq, is_macro::Is)] +pub enum Pattern { + MatchValue(PatternMatchValue), + MatchSingleton(PatternMatchSingleton), + MatchSequence(PatternMatchSequence), + MatchMapping(PatternMatchMapping), + MatchClass(PatternMatchClass), + MatchStar(PatternMatchStar), + MatchAs(PatternMatchAs), + MatchOr(PatternMatchOr), +} + +/// See also [MatchValue](https://docs.python.org/3/library/ast.html#ast.MatchValue) +#[derive(Clone, Debug, PartialEq)] +pub struct PatternMatchValue { + pub range: TextRange, + pub value: Box, +} + +impl Node for PatternMatchValue { + const NAME: &'static str = "MatchValue"; + const FIELD_NAMES: &'static [&'static str] = &["value"]; +} +impl From for Pattern { + fn from(payload: PatternMatchValue) -> Self { + Pattern::MatchValue(payload) + } +} +impl From for Ast { + fn from(payload: PatternMatchValue) -> Self { + Pattern::from(payload).into() + } +} + +/// See also [MatchSingleton](https://docs.python.org/3/library/ast.html#ast.MatchSingleton) +#[derive(Clone, Debug, PartialEq)] +pub struct PatternMatchSingleton { + pub range: TextRange, + pub value: Constant, +} + +impl Node for PatternMatchSingleton { + const NAME: &'static str = "MatchSingleton"; + const FIELD_NAMES: &'static [&'static str] = &["value"]; +} +impl From for Pattern { + fn from(payload: PatternMatchSingleton) -> Self { + Pattern::MatchSingleton(payload) + } +} +impl From for Ast { + fn from(payload: PatternMatchSingleton) -> Self { + Pattern::from(payload).into() + } +} + +/// See also [MatchSequence](https://docs.python.org/3/library/ast.html#ast.MatchSequence) +#[derive(Clone, Debug, PartialEq)] +pub struct PatternMatchSequence { + pub range: TextRange, + pub patterns: Vec, +} + +impl Node for PatternMatchSequence { + const NAME: &'static str = "MatchSequence"; + const FIELD_NAMES: &'static [&'static str] = &["patterns"]; +} +impl From for Pattern { + fn from(payload: PatternMatchSequence) -> Self { + Pattern::MatchSequence(payload) + } +} +impl From for Ast { + fn from(payload: PatternMatchSequence) -> Self { + Pattern::from(payload).into() + } +} + +/// See also [MatchMapping](https://docs.python.org/3/library/ast.html#ast.MatchMapping) +#[derive(Clone, Debug, PartialEq)] +pub struct PatternMatchMapping { + pub range: TextRange, + pub keys: Vec, + pub patterns: Vec, + pub rest: Option, +} + +impl Node for PatternMatchMapping { + const NAME: &'static str = "MatchMapping"; + const FIELD_NAMES: &'static [&'static str] = &["keys", "patterns", "rest"]; +} +impl From for Pattern { + fn from(payload: PatternMatchMapping) -> Self { + Pattern::MatchMapping(payload) + } +} +impl From for Ast { + fn from(payload: PatternMatchMapping) -> Self { + Pattern::from(payload).into() + } +} + +/// See also [MatchClass](https://docs.python.org/3/library/ast.html#ast.MatchClass) +#[derive(Clone, Debug, PartialEq)] +pub struct PatternMatchClass { + pub range: TextRange, + pub cls: Box, + pub patterns: Vec, + pub kwd_attrs: Vec, + pub kwd_patterns: Vec, +} + +impl Node for PatternMatchClass { + const NAME: &'static str = "MatchClass"; + const FIELD_NAMES: &'static [&'static str] = &["cls", "patterns", "kwd_attrs", "kwd_patterns"]; +} +impl From for Pattern { + fn from(payload: PatternMatchClass) -> Self { + Pattern::MatchClass(payload) + } +} +impl From for Ast { + fn from(payload: PatternMatchClass) -> Self { + Pattern::from(payload).into() + } +} + +/// See also [MatchStar](https://docs.python.org/3/library/ast.html#ast.MatchStar) +#[derive(Clone, Debug, PartialEq)] +pub struct PatternMatchStar { + pub range: TextRange, + pub name: Option, +} + +impl Node for PatternMatchStar { + const NAME: &'static str = "MatchStar"; + const FIELD_NAMES: &'static [&'static str] = &["name"]; +} +impl From for Pattern { + fn from(payload: PatternMatchStar) -> Self { + Pattern::MatchStar(payload) + } +} +impl From for Ast { + fn from(payload: PatternMatchStar) -> Self { + Pattern::from(payload).into() + } +} + +/// See also [MatchAs](https://docs.python.org/3/library/ast.html#ast.MatchAs) +#[derive(Clone, Debug, PartialEq)] +pub struct PatternMatchAs { + pub range: TextRange, + pub pattern: Option>, + pub name: Option, +} + +impl Node for PatternMatchAs { + const NAME: &'static str = "MatchAs"; + const FIELD_NAMES: &'static [&'static str] = &["pattern", "name"]; +} +impl From for Pattern { + fn from(payload: PatternMatchAs) -> Self { + Pattern::MatchAs(payload) + } +} +impl From for Ast { + fn from(payload: PatternMatchAs) -> Self { + Pattern::from(payload).into() + } +} + +/// See also [MatchOr](https://docs.python.org/3/library/ast.html#ast.MatchOr) +#[derive(Clone, Debug, PartialEq)] +pub struct PatternMatchOr { + pub range: TextRange, + pub patterns: Vec, +} + +impl Node for PatternMatchOr { + const NAME: &'static str = "MatchOr"; + const FIELD_NAMES: &'static [&'static str] = &["patterns"]; +} +impl From for Pattern { + fn from(payload: PatternMatchOr) -> Self { + Pattern::MatchOr(payload) + } +} +impl From for Ast { + fn from(payload: PatternMatchOr) -> Self { + Pattern::from(payload).into() + } +} + +impl Node for Pattern { + const NAME: &'static str = "pattern"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} + +/// See also [type_ignore](https://docs.python.org/3/library/ast.html#ast.type_ignore) +#[derive(Clone, Debug, PartialEq, is_macro::Is)] +pub enum TypeIgnore { + TypeIgnore(TypeIgnoreTypeIgnore), +} + +/// See also [TypeIgnore](https://docs.python.org/3/library/ast.html#ast.TypeIgnore) +#[derive(Clone, Debug, PartialEq)] +pub struct TypeIgnoreTypeIgnore { + pub range: TextRange, + pub lineno: Int, + pub tag: String, +} + +impl Node for TypeIgnoreTypeIgnore { + const NAME: &'static str = "TypeIgnore"; + const FIELD_NAMES: &'static [&'static str] = &["lineno", "tag"]; +} +impl From for TypeIgnore { + fn from(payload: TypeIgnoreTypeIgnore) -> Self { + TypeIgnore::TypeIgnore(payload) + } +} +impl From for Ast { + fn from(payload: TypeIgnoreTypeIgnore) -> Self { + TypeIgnore::from(payload).into() + } +} + +impl Node for TypeIgnore { + const NAME: &'static str = "type_ignore"; + const FIELD_NAMES: &'static [&'static str] = &[]; +} + +/// See also [decorator](https://docs.python.org/3/library/ast.html#ast.decorator) +#[derive(Clone, Debug, PartialEq)] +pub struct Decorator { + pub range: TextRange, + pub expression: Expr, +} + +impl Node for Decorator { + const NAME: &'static str = "decorator"; + const FIELD_NAMES: &'static [&'static str] = &["expression"]; +} + +/// An alternative type of AST `arguments`. This is parser-friendly and human-friendly definition of function arguments. +/// This form also has advantage to implement pre-order traverse. +/// `defaults` and `kw_defaults` fields are removed and the default values are placed under each `arg_with_default` typed argument. +/// `vararg` and `kwarg` are still typed as `arg` because they never can have a default value. +/// +/// The matching Python style AST type is [PythonArguments]. While [PythonArguments] has ordered `kwonlyargs` fields by +/// default existence, [Arguments] has location-ordered kwonlyargs fields. +/// +/// NOTE: This type is different from original Python AST. + +#[derive(Clone, Debug, PartialEq)] +pub struct Arguments { + pub range: TextRange, + pub posonlyargs: Vec, + pub args: Vec, + pub vararg: Option>, + pub kwonlyargs: Vec, + pub kwarg: Option>, +} + +impl Node for Arguments { + const NAME: &'static str = "alt:arguments"; + const FIELD_NAMES: &'static [&'static str] = + &["posonlyargs", "args", "vararg", "kwonlyargs", "kwarg"]; +} + +/// An alternative type of AST `arg`. This is used for each function argument that might have a default value. +/// Used by `Arguments` original type. +/// +/// NOTE: This type is different from original Python AST. + +#[derive(Clone, Debug, PartialEq)] +pub struct ArgWithDefault { + pub range: TextRange, + pub def: Arg, + pub default: Option>, +} + +impl Node for ArgWithDefault { + const NAME: &'static str = "arg_with_default"; + const FIELD_NAMES: &'static [&'static str] = &["def", "default"]; +} + pub type Suite = Vec; impl CmpOp { @@ -85,5 +3222,3 @@ impl Arguments { (args, with_defaults) } } - -include!("gen/generic.rs"); diff --git a/ast/src/ranged.rs b/ast/src/ranged.rs index 560e14c5eb..b7b7949f13 100644 --- a/ast/src/ranged.rs +++ b/ast/src/ranged.rs @@ -1,3 +1,5 @@ +// This file was originally generated from asdl by a python script, but we now edit it manually + use crate::text_size::{TextRange, TextSize}; pub use crate::builtin::*; @@ -29,4 +31,503 @@ where } } -include!("gen/ranged.rs"); +impl Ranged for crate::generic::ModModule { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ModInteractive { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ModExpression { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ModFunctionType { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::Mod { + fn range(&self) -> TextRange { + match self { + Self::Module(node) => node.range(), + Self::Interactive(node) => node.range(), + Self::Expression(node) => node.range(), + Self::FunctionType(node) => node.range(), + } + } +} + +impl Ranged for crate::generic::StmtFunctionDef { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtAsyncFunctionDef { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtClassDef { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtReturn { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtDelete { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtAssign { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtAugAssign { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtAnnAssign { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtFor { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtAsyncFor { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtWhile { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtIf { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtWith { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtAsyncWith { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtMatch { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtRaise { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtTry { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtTryStar { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtAssert { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtImport { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtImportFrom { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtGlobal { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtNonlocal { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtExpr { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtPass { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtBreak { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::StmtContinue { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::Stmt { + fn range(&self) -> TextRange { + match self { + Self::FunctionDef(node) => node.range(), + Self::AsyncFunctionDef(node) => node.range(), + Self::ClassDef(node) => node.range(), + Self::Return(node) => node.range(), + Self::Delete(node) => node.range(), + Self::Assign(node) => node.range(), + Self::AugAssign(node) => node.range(), + Self::AnnAssign(node) => node.range(), + Self::For(node) => node.range(), + Self::AsyncFor(node) => node.range(), + Self::While(node) => node.range(), + Self::If(node) => node.range(), + Self::With(node) => node.range(), + Self::AsyncWith(node) => node.range(), + Self::Match(node) => node.range(), + Self::Raise(node) => node.range(), + Self::Try(node) => node.range(), + Self::TryStar(node) => node.range(), + Self::Assert(node) => node.range(), + Self::Import(node) => node.range(), + Self::ImportFrom(node) => node.range(), + Self::Global(node) => node.range(), + Self::Nonlocal(node) => node.range(), + Self::Expr(node) => node.range(), + Self::Pass(node) => node.range(), + Self::Break(node) => node.range(), + Self::Continue(node) => node.range(), + } + } +} + +impl Ranged for crate::generic::ExprBoolOp { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprNamedExpr { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprBinOp { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprUnaryOp { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprLambda { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprIfExp { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprDict { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprSet { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprListComp { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprSetComp { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprDictComp { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprGeneratorExp { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprAwait { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprYield { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprYieldFrom { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprCompare { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprCall { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprFormattedValue { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprJoinedStr { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprConstant { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprAttribute { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprSubscript { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprStarred { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprName { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprList { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprTuple { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExprSlice { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::Expr { + fn range(&self) -> TextRange { + match self { + Self::BoolOp(node) => node.range(), + Self::NamedExpr(node) => node.range(), + Self::BinOp(node) => node.range(), + Self::UnaryOp(node) => node.range(), + Self::Lambda(node) => node.range(), + Self::IfExp(node) => node.range(), + Self::Dict(node) => node.range(), + Self::Set(node) => node.range(), + Self::ListComp(node) => node.range(), + Self::SetComp(node) => node.range(), + Self::DictComp(node) => node.range(), + Self::GeneratorExp(node) => node.range(), + Self::Await(node) => node.range(), + Self::Yield(node) => node.range(), + Self::YieldFrom(node) => node.range(), + Self::Compare(node) => node.range(), + Self::Call(node) => node.range(), + Self::FormattedValue(node) => node.range(), + Self::JoinedStr(node) => node.range(), + Self::Constant(node) => node.range(), + Self::Attribute(node) => node.range(), + Self::Subscript(node) => node.range(), + Self::Starred(node) => node.range(), + Self::Name(node) => node.range(), + Self::List(node) => node.range(), + Self::Tuple(node) => node.range(), + Self::Slice(node) => node.range(), + } + } +} + +impl Ranged for crate::generic::Comprehension { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ExceptHandlerExceptHandler { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::ExceptHandler { + fn range(&self) -> TextRange { + match self { + Self::ExceptHandler(node) => node.range(), + } + } +} + +impl Ranged for crate::generic::PythonArguments { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::Arg { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::Keyword { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::Alias { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::WithItem { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::MatchCase { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::PatternMatchValue { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::PatternMatchSingleton { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::PatternMatchSequence { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::PatternMatchMapping { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::PatternMatchClass { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::PatternMatchStar { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::PatternMatchAs { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::PatternMatchOr { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::Pattern { + fn range(&self) -> TextRange { + match self { + Self::MatchValue(node) => node.range(), + Self::MatchSingleton(node) => node.range(), + Self::MatchSequence(node) => node.range(), + Self::MatchMapping(node) => node.range(), + Self::MatchClass(node) => node.range(), + Self::MatchStar(node) => node.range(), + Self::MatchAs(node) => node.range(), + Self::MatchOr(node) => node.range(), + } + } +} + +impl Ranged for crate::generic::TypeIgnoreTypeIgnore { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::TypeIgnore { + fn range(&self) -> TextRange { + match self { + Self::TypeIgnore(node) => node.range(), + } + } +} + +impl Ranged for crate::generic::Decorator { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::Arguments { + fn range(&self) -> TextRange { + self.range + } +} +impl Ranged for crate::generic::ArgWithDefault { + fn range(&self) -> TextRange { + self.range + } +} diff --git a/parser/src/gen/parse.rs b/parser/src/gen/parse.rs index 01856ac2d3..4dfa47eb1d 100644 --- a/parser/src/gen/parse.rs +++ b/parser/src/gen/parse.rs @@ -1,4 +1,4 @@ -// File automatically generated by ast/asdl_rs.py. +// This file was originally generated from asdl by a python script, but we now edit it manually impl Parse for ast::StmtFunctionDef { fn lex_starts_at( diff --git a/scripts/cspell.sh b/scripts/cspell.sh index 116ce9ed53..62f8cf2992 100644 --- a/scripts/cspell.sh +++ b/scripts/cspell.sh @@ -1,3 +1,2 @@ #!/bin/bash cspell "ast/**/*.rs" "literal/**/*.rs" "core/**/*.rs" "parser/**/*.rs" -cspell ast/asdl_rs.py diff --git a/scripts/update_asdl.sh b/scripts/update_asdl.sh deleted file mode 100755 index 985d780ee9..0000000000 --- a/scripts/update_asdl.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e - -cd "$(dirname "$(dirname "$0")")" - -# rm ast/src/gen/*.rs -python ast/asdl_rs.py --ast-dir ast/src/gen/ --parser-dir parser/src/gen/ ast/Python.asdl -rustfmt ast/src/gen/*.rs parser/src/gen/*.rs