rust/xtask/src/ast_src.rs

261 lines
6.1 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",
2020-07-30 10:50:40 -05:00
"STRUCT",
2020-07-30 10:36:46 -05:00
"UNION",
2020-07-30 10:52:53 -05:00
"ENUM",
2020-07-30 07:51:08 -05:00
"FN",
"RET_TYPE",
2020-07-30 05:26:57 -05:00
"EXTERN_CRATE",
"MODULE",
2020-07-30 07:12:04 -05:00
"USE",
2020-07-30 11:02:20 -05:00
"STATIC",
"CONST",
"TRAIT_DEF",
2020-02-29 14:24:40 -06:00
"IMPL_DEF",
2020-07-30 08:25:46 -05:00
"TYPE_ALIAS",
"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",
2020-07-30 09:21:30 -05:00
"RECORD_EXPR",
"RECORD_EXPR_FIELD_LIST",
"RECORD_EXPR_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",
2020-07-30 10:56:53 -05:00
"VARIANT",
2020-07-30 09:49:13 -05:00
"RECORD_FIELD_LIST",
"RECORD_FIELD",
"TUPLE_FIELD_LIST",
"TUPLE_FIELD",
2020-07-30 10:56:53 -05:00
"VARIANT_LIST",
"ITEM_LIST",
2020-07-30 04:42:51 -05:00
"ASSOC_ITEM_LIST",
"ATTR",
"META_ITEM", // not an item actually
"USE_TREE",
"USE_TREE_LIST",
"PATH",
"PATH_SEGMENT",
"LITERAL",
2020-07-30 04:58:41 -05:00
"RENAME",
"VISIBILITY",
"WHERE_CLAUSE",
"WHERE_PRED",
"ABI",
"NAME",
"NAME_REF",
"LET_STMT",
"EXPR_STMT",
"GENERIC_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",
],
};
#[derive(Default, Debug)]
2020-07-29 04:48:32 -05:00
pub(crate) struct AstSrc {
pub(crate) tokens: Vec<String>,
pub(crate) nodes: Vec<AstNodeSrc>,
pub(crate) enums: Vec<AstEnumSrc>,
}
#[derive(Debug)]
2020-07-29 04:48:32 -05:00
pub(crate) struct AstNodeSrc {
pub(crate) doc: Vec<String>,
pub(crate) name: String,
pub(crate) traits: Vec<String>,
pub(crate) fields: Vec<Field>,
2020-04-10 03:07:09 -05:00
}
#[derive(Debug, Eq, PartialEq)]
2020-07-29 04:48:32 -05:00
pub(crate) enum Field {
Token(String),
2020-07-30 10:19:51 -05:00
Node { name: String, ty: String, cardinality: Cardinality },
}
#[derive(Debug, Eq, PartialEq)]
2020-07-30 10:19:51 -05:00
pub(crate) enum Cardinality {
2020-07-30 10:10:44 -05:00
Optional,
Many,
}
#[derive(Debug)]
2020-07-29 04:48:32 -05:00
pub(crate) struct AstEnumSrc {
pub(crate) doc: Vec<String>,
pub(crate) name: String,
pub(crate) traits: Vec<String>,
pub(crate) variants: Vec<String>,
}