rust/crates/ra_syntax/src/grammar.ron

557 lines
14 KiB
Text
Raw Normal View History

2018-10-04 22:43:58 +02:00
// Stores definitions which must be used in multiple places
2018-10-16 20:09:22 +02:00
// See `cargo gen-syntax` (defined in crates/tools/src/main.rs)
2017-12-28 23:21:54 +01:00
Grammar(
2018-07-30 16:46:50 +02:00
single_byte_tokens: [
[";", "SEMI"],
[",", "COMMA"],
["(", "L_PAREN"],
[")", "R_PAREN"],
["{", "L_CURLY"],
["}", "R_CURLY"],
["[", "L_BRACK"],
["]", "R_BRACK"],
["<", "L_ANGLE"],
[">", "R_ANGLE"],
["@", "AT"],
["#", "POUND"],
["~", "TILDE"],
["?", "QUESTION"],
["$", "DOLLAR"],
2018-08-05 17:18:02 +02:00
["&", "AMP"],
2018-07-30 16:46:50 +02:00
["|", "PIPE"],
["+", "PLUS"],
["*", "STAR"],
["/", "SLASH"],
["^", "CARET"],
["%", "PERCENT"],
],
// Tokens for which the longest match must be chosen (e.g. `..` is a DOTDOT, but `.` is a DOT)
2018-07-30 16:46:50 +02:00
multi_byte_tokens: [
[".", "DOT"],
2018-07-30 16:46:50 +02:00
["..", "DOTDOT"],
["...", "DOTDOTDOT"],
["..=", "DOTDOTEQ"],
[":", "COLON"],
["::", "COLONCOLON"],
["=", "EQ"],
["==", "EQEQ"],
["=>", "FAT_ARROW"],
["!", "EXCL"],
["!=", "NEQ"],
["-", "MINUS"],
["->", "THIN_ARROW"],
2018-08-05 15:09:25 +02:00
["<=", "LTEQ"],
[">=", "GTEQ"],
["+=", "PLUSEQ"],
["-=", "MINUSEQ"],
2018-08-23 23:48:10 +02:00
["|=", "PIPEEQ"],
["&=", "AMPEQ"],
["^=", "CARETEQ"],
["/=", "SLASHEQ"],
["*=", "STAREQ"],
2018-08-05 17:18:02 +02:00
["&&", "AMPAMP"],
2018-08-05 17:16:52 +02:00
["||", "PIPEPIPE"],
2018-08-07 13:24:03 +02:00
["<<", "SHL"],
[">>", "SHR"],
["<<=", "SHLEQ"],
[">>=", "SHREQ"],
2018-07-30 16:46:50 +02:00
],
2018-01-01 16:58:46 +01:00
keywords: [
"use",
"fn",
"struct",
"enum",
"trait",
"impl",
2018-08-13 16:42:43 +02:00
"dyn",
2018-01-08 19:21:59 +01:00
"true",
"false",
2018-01-08 22:06:42 +01:00
"as",
"extern",
"crate",
2018-01-09 20:35:55 +01:00
"mod",
2018-01-12 20:05:46 +01:00
"pub",
"self",
"super",
2018-01-13 09:55:03 +01:00
"in",
2018-01-13 20:00:26 +01:00
"where",
2018-01-30 20:53:19 +01:00
"for",
"loop",
"while",
2018-08-24 10:21:13 +02:00
"continue",
"break",
2018-01-30 20:53:19 +01:00
"if",
2018-07-31 23:14:26 +02:00
"else",
2018-02-02 21:30:17 +01:00
"match",
"const",
"static",
2018-02-02 21:45:15 +01:00
"mut",
2018-02-03 10:05:25 +01:00
"unsafe",
2018-02-10 10:35:40 +01:00
"type",
"ref",
"let",
2018-07-31 23:30:17 +02:00
"move",
2018-08-01 10:27:31 +02:00
"return",
2018-01-01 16:58:46 +01:00
],
2018-02-04 14:46:26 +01:00
contextual_keywords: [
"auto",
"default",
"union",
],
2017-12-31 21:27:36 +01:00
tokens: [
2017-12-29 22:48:47 +01:00
"ERROR",
2017-12-28 23:21:54 +01:00
"IDENT",
2017-12-29 22:48:47 +01:00
"UNDERSCORE",
2017-12-28 23:21:54 +01:00
"WHITESPACE",
2017-12-30 13:22:40 +01:00
"INT_NUMBER",
"FLOAT_NUMBER",
2017-12-31 08:41:42 +01:00
"LIFETIME",
2017-12-31 12:02:55 +01:00
"CHAR",
"BYTE",
"STRING",
"RAW_STRING",
"BYTE_STRING",
"RAW_BYTE_STRING",
2017-12-31 14:42:22 +01:00
"COMMENT",
"SHEBANG",
2017-12-31 21:27:36 +01:00
],
nodes: [
2018-11-07 16:38:43 +01:00
"SOURCE_FILE",
2018-02-02 20:08:14 +01:00
2018-08-13 17:27:26 +02:00
"STRUCT_DEF",
"ENUM_DEF",
"FN_DEF",
2018-08-28 20:11:17 +02:00
"RET_TYPE",
2018-01-08 22:06:42 +01:00
"EXTERN_CRATE_ITEM",
2018-08-11 09:56:40 +02:00
"MODULE",
2018-01-09 21:32:18 +01:00
"USE_ITEM",
2018-08-13 17:27:26 +02:00
"STATIC_DEF",
"CONST_DEF",
"TRAIT_DEF",
2018-02-04 11:39:24 +01:00
"IMPL_ITEM",
2018-08-13 17:27:26 +02:00
"TYPE_DEF",
2018-08-05 13:08:46 +02:00
"MACRO_CALL",
"TOKEN_TREE",
2018-02-02 20:08:14 +01:00
2018-02-10 22:46:17 +01:00
"PAREN_TYPE",
"TUPLE_TYPE",
"NEVER_TYPE",
"PATH_TYPE",
2018-02-11 09:19:54 +01:00
"POINTER_TYPE",
2018-02-11 09:37:08 +01:00
"ARRAY_TYPE",
"SLICE_TYPE",
2018-02-11 09:54:09 +01:00
"REFERENCE_TYPE",
2018-02-11 09:57:05 +01:00
"PLACEHOLDER_TYPE",
2018-02-11 10:51:09 +01:00
"FN_POINTER_TYPE",
2018-02-11 21:32:49 +01:00
"FOR_TYPE",
2018-07-31 21:41:29 +02:00
"IMPL_TRAIT_TYPE",
2018-08-13 16:42:43 +02:00
"DYN_TRAIT_TYPE",
2018-02-10 22:46:17 +01:00
"REF_PAT",
"BIND_PAT",
"PLACEHOLDER_PAT",
2018-08-04 14:47:45 +02:00
"PATH_PAT",
"STRUCT_PAT",
2018-08-24 18:27:30 +02:00
"FIELD_PAT_LIST",
2018-08-07 13:41:03 +02:00
"TUPLE_STRUCT_PAT",
2018-08-04 14:47:45 +02:00
"TUPLE_PAT",
2018-08-07 16:00:45 +02:00
"SLICE_PAT",
2018-08-08 14:05:33 +02:00
"RANGE_PAT",
2018-08-04 15:34:54 +02:00
// atoms
"TUPLE_EXPR",
2018-08-05 17:24:56 +02:00
"ARRAY_EXPR",
2018-08-05 16:19:03 +02:00
"PAREN_EXPR",
2018-07-30 16:02:51 +02:00
"PATH_EXPR",
2018-07-31 22:13:08 +02:00
"LAMBDA_EXPR",
2018-07-31 23:14:26 +02:00
"IF_EXPR",
2018-08-27 11:22:09 +02:00
"WHILE_EXPR",
"CONDITION",
2018-08-05 17:16:52 +02:00
"LOOP_EXPR",
2018-08-24 10:45:14 +02:00
"FOR_EXPR",
2018-08-24 10:21:13 +02:00
"CONTINUE_EXPR",
"BREAK_EXPR",
2018-08-24 10:45:14 +02:00
"LABEL",
2018-08-01 10:27:31 +02:00
"BLOCK_EXPR",
"RETURN_EXPR",
2018-08-04 12:39:03 +02:00
"MATCH_EXPR",
2018-08-24 18:27:30 +02:00
"MATCH_ARM_LIST",
2018-08-04 12:39:03 +02:00
"MATCH_ARM",
"MATCH_GUARD",
2018-08-04 15:34:54 +02:00
"STRUCT_LIT",
2018-08-24 18:27:30 +02:00
"NAMED_FIELD_LIST",
"NAMED_FIELD",
2018-08-04 15:34:54 +02:00
// postfix
"CALL_EXPR",
2018-08-05 16:24:44 +02:00
"INDEX_EXPR",
2018-08-04 15:34:54 +02:00
"METHOD_CALL_EXPR",
"FIELD_EXPR",
"TRY_EXPR",
2018-08-07 02:55:16 +02:00
"CAST_EXPR",
2018-08-04 15:34:54 +02:00
// unary
"REF_EXPR",
2018-08-07 13:52:03 +02:00
"PREFIX_EXPR",
2018-08-04 15:34:54 +02:00
2018-08-05 17:07:06 +02:00
"RANGE_EXPR", // just weird
2018-08-04 15:34:54 +02:00
"BIN_EXPR",
2018-08-24 18:27:30 +02:00
"BLOCK",
"EXTERN_BLOCK",
"EXTERN_ITEM_LIST",
2018-02-02 20:08:14 +01:00
"ENUM_VARIANT",
2018-08-24 18:27:30 +02:00
"NAMED_FIELD_DEF_LIST",
"NAMED_FIELD_DEF",
"POS_FIELD_LIST",
2018-02-02 20:08:14 +01:00
"POS_FIELD",
2018-08-24 18:27:30 +02:00
"ENUM_VARIANT_LIST",
"ITEM_LIST",
2018-02-02 20:08:14 +01:00
"ATTR",
"META_ITEM", // not an item actually
2018-01-13 11:42:19 +01:00
"USE_TREE",
2018-08-24 18:27:30 +02:00
"USE_TREE_LIST",
2018-01-09 21:32:18 +01:00
"PATH",
"PATH_SEGMENT",
2018-01-08 19:40:00 +01:00
"LITERAL",
2018-01-08 22:06:42 +01:00
"ALIAS",
2018-01-12 20:05:46 +01:00
"VISIBILITY",
2018-02-10 10:53:07 +01:00
"WHERE_CLAUSE",
2018-08-08 18:26:38 +02:00
"WHERE_PRED",
2018-02-02 20:08:14 +01:00
"ABI",
2018-02-10 12:00:23 +01:00
"NAME",
"NAME_REF",
2018-07-31 11:59:52 +02:00
"LET_STMT",
2018-07-31 11:59:52 +02:00
"EXPR_STMT",
2018-07-30 16:02:51 +02:00
"TYPE_PARAM_LIST",
2018-07-31 18:37:40 +02:00
"LIFETIME_PARAM",
"TYPE_PARAM",
2018-07-30 16:02:51 +02:00
"TYPE_ARG_LIST",
2018-07-31 18:37:40 +02:00
"LIFETIME_ARG",
"TYPE_ARG",
"ASSOC_TYPE_ARG",
2018-07-31 11:32:53 +02:00
"PARAM_LIST",
2018-07-31 22:13:55 +02:00
"PARAM",
2018-07-31 17:03:50 +02:00
"SELF_PARAM",
2018-07-31 11:32:53 +02:00
"ARG_LIST",
2018-08-09 16:43:39 +02:00
],
2018-08-11 09:11:58 +02:00
ast: {
2018-11-07 16:38:43 +01:00
"SourceFile": (
2018-09-08 00:35:20 +02:00
traits: [ "ModuleItemOwner", "FnDefOwner" ],
2018-08-11 08:38:27 +02:00
collections: [
2018-08-21 17:30:10 +02:00
["modules", "Module"],
2018-08-11 08:38:27 +02:00
]
2018-08-09 16:43:39 +02:00
),
2018-08-26 11:09:28 +02:00
"FnDef": (
traits: [
"NameOwner",
"TypeParamsOwner",
"AttrsOwner",
"DocCommentsOwner"
2018-08-26 11:09:28 +02:00
],
2018-08-31 14:10:37 +02:00
options: [ "ParamList", ["body", "Block"], "RetType" ],
2018-08-26 11:09:28 +02:00
),
"RetType": (options: ["TypeRef"]),
2018-08-14 13:45:56 +02:00
"StructDef": (
2018-08-22 15:46:42 +02:00
traits: [
"NameOwner",
"TypeParamsOwner",
"AttrsOwner",
2018-11-02 14:59:07 +01:00
"DocCommentsOwner"
2018-08-14 13:45:56 +02:00
]
),
"NamedFieldDefList": (collections: [["fields", "NamedFieldDef"]]),
"NamedFieldDef": ( traits: ["NameOwner", "AttrsOwner"], options: ["TypeRef"] ),
"PosFieldList": (collections: [["fields", "PosField"]]),
"PosField": ( traits: ["AttrsOwner"], options: ["TypeRef"]),
2018-08-22 15:46:42 +02:00
"EnumDef": ( traits: [
"NameOwner",
"TypeParamsOwner",
"AttrsOwner",
2018-11-02 14:59:07 +01:00
"DocCommentsOwner"
], options: [["variant_list", "EnumVariantList"]] ),
"EnumVariantList": ( collections: [["variants", "EnumVariant"]] ),
"EnumVariant": ( traits: ["NameOwner"], options: ["Expr"] ),
2018-11-02 14:59:07 +01:00
"TraitDef": ( traits: ["NameOwner", "AttrsOwner", "DocCommentsOwner"] ),
2018-08-21 17:30:10 +02:00
"Module": (
2018-11-02 14:59:07 +01:00
traits: ["NameOwner", "AttrsOwner", "DocCommentsOwner" ],
2018-09-03 14:10:06 +02:00
options: [ "ItemList" ]
),
"ItemList": (
2018-09-08 00:35:20 +02:00
traits: [ "FnDefOwner", "ModuleItemOwner" ],
2018-08-21 17:30:10 +02:00
),
2018-08-22 15:46:42 +02:00
"ConstDef": ( traits: [
"NameOwner",
"TypeParamsOwner",
"AttrsOwner",
2018-11-02 14:59:07 +01:00
"DocCommentsOwner"
2018-08-22 15:46:42 +02:00
] ),
"StaticDef": ( traits: [
"NameOwner",
"TypeParamsOwner",
"AttrsOwner",
2018-11-02 14:59:07 +01:00
"DocCommentsOwner"
2018-08-22 15:46:42 +02:00
] ),
"TypeDef": ( traits: [
"NameOwner",
"TypeParamsOwner",
"AttrsOwner",
2018-11-02 14:59:07 +01:00
"DocCommentsOwner"
2018-08-22 15:46:42 +02:00
] ),
2018-08-14 10:20:09 +02:00
"ImplItem": (),
2018-08-14 13:45:56 +02:00
2018-08-14 11:38:20 +02:00
"ParenType": (),
"TupleType": (),
"NeverType": (),
2018-12-22 22:17:55 +01:00
"PathType": (options: ["Path"]),
2018-08-14 11:38:20 +02:00
"PointerType": (),
"ArrayType": (),
"SliceType": (),
"ReferenceType": (),
"PlaceholderType": (),
"FnPointerType": (),
"ForType": (),
"ImplTraitType": (),
"DynTraitType": (),
"TypeRef": ( enum: [
"ParenType",
"TupleType",
"NeverType",
"PathType",
"PointerType",
"ArrayType",
"SliceType",
"ReferenceType",
"PlaceholderType",
"FnPointerType",
"ForType",
"ImplTraitType",
"DynTraitType",
2018-08-14 12:33:44 +02:00
]),
2018-08-16 12:11:20 +02:00
"NominalDef": (
enum: ["StructDef", "EnumDef"],
2018-08-22 17:05:43 +02:00
traits: [
"NameOwner",
"TypeParamsOwner",
"AttrsOwner"
],
2018-08-16 12:11:20 +02:00
),
2018-08-28 10:12:42 +02:00
"ModuleItem": (
2018-09-01 11:30:53 +02:00
enum: ["StructDef", "EnumDef", "FnDef", "TraitDef", "TypeDef", "ImplItem",
2018-08-30 19:37:33 +02:00
"UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ]
2018-08-28 10:12:42 +02:00
),
2018-08-22 15:46:42 +02:00
2018-08-25 12:42:40 +02:00
"TupleExpr": (),
"ArrayExpr": (),
2018-12-20 21:56:28 +01:00
"ParenExpr": (options: ["Expr"]),
"PathExpr": (options: ["Path"]),
2018-08-28 22:59:57 +02:00
"LambdaExpr": (
options: [
2018-08-31 14:10:37 +02:00
"ParamList",
2018-08-28 22:59:57 +02:00
["body", "Expr"],
]
),
2018-08-27 11:22:09 +02:00
"IfExpr": (
2018-08-31 14:10:37 +02:00
options: [ "Condition" ]
2018-08-27 11:22:09 +02:00
),
"LoopExpr": (
2018-08-30 20:32:12 +02:00
traits: ["LoopBodyOwner"],
2018-08-27 11:22:09 +02:00
),
"ForExpr": (
2018-08-30 20:32:12 +02:00
traits: ["LoopBodyOwner"],
2018-08-27 21:03:19 +02:00
options: [
2018-08-31 14:10:37 +02:00
"Pat",
2018-08-27 21:03:19 +02:00
["iterable", "Expr"],
]
2018-08-27 11:22:09 +02:00
),
"WhileExpr": (
2018-08-30 20:32:12 +02:00
traits: ["LoopBodyOwner"],
2018-08-31 14:10:37 +02:00
options: [ "Condition" ]
2018-08-27 11:22:09 +02:00
),
2018-08-25 12:42:40 +02:00
"ContinueExpr": (),
"BreakExpr": (),
"Label": (),
2018-08-27 11:22:09 +02:00
"BlockExpr": (
2018-08-31 14:10:37 +02:00
options: [ "Block" ]
2018-08-27 11:22:09 +02:00
),
2018-12-20 21:56:28 +01:00
"ReturnExpr": (options: ["Expr"]),
2018-09-03 00:51:46 +02:00
"MatchExpr": (
options: [ "Expr", "MatchArmList" ],
),
"MatchArmList": (
collections: [ ["arms", "MatchArm"] ],
),
"MatchArm": (
options: [
[ "guard", "MatchGuard" ],
"Expr",
],
collections: [ [ "pats", "Pat" ] ]
),
2018-08-25 12:42:40 +02:00
"MatchGuard": (),
"StructLit": (options: ["Path", "NamedFieldList"]),
"NamedFieldList": (collections: [ ["fields", "NamedField"] ]),
"NamedField": (options: ["NameRef", "Expr"]),
2018-08-28 22:59:57 +02:00
"CallExpr": (
2018-09-03 01:01:43 +02:00
traits: ["ArgListOwner"],
options: [ "Expr" ],
),
"MethodCallExpr": (
traits: ["ArgListOwner"],
options: [ "Expr" ],
2018-08-28 22:59:57 +02:00
),
2018-08-25 12:42:40 +02:00
"IndexExpr": (),
"FieldExpr": (),
2018-12-20 21:56:28 +01:00
"TryExpr": (options: ["Expr"]),
"CastExpr": (options: ["Expr", "TypeRef"]),
"RefExpr": (options: ["Expr"]),
"PrefixExpr": (options: ["Expr"]),
2018-08-25 12:42:40 +02:00
"RangeExpr": (),
"BinExpr": (),
2018-11-08 15:42:00 +01:00
"String": (),
2018-11-11 20:27:00 +01:00
"Byte": (),
2018-11-11 20:41:43 +01:00
"ByteString": (),
"Char": (),
2018-08-28 13:21:37 +02:00
"Literal": (),
2018-08-25 12:42:40 +02:00
"Expr": (
enum: [
"TupleExpr",
"ArrayExpr",
"ParenExpr",
"PathExpr",
"LambdaExpr",
"IfExpr",
"LoopExpr",
"ForExpr",
"WhileExpr",
"ContinueExpr",
"BreakExpr",
"Label",
"BlockExpr",
"ReturnExpr",
"MatchExpr",
"MatchArmList",
"MatchArm",
"MatchGuard",
"StructLit",
"NamedFieldList",
"NamedField",
"CallExpr",
"IndexExpr",
"MethodCallExpr",
"FieldExpr",
"TryExpr",
"CastExpr",
"RefExpr",
"PrefixExpr",
"RangeExpr",
"BinExpr",
2018-08-28 13:21:37 +02:00
"Literal",
2018-08-25 12:42:40 +02:00
],
),
2018-08-26 11:09:28 +02:00
"RefPat": (),
"BindPat": ( traits: ["NameOwner"] ),
"PlaceholderPat": (),
"PathPat": (),
"StructPat": (),
"FieldPatList": (),
"TupleStructPat": (),
"TuplePat": (),
"SlicePat": (),
"RangePat": (),
"Pat": (
enum: [
"RefPat",
"BindPat",
"PlaceholderPat",
"PathPat",
"StructPat",
"FieldPatList",
"TupleStructPat",
"TuplePat",
"SlicePat",
"RangePat",
],
),
2018-08-22 15:46:42 +02:00
"Name": (),
"NameRef": (),
"Attr": ( options: [ ["value", "TokenTree"] ] ),
"TokenTree": (),
2018-08-28 22:59:57 +02:00
"TypeParamList": (
collections: [
["type_params", "TypeParam" ],
["lifetime_params", "LifetimeParam" ],
]
),
2018-08-26 11:09:28 +02:00
"TypeParam": ( traits: ["NameOwner"] ),
2018-08-31 14:10:37 +02:00
"LifetimeParam": ( options: [ "Lifetime" ] ),
2018-08-28 22:59:57 +02:00
"Lifetime": (),
2018-08-22 15:46:42 +02:00
"WhereClause": (),
2018-08-27 11:22:09 +02:00
"ExprStmt": (
options: [ ["expr", "Expr"] ]
),
2018-08-27 09:01:31 +02:00
"LetStmt": ( options: [
["pat", "Pat"],
2018-12-23 13:22:29 +01:00
["type_ref", "TypeRef"],
2018-08-27 09:01:31 +02:00
["initializer", "Expr"],
]),
2018-08-27 11:22:09 +02:00
"Condition": (
2018-08-31 14:10:37 +02:00
options: [ "Pat", "Expr" ]
2018-08-27 11:22:09 +02:00
),
2018-08-27 09:12:28 +02:00
"Stmt": (
enum: ["ExprStmt", "LetStmt"],
),
2018-08-26 11:09:28 +02:00
"Block": (
2018-08-31 14:10:37 +02:00
options: [ "Expr" ],
2018-08-26 11:09:28 +02:00
collections: [
2018-08-27 09:12:28 +02:00
["statements", "Stmt"],
2018-08-26 11:09:28 +02:00
]
),
"ParamList": (
2018-08-31 15:30:42 +02:00
options: [ "SelfParam" ],
2018-08-26 11:09:28 +02:00
collections: [
["params", "Param"]
]
),
2018-08-31 15:30:42 +02:00
"SelfParam": (),
2018-08-26 11:09:28 +02:00
"Param": (
2018-12-20 21:56:28 +01:00
options: [ "Pat", "TypeRef" ],
2018-08-28 10:12:42 +02:00
),
2018-08-30 19:37:33 +02:00
"UseItem": (
2018-08-31 14:10:37 +02:00
options: [ "UseTree" ]
2018-08-30 19:37:33 +02:00
),
"UseTree": (
2018-08-31 14:10:37 +02:00
options: [ "Path", "UseTreeList" ]
2018-08-30 19:37:33 +02:00
),
"UseTreeList": (
collections: [["use_trees", "UseTree"]]
),
2018-08-28 10:12:42 +02:00
"ExternCrateItem": (),
2018-08-28 22:59:57 +02:00
"ArgList": (
collections: [
["args", "Expr"]
]
2018-08-30 19:03:18 +02:00
),
2018-08-30 19:37:33 +02:00
"Path": (
options: [
2018-10-24 17:37:25 +02:00
["segment", "PathSegment"],
["qualifier", "Path"],
2018-08-30 19:37:33 +02:00
]
),
"PathSegment": (
2018-08-31 14:10:37 +02:00
options: [ "NameRef" ]
2018-08-30 19:37:33 +02:00
),
2018-10-11 16:25:35 +02:00
"Comment": (),
"Whitespace": (),
2018-08-11 09:11:58 +02:00
},
2018-01-28 16:53:53 +01:00
)