import {DocComment} from ast; // == Modules == struct RustModule { field name: List[RustIdentifier]; field items: List[RustItem]; } // == Items == sum RustItem { variant RustEnum; variant RustFunction; variant RustInherentImpl; variant RustStructStruct; variant RustTraitImpl; variant RustTypeAlias; } // === Functions === struct RustFunction { field visibility: Option[RustVisibility]; field name: RustIdentifier; field typeParams: List[RustTypeParam]; field params: List[RustFunctionParam]; field returnType: Option[RustType]; field body: Option[RustBlockExpression]; } struct RustFunctionParam { field name: RustIdentifier; field type: RustType; } // === Type aliases === struct RustTypeAlias { field visibility: Option[RustVisibility]; field name: RustIdentifier; field params: List[RustTypeParam]; field type: RustType; } // === Structs === struct RustStructStruct { field attributes: List[RustOuterAttribute]; field name: RustIdentifier; field typeParams: List[RustTypeParam]; field fields: Option[List[RustStructField]]; field docComment: DocComment; } struct RustStructField { field name: RustIdentifier; field type: RustType; } struct RustTupleField { field type: RustType; } // === Enumerations === struct RustEnum { field attributes: List[RustOuterAttribute]; field name: RustIdentifier; field variants: List[RustEnumVariant]; field docComment: DocComment; } struct RustEnumVariant { field name: RustIdentifier; field fields: RustEnumVariantFields; } sum RustEnumVariantFields { variant RustEnumVariantNoFields; variant RustEnumVariantTuple; } struct RustEnumVariantNoFields { } struct RustEnumVariantTuple { field fields: List[RustTupleField]; } // === Implementations === struct RustInherentImpl { field type: RustType; field items: List[RustAssociatedItem]; } struct RustTraitImpl { field implementedTrait: RustPath; field type: RustType; field items: List[RustAssociatedItem]; } // === Generic parameters === struct RustTypeParam { field name: RustIdentifier; field bounds: List[RustPath]; } // === Associated items === sum RustAssociatedItem { variant RustFunction; } // == Attributes == struct RustOuterAttribute { field path: RustPath; field input: Option[String]; } // == Statements == sum RustStatement { variant RustExpressionStatement; variant RustLetStatement; } struct RustExpressionStatement { field expression: RustExpression; } struct RustLetStatement { field variableName: RustIdentifier; field mutable: Bool; field value: RustExpression; } // == Expressions == sum RustExpression { variant RustArrayRepeatExpression; variant RustBinaryExpression; variant RustBlockExpression; variant RustBoolLiteral; variant RustCallExpression; variant RustClosureExpression; variant RustFieldExpression; variant RustIfExpression; variant RustIndexExpression; variant RustIntegerLiteral; variant RustIteratorLoopExpression; variant RustMatchExpression; variant RustPath; variant RustPrefixExpression; variant RustRangeExpr; variant RustStringLiteral; variant RustStructExpression; variant RustTryPropagationExpression; variant RustTupleExpression; variant RustTypeCastExpression; variant RustVecRepeatExpression; } sum RustLiteralExpression { variant RustBoolLiteral; variant RustIntegerLiteral; } struct RustArrayRepeatExpression { field repeatOperand: RustExpression; field lengthOperand: RustExpression; } struct RustBinaryExpression { field operator: RustBinaryOperator; field left: RustExpression; field right: RustExpression; } enum RustBinaryOperator { variant add; variant equal; variant lessThan; variant notEqual; } struct RustBlockExpression { field statements: List[RustStatement]; field finalOperand: Option[RustExpression]; } struct RustBoolLiteral { field value: Bool; } struct RustCallExpression { field function: RustExpression; field args: List[RustExpression]; } struct RustClosureExpression { field params: List[RustPattern]; field body: RustExpression; } struct RustFieldExpression { field containerOperand: RustExpression; field fieldName: RustIdentifier; } struct RustIfExpression { field condition: RustExpression; field ifTrue: RustBlockExpression; field ifFalse: RustBlockExpression; } struct RustIndexExpression { field indexed: RustExpression; field index: RustExpression; } struct RustIntegerLiteral { field value: Int64; field type: Option[RustIdentifier]; } struct RustIteratorLoopExpression { field pattern: RustPattern; field elements: RustExpression; field body: RustBlockExpression; } struct RustMatchExpression { field scrutinee: RustExpression; field arms: List[RustMatchArm]; } struct RustMatchArm { field pattern: RustPattern; field body: RustExpression; } struct RustPrefixExpression { field operator: RustPrefixOperator; field operand: RustExpression; } enum RustPrefixOperator { variant borrow; variant borrowMutable; variant dereference; } struct RustRangeExpr { field start: RustExpression; field end: RustExpression; } struct RustStringLiteral { field value: String; } struct RustStructExpression { field structPath: RustPath; field fieldValues: List[RustStructExprField]; } struct RustStructExprField { field name: RustIdentifier; field value: RustExpression; } struct RustTryPropagationExpression { field operand: RustExpression; } struct RustTupleExpression { field elements: List[RustExpression]; } struct RustTypeCastExpression { field left: RustExpression; field right: RustType; } struct RustVecRepeatExpression { field repeatOperand: RustExpression; field lengthOperand: RustExpression; } // == Patterns == sum RustPattern { variant RustIdentifierPattern; variant RustLiteralPattern; variant RustPathPattern; variant RustTupleStructPattern; variant RustWildcardPattern; } struct RustIdentifierPattern { field variableName: RustIdentifier; } struct RustLiteralPattern { field literal: RustLiteralExpression; } struct RustPathPattern { field path: RustPath; } struct RustTupleStructPattern { field constructor: RustPath; field items: List[RustPattern]; } struct RustWildcardPattern {} // == Types == sum RustType { variant RustFunctionPointerType; variant RustImplTraitType; variant RustMutableReferenceType; variant RustPath; variant RustSharedReferenceType; variant RustTraitObjectType; variant RustTupleType; } struct RustFunctionPointerType { field params: List[RustType]; field returnType: RustType; } struct RustImplTraitType { field trait: RustPath; } struct RustMutableReferenceType { field referencedType: RustType; } struct RustSharedReferenceType { field referencedType: RustType; } struct RustTraitObjectType { field bounds: List[RustPath]; } struct RustTupleType { field elementTypes: List[RustType]; } // == Paths == struct RustPath { field segments: List[RustPathSegment]; } struct RustPathSegment { field pathIdentSegment: RustPathIdentSegment; field args: Option[List[RustType]]; } sum RustPathIdentSegment { variant RustPathIdentSegmentCrate; variant RustPathIdentSegmentGlobal; variant RustPathIdentSegmentIdentifier; variant RustPathIdentSegmentSelfType; } struct RustPathIdentSegmentCrate { } struct RustPathIdentSegmentGlobal { } struct RustPathIdentSegmentIdentifier { field name: RustIdentifier; } struct RustPathIdentSegmentSelfType { } // == Visibility == enum RustVisibility { variant pub; } // == Identifiers == struct RustIdentifier { field value: String; }