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],
|
|
|
|
}
|
|
|
|
|
2022-07-20 08:02:08 -05:00
|
|
|
pub(crate) const KINDS_SRC: KindsSrc<'_> = KindsSrc {
|
2020-01-03 13:37:02 -06:00
|
|
|
punct: &[
|
2020-04-10 10:06:57 -05:00
|
|
|
(";", "SEMICOLON"),
|
2020-01-03 13:37:02 -06:00
|
|
|
(",", "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"),
|
2020-01-03 13:37:02 -06:00
|
|
|
(":", "COLON"),
|
2020-04-10 10:06:57 -05:00
|
|
|
("::", "COLON2"),
|
2020-01-03 13:37:02 -06:00
|
|
|
("=", "EQ"),
|
2020-04-10 10:06:57 -05:00
|
|
|
("==", "EQ2"),
|
2020-01-03 13:37:02 -06:00
|
|
|
("=>", "FAT_ARROW"),
|
2020-04-10 10:06:57 -05:00
|
|
|
("!", "BANG"),
|
2020-01-03 13:37:02 -06:00
|
|
|
("!=", "NEQ"),
|
|
|
|
("-", "MINUS"),
|
|
|
|
("->", "THIN_ARROW"),
|
|
|
|
("<=", "LTEQ"),
|
|
|
|
(">=", "GTEQ"),
|
|
|
|
("+=", "PLUSEQ"),
|
|
|
|
("-=", "MINUSEQ"),
|
|
|
|
("|=", "PIPEEQ"),
|
|
|
|
("&=", "AMPEQ"),
|
|
|
|
("^=", "CARETEQ"),
|
|
|
|
("/=", "SLASHEQ"),
|
|
|
|
("*=", "STAREQ"),
|
|
|
|
("%=", "PERCENTEQ"),
|
2020-04-10 10:06:57 -05:00
|
|
|
("&&", "AMP2"),
|
|
|
|
("||", "PIPE2"),
|
2020-01-03 13:37:02 -06:00
|
|
|
("<<", "SHL"),
|
|
|
|
(">>", "SHR"),
|
|
|
|
("<<=", "SHLEQ"),
|
|
|
|
(">>=", "SHREQ"),
|
|
|
|
],
|
|
|
|
keywords: &[
|
2022-12-28 16:42:26 -06:00
|
|
|
"as", "async", "await", "box", "break", "const", "continue", "crate", "do", "dyn", "else",
|
2020-01-03 13:37:02 -06:00
|
|
|
"enum", "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "macro",
|
2022-03-05 16:20:06 -06:00
|
|
|
"match", "mod", "move", "mut", "pub", "ref", "return", "self", "Self", "static", "struct",
|
|
|
|
"super", "trait", "true", "try", "type", "unsafe", "use", "where", "while", "yield",
|
2020-01-03 13:37:02 -06:00
|
|
|
],
|
2022-12-28 16:42:26 -06:00
|
|
|
contextual_keywords: &["auto", "default", "existential", "union", "raw", "macro_rules", "yeet"],
|
2022-05-13 08:08:14 -05:00
|
|
|
literals: &["INT_NUMBER", "FLOAT_NUMBER", "CHAR", "BYTE", "STRING", "BYTE_STRING"],
|
2021-10-23 12:43:45 -05:00
|
|
|
tokens: &["ERROR", "IDENT", "WHITESPACE", "LIFETIME_IDENT", "COMMENT", "SHEBANG"],
|
2020-01-03 13:37:02 -06:00
|
|
|
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",
|
2020-01-03 13:37:02 -06:00
|
|
|
"RET_TYPE",
|
2020-07-30 05:26:57 -05:00
|
|
|
"EXTERN_CRATE",
|
2020-01-03 13:37:02 -06:00
|
|
|
"MODULE",
|
2020-07-30 07:12:04 -05:00
|
|
|
"USE",
|
2020-07-30 11:02:20 -05:00
|
|
|
"STATIC",
|
|
|
|
"CONST",
|
2020-07-30 11:17:28 -05:00
|
|
|
"TRAIT",
|
2020-07-30 11:28:28 -05:00
|
|
|
"IMPL",
|
2020-07-30 08:25:46 -05:00
|
|
|
"TYPE_ALIAS",
|
2020-01-03 13:37:02 -06:00
|
|
|
"MACRO_CALL",
|
2020-12-15 08:37:37 -06:00
|
|
|
"MACRO_RULES",
|
|
|
|
"MACRO_ARM",
|
2020-01-03 13:37:02 -06:00
|
|
|
"TOKEN_TREE",
|
|
|
|
"MACRO_DEF",
|
|
|
|
"PAREN_TYPE",
|
|
|
|
"TUPLE_TYPE",
|
2021-01-18 09:58:43 -06:00
|
|
|
"MACRO_TYPE",
|
2020-01-03 13:37:02 -06:00
|
|
|
"NEVER_TYPE",
|
|
|
|
"PATH_TYPE",
|
2020-08-01 06:47:19 -05:00
|
|
|
"PTR_TYPE",
|
2020-01-03 13:37:02 -06:00
|
|
|
"ARRAY_TYPE",
|
|
|
|
"SLICE_TYPE",
|
2020-08-01 06:47:19 -05:00
|
|
|
"REF_TYPE",
|
2020-07-31 06:22:47 -05:00
|
|
|
"INFER_TYPE",
|
2020-08-01 06:47:19 -05:00
|
|
|
"FN_PTR_TYPE",
|
2020-01-03 13:37:02 -06:00
|
|
|
"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",
|
2020-07-31 13:09:09 -05:00
|
|
|
"IDENT_PAT",
|
2020-07-31 13:07:21 -05:00
|
|
|
"WILDCARD_PAT",
|
2020-07-31 14:45:29 -05:00
|
|
|
"REST_PAT",
|
2020-01-03 13:37:02 -06:00
|
|
|
"PATH_PAT",
|
|
|
|
"RECORD_PAT",
|
2020-07-31 12:54:16 -05:00
|
|
|
"RECORD_PAT_FIELD_LIST",
|
|
|
|
"RECORD_PAT_FIELD",
|
2020-01-03 13:37:02 -06:00
|
|
|
"TUPLE_STRUCT_PAT",
|
|
|
|
"TUPLE_PAT",
|
|
|
|
"SLICE_PAT",
|
|
|
|
"RANGE_PAT",
|
|
|
|
"LITERAL_PAT",
|
2020-04-03 08:38:42 -05:00
|
|
|
"MACRO_PAT",
|
2020-12-22 18:26:31 -06:00
|
|
|
"CONST_BLOCK_PAT",
|
2020-01-03 13:37:02 -06:00
|
|
|
// atoms
|
|
|
|
"TUPLE_EXPR",
|
|
|
|
"ARRAY_EXPR",
|
|
|
|
"PAREN_EXPR",
|
|
|
|
"PATH_EXPR",
|
2020-07-31 10:08:58 -05:00
|
|
|
"CLOSURE_EXPR",
|
2020-01-03 13:37:02 -06:00
|
|
|
"IF_EXPR",
|
|
|
|
"WHILE_EXPR",
|
|
|
|
"LOOP_EXPR",
|
|
|
|
"FOR_EXPR",
|
|
|
|
"CONTINUE_EXPR",
|
|
|
|
"BREAK_EXPR",
|
|
|
|
"LABEL",
|
|
|
|
"BLOCK_EXPR",
|
2021-09-26 04:12:57 -05:00
|
|
|
"STMT_LIST",
|
2020-01-03 13:37:02 -06:00
|
|
|
"RETURN_EXPR",
|
2021-01-13 09:01:50 -06:00
|
|
|
"YIELD_EXPR",
|
2022-12-28 16:42:26 -06:00
|
|
|
"YEET_EXPR",
|
2022-01-22 20:21:09 -06:00
|
|
|
"LET_EXPR",
|
2022-02-24 02:49:47 -06:00
|
|
|
"UNDERSCORE_EXPR",
|
2022-04-05 10:42:07 -05:00
|
|
|
"MACRO_EXPR",
|
2020-01-03 13:37:02 -06:00
|
|
|
"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-01-03 13:37:02 -06:00
|
|
|
"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",
|
2020-01-03 13:37:02 -06:00
|
|
|
"ITEM_LIST",
|
2020-07-30 04:42:51 -05:00
|
|
|
"ASSOC_ITEM_LIST",
|
2020-01-03 13:37:02 -06:00
|
|
|
"ATTR",
|
2021-06-11 11:12:51 -05:00
|
|
|
"META",
|
2020-01-03 13:37:02 -06:00
|
|
|
"USE_TREE",
|
|
|
|
"USE_TREE_LIST",
|
|
|
|
"PATH",
|
|
|
|
"PATH_SEGMENT",
|
|
|
|
"LITERAL",
|
2020-07-30 04:58:41 -05:00
|
|
|
"RENAME",
|
2020-01-03 13:37:02 -06:00
|
|
|
"VISIBILITY",
|
|
|
|
"WHERE_CLAUSE",
|
|
|
|
"WHERE_PRED",
|
|
|
|
"ABI",
|
|
|
|
"NAME",
|
|
|
|
"NAME_REF",
|
|
|
|
"LET_STMT",
|
2021-10-07 10:05:50 -05:00
|
|
|
"LET_ELSE",
|
2020-01-03 13:37:02 -06:00
|
|
|
"EXPR_STMT",
|
2020-07-30 08:36:21 -05:00
|
|
|
"GENERIC_PARAM_LIST",
|
2020-07-30 11:52:02 -05:00
|
|
|
"GENERIC_PARAM",
|
2020-01-03 13:37:02 -06:00
|
|
|
"LIFETIME_PARAM",
|
|
|
|
"TYPE_PARAM",
|
|
|
|
"CONST_PARAM",
|
2020-07-31 11:29:29 -05:00
|
|
|
"GENERIC_ARG_LIST",
|
2020-12-15 12:23:51 -06:00
|
|
|
"LIFETIME",
|
2020-01-03 13:37:02 -06:00
|
|
|
"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",
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2020-07-29 08:45:23 -05:00
|
|
|
#[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>,
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
2020-07-29 08:45:23 -05:00
|
|
|
#[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
|
|
|
}
|
|
|
|
|
2020-07-29 08:45:23 -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 },
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
2020-07-29 08:45:23 -05:00
|
|
|
#[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,
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|
|
|
|
|
2020-07-29 08:45:23 -05:00
|
|
|
#[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>,
|
2020-01-03 13:37:02 -06:00
|
|
|
}
|