rust/xtask/src/ast_src.rs

767 lines
21 KiB
Rust
Raw Normal View History

2020-02-27 04:07:26 -06:00
//! Defines input for code generation process.
pub(crate) struct KindsSrc<'a> {
pub(crate) punct: &'a [(&'a str, &'a str)],
pub(crate) keywords: &'a [&'a str],
pub(crate) contextual_keywords: &'a [&'a str],
pub(crate) literals: &'a [&'a str],
pub(crate) tokens: &'a [&'a str],
pub(crate) nodes: &'a [&'a str],
}
pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
punct: &[
2020-04-10 10:06:57 -05:00
(";", "SEMICOLON"),
(",", "COMMA"),
("(", "L_PAREN"),
(")", "R_PAREN"),
("{", "L_CURLY"),
("}", "R_CURLY"),
("[", "L_BRACK"),
("]", "R_BRACK"),
("<", "L_ANGLE"),
(">", "R_ANGLE"),
("@", "AT"),
("#", "POUND"),
("~", "TILDE"),
("?", "QUESTION"),
("$", "DOLLAR"),
("&", "AMP"),
("|", "PIPE"),
("+", "PLUS"),
("*", "STAR"),
("/", "SLASH"),
("^", "CARET"),
("%", "PERCENT"),
("_", "UNDERSCORE"),
(".", "DOT"),
2020-04-10 10:06:57 -05:00
("..", "DOT2"),
("...", "DOT3"),
("..=", "DOT2EQ"),
(":", "COLON"),
2020-04-10 10:06:57 -05:00
("::", "COLON2"),
("=", "EQ"),
2020-04-10 10:06:57 -05:00
("==", "EQ2"),
("=>", "FAT_ARROW"),
2020-04-10 10:06:57 -05:00
("!", "BANG"),
("!=", "NEQ"),
("-", "MINUS"),
("->", "THIN_ARROW"),
("<=", "LTEQ"),
(">=", "GTEQ"),
("+=", "PLUSEQ"),
("-=", "MINUSEQ"),
("|=", "PIPEEQ"),
("&=", "AMPEQ"),
("^=", "CARETEQ"),
("/=", "SLASHEQ"),
("*=", "STAREQ"),
("%=", "PERCENTEQ"),
2020-04-10 10:06:57 -05:00
("&&", "AMP2"),
("||", "PIPE2"),
("<<", "SHL"),
(">>", "SHR"),
("<<=", "SHLEQ"),
(">>=", "SHREQ"),
],
keywords: &[
"as", "async", "await", "box", "break", "const", "continue", "crate", "dyn", "else",
"enum", "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "macro",
"match", "mod", "move", "mut", "pub", "ref", "return", "self", "static", "struct", "super",
"trait", "true", "try", "type", "unsafe", "use", "where", "while",
],
contextual_keywords: &["auto", "default", "existential", "union", "raw"],
literals: &[
"INT_NUMBER",
"FLOAT_NUMBER",
"CHAR",
"BYTE",
"STRING",
"RAW_STRING",
"BYTE_STRING",
"RAW_BYTE_STRING",
],
tokens: &[
"ERROR",
"IDENT",
"WHITESPACE",
"LIFETIME",
"COMMENT",
"SHEBANG",
"L_DOLLAR",
"R_DOLLAR",
],
nodes: &[
"SOURCE_FILE",
"STRUCT_DEF",
"UNION_DEF",
"ENUM_DEF",
"FN_DEF",
"RET_TYPE",
"EXTERN_CRATE_ITEM",
"MODULE",
"USE_ITEM",
"STATIC_DEF",
"CONST_DEF",
"TRAIT_DEF",
2020-02-29 14:24:40 -06:00
"IMPL_DEF",
"TYPE_ALIAS_DEF",
"MACRO_CALL",
"TOKEN_TREE",
"MACRO_DEF",
"PAREN_TYPE",
"TUPLE_TYPE",
"NEVER_TYPE",
"PATH_TYPE",
"POINTER_TYPE",
"ARRAY_TYPE",
"SLICE_TYPE",
"REFERENCE_TYPE",
"PLACEHOLDER_TYPE",
"FN_POINTER_TYPE",
"FOR_TYPE",
"IMPL_TRAIT_TYPE",
"DYN_TRAIT_TYPE",
2020-02-09 12:57:01 -06:00
"OR_PAT",
"PAREN_PAT",
"REF_PAT",
"BOX_PAT",
"BIND_PAT",
"PLACEHOLDER_PAT",
"DOT_DOT_PAT",
"PATH_PAT",
"RECORD_PAT",
"RECORD_FIELD_PAT_LIST",
"RECORD_FIELD_PAT",
"TUPLE_STRUCT_PAT",
"TUPLE_PAT",
"SLICE_PAT",
"RANGE_PAT",
"LITERAL_PAT",
"MACRO_PAT",
// atoms
"TUPLE_EXPR",
"ARRAY_EXPR",
"PAREN_EXPR",
"PATH_EXPR",
"LAMBDA_EXPR",
"IF_EXPR",
"WHILE_EXPR",
"CONDITION",
"LOOP_EXPR",
"FOR_EXPR",
"CONTINUE_EXPR",
"BREAK_EXPR",
"LABEL",
"BLOCK_EXPR",
"RETURN_EXPR",
"MATCH_EXPR",
"MATCH_ARM_LIST",
"MATCH_ARM",
"MATCH_GUARD",
"RECORD_LIT",
"RECORD_FIELD_LIST",
"RECORD_FIELD",
2020-05-01 18:18:19 -05:00
"EFFECT_EXPR",
"BOX_EXPR",
// postfix
"CALL_EXPR",
"INDEX_EXPR",
"METHOD_CALL_EXPR",
"FIELD_EXPR",
"AWAIT_EXPR",
"TRY_EXPR",
"CAST_EXPR",
// unary
"REF_EXPR",
"PREFIX_EXPR",
"RANGE_EXPR", // just weird
"BIN_EXPR",
"EXTERN_BLOCK",
"EXTERN_ITEM_LIST",
"ENUM_VARIANT",
"RECORD_FIELD_DEF_LIST",
"RECORD_FIELD_DEF",
"TUPLE_FIELD_DEF_LIST",
"TUPLE_FIELD_DEF",
"ENUM_VARIANT_LIST",
"ITEM_LIST",
"ATTR",
"META_ITEM", // not an item actually
"USE_TREE",
"USE_TREE_LIST",
"PATH",
"PATH_SEGMENT",
"LITERAL",
"ALIAS",
"VISIBILITY",
"WHERE_CLAUSE",
"WHERE_PRED",
"ABI",
"NAME",
"NAME_REF",
"LET_STMT",
"EXPR_STMT",
"TYPE_PARAM_LIST",
"LIFETIME_PARAM",
"TYPE_PARAM",
"CONST_PARAM",
"TYPE_ARG_LIST",
"LIFETIME_ARG",
"TYPE_ARG",
"ASSOC_TYPE_ARG",
"CONST_ARG",
"PARAM_LIST",
"PARAM",
"SELF_PARAM",
"ARG_LIST",
"TYPE_BOUND",
"TYPE_BOUND_LIST",
// macro related
"MACRO_ITEMS",
"MACRO_STMTS",
],
};
pub(crate) struct AstSrc<'a> {
pub(crate) tokens: &'a [&'a str],
pub(crate) nodes: &'a [AstNodeSrc<'a>],
pub(crate) enums: &'a [AstEnumSrc<'a>],
}
pub(crate) struct AstNodeSrc<'a> {
pub(crate) name: &'a str,
pub(crate) traits: &'a [&'a str],
2020-04-10 03:07:09 -05:00
pub(crate) fields: &'a [Field<'a>],
}
pub(crate) enum Field<'a> {
Token(&'a str),
Node { name: &'a str, src: FieldSrc<'a> },
}
2020-04-10 02:14:14 -05:00
pub(crate) enum FieldSrc<'a> {
Shorthand,
2020-04-10 02:14:14 -05:00
Optional(&'a str),
Many(&'a str),
}
pub(crate) struct AstEnumSrc<'a> {
pub(crate) name: &'a str,
pub(crate) traits: &'a [&'a str],
pub(crate) variants: &'a [&'a str],
}
macro_rules! ast_nodes {
($(
struct $name:ident$(: $($trait:ident),*)? {
2020-04-10 03:07:09 -05:00
$($field_name:ident $(![$token:tt])? $(: $ty:tt)?),*$(,)?
}
)*) => {
[$(
AstNodeSrc {
name: stringify!($name),
traits: &[$($(stringify!($trait)),*)?],
2020-04-10 03:07:09 -05:00
fields: &[
$(field!($(T![$token])? $field_name $($ty)?)),*
],
}
),*]
};
}
2020-04-10 03:07:09 -05:00
macro_rules! field {
(T![$token:tt] T) => {
Field::Token(stringify!($token))
};
($field_name:ident) => {
2020-04-10 03:07:09 -05:00
Field::Node { name: stringify!($field_name), src: FieldSrc::Shorthand }
};
($field_name:ident [$ty:ident]) => {
2020-04-10 03:07:09 -05:00
Field::Node { name: stringify!($field_name), src: FieldSrc::Many(stringify!($ty)) }
};
($field_name:ident $ty:ident) => {
2020-04-10 03:07:09 -05:00
Field::Node { name: stringify!($field_name), src: FieldSrc::Optional(stringify!($ty)) }
};
}
macro_rules! ast_enums {
($(
enum $name:ident $(: $($trait:ident),*)? {
$($variant:ident),*$(,)?
}
)*) => {
[$(
AstEnumSrc {
name: stringify!($name),
traits: &[$($(stringify!($trait)),*)?],
variants: &[$(stringify!($variant)),*],
}
),*]
};
}
pub(crate) const AST_SRC: AstSrc = AstSrc {
tokens: &["Whitespace", "Comment", "String", "RawString"],
nodes: &ast_nodes! {
struct SourceFile: ModuleItemOwner, AttrsOwner, DocCommentsOwner {
modules: [Module],
}
struct FnDef: VisibilityOwner, NameOwner, TypeParamsOwner, DocCommentsOwner, AttrsOwner {
Abi,
2020-04-10 03:07:09 -05:00
T![const],
T![default],
T![async],
T![unsafe],
T![fn],
ParamList,
RetType,
body: BlockExpr,
2020-04-10 03:11:05 -05:00
T![;]
}
2020-04-10 03:18:43 -05:00
struct RetType { T![->], TypeRef }
struct StructDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
2020-04-10 03:07:09 -05:00
T![struct],
FieldDefList,
2020-04-10 03:11:05 -05:00
T![;]
}
struct UnionDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
2020-04-10 03:07:09 -05:00
T![union],
RecordFieldDefList,
}
2020-04-10 03:27:23 -05:00
struct RecordFieldDefList { T!['{'], fields: [RecordFieldDef], T!['}'] }
struct RecordFieldDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { }
2020-04-10 03:29:59 -05:00
struct TupleFieldDefList { T!['('], fields: [TupleFieldDef], T![')'] }
struct TupleFieldDef: VisibilityOwner, AttrsOwner {
TypeRef,
}
struct EnumDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
2020-04-10 03:07:09 -05:00
T![enum],
variant_list: EnumVariantList,
}
struct EnumVariantList {
2020-04-10 03:27:23 -05:00
T!['{'],
variants: [EnumVariant],
2020-04-10 03:27:23 -05:00
T!['}']
}
struct EnumVariant: VisibilityOwner, NameOwner, DocCommentsOwner, AttrsOwner {
FieldDefList,
2020-04-10 03:35:39 -05:00
T![=],
Expr
}
struct TraitDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeParamsOwner, TypeBoundsOwner {
2020-04-10 03:07:09 -05:00
T![unsafe],
T![auto],
T![trait],
ItemList,
}
struct Module: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner {
2020-04-10 03:07:09 -05:00
T![mod],
ItemList,
2020-04-10 03:11:05 -05:00
T![;]
}
2020-04-09 16:02:10 -05:00
struct ItemList: ModuleItemOwner {
2020-04-10 03:27:23 -05:00
T!['{'],
2020-05-05 10:56:10 -05:00
assoc_items: [AssocItem],
2020-04-10 03:27:23 -05:00
T!['}']
}
struct ConstDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner {
2020-04-10 03:07:09 -05:00
T![default],
T![const],
2020-04-10 03:35:39 -05:00
T![=],
body: Expr,
2020-04-10 03:11:05 -05:00
T![;]
}
struct StaticDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner {
2020-04-10 03:07:09 -05:00
T![static],
T![mut],
2020-04-10 03:35:39 -05:00
T![=],
body: Expr,
2020-04-10 03:11:05 -05:00
T![;]
}
struct TypeAliasDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeBoundsOwner {
2020-04-10 03:07:09 -05:00
T![default],
T![type],
2020-04-10 03:35:39 -05:00
T![=],
TypeRef,
2020-04-10 03:11:05 -05:00
T![;]
}
struct ImplDef: TypeParamsOwner, AttrsOwner, DocCommentsOwner {
2020-04-10 03:07:09 -05:00
T![default],
T![const],
T![unsafe],
T![impl],
2020-04-10 03:35:39 -05:00
T![!],
2020-04-10 03:07:09 -05:00
T![for],
ItemList,
}
2020-04-10 03:29:59 -05:00
struct ParenType { T!['('], TypeRef, T![')'] }
struct TupleType { T!['('], fields: [TypeRef], T![')'] }
2020-04-10 03:35:39 -05:00
struct NeverType { T![!] }
struct PathType { Path }
2020-04-10 04:49:13 -05:00
struct PointerType { T![*], T![const], T![mut], TypeRef }
2020-04-10 03:29:59 -05:00
struct ArrayType { T!['['], TypeRef, T![;], Expr, T![']'] }
struct SliceType { T!['['], TypeRef, T![']'] }
2020-04-10 04:49:13 -05:00
struct ReferenceType { T![&], T![lifetime], T![mut], TypeRef }
struct PlaceholderType { T![_] }
2020-04-10 03:07:09 -05:00
struct FnPointerType { Abi, T![unsafe], T![fn], ParamList, RetType }
struct ForType { T![for], TypeParamList, TypeRef }
struct ImplTraitType: TypeBoundsOwner { T![impl] }
struct DynTraitType: TypeBoundsOwner { T![dyn] }
2020-04-10 03:29:59 -05:00
struct TupleExpr: AttrsOwner { T!['('], exprs: [Expr], T![')'] }
struct ArrayExpr: AttrsOwner { T!['['], exprs: [Expr], T![;], T![']'] }
struct ParenExpr: AttrsOwner { T!['('], Expr, T![')'] }
struct PathExpr { Path }
struct LambdaExpr: AttrsOwner {
2020-04-10 03:07:09 -05:00
T![static],
T![async],
T![move],
ParamList,
RetType,
body: Expr,
}
2020-04-10 03:07:09 -05:00
struct IfExpr: AttrsOwner { T![if], Condition }
struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] }
2020-05-01 18:18:19 -05:00
struct EffectExpr: AttrsOwner { Label, T![try], T![unsafe], T![async], BlockExpr }
struct ForExpr: AttrsOwner, LoopBodyOwner {
2020-04-10 03:07:09 -05:00
T![for],
Pat,
2020-04-10 03:07:09 -05:00
T![in],
iterable: Expr,
}
2020-04-10 03:07:09 -05:00
struct WhileExpr: AttrsOwner, LoopBodyOwner { T![while], Condition }
2020-04-10 04:49:13 -05:00
struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] }
struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr }
struct Label { T![lifetime] }
2020-05-01 18:18:19 -05:00
struct BlockExpr: AttrsOwner, ModuleItemOwner {
T!['{'], statements: [Stmt], Expr, T!['}'],
}
struct ReturnExpr: AttrsOwner { Expr }
struct CallExpr: ArgListOwner { Expr }
struct MethodCallExpr: AttrsOwner, ArgListOwner {
2020-04-10 04:49:13 -05:00
Expr, T![.], NameRef, TypeArgList,
}
2020-04-10 03:29:59 -05:00
struct IndexExpr: AttrsOwner { T!['['], T![']'] }
2020-04-10 04:49:13 -05:00
struct FieldExpr: AttrsOwner { Expr, T![.], NameRef }
struct AwaitExpr: AttrsOwner { Expr, T![.], T![await] }
2020-05-01 18:18:19 -05:00
struct TryExpr: AttrsOwner { Expr, T![?] }
2020-04-10 03:07:09 -05:00
struct CastExpr: AttrsOwner { Expr, T![as], TypeRef }
2020-04-10 04:49:13 -05:00
struct RefExpr: AttrsOwner { T![&], T![raw], T![mut], Expr }
struct PrefixExpr: AttrsOwner { /*PrefixOp,*/ Expr }
2020-04-10 03:07:09 -05:00
struct BoxExpr: AttrsOwner { T![box], Expr }
2020-04-10 04:49:13 -05:00
struct RangeExpr: AttrsOwner { /*RangeOp*/ }
2020-04-10 03:35:39 -05:00
struct BinExpr: AttrsOwner { /*BinOp*/ }
2020-04-10 04:49:13 -05:00
struct Literal { /*LiteralToken*/ }
2020-04-10 03:07:09 -05:00
struct MatchExpr: AttrsOwner { T![match], Expr, MatchArmList }
2020-04-10 03:27:23 -05:00
struct MatchArmList: AttrsOwner { T!['{'], arms: [MatchArm], T!['}'] }
struct MatchArm: AttrsOwner {
2020-02-09 12:57:01 -06:00
pat: Pat,
guard: MatchGuard,
2020-04-10 04:49:13 -05:00
T![=>],
Expr,
}
2020-04-10 03:07:09 -05:00
struct MatchGuard { T![if], Expr }
struct RecordLit { Path, RecordFieldList}
struct RecordFieldList {
2020-04-10 03:27:23 -05:00
T!['{'],
fields: [RecordField],
2020-04-10 04:49:13 -05:00
T![..],
spread: Expr,
2020-04-10 03:27:23 -05:00
T!['}']
}
2020-04-10 04:49:13 -05:00
struct RecordField: AttrsOwner { NameRef, T![:], Expr }
2020-02-09 12:57:01 -06:00
struct OrPat { pats: [Pat] }
2020-04-10 03:29:59 -05:00
struct ParenPat { T!['('], Pat, T![')'] }
2020-04-10 04:49:13 -05:00
struct RefPat { T![&], T![mut], Pat }
2020-04-10 03:07:09 -05:00
struct BoxPat { T![box], Pat }
2020-04-10 04:49:13 -05:00
struct BindPat: AttrsOwner, NameOwner { T![ref], T![mut], T![@], Pat }
struct PlaceholderPat { T![_] }
struct DotDotPat { T![..] }
struct PathPat { Path }
2020-04-10 03:29:59 -05:00
struct SlicePat { T!['['], args: [Pat], T![']'] }
2020-04-10 04:49:13 -05:00
struct RangePat { /*RangeSeparator*/ }
struct LiteralPat { Literal }
struct MacroPat { MacroCall }
struct RecordPat { RecordFieldPatList, Path }
struct RecordFieldPatList {
2020-04-10 03:27:23 -05:00
T!['{'],
pats: [RecordInnerPat],
record_field_pats: [RecordFieldPat],
bind_pats: [BindPat],
2020-04-10 04:49:13 -05:00
T![..],
2020-04-10 03:27:23 -05:00
T!['}']
}
struct RecordFieldPat: AttrsOwner { NameRef, T![:], Pat }
2020-04-10 03:29:59 -05:00
struct TupleStructPat { Path, T!['('], args: [Pat], T![')'] }
struct TuplePat { T!['('], args: [Pat], T![')'] }
2020-04-10 03:07:09 -05:00
struct Visibility { T![pub], T![super], T![self], T![crate] }
2020-04-10 04:49:13 -05:00
struct Name { T![ident] }
struct NameRef { /*NameRefToken*/ }
struct MacroCall: NameOwner, AttrsOwner,DocCommentsOwner {
2020-04-10 03:35:39 -05:00
Path, T![!], TokenTree, T![;]
}
2020-04-10 04:49:13 -05:00
struct Attr { T![#], T![!], T!['['], Path, T![=], input: AttrInput, T![']'] }
struct TokenTree {}
struct TypeParamList {
2020-04-10 04:49:13 -05:00
T![<],
generic_params: [GenericParam],
type_params: [TypeParam],
lifetime_params: [LifetimeParam],
const_params: [ConstParam],
2020-04-10 04:49:13 -05:00
T![>]
}
struct TypeParam: NameOwner, AttrsOwner, TypeBoundsOwner {
2020-04-10 03:35:39 -05:00
T![=],
default_type: TypeRef,
}
struct ConstParam: NameOwner, AttrsOwner, TypeAscriptionOwner {
2020-04-10 03:35:39 -05:00
T![=],
default_val: Expr,
}
2020-04-10 04:49:13 -05:00
struct LifetimeParam: AttrsOwner { T![lifetime] }
struct TypeBound { T![lifetime], /* Question, */ T![const], /* Question, */ TypeRef}
struct TypeBoundList { bounds: [TypeBound] }
2020-04-10 04:49:13 -05:00
struct WherePred: TypeBoundsOwner { T![lifetime], TypeRef }
2020-04-10 03:07:09 -05:00
struct WhereClause { T![where], predicates: [WherePred] }
2020-04-10 04:49:13 -05:00
struct Abi { /*String*/ }
2020-04-10 03:11:05 -05:00
struct ExprStmt: AttrsOwner { Expr, T![;] }
struct LetStmt: AttrsOwner, TypeAscriptionOwner {
2020-04-10 03:07:09 -05:00
T![let],
Pat,
2020-04-10 03:35:39 -05:00
T![=],
initializer: Expr,
2020-04-10 03:11:05 -05:00
T![;],
}
2020-04-10 03:35:39 -05:00
struct Condition { T![let], Pat, T![=], Expr }
struct ParamList {
2020-04-10 03:29:59 -05:00
T!['('],
SelfParam,
params: [Param],
2020-04-10 03:29:59 -05:00
T![')']
}
2020-04-10 10:47:49 -05:00
struct SelfParam: TypeAscriptionOwner, AttrsOwner { T![&], T![mut], T![lifetime], T![self] }
struct Param: TypeAscriptionOwner, AttrsOwner {
Pat,
2020-04-10 04:49:13 -05:00
T![...]
}
struct UseItem: AttrsOwner, VisibilityOwner {
2020-04-10 03:07:09 -05:00
T![use],
UseTree,
}
struct UseTree {
2020-04-10 04:49:13 -05:00
Path, T![*], UseTreeList, Alias
}
2020-04-10 03:07:09 -05:00
struct Alias: NameOwner { T![as] }
2020-04-10 03:27:23 -05:00
struct UseTreeList { T!['{'], use_trees: [UseTree], T!['}'] }
struct ExternCrateItem: AttrsOwner, VisibilityOwner {
2020-04-10 03:07:09 -05:00
T![extern], T![crate], NameRef, Alias,
}
struct ArgList {
2020-04-10 03:29:59 -05:00
T!['('],
args: [Expr],
2020-04-10 03:29:59 -05:00
T![')']
}
struct Path {
segment: PathSegment,
qualifier: Path,
}
struct PathSegment {
2020-05-01 10:59:24 -05:00
T![::], T![crate], T![self], T![super], T![<], NameRef, TypeArgList, ParamList, RetType, PathType, T![>]
}
struct TypeArgList {
2020-04-10 04:49:13 -05:00
T![::],
T![<],
generic_args: [GenericArg],
type_args: [TypeArg],
lifetime_args: [LifetimeArg],
assoc_type_args: [AssocTypeArg],
const_args: [ConstArg],
2020-04-10 04:49:13 -05:00
T![>]
}
struct TypeArg { TypeRef }
2020-04-10 03:35:39 -05:00
struct AssocTypeArg : TypeBoundsOwner { NameRef, T![=], TypeRef }
2020-04-10 04:49:13 -05:00
struct LifetimeArg { T![lifetime] }
2020-04-10 03:35:39 -05:00
struct ConstArg { Literal, T![=], BlockExpr }
2020-04-09 16:02:10 -05:00
struct MacroItems: ModuleItemOwner{ }
struct MacroStmts {
statements: [Stmt],
Expr,
}
2020-04-09 16:02:10 -05:00
struct ExternItemList: ModuleItemOwner {
2020-04-10 03:27:23 -05:00
T!['{'],
extern_items: [ExternItem],
2020-04-10 03:27:23 -05:00
T!['}']
}
struct ExternBlock {
Abi,
ExternItemList
}
struct MetaItem {
2020-04-10 03:35:39 -05:00
Path, T![=], AttrInput, nested_meta_items: [MetaItem]
}
struct MacroDef {
Name, TokenTree
}
},
enums: &ast_enums! {
enum NominalDef: NameOwner, TypeParamsOwner, AttrsOwner {
StructDef, EnumDef, UnionDef,
}
enum GenericParam {
LifetimeParam,
TypeParam,
ConstParam
}
enum GenericArg {
LifetimeArg,
TypeArg,
ConstArg,
AssocTypeArg
}
enum TypeRef {
ParenType,
TupleType,
NeverType,
PathType,
PointerType,
ArrayType,
SliceType,
ReferenceType,
PlaceholderType,
FnPointerType,
ForType,
ImplTraitType,
DynTraitType,
}
enum ModuleItem: NameOwner, AttrsOwner, VisibilityOwner {
StructDef,
UnionDef,
EnumDef,
FnDef,
TraitDef,
TypeAliasDef,
2020-02-29 14:24:40 -06:00
ImplDef,
UseItem,
ExternCrateItem,
ConstDef,
StaticDef,
Module,
2020-03-26 10:10:01 -05:00
MacroCall,
ExternBlock
}
/* impl blocks can also contain MacroCall */
2020-05-05 10:56:10 -05:00
enum AssocItem: NameOwner, AttrsOwner {
FnDef, TypeAliasDef, ConstDef
}
/* extern blocks can also contain MacroCall */
enum ExternItem: NameOwner, AttrsOwner, VisibilityOwner {
FnDef, StaticDef
}
enum Expr: AttrsOwner {
TupleExpr,
ArrayExpr,
ParenExpr,
PathExpr,
LambdaExpr,
IfExpr,
LoopExpr,
ForExpr,
WhileExpr,
ContinueExpr,
BreakExpr,
Label,
BlockExpr,
ReturnExpr,
MatchExpr,
RecordLit,
CallExpr,
IndexExpr,
MethodCallExpr,
FieldExpr,
AwaitExpr,
TryExpr,
2020-05-01 18:18:19 -05:00
EffectExpr,
CastExpr,
RefExpr,
PrefixExpr,
RangeExpr,
BinExpr,
Literal,
MacroCall,
BoxExpr,
}
enum Pat {
2020-02-09 12:57:01 -06:00
OrPat,
ParenPat,
RefPat,
BoxPat,
BindPat,
PlaceholderPat,
DotDotPat,
PathPat,
RecordPat,
TupleStructPat,
TuplePat,
SlicePat,
RangePat,
LiteralPat,
MacroPat,
}
enum RecordInnerPat {
RecordFieldPat,
BindPat
}
enum AttrInput { Literal, TokenTree }
enum Stmt {
LetStmt,
ExprStmt,
// macro calls are parsed as expression statements */
}
enum FieldDefList {
RecordFieldDefList,
TupleFieldDefList,
}
},
};