2020-02-27 04:07:26 -06:00
|
|
|
//! Defines input for code generation process.
|
|
|
|
|
2020-01-03 13:37:02 -06:00
|
|
|
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: &[
|
|
|
|
(";", "SEMI"),
|
|
|
|
(",", "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"),
|
|
|
|
("..", "DOTDOT"),
|
|
|
|
("...", "DOTDOTDOT"),
|
|
|
|
("..=", "DOTDOTEQ"),
|
|
|
|
(":", "COLON"),
|
|
|
|
("::", "COLONCOLON"),
|
|
|
|
("=", "EQ"),
|
|
|
|
("==", "EQEQ"),
|
|
|
|
("=>", "FAT_ARROW"),
|
|
|
|
("!", "EXCL"),
|
|
|
|
("!=", "NEQ"),
|
|
|
|
("-", "MINUS"),
|
|
|
|
("->", "THIN_ARROW"),
|
|
|
|
("<=", "LTEQ"),
|
|
|
|
(">=", "GTEQ"),
|
|
|
|
("+=", "PLUSEQ"),
|
|
|
|
("-=", "MINUSEQ"),
|
|
|
|
("|=", "PIPEEQ"),
|
|
|
|
("&=", "AMPEQ"),
|
|
|
|
("^=", "CARETEQ"),
|
|
|
|
("/=", "SLASHEQ"),
|
|
|
|
("*=", "STAREQ"),
|
|
|
|
("%=", "PERCENTEQ"),
|
|
|
|
("&&", "AMPAMP"),
|
|
|
|
("||", "PIPEPIPE"),
|
|
|
|
("<<", "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",
|
|
|
|
],
|
2020-04-03 14:12:09 -05:00
|
|
|
contextual_keywords: &["auto", "default", "existential", "union", "raw"],
|
2020-01-03 13:37:02 -06:00
|
|
|
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",
|
2020-01-03 13:37:02 -06:00
|
|
|
"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",
|
2020-01-03 13:37:02 -06:00
|
|
|
"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",
|
2020-04-03 08:38:42 -05:00
|
|
|
"MACRO_PAT",
|
2020-01-03 13:37:02 -06:00
|
|
|
// 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",
|
|
|
|
"TRY_BLOCK_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",
|
|
|
|
"BLOCK",
|
|
|
|
"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",
|
2020-01-06 16:59:03 -06:00
|
|
|
"CONST_ARG",
|
2020-01-03 13:37:02 -06:00
|
|
|
"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) nodes: &'a [AstNodeSrc<'a>],
|
|
|
|
pub(crate) enums: &'a [AstEnumSrc<'a>],
|
2020-04-09 10:58:15 -05:00
|
|
|
pub(crate) token_enums: &'a [AstEnumSrc<'a>],
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) struct AstNodeSrc<'a> {
|
|
|
|
pub(crate) name: &'a str,
|
|
|
|
pub(crate) traits: &'a [&'a str],
|
2020-04-10 02:14:14 -05:00
|
|
|
pub(crate) fields: &'a [(&'a str, FieldSrc<'a>)],
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
2020-04-10 02:14:14 -05:00
|
|
|
pub(crate) enum FieldSrc<'a> {
|
2020-01-03 13:37:02 -06:00
|
|
|
Shorthand,
|
2020-04-10 02:14:14 -05:00
|
|
|
Optional(&'a str),
|
|
|
|
Many(&'a str),
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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),*)? {
|
|
|
|
$($field_name:ident $(: $ty:tt)?),*$(,)?
|
|
|
|
}
|
|
|
|
)*) => {
|
|
|
|
[$(
|
|
|
|
AstNodeSrc {
|
|
|
|
name: stringify!($name),
|
|
|
|
traits: &[$($(stringify!($trait)),*)?],
|
|
|
|
fields: &[$(
|
|
|
|
(stringify!($field_name), field_ty!($field_name $($ty)?))
|
|
|
|
),*],
|
|
|
|
|
|
|
|
}
|
|
|
|
),*]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! field_ty {
|
|
|
|
($field_name:ident) => {
|
|
|
|
FieldSrc::Shorthand
|
|
|
|
};
|
|
|
|
($field_name:ident [$ty:ident]) => {
|
|
|
|
FieldSrc::Many(stringify!($ty))
|
|
|
|
};
|
|
|
|
($field_name:ident $ty:ident) => {
|
|
|
|
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 {
|
|
|
|
nodes: &ast_nodes! {
|
2020-04-09 16:02:10 -05:00
|
|
|
struct SourceFile: ModuleItemOwner, AttrsOwner {
|
2020-01-03 13:37:02 -06:00
|
|
|
modules: [Module],
|
|
|
|
}
|
|
|
|
|
|
|
|
struct FnDef: VisibilityOwner, NameOwner, TypeParamsOwner, DocCommentsOwner, AttrsOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
Abi,
|
|
|
|
ConstKw,
|
|
|
|
DefaultKw,
|
|
|
|
AsyncKw,
|
|
|
|
UnsafeKw,
|
|
|
|
FnKw,
|
2020-01-03 13:37:02 -06:00
|
|
|
ParamList,
|
|
|
|
RetType,
|
|
|
|
body: BlockExpr,
|
2020-04-03 14:12:09 -05:00
|
|
|
Semi
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
2020-04-03 14:12:09 -05:00
|
|
|
struct RetType { ThinArrow, TypeRef }
|
2020-01-03 13:37:02 -06:00
|
|
|
|
|
|
|
struct StructDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
StructKw,
|
|
|
|
FieldDefList,
|
|
|
|
Semi
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
struct UnionDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
UnionKw,
|
2020-01-03 13:37:02 -06:00
|
|
|
RecordFieldDefList,
|
|
|
|
}
|
|
|
|
|
2020-04-03 14:12:09 -05:00
|
|
|
struct RecordFieldDefList { LCurly, fields: [RecordFieldDef], RCurly }
|
2020-01-03 13:37:02 -06:00
|
|
|
struct RecordFieldDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { }
|
|
|
|
|
2020-04-03 14:12:09 -05:00
|
|
|
struct TupleFieldDefList { LParen, fields: [TupleFieldDef], RParen }
|
2020-01-03 13:37:02 -06:00
|
|
|
struct TupleFieldDef: VisibilityOwner, AttrsOwner {
|
|
|
|
TypeRef,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct EnumDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
EnumKw,
|
2020-01-03 13:37:02 -06:00
|
|
|
variant_list: EnumVariantList,
|
|
|
|
}
|
|
|
|
struct EnumVariantList {
|
2020-04-03 14:12:09 -05:00
|
|
|
LCurly,
|
2020-01-03 13:37:02 -06:00
|
|
|
variants: [EnumVariant],
|
2020-04-03 14:12:09 -05:00
|
|
|
RCurly
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
2020-04-03 14:12:09 -05:00
|
|
|
struct EnumVariant: VisibilityOwner, NameOwner, DocCommentsOwner, AttrsOwner {
|
|
|
|
FieldDefList,
|
|
|
|
Eq,
|
2020-01-03 13:37:02 -06:00
|
|
|
Expr
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TraitDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeParamsOwner, TypeBoundsOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
UnsafeKw,
|
|
|
|
AutoKw,
|
|
|
|
TraitKw,
|
2020-01-03 13:37:02 -06:00
|
|
|
ItemList,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Module: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
ModKw,
|
2020-01-03 13:37:02 -06:00
|
|
|
ItemList,
|
2020-04-03 14:12:09 -05:00
|
|
|
Semi
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
2020-04-09 16:02:10 -05:00
|
|
|
struct ItemList: ModuleItemOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
LCurly,
|
2020-01-03 13:37:02 -06:00
|
|
|
impl_items: [ImplItem],
|
2020-04-03 14:12:09 -05:00
|
|
|
RCurly
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ConstDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
DefaultKw,
|
|
|
|
ConstKw,
|
|
|
|
Eq,
|
2020-01-03 13:37:02 -06:00
|
|
|
body: Expr,
|
2020-04-03 14:12:09 -05:00
|
|
|
Semi
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
struct StaticDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
StaticKw,
|
|
|
|
MutKw,
|
|
|
|
Eq,
|
2020-01-03 13:37:02 -06:00
|
|
|
body: Expr,
|
2020-04-03 14:12:09 -05:00
|
|
|
Semi
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TypeAliasDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeBoundsOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
DefaultKw,
|
|
|
|
TypeKw,
|
|
|
|
Eq,
|
2020-01-03 13:37:02 -06:00
|
|
|
TypeRef,
|
2020-04-03 14:12:09 -05:00
|
|
|
Semi
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
2020-02-29 14:24:40 -06:00
|
|
|
struct ImplDef: TypeParamsOwner, AttrsOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
DefaultKw,
|
|
|
|
ConstKw,
|
|
|
|
UnsafeKw,
|
|
|
|
ImplKw,
|
|
|
|
Excl,
|
|
|
|
ForKw,
|
2020-01-03 13:37:02 -06:00
|
|
|
ItemList,
|
|
|
|
}
|
|
|
|
|
2020-04-03 14:12:09 -05:00
|
|
|
struct ParenType { LParen, TypeRef, RParen }
|
|
|
|
struct TupleType { LParen, fields: [TypeRef], RParen }
|
|
|
|
struct NeverType { Excl }
|
2020-01-03 13:37:02 -06:00
|
|
|
struct PathType { Path }
|
2020-04-09 11:40:43 -05:00
|
|
|
struct PointerType { Star, ConstKw, MutKw, TypeRef }
|
2020-04-03 14:12:09 -05:00
|
|
|
struct ArrayType { LBrack, TypeRef, Semi, Expr, RBrack }
|
|
|
|
struct SliceType { LBrack, TypeRef, RBrack }
|
|
|
|
struct ReferenceType { Amp, Lifetime, MutKw, TypeRef }
|
|
|
|
struct PlaceholderType { Underscore }
|
|
|
|
struct FnPointerType { Abi, UnsafeKw, FnKw, ParamList, RetType }
|
|
|
|
struct ForType { ForKw, TypeParamList, TypeRef }
|
|
|
|
struct ImplTraitType: TypeBoundsOwner { ImplKw }
|
|
|
|
struct DynTraitType: TypeBoundsOwner { DynKw }
|
|
|
|
|
|
|
|
struct TupleExpr: AttrsOwner { LParen, exprs: [Expr], RParen }
|
|
|
|
struct ArrayExpr: AttrsOwner { LBrack, exprs: [Expr], Semi, RBrack }
|
|
|
|
struct ParenExpr: AttrsOwner { LParen, Expr, RParen }
|
2020-01-03 13:37:02 -06:00
|
|
|
struct PathExpr { Path }
|
2020-04-03 14:12:09 -05:00
|
|
|
struct LambdaExpr: AttrsOwner {
|
|
|
|
StaticKw,
|
|
|
|
AsyncKw,
|
|
|
|
MoveKw,
|
2020-01-03 13:37:02 -06:00
|
|
|
ParamList,
|
|
|
|
RetType,
|
|
|
|
body: Expr,
|
|
|
|
}
|
2020-04-03 14:12:09 -05:00
|
|
|
struct IfExpr: AttrsOwner { IfKw, Condition }
|
|
|
|
struct LoopExpr: AttrsOwner, LoopBodyOwner { LoopKw }
|
|
|
|
struct TryBlockExpr: AttrsOwner { TryKw, body: BlockExpr }
|
|
|
|
struct ForExpr: AttrsOwner, LoopBodyOwner {
|
|
|
|
ForKw,
|
2020-01-03 13:37:02 -06:00
|
|
|
Pat,
|
2020-04-03 14:12:09 -05:00
|
|
|
InKw,
|
2020-01-03 13:37:02 -06:00
|
|
|
iterable: Expr,
|
|
|
|
}
|
2020-04-03 14:12:09 -05:00
|
|
|
struct WhileExpr: AttrsOwner, LoopBodyOwner { WhileKw, Condition }
|
|
|
|
struct ContinueExpr: AttrsOwner { ContinueKw, Lifetime }
|
|
|
|
struct BreakExpr: AttrsOwner { BreakKw, Lifetime, Expr }
|
|
|
|
struct Label { Lifetime }
|
|
|
|
struct BlockExpr: AttrsOwner { Label, UnsafeKw, Block }
|
|
|
|
struct ReturnExpr: AttrsOwner { Expr }
|
2020-01-03 13:37:02 -06:00
|
|
|
struct CallExpr: ArgListOwner { Expr }
|
2020-04-03 14:12:09 -05:00
|
|
|
struct MethodCallExpr: AttrsOwner, ArgListOwner {
|
|
|
|
Expr, Dot, NameRef, TypeArgList,
|
|
|
|
}
|
|
|
|
struct IndexExpr: AttrsOwner { LBrack, RBrack }
|
|
|
|
struct FieldExpr: AttrsOwner { Expr, Dot, NameRef }
|
|
|
|
struct AwaitExpr: AttrsOwner { Expr, Dot, AwaitKw }
|
|
|
|
struct TryExpr: AttrsOwner { TryKw, Expr }
|
|
|
|
struct CastExpr: AttrsOwner { Expr, AsKw, TypeRef }
|
|
|
|
struct RefExpr: AttrsOwner { Amp, RawKw, MutKw, Expr }
|
|
|
|
struct PrefixExpr: AttrsOwner { PrefixOp, Expr }
|
|
|
|
struct BoxExpr: AttrsOwner { BoxKw, Expr }
|
|
|
|
struct RangeExpr: AttrsOwner { RangeOp }
|
|
|
|
struct BinExpr: AttrsOwner { BinOp }
|
|
|
|
struct Literal { LiteralToken }
|
|
|
|
|
|
|
|
struct MatchExpr: AttrsOwner { MatchKw, Expr, MatchArmList }
|
|
|
|
struct MatchArmList: AttrsOwner { LCurly, arms: [MatchArm], RCurly }
|
2020-01-03 13:37:02 -06:00
|
|
|
struct MatchArm: AttrsOwner {
|
2020-02-09 12:57:01 -06:00
|
|
|
pat: Pat,
|
2020-01-03 13:37:02 -06:00
|
|
|
guard: MatchGuard,
|
2020-04-03 14:12:09 -05:00
|
|
|
FatArrow,
|
2020-01-03 13:37:02 -06:00
|
|
|
Expr,
|
2020-02-11 15:33:11 -06:00
|
|
|
}
|
2020-04-03 14:12:09 -05:00
|
|
|
struct MatchGuard { IfKw, Expr }
|
2020-01-03 13:37:02 -06:00
|
|
|
|
2020-04-03 14:12:09 -05:00
|
|
|
struct RecordLit { Path, RecordFieldList}
|
2020-01-03 13:37:02 -06:00
|
|
|
struct RecordFieldList {
|
2020-04-03 14:12:09 -05:00
|
|
|
LCurly,
|
2020-01-03 13:37:02 -06:00
|
|
|
fields: [RecordField],
|
2020-04-03 14:12:09 -05:00
|
|
|
Dotdot,
|
2020-01-03 13:37:02 -06:00
|
|
|
spread: Expr,
|
2020-04-03 14:12:09 -05:00
|
|
|
RCurly
|
2020-02-11 15:33:11 -06:00
|
|
|
}
|
2020-04-03 14:12:09 -05:00
|
|
|
struct RecordField: AttrsOwner { NameRef, Colon, Expr }
|
2020-01-03 13:37:02 -06:00
|
|
|
|
2020-02-09 12:57:01 -06:00
|
|
|
struct OrPat { pats: [Pat] }
|
2020-04-03 14:12:09 -05:00
|
|
|
struct ParenPat { LParen, Pat, RParen }
|
|
|
|
struct RefPat { Amp, MutKw, Pat }
|
|
|
|
struct BoxPat { BoxKw, Pat }
|
2020-04-09 11:40:43 -05:00
|
|
|
struct BindPat: AttrsOwner, NameOwner { RefKw, MutKw, At, Pat }
|
2020-04-03 14:12:09 -05:00
|
|
|
struct PlaceholderPat { Underscore }
|
|
|
|
struct DotDotPat { Dotdot }
|
2020-02-11 15:33:11 -06:00
|
|
|
struct PathPat { Path }
|
2020-04-03 14:12:09 -05:00
|
|
|
struct SlicePat { LBrack, args: [Pat], RBrack }
|
|
|
|
struct RangePat { RangeSeparator }
|
2020-01-03 13:37:02 -06:00
|
|
|
struct LiteralPat { Literal }
|
2020-04-03 08:38:42 -05:00
|
|
|
struct MacroPat { MacroCall }
|
2020-01-03 13:37:02 -06:00
|
|
|
|
|
|
|
struct RecordPat { RecordFieldPatList, Path }
|
|
|
|
struct RecordFieldPatList {
|
2020-04-03 14:12:09 -05:00
|
|
|
LCurly,
|
|
|
|
pats: [RecordInnerPat],
|
2020-01-03 13:37:02 -06:00
|
|
|
record_field_pats: [RecordFieldPat],
|
|
|
|
bind_pats: [BindPat],
|
2020-04-03 14:12:09 -05:00
|
|
|
Dotdot,
|
|
|
|
RCurly
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
2020-04-03 14:12:09 -05:00
|
|
|
struct RecordFieldPat: AttrsOwner, NameOwner { Colon, Pat }
|
2020-01-03 13:37:02 -06:00
|
|
|
|
2020-04-03 14:12:09 -05:00
|
|
|
struct TupleStructPat { Path, LParen, args: [Pat], RParen }
|
|
|
|
struct TuplePat { LParen, args: [Pat], RParen }
|
2020-01-03 13:37:02 -06:00
|
|
|
|
2020-04-03 14:12:09 -05:00
|
|
|
struct Visibility { PubKw, SuperKw, SelfKw, CrateKw }
|
|
|
|
struct Name { Ident }
|
|
|
|
struct NameRef { NameRefToken }
|
2020-01-03 13:37:02 -06:00
|
|
|
|
|
|
|
struct MacroCall: NameOwner, AttrsOwner,DocCommentsOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
Path, Excl, TokenTree, Semi
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
2020-04-03 14:12:09 -05:00
|
|
|
struct Attr { Pound, Excl, LBrack, Path, Eq, input: AttrInput, RBrack }
|
2020-01-03 13:37:02 -06:00
|
|
|
struct TokenTree {}
|
|
|
|
struct TypeParamList {
|
2020-04-03 14:12:09 -05:00
|
|
|
LAngle,
|
|
|
|
generic_params: [GenericParam],
|
2020-01-03 13:37:02 -06:00
|
|
|
type_params: [TypeParam],
|
|
|
|
lifetime_params: [LifetimeParam],
|
2020-04-03 14:12:09 -05:00
|
|
|
const_params: [ConstParam],
|
|
|
|
RAngle
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
struct TypeParam: NameOwner, AttrsOwner, TypeBoundsOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
Eq,
|
2020-01-03 13:37:02 -06:00
|
|
|
default_type: TypeRef,
|
|
|
|
}
|
|
|
|
struct ConstParam: NameOwner, AttrsOwner, TypeAscriptionOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
Eq,
|
2020-01-03 13:37:02 -06:00
|
|
|
default_val: Expr,
|
|
|
|
}
|
2020-04-03 14:12:09 -05:00
|
|
|
struct LifetimeParam: AttrsOwner { Lifetime}
|
|
|
|
struct TypeBound { Lifetime, /* Question, */ ConstKw, /* Question, */ TypeRef}
|
2020-01-03 13:37:02 -06:00
|
|
|
struct TypeBoundList { bounds: [TypeBound] }
|
2020-04-03 14:12:09 -05:00
|
|
|
struct WherePred: TypeBoundsOwner { Lifetime, TypeRef }
|
|
|
|
struct WhereClause { WhereKw, predicates: [WherePred] }
|
|
|
|
struct Abi { String }
|
|
|
|
struct ExprStmt: AttrsOwner { Expr, Semi }
|
|
|
|
struct LetStmt: AttrsOwner, TypeAscriptionOwner {
|
|
|
|
LetKw,
|
2020-01-03 13:37:02 -06:00
|
|
|
Pat,
|
2020-04-03 14:12:09 -05:00
|
|
|
Eq,
|
2020-01-03 13:37:02 -06:00
|
|
|
initializer: Expr,
|
2020-04-09 11:40:43 -05:00
|
|
|
Semi,
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
2020-04-03 14:12:09 -05:00
|
|
|
struct Condition { LetKw, Pat, Eq, Expr }
|
2020-01-03 13:37:02 -06:00
|
|
|
struct Block: AttrsOwner, ModuleItemOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
LCurly,
|
2020-01-03 13:37:02 -06:00
|
|
|
statements: [Stmt],
|
|
|
|
Expr,
|
2020-04-03 14:12:09 -05:00
|
|
|
RCurly,
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
struct ParamList {
|
2020-04-03 14:12:09 -05:00
|
|
|
LParen,
|
2020-01-03 13:37:02 -06:00
|
|
|
SelfParam,
|
|
|
|
params: [Param],
|
2020-04-03 14:12:09 -05:00
|
|
|
RParen
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
2020-04-03 14:12:09 -05:00
|
|
|
struct SelfParam: TypeAscriptionOwner, AttrsOwner { Amp, Lifetime, SelfKw }
|
2020-01-03 13:37:02 -06:00
|
|
|
struct Param: TypeAscriptionOwner, AttrsOwner {
|
|
|
|
Pat,
|
2020-04-03 14:12:09 -05:00
|
|
|
Dotdotdot
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
struct UseItem: AttrsOwner, VisibilityOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
UseKw,
|
2020-01-03 13:37:02 -06:00
|
|
|
UseTree,
|
|
|
|
}
|
|
|
|
struct UseTree {
|
2020-04-03 14:12:09 -05:00
|
|
|
Path, Star, UseTreeList, Alias
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
2020-04-03 14:12:09 -05:00
|
|
|
struct Alias: NameOwner { AsKw }
|
|
|
|
struct UseTreeList { LCurly, use_trees: [UseTree], RCurly }
|
2020-01-03 13:37:02 -06:00
|
|
|
struct ExternCrateItem: AttrsOwner, VisibilityOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
ExternKw, CrateKw, NameRef, Alias,
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
struct ArgList {
|
2020-04-03 14:12:09 -05:00
|
|
|
LParen,
|
2020-01-03 13:37:02 -06:00
|
|
|
args: [Expr],
|
2020-04-03 14:12:09 -05:00
|
|
|
RParen
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
struct Path {
|
|
|
|
segment: PathSegment,
|
|
|
|
qualifier: Path,
|
|
|
|
}
|
|
|
|
struct PathSegment {
|
2020-04-03 14:12:09 -05:00
|
|
|
Coloncolon, LAngle, NameRef, TypeArgList, ParamList, RetType, PathType, RAngle
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
struct TypeArgList {
|
2020-04-03 14:12:09 -05:00
|
|
|
Coloncolon,
|
|
|
|
LAngle,
|
|
|
|
generic_args: [GenericArg],
|
2020-01-03 13:37:02 -06:00
|
|
|
type_args: [TypeArg],
|
|
|
|
lifetime_args: [LifetimeArg],
|
|
|
|
assoc_type_args: [AssocTypeArg],
|
2020-04-03 14:12:09 -05:00
|
|
|
const_args: [ConstArg],
|
|
|
|
RAngle
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
struct TypeArg { TypeRef }
|
2020-04-03 14:12:09 -05:00
|
|
|
struct AssocTypeArg : TypeBoundsOwner { NameRef, Eq, TypeRef }
|
|
|
|
struct LifetimeArg { Lifetime }
|
|
|
|
struct ConstArg { Literal, Eq, BlockExpr }
|
2020-01-03 13:37:02 -06:00
|
|
|
|
2020-04-09 16:02:10 -05:00
|
|
|
struct MacroItems: ModuleItemOwner{ }
|
2020-01-03 13:37:02 -06:00
|
|
|
|
|
|
|
struct MacroStmts {
|
|
|
|
statements: [Stmt],
|
|
|
|
Expr,
|
|
|
|
}
|
2020-04-03 14:12:09 -05:00
|
|
|
|
2020-04-09 16:02:10 -05:00
|
|
|
struct ExternItemList: ModuleItemOwner {
|
2020-04-03 14:12:09 -05:00
|
|
|
LCurly,
|
|
|
|
extern_items: [ExternItem],
|
|
|
|
RCurly
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ExternBlock {
|
|
|
|
Abi,
|
|
|
|
ExternItemList
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MetaItem {
|
|
|
|
Path, Eq, AttrInput, nested_meta_items: [MetaItem]
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MacroDef {
|
|
|
|
Name, TokenTree
|
|
|
|
}
|
2020-01-03 13:37:02 -06:00
|
|
|
},
|
|
|
|
enums: &ast_enums! {
|
|
|
|
enum NominalDef: NameOwner, TypeParamsOwner, AttrsOwner {
|
|
|
|
StructDef, EnumDef, UnionDef,
|
|
|
|
}
|
|
|
|
|
2020-04-03 14:12:09 -05:00
|
|
|
enum GenericParam {
|
|
|
|
LifetimeParam,
|
|
|
|
TypeParam,
|
|
|
|
ConstParam
|
|
|
|
}
|
|
|
|
|
|
|
|
enum GenericArg {
|
|
|
|
LifetimeArg,
|
|
|
|
TypeArg,
|
|
|
|
ConstArg,
|
|
|
|
AssocTypeArg
|
|
|
|
}
|
|
|
|
|
2020-01-03 13:37:02 -06:00
|
|
|
enum TypeRef {
|
|
|
|
ParenType,
|
|
|
|
TupleType,
|
|
|
|
NeverType,
|
|
|
|
PathType,
|
|
|
|
PointerType,
|
|
|
|
ArrayType,
|
|
|
|
SliceType,
|
|
|
|
ReferenceType,
|
|
|
|
PlaceholderType,
|
|
|
|
FnPointerType,
|
|
|
|
ForType,
|
|
|
|
ImplTraitType,
|
|
|
|
DynTraitType,
|
|
|
|
}
|
|
|
|
|
2020-04-03 14:12:09 -05:00
|
|
|
enum ModuleItem: NameOwner, AttrsOwner, VisibilityOwner {
|
2020-01-03 13:37:02 -06:00
|
|
|
StructDef,
|
|
|
|
UnionDef,
|
|
|
|
EnumDef,
|
|
|
|
FnDef,
|
|
|
|
TraitDef,
|
|
|
|
TypeAliasDef,
|
2020-02-29 14:24:40 -06:00
|
|
|
ImplDef,
|
2020-01-03 13:37:02 -06:00
|
|
|
UseItem,
|
|
|
|
ExternCrateItem,
|
|
|
|
ConstDef,
|
|
|
|
StaticDef,
|
|
|
|
Module,
|
2020-03-26 10:10:01 -05:00
|
|
|
MacroCall,
|
2020-04-03 14:12:09 -05:00
|
|
|
ExternBlock
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
2020-04-03 14:12:09 -05:00
|
|
|
/* impl blocks can also contain MacroCall */
|
|
|
|
enum ImplItem: NameOwner, AttrsOwner {
|
|
|
|
FnDef, TypeAliasDef, ConstDef
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
2020-04-03 14:12:09 -05:00
|
|
|
/* extern blocks can also contain MacroCall */
|
|
|
|
enum ExternItem: NameOwner, AttrsOwner, VisibilityOwner {
|
|
|
|
FnDef, StaticDef
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Expr: AttrsOwner {
|
2020-01-03 13:37:02 -06:00
|
|
|
TupleExpr,
|
|
|
|
ArrayExpr,
|
|
|
|
ParenExpr,
|
|
|
|
PathExpr,
|
|
|
|
LambdaExpr,
|
|
|
|
IfExpr,
|
|
|
|
LoopExpr,
|
|
|
|
ForExpr,
|
|
|
|
WhileExpr,
|
|
|
|
ContinueExpr,
|
|
|
|
BreakExpr,
|
|
|
|
Label,
|
|
|
|
BlockExpr,
|
|
|
|
ReturnExpr,
|
|
|
|
MatchExpr,
|
|
|
|
RecordLit,
|
|
|
|
CallExpr,
|
|
|
|
IndexExpr,
|
|
|
|
MethodCallExpr,
|
|
|
|
FieldExpr,
|
|
|
|
AwaitExpr,
|
|
|
|
TryExpr,
|
|
|
|
TryBlockExpr,
|
|
|
|
CastExpr,
|
|
|
|
RefExpr,
|
|
|
|
PrefixExpr,
|
|
|
|
RangeExpr,
|
|
|
|
BinExpr,
|
|
|
|
Literal,
|
|
|
|
MacroCall,
|
|
|
|
BoxExpr,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Pat {
|
2020-02-09 12:57:01 -06:00
|
|
|
OrPat,
|
|
|
|
ParenPat,
|
2020-01-03 13:37:02 -06:00
|
|
|
RefPat,
|
|
|
|
BoxPat,
|
|
|
|
BindPat,
|
|
|
|
PlaceholderPat,
|
|
|
|
DotDotPat,
|
|
|
|
PathPat,
|
|
|
|
RecordPat,
|
|
|
|
TupleStructPat,
|
|
|
|
TuplePat,
|
|
|
|
SlicePat,
|
|
|
|
RangePat,
|
|
|
|
LiteralPat,
|
2020-04-03 08:38:42 -05:00
|
|
|
MacroPat,
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
2020-04-03 14:12:09 -05:00
|
|
|
enum RecordInnerPat {
|
|
|
|
RecordFieldPat,
|
|
|
|
BindPat
|
|
|
|
}
|
|
|
|
|
2020-01-03 13:37:02 -06:00
|
|
|
enum AttrInput { Literal, TokenTree }
|
2020-04-03 14:12:09 -05:00
|
|
|
enum Stmt {
|
|
|
|
LetStmt,
|
|
|
|
ExprStmt,
|
|
|
|
// macro calls are parsed as expression statements */
|
|
|
|
}
|
|
|
|
|
2020-04-09 10:58:15 -05:00
|
|
|
enum FieldDefList {
|
|
|
|
RecordFieldDefList,
|
|
|
|
TupleFieldDefList,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
token_enums: &ast_enums! {
|
2020-04-03 14:12:09 -05:00
|
|
|
enum LeftDelimiter { LParen, LBrack, LCurly }
|
|
|
|
enum RightDelimiter { RParen, RBrack, RCurly }
|
|
|
|
enum RangeSeparator { Dotdot, Dotdotdot, Dotdoteq}
|
|
|
|
|
|
|
|
enum BinOp {
|
|
|
|
Pipepipe,
|
|
|
|
Ampamp,
|
|
|
|
Eqeq,
|
|
|
|
Neq,
|
|
|
|
Lteq,
|
|
|
|
Gteq,
|
|
|
|
LAngle,
|
|
|
|
RAngle,
|
|
|
|
Plus,
|
|
|
|
Star,
|
|
|
|
Minus,
|
|
|
|
Slash,
|
|
|
|
Percent,
|
|
|
|
Shl,
|
|
|
|
Shr,
|
|
|
|
Caret,
|
|
|
|
Pipe,
|
|
|
|
Amp,
|
|
|
|
Eq,
|
|
|
|
Pluseq,
|
|
|
|
Slasheq,
|
|
|
|
Stareq,
|
|
|
|
Percenteq,
|
|
|
|
Shreq,
|
|
|
|
Shleq,
|
|
|
|
Minuseq,
|
|
|
|
Pipeeq,
|
|
|
|
Ampeq,
|
|
|
|
Careteq,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum PrefixOp {
|
|
|
|
Minus,
|
|
|
|
Excl,
|
|
|
|
Star
|
|
|
|
}
|
|
|
|
|
|
|
|
enum RangeOp {
|
|
|
|
Dotdot,
|
|
|
|
Dotdoteq
|
|
|
|
}
|
|
|
|
|
|
|
|
enum LiteralToken {
|
|
|
|
IntNumber,
|
|
|
|
FloatNumber,
|
|
|
|
String,
|
|
|
|
RawString,
|
2020-04-09 16:35:05 -05:00
|
|
|
// TrueKw,
|
|
|
|
// FalseKw,
|
2020-04-03 14:12:09 -05:00
|
|
|
ByteString,
|
|
|
|
RawByteString,
|
|
|
|
Char,
|
|
|
|
Byte
|
|
|
|
}
|
|
|
|
|
|
|
|
enum NameRefToken {
|
|
|
|
Ident,
|
|
|
|
IntNumber
|
|
|
|
}
|
2020-01-03 13:37:02 -06:00
|
|
|
},
|
|
|
|
};
|