mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
internal: more local parsing tests for macros
This commit is contained in:
parent
073d5f7733
commit
77e8421d0f
9 changed files with 145 additions and 150 deletions
|
@ -249,14 +249,8 @@ fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
|
||||||
T![enum] => adt::enum_(p, m),
|
T![enum] => adt::enum_(p, m),
|
||||||
IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => adt::union(p, m),
|
IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => adt::union(p, m),
|
||||||
|
|
||||||
// test pub_macro_def
|
T![macro] => macro_def(p, m),
|
||||||
// pub macro m($:ident) {}
|
IDENT if p.at_contextual_kw("macro_rules") && p.nth(1) == BANG => macro_rules(p, m),
|
||||||
T![macro] => {
|
|
||||||
macro_def(p, m);
|
|
||||||
}
|
|
||||||
IDENT if p.at_contextual_kw("macro_rules") && p.nth(1) == BANG => {
|
|
||||||
macro_rules(p, m);
|
|
||||||
}
|
|
||||||
|
|
||||||
T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m),
|
T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m),
|
||||||
T![static] => consts::static_(p, m),
|
T![static] => consts::static_(p, m),
|
||||||
|
@ -413,12 +407,13 @@ fn macro_rules(p: &mut Parser, m: Marker) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// test macro_def
|
// test macro_def
|
||||||
// macro m { ($i:ident) => {} }
|
|
||||||
// macro m($i:ident) {}
|
// macro m($i:ident) {}
|
||||||
fn macro_def(p: &mut Parser, m: Marker) {
|
fn macro_def(p: &mut Parser, m: Marker) {
|
||||||
p.expect(T![macro]);
|
p.expect(T![macro]);
|
||||||
name_r(p, ITEM_RECOVERY_SET);
|
name_r(p, ITEM_RECOVERY_SET);
|
||||||
if p.at(T!['{']) {
|
if p.at(T!['{']) {
|
||||||
|
// test macro_def_curly
|
||||||
|
// macro m { ($i:ident) => {} }
|
||||||
token_tree(p);
|
token_tree(p);
|
||||||
} else if !p.at(T!['(']) {
|
} else if !p.at(T!['(']) {
|
||||||
p.error("unmatched `(`");
|
p.error("unmatched `(`");
|
||||||
|
|
|
@ -1,45 +1,19 @@
|
||||||
SOURCE_FILE@0..50
|
SOURCE_FILE@0..21
|
||||||
MACRO_DEF@0..28
|
MACRO_DEF@0..20
|
||||||
MACRO_KW@0..5 "macro"
|
MACRO_KW@0..5 "macro"
|
||||||
WHITESPACE@5..6 " "
|
WHITESPACE@5..6 " "
|
||||||
NAME@6..7
|
NAME@6..7
|
||||||
IDENT@6..7 "m"
|
IDENT@6..7 "m"
|
||||||
WHITESPACE@7..8 " "
|
TOKEN_TREE@7..20
|
||||||
TOKEN_TREE@8..28
|
TOKEN_TREE@7..17
|
||||||
L_CURLY@8..9 "{"
|
L_PAREN@7..8 "("
|
||||||
WHITESPACE@9..10 " "
|
DOLLAR@8..9 "$"
|
||||||
TOKEN_TREE@10..20
|
IDENT@9..10 "i"
|
||||||
L_PAREN@10..11 "("
|
COLON@10..11 ":"
|
||||||
DOLLAR@11..12 "$"
|
IDENT@11..16 "ident"
|
||||||
IDENT@12..13 "i"
|
R_PAREN@16..17 ")"
|
||||||
COLON@13..14 ":"
|
WHITESPACE@17..18 " "
|
||||||
IDENT@14..19 "ident"
|
TOKEN_TREE@18..20
|
||||||
R_PAREN@19..20 ")"
|
L_CURLY@18..19 "{"
|
||||||
WHITESPACE@20..21 " "
|
R_CURLY@19..20 "}"
|
||||||
EQ@21..22 "="
|
WHITESPACE@20..21 "\n"
|
||||||
R_ANGLE@22..23 ">"
|
|
||||||
WHITESPACE@23..24 " "
|
|
||||||
TOKEN_TREE@24..26
|
|
||||||
L_CURLY@24..25 "{"
|
|
||||||
R_CURLY@25..26 "}"
|
|
||||||
WHITESPACE@26..27 " "
|
|
||||||
R_CURLY@27..28 "}"
|
|
||||||
WHITESPACE@28..29 "\n"
|
|
||||||
MACRO_DEF@29..49
|
|
||||||
MACRO_KW@29..34 "macro"
|
|
||||||
WHITESPACE@34..35 " "
|
|
||||||
NAME@35..36
|
|
||||||
IDENT@35..36 "m"
|
|
||||||
TOKEN_TREE@36..49
|
|
||||||
TOKEN_TREE@36..46
|
|
||||||
L_PAREN@36..37 "("
|
|
||||||
DOLLAR@37..38 "$"
|
|
||||||
IDENT@38..39 "i"
|
|
||||||
COLON@39..40 ":"
|
|
||||||
IDENT@40..45 "ident"
|
|
||||||
R_PAREN@45..46 ")"
|
|
||||||
WHITESPACE@46..47 " "
|
|
||||||
TOKEN_TREE@47..49
|
|
||||||
L_CURLY@47..48 "{"
|
|
||||||
R_CURLY@48..49 "}"
|
|
||||||
WHITESPACE@49..50 "\n"
|
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
macro m { ($i:ident) => {} }
|
|
||||||
macro m($i:ident) {}
|
macro m($i:ident) {}
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
SOURCE_FILE@0..24
|
|
||||||
MACRO_DEF@0..23
|
|
||||||
VISIBILITY@0..3
|
|
||||||
PUB_KW@0..3 "pub"
|
|
||||||
WHITESPACE@3..4 " "
|
|
||||||
MACRO_KW@4..9 "macro"
|
|
||||||
WHITESPACE@9..10 " "
|
|
||||||
NAME@10..11
|
|
||||||
IDENT@10..11 "m"
|
|
||||||
TOKEN_TREE@11..23
|
|
||||||
TOKEN_TREE@11..20
|
|
||||||
L_PAREN@11..12 "("
|
|
||||||
DOLLAR@12..13 "$"
|
|
||||||
COLON@13..14 ":"
|
|
||||||
IDENT@14..19 "ident"
|
|
||||||
R_PAREN@19..20 ")"
|
|
||||||
WHITESPACE@20..21 " "
|
|
||||||
TOKEN_TREE@21..23
|
|
||||||
L_CURLY@21..22 "{"
|
|
||||||
R_CURLY@22..23 "}"
|
|
||||||
WHITESPACE@23..24 "\n"
|
|
|
@ -1 +0,0 @@
|
||||||
pub macro m($:ident) {}
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
SOURCE_FILE@0..29
|
||||||
|
MACRO_DEF@0..28
|
||||||
|
MACRO_KW@0..5 "macro"
|
||||||
|
WHITESPACE@5..6 " "
|
||||||
|
NAME@6..7
|
||||||
|
IDENT@6..7 "m"
|
||||||
|
WHITESPACE@7..8 " "
|
||||||
|
TOKEN_TREE@8..28
|
||||||
|
L_CURLY@8..9 "{"
|
||||||
|
WHITESPACE@9..10 " "
|
||||||
|
TOKEN_TREE@10..20
|
||||||
|
L_PAREN@10..11 "("
|
||||||
|
DOLLAR@11..12 "$"
|
||||||
|
IDENT@12..13 "i"
|
||||||
|
COLON@13..14 ":"
|
||||||
|
IDENT@14..19 "ident"
|
||||||
|
R_PAREN@19..20 ")"
|
||||||
|
WHITESPACE@20..21 " "
|
||||||
|
EQ@21..22 "="
|
||||||
|
R_ANGLE@22..23 ">"
|
||||||
|
WHITESPACE@23..24 " "
|
||||||
|
TOKEN_TREE@24..26
|
||||||
|
L_CURLY@24..25 "{"
|
||||||
|
R_CURLY@25..26 "}"
|
||||||
|
WHITESPACE@26..27 " "
|
||||||
|
R_CURLY@27..28 "}"
|
||||||
|
WHITESPACE@28..29 "\n"
|
|
@ -0,0 +1 @@
|
||||||
|
macro m { ($i:ident) => {} }
|
|
@ -1,4 +1,4 @@
|
||||||
SOURCE_FILE@0..98
|
SOURCE_FILE@0..122
|
||||||
FN@0..9
|
FN@0..9
|
||||||
FN_KW@0..2 "fn"
|
FN_KW@0..2 "fn"
|
||||||
WHITESPACE@2..3 " "
|
WHITESPACE@2..3 " "
|
||||||
|
@ -28,81 +28,101 @@ SOURCE_FILE@0..98
|
||||||
L_CURLY@21..22 "{"
|
L_CURLY@21..22 "{"
|
||||||
R_CURLY@22..23 "}"
|
R_CURLY@22..23 "}"
|
||||||
WHITESPACE@23..24 "\n"
|
WHITESPACE@23..24 "\n"
|
||||||
FN@24..44
|
MACRO_DEF@24..47
|
||||||
VISIBILITY@24..34
|
VISIBILITY@24..27
|
||||||
PUB_KW@24..27 "pub"
|
PUB_KW@24..27 "pub"
|
||||||
L_PAREN@27..28 "("
|
WHITESPACE@27..28 " "
|
||||||
PATH@28..33
|
MACRO_KW@28..33 "macro"
|
||||||
PATH_SEGMENT@28..33
|
WHITESPACE@33..34 " "
|
||||||
NAME_REF@28..33
|
NAME@34..35
|
||||||
CRATE_KW@28..33 "crate"
|
IDENT@34..35 "m"
|
||||||
R_PAREN@33..34 ")"
|
TOKEN_TREE@35..47
|
||||||
WHITESPACE@34..35 " "
|
TOKEN_TREE@35..44
|
||||||
FN_KW@35..37 "fn"
|
L_PAREN@35..36 "("
|
||||||
WHITESPACE@37..38 " "
|
DOLLAR@36..37 "$"
|
||||||
NAME@38..39
|
COLON@37..38 ":"
|
||||||
IDENT@38..39 "c"
|
IDENT@38..43 "ident"
|
||||||
PARAM_LIST@39..41
|
R_PAREN@43..44 ")"
|
||||||
L_PAREN@39..40 "("
|
WHITESPACE@44..45 " "
|
||||||
R_PAREN@40..41 ")"
|
TOKEN_TREE@45..47
|
||||||
WHITESPACE@41..42 " "
|
L_CURLY@45..46 "{"
|
||||||
BLOCK_EXPR@42..44
|
R_CURLY@46..47 "}"
|
||||||
L_CURLY@42..43 "{"
|
WHITESPACE@47..48 "\n"
|
||||||
R_CURLY@43..44 "}"
|
FN@48..68
|
||||||
WHITESPACE@44..45 "\n"
|
VISIBILITY@48..58
|
||||||
FN@45..65
|
PUB_KW@48..51 "pub"
|
||||||
VISIBILITY@45..55
|
L_PAREN@51..52 "("
|
||||||
PUB_KW@45..48 "pub"
|
PATH@52..57
|
||||||
L_PAREN@48..49 "("
|
PATH_SEGMENT@52..57
|
||||||
PATH@49..54
|
NAME_REF@52..57
|
||||||
PATH_SEGMENT@49..54
|
CRATE_KW@52..57 "crate"
|
||||||
NAME_REF@49..54
|
R_PAREN@57..58 ")"
|
||||||
SUPER_KW@49..54 "super"
|
|
||||||
R_PAREN@54..55 ")"
|
|
||||||
WHITESPACE@55..56 " "
|
|
||||||
FN_KW@56..58 "fn"
|
|
||||||
WHITESPACE@58..59 " "
|
WHITESPACE@58..59 " "
|
||||||
NAME@59..60
|
FN_KW@59..61 "fn"
|
||||||
IDENT@59..60 "d"
|
WHITESPACE@61..62 " "
|
||||||
PARAM_LIST@60..62
|
NAME@62..63
|
||||||
L_PAREN@60..61 "("
|
IDENT@62..63 "c"
|
||||||
R_PAREN@61..62 ")"
|
PARAM_LIST@63..65
|
||||||
WHITESPACE@62..63 " "
|
L_PAREN@63..64 "("
|
||||||
BLOCK_EXPR@63..65
|
R_PAREN@64..65 ")"
|
||||||
L_CURLY@63..64 "{"
|
WHITESPACE@65..66 " "
|
||||||
R_CURLY@64..65 "}"
|
BLOCK_EXPR@66..68
|
||||||
WHITESPACE@65..66 "\n"
|
L_CURLY@66..67 "{"
|
||||||
FN@66..97
|
R_CURLY@67..68 "}"
|
||||||
VISIBILITY@66..87
|
WHITESPACE@68..69 "\n"
|
||||||
PUB_KW@66..69 "pub"
|
FN@69..89
|
||||||
L_PAREN@69..70 "("
|
VISIBILITY@69..79
|
||||||
IN_KW@70..72 "in"
|
PUB_KW@69..72 "pub"
|
||||||
WHITESPACE@72..73 " "
|
L_PAREN@72..73 "("
|
||||||
PATH@73..86
|
PATH@73..78
|
||||||
PATH@73..81
|
PATH_SEGMENT@73..78
|
||||||
PATH@73..76
|
NAME_REF@73..78
|
||||||
PATH_SEGMENT@73..76
|
SUPER_KW@73..78 "super"
|
||||||
NAME_REF@73..76
|
R_PAREN@78..79 ")"
|
||||||
IDENT@73..76 "foo"
|
WHITESPACE@79..80 " "
|
||||||
COLON2@76..78 "::"
|
FN_KW@80..82 "fn"
|
||||||
PATH_SEGMENT@78..81
|
WHITESPACE@82..83 " "
|
||||||
NAME_REF@78..81
|
NAME@83..84
|
||||||
IDENT@78..81 "bar"
|
IDENT@83..84 "d"
|
||||||
COLON2@81..83 "::"
|
PARAM_LIST@84..86
|
||||||
PATH_SEGMENT@83..86
|
L_PAREN@84..85 "("
|
||||||
NAME_REF@83..86
|
R_PAREN@85..86 ")"
|
||||||
IDENT@83..86 "baz"
|
WHITESPACE@86..87 " "
|
||||||
R_PAREN@86..87 ")"
|
BLOCK_EXPR@87..89
|
||||||
WHITESPACE@87..88 " "
|
L_CURLY@87..88 "{"
|
||||||
FN_KW@88..90 "fn"
|
R_CURLY@88..89 "}"
|
||||||
WHITESPACE@90..91 " "
|
WHITESPACE@89..90 "\n"
|
||||||
NAME@91..92
|
FN@90..121
|
||||||
IDENT@91..92 "e"
|
VISIBILITY@90..111
|
||||||
PARAM_LIST@92..94
|
PUB_KW@90..93 "pub"
|
||||||
L_PAREN@92..93 "("
|
L_PAREN@93..94 "("
|
||||||
R_PAREN@93..94 ")"
|
IN_KW@94..96 "in"
|
||||||
WHITESPACE@94..95 " "
|
WHITESPACE@96..97 " "
|
||||||
BLOCK_EXPR@95..97
|
PATH@97..110
|
||||||
L_CURLY@95..96 "{"
|
PATH@97..105
|
||||||
R_CURLY@96..97 "}"
|
PATH@97..100
|
||||||
WHITESPACE@97..98 "\n"
|
PATH_SEGMENT@97..100
|
||||||
|
NAME_REF@97..100
|
||||||
|
IDENT@97..100 "foo"
|
||||||
|
COLON2@100..102 "::"
|
||||||
|
PATH_SEGMENT@102..105
|
||||||
|
NAME_REF@102..105
|
||||||
|
IDENT@102..105 "bar"
|
||||||
|
COLON2@105..107 "::"
|
||||||
|
PATH_SEGMENT@107..110
|
||||||
|
NAME_REF@107..110
|
||||||
|
IDENT@107..110 "baz"
|
||||||
|
R_PAREN@110..111 ")"
|
||||||
|
WHITESPACE@111..112 " "
|
||||||
|
FN_KW@112..114 "fn"
|
||||||
|
WHITESPACE@114..115 " "
|
||||||
|
NAME@115..116
|
||||||
|
IDENT@115..116 "e"
|
||||||
|
PARAM_LIST@116..118
|
||||||
|
L_PAREN@116..117 "("
|
||||||
|
R_PAREN@117..118 ")"
|
||||||
|
WHITESPACE@118..119 " "
|
||||||
|
BLOCK_EXPR@119..121
|
||||||
|
L_CURLY@119..120 "{"
|
||||||
|
R_CURLY@120..121 "}"
|
||||||
|
WHITESPACE@121..122 "\n"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
fn a() {}
|
fn a() {}
|
||||||
pub fn b() {}
|
pub fn b() {}
|
||||||
|
pub macro m($:ident) {}
|
||||||
pub(crate) fn c() {}
|
pub(crate) fn c() {}
|
||||||
pub(super) fn d() {}
|
pub(super) fn d() {}
|
||||||
pub(in foo::bar::baz) fn e() {}
|
pub(in foo::bar::baz) fn e() {}
|
||||||
|
|
Loading…
Reference in a new issue