mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
G: visibility
This commit is contained in:
parent
c111a1f7b8
commit
f31d858607
8 changed files with 198 additions and 69 deletions
|
@ -12,6 +12,9 @@ Grammar(
|
||||||
"extern",
|
"extern",
|
||||||
"crate",
|
"crate",
|
||||||
"mod",
|
"mod",
|
||||||
|
"pub",
|
||||||
|
"self",
|
||||||
|
"super",
|
||||||
],
|
],
|
||||||
tokens: [
|
tokens: [
|
||||||
"ERROR",
|
"ERROR",
|
||||||
|
@ -80,5 +83,6 @@ Grammar(
|
||||||
"PATH_SEGMENT",
|
"PATH_SEGMENT",
|
||||||
"LITERAL",
|
"LITERAL",
|
||||||
"ALIAS",
|
"ALIAS",
|
||||||
|
"VISIBILITY",
|
||||||
]
|
]
|
||||||
)
|
)
|
|
@ -12,7 +12,7 @@ pub(super) fn mod_contents(p: &mut Parser) {
|
||||||
|
|
||||||
fn item_first(p: &Parser) -> bool {
|
fn item_first(p: &Parser) -> bool {
|
||||||
match p.current() {
|
match p.current() {
|
||||||
STRUCT_KW | FN_KW | EXTERN_KW | MOD_KW | USE_KW | POUND => true,
|
STRUCT_KW | FN_KW | EXTERN_KW | MOD_KW | USE_KW | POUND | PUB_KW => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,25 @@ pub(crate) fn file(p: &mut Parser) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visibility(_: &mut Parser) {
|
fn visibility(p: &mut Parser) {
|
||||||
|
node_if(p, PUB_KW, VISIBILITY, |p| {
|
||||||
|
if p.current() != L_PAREN {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
match p.raw_lookahead(1) {
|
||||||
|
CRATE_KW | SELF_KW | SUPER_KW => {
|
||||||
|
p.bump();
|
||||||
|
p.bump();
|
||||||
|
}
|
||||||
|
IN_KW => {
|
||||||
|
p.bump();
|
||||||
|
p.bump();
|
||||||
|
paths::use_path(p);
|
||||||
|
}
|
||||||
|
_ => return
|
||||||
|
}
|
||||||
|
p.expect(R_PAREN);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alias(p: &mut Parser) -> bool {
|
fn alias(p: &mut Parser) -> bool {
|
||||||
|
|
|
@ -13,72 +13,76 @@ pub const AS_KW: SyntaxKind = SyntaxKind(8);
|
||||||
pub const EXTERN_KW: SyntaxKind = SyntaxKind(9);
|
pub const EXTERN_KW: SyntaxKind = SyntaxKind(9);
|
||||||
pub const CRATE_KW: SyntaxKind = SyntaxKind(10);
|
pub const CRATE_KW: SyntaxKind = SyntaxKind(10);
|
||||||
pub const MOD_KW: SyntaxKind = SyntaxKind(11);
|
pub const MOD_KW: SyntaxKind = SyntaxKind(11);
|
||||||
pub const ERROR: SyntaxKind = SyntaxKind(12);
|
pub const PUB_KW: SyntaxKind = SyntaxKind(12);
|
||||||
pub const IDENT: SyntaxKind = SyntaxKind(13);
|
pub const SELF_KW: SyntaxKind = SyntaxKind(13);
|
||||||
pub const UNDERSCORE: SyntaxKind = SyntaxKind(14);
|
pub const SUPER_KW: SyntaxKind = SyntaxKind(14);
|
||||||
pub const WHITESPACE: SyntaxKind = SyntaxKind(15);
|
pub const ERROR: SyntaxKind = SyntaxKind(15);
|
||||||
pub const INT_NUMBER: SyntaxKind = SyntaxKind(16);
|
pub const IDENT: SyntaxKind = SyntaxKind(16);
|
||||||
pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(17);
|
pub const UNDERSCORE: SyntaxKind = SyntaxKind(17);
|
||||||
pub const SEMI: SyntaxKind = SyntaxKind(18);
|
pub const WHITESPACE: SyntaxKind = SyntaxKind(18);
|
||||||
pub const COMMA: SyntaxKind = SyntaxKind(19);
|
pub const INT_NUMBER: SyntaxKind = SyntaxKind(19);
|
||||||
pub const DOT: SyntaxKind = SyntaxKind(20);
|
pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(20);
|
||||||
pub const DOTDOT: SyntaxKind = SyntaxKind(21);
|
pub const SEMI: SyntaxKind = SyntaxKind(21);
|
||||||
pub const DOTDOTDOT: SyntaxKind = SyntaxKind(22);
|
pub const COMMA: SyntaxKind = SyntaxKind(22);
|
||||||
pub const DOTDOTEQ: SyntaxKind = SyntaxKind(23);
|
pub const DOT: SyntaxKind = SyntaxKind(23);
|
||||||
pub const L_PAREN: SyntaxKind = SyntaxKind(24);
|
pub const DOTDOT: SyntaxKind = SyntaxKind(24);
|
||||||
pub const R_PAREN: SyntaxKind = SyntaxKind(25);
|
pub const DOTDOTDOT: SyntaxKind = SyntaxKind(25);
|
||||||
pub const L_CURLY: SyntaxKind = SyntaxKind(26);
|
pub const DOTDOTEQ: SyntaxKind = SyntaxKind(26);
|
||||||
pub const R_CURLY: SyntaxKind = SyntaxKind(27);
|
pub const L_PAREN: SyntaxKind = SyntaxKind(27);
|
||||||
pub const L_BRACK: SyntaxKind = SyntaxKind(28);
|
pub const R_PAREN: SyntaxKind = SyntaxKind(28);
|
||||||
pub const R_BRACK: SyntaxKind = SyntaxKind(29);
|
pub const L_CURLY: SyntaxKind = SyntaxKind(29);
|
||||||
pub const L_ANGLE: SyntaxKind = SyntaxKind(30);
|
pub const R_CURLY: SyntaxKind = SyntaxKind(30);
|
||||||
pub const R_ANGLE: SyntaxKind = SyntaxKind(31);
|
pub const L_BRACK: SyntaxKind = SyntaxKind(31);
|
||||||
pub const AT: SyntaxKind = SyntaxKind(32);
|
pub const R_BRACK: SyntaxKind = SyntaxKind(32);
|
||||||
pub const POUND: SyntaxKind = SyntaxKind(33);
|
pub const L_ANGLE: SyntaxKind = SyntaxKind(33);
|
||||||
pub const TILDE: SyntaxKind = SyntaxKind(34);
|
pub const R_ANGLE: SyntaxKind = SyntaxKind(34);
|
||||||
pub const QUESTION: SyntaxKind = SyntaxKind(35);
|
pub const AT: SyntaxKind = SyntaxKind(35);
|
||||||
pub const COLON: SyntaxKind = SyntaxKind(36);
|
pub const POUND: SyntaxKind = SyntaxKind(36);
|
||||||
pub const COLONCOLON: SyntaxKind = SyntaxKind(37);
|
pub const TILDE: SyntaxKind = SyntaxKind(37);
|
||||||
pub const DOLLAR: SyntaxKind = SyntaxKind(38);
|
pub const QUESTION: SyntaxKind = SyntaxKind(38);
|
||||||
pub const EQ: SyntaxKind = SyntaxKind(39);
|
pub const COLON: SyntaxKind = SyntaxKind(39);
|
||||||
pub const EQEQ: SyntaxKind = SyntaxKind(40);
|
pub const COLONCOLON: SyntaxKind = SyntaxKind(40);
|
||||||
pub const FAT_ARROW: SyntaxKind = SyntaxKind(41);
|
pub const DOLLAR: SyntaxKind = SyntaxKind(41);
|
||||||
pub const NEQ: SyntaxKind = SyntaxKind(42);
|
pub const EQ: SyntaxKind = SyntaxKind(42);
|
||||||
pub const EXCL: SyntaxKind = SyntaxKind(43);
|
pub const EQEQ: SyntaxKind = SyntaxKind(43);
|
||||||
pub const LIFETIME: SyntaxKind = SyntaxKind(44);
|
pub const FAT_ARROW: SyntaxKind = SyntaxKind(44);
|
||||||
pub const CHAR: SyntaxKind = SyntaxKind(45);
|
pub const NEQ: SyntaxKind = SyntaxKind(45);
|
||||||
pub const BYTE: SyntaxKind = SyntaxKind(46);
|
pub const EXCL: SyntaxKind = SyntaxKind(46);
|
||||||
pub const STRING: SyntaxKind = SyntaxKind(47);
|
pub const LIFETIME: SyntaxKind = SyntaxKind(47);
|
||||||
pub const RAW_STRING: SyntaxKind = SyntaxKind(48);
|
pub const CHAR: SyntaxKind = SyntaxKind(48);
|
||||||
pub const BYTE_STRING: SyntaxKind = SyntaxKind(49);
|
pub const BYTE: SyntaxKind = SyntaxKind(49);
|
||||||
pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(50);
|
pub const STRING: SyntaxKind = SyntaxKind(50);
|
||||||
pub const PLUS: SyntaxKind = SyntaxKind(51);
|
pub const RAW_STRING: SyntaxKind = SyntaxKind(51);
|
||||||
pub const MINUS: SyntaxKind = SyntaxKind(52);
|
pub const BYTE_STRING: SyntaxKind = SyntaxKind(52);
|
||||||
pub const STAR: SyntaxKind = SyntaxKind(53);
|
pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(53);
|
||||||
pub const SLASH: SyntaxKind = SyntaxKind(54);
|
pub const PLUS: SyntaxKind = SyntaxKind(54);
|
||||||
pub const CARET: SyntaxKind = SyntaxKind(55);
|
pub const MINUS: SyntaxKind = SyntaxKind(55);
|
||||||
pub const PERCENT: SyntaxKind = SyntaxKind(56);
|
pub const STAR: SyntaxKind = SyntaxKind(56);
|
||||||
pub const AMPERSAND: SyntaxKind = SyntaxKind(57);
|
pub const SLASH: SyntaxKind = SyntaxKind(57);
|
||||||
pub const PIPE: SyntaxKind = SyntaxKind(58);
|
pub const CARET: SyntaxKind = SyntaxKind(58);
|
||||||
pub const THIN_ARROW: SyntaxKind = SyntaxKind(59);
|
pub const PERCENT: SyntaxKind = SyntaxKind(59);
|
||||||
pub const COMMENT: SyntaxKind = SyntaxKind(60);
|
pub const AMPERSAND: SyntaxKind = SyntaxKind(60);
|
||||||
pub const DOC_COMMENT: SyntaxKind = SyntaxKind(61);
|
pub const PIPE: SyntaxKind = SyntaxKind(61);
|
||||||
pub const SHEBANG: SyntaxKind = SyntaxKind(62);
|
pub const THIN_ARROW: SyntaxKind = SyntaxKind(62);
|
||||||
pub const FILE: SyntaxKind = SyntaxKind(63);
|
pub const COMMENT: SyntaxKind = SyntaxKind(63);
|
||||||
pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(64);
|
pub const DOC_COMMENT: SyntaxKind = SyntaxKind(64);
|
||||||
pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(65);
|
pub const SHEBANG: SyntaxKind = SyntaxKind(65);
|
||||||
pub const FN_ITEM: SyntaxKind = SyntaxKind(66);
|
pub const FILE: SyntaxKind = SyntaxKind(66);
|
||||||
pub const EXTERN_CRATE_ITEM: SyntaxKind = SyntaxKind(67);
|
pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(67);
|
||||||
pub const ATTR: SyntaxKind = SyntaxKind(68);
|
pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(68);
|
||||||
pub const META_ITEM: SyntaxKind = SyntaxKind(69);
|
pub const FN_ITEM: SyntaxKind = SyntaxKind(69);
|
||||||
pub const MOD_ITEM: SyntaxKind = SyntaxKind(70);
|
pub const EXTERN_CRATE_ITEM: SyntaxKind = SyntaxKind(70);
|
||||||
pub const USE_ITEM: SyntaxKind = SyntaxKind(71);
|
pub const ATTR: SyntaxKind = SyntaxKind(71);
|
||||||
pub const PATH: SyntaxKind = SyntaxKind(72);
|
pub const META_ITEM: SyntaxKind = SyntaxKind(72);
|
||||||
pub const PATH_SEGMENT: SyntaxKind = SyntaxKind(73);
|
pub const MOD_ITEM: SyntaxKind = SyntaxKind(73);
|
||||||
pub const LITERAL: SyntaxKind = SyntaxKind(74);
|
pub const USE_ITEM: SyntaxKind = SyntaxKind(74);
|
||||||
pub const ALIAS: SyntaxKind = SyntaxKind(75);
|
pub const PATH: SyntaxKind = SyntaxKind(75);
|
||||||
|
pub const PATH_SEGMENT: SyntaxKind = SyntaxKind(76);
|
||||||
|
pub const LITERAL: SyntaxKind = SyntaxKind(77);
|
||||||
|
pub const ALIAS: SyntaxKind = SyntaxKind(78);
|
||||||
|
pub const VISIBILITY: SyntaxKind = SyntaxKind(79);
|
||||||
|
|
||||||
static INFOS: [SyntaxInfo; 76] = [
|
static INFOS: [SyntaxInfo; 80] = [
|
||||||
SyntaxInfo { name: "USE_KW" },
|
SyntaxInfo { name: "USE_KW" },
|
||||||
SyntaxInfo { name: "FN_KW" },
|
SyntaxInfo { name: "FN_KW" },
|
||||||
SyntaxInfo { name: "STRUCT_KW" },
|
SyntaxInfo { name: "STRUCT_KW" },
|
||||||
|
@ -91,6 +95,9 @@ static INFOS: [SyntaxInfo; 76] = [
|
||||||
SyntaxInfo { name: "EXTERN_KW" },
|
SyntaxInfo { name: "EXTERN_KW" },
|
||||||
SyntaxInfo { name: "CRATE_KW" },
|
SyntaxInfo { name: "CRATE_KW" },
|
||||||
SyntaxInfo { name: "MOD_KW" },
|
SyntaxInfo { name: "MOD_KW" },
|
||||||
|
SyntaxInfo { name: "PUB_KW" },
|
||||||
|
SyntaxInfo { name: "SELF_KW" },
|
||||||
|
SyntaxInfo { name: "SUPER_KW" },
|
||||||
SyntaxInfo { name: "ERROR" },
|
SyntaxInfo { name: "ERROR" },
|
||||||
SyntaxInfo { name: "IDENT" },
|
SyntaxInfo { name: "IDENT" },
|
||||||
SyntaxInfo { name: "UNDERSCORE" },
|
SyntaxInfo { name: "UNDERSCORE" },
|
||||||
|
@ -155,6 +162,7 @@ static INFOS: [SyntaxInfo; 76] = [
|
||||||
SyntaxInfo { name: "PATH_SEGMENT" },
|
SyntaxInfo { name: "PATH_SEGMENT" },
|
||||||
SyntaxInfo { name: "LITERAL" },
|
SyntaxInfo { name: "LITERAL" },
|
||||||
SyntaxInfo { name: "ALIAS" },
|
SyntaxInfo { name: "ALIAS" },
|
||||||
|
SyntaxInfo { name: "VISIBILITY" },
|
||||||
];
|
];
|
||||||
|
|
||||||
pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo {
|
pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo {
|
||||||
|
@ -175,6 +183,9 @@ pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> {
|
||||||
"extern" => Some(EXTERN_KW),
|
"extern" => Some(EXTERN_KW),
|
||||||
"crate" => Some(CRATE_KW),
|
"crate" => Some(CRATE_KW),
|
||||||
"mod" => Some(MOD_KW),
|
"mod" => Some(MOD_KW),
|
||||||
|
"pub" => Some(PUB_KW),
|
||||||
|
"self" => Some(SELF_KW),
|
||||||
|
"super" => Some(SUPER_KW),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
fn use struct trait enum impl true false as extern crate mod
|
fn use struct trait enum impl true false as extern crate mod pub self super
|
||||||
|
|
||||||
|
|
|
@ -21,4 +21,10 @@ WHITESPACE 1 " "
|
||||||
CRATE_KW 5 "crate"
|
CRATE_KW 5 "crate"
|
||||||
WHITESPACE 1 " "
|
WHITESPACE 1 " "
|
||||||
MOD_KW 3 "mod"
|
MOD_KW 3 "mod"
|
||||||
WHITESPACE 1 "\n"
|
WHITESPACE 1 " "
|
||||||
|
PUB_KW 3 "pub"
|
||||||
|
WHITESPACE 1 " "
|
||||||
|
SELF_KW 4 "self"
|
||||||
|
WHITESPACE 1 " "
|
||||||
|
SUPER_KW 5 "super"
|
||||||
|
WHITESPACE 2 "\n\n"
|
||||||
|
|
5
tests/data/parser/ok/0012_visibility.rs
Normal file
5
tests/data/parser/ok/0012_visibility.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
fn a() {}
|
||||||
|
pub fn b() {}
|
||||||
|
pub(crate) fn c() {}
|
||||||
|
pub(super) fn d() {}
|
||||||
|
pub(in foo::bar::baz) fn e() {}
|
84
tests/data/parser/ok/0012_visibility.txt
Normal file
84
tests/data/parser/ok/0012_visibility.txt
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
FILE@[0; 98)
|
||||||
|
FN_ITEM@[0; 10)
|
||||||
|
FN_KW@[0; 2)
|
||||||
|
WHITESPACE@[2; 3)
|
||||||
|
IDENT@[3; 4)
|
||||||
|
L_PAREN@[4; 5)
|
||||||
|
R_PAREN@[5; 6)
|
||||||
|
WHITESPACE@[6; 7)
|
||||||
|
L_CURLY@[7; 8)
|
||||||
|
R_CURLY@[8; 9)
|
||||||
|
WHITESPACE@[9; 10)
|
||||||
|
FN_ITEM@[10; 24)
|
||||||
|
VISIBILITY@[10; 14)
|
||||||
|
PUB_KW@[10; 13)
|
||||||
|
WHITESPACE@[13; 14)
|
||||||
|
FN_KW@[14; 16)
|
||||||
|
WHITESPACE@[16; 17)
|
||||||
|
IDENT@[17; 18)
|
||||||
|
L_PAREN@[18; 19)
|
||||||
|
R_PAREN@[19; 20)
|
||||||
|
WHITESPACE@[20; 21)
|
||||||
|
L_CURLY@[21; 22)
|
||||||
|
R_CURLY@[22; 23)
|
||||||
|
WHITESPACE@[23; 24)
|
||||||
|
FN_ITEM@[24; 45)
|
||||||
|
VISIBILITY@[24; 35)
|
||||||
|
PUB_KW@[24; 27)
|
||||||
|
L_PAREN@[27; 28)
|
||||||
|
CRATE_KW@[28; 33)
|
||||||
|
R_PAREN@[33; 34)
|
||||||
|
WHITESPACE@[34; 35)
|
||||||
|
FN_KW@[35; 37)
|
||||||
|
WHITESPACE@[37; 38)
|
||||||
|
IDENT@[38; 39)
|
||||||
|
L_PAREN@[39; 40)
|
||||||
|
R_PAREN@[40; 41)
|
||||||
|
WHITESPACE@[41; 42)
|
||||||
|
L_CURLY@[42; 43)
|
||||||
|
R_CURLY@[43; 44)
|
||||||
|
WHITESPACE@[44; 45)
|
||||||
|
FN_ITEM@[45; 66)
|
||||||
|
VISIBILITY@[45; 56)
|
||||||
|
PUB_KW@[45; 48)
|
||||||
|
L_PAREN@[48; 49)
|
||||||
|
SUPER_KW@[49; 54)
|
||||||
|
R_PAREN@[54; 55)
|
||||||
|
WHITESPACE@[55; 56)
|
||||||
|
FN_KW@[56; 58)
|
||||||
|
WHITESPACE@[58; 59)
|
||||||
|
IDENT@[59; 60)
|
||||||
|
L_PAREN@[60; 61)
|
||||||
|
R_PAREN@[61; 62)
|
||||||
|
WHITESPACE@[62; 63)
|
||||||
|
L_CURLY@[63; 64)
|
||||||
|
R_CURLY@[64; 65)
|
||||||
|
WHITESPACE@[65; 66)
|
||||||
|
FN_ITEM@[66; 98)
|
||||||
|
VISIBILITY@[66; 88)
|
||||||
|
PUB_KW@[66; 69)
|
||||||
|
L_PAREN@[69; 70)
|
||||||
|
IDENT@[70; 72)
|
||||||
|
PATH@[72; 86)
|
||||||
|
PATH@[72; 81)
|
||||||
|
PATH@[72; 76)
|
||||||
|
PATH_SEGMENT@[72; 76)
|
||||||
|
WHITESPACE@[72; 73)
|
||||||
|
IDENT@[73; 76)
|
||||||
|
COLONCOLON@[76; 78)
|
||||||
|
PATH_SEGMENT@[78; 81)
|
||||||
|
IDENT@[78; 81)
|
||||||
|
COLONCOLON@[81; 83)
|
||||||
|
PATH_SEGMENT@[83; 86)
|
||||||
|
IDENT@[83; 86)
|
||||||
|
R_PAREN@[86; 87)
|
||||||
|
WHITESPACE@[87; 88)
|
||||||
|
FN_KW@[88; 90)
|
||||||
|
WHITESPACE@[90; 91)
|
||||||
|
IDENT@[91; 92)
|
||||||
|
L_PAREN@[92; 93)
|
||||||
|
R_PAREN@[93; 94)
|
||||||
|
WHITESPACE@[94; 95)
|
||||||
|
L_CURLY@[95; 96)
|
||||||
|
R_CURLY@[96; 97)
|
||||||
|
WHITESPACE@[97; 98)
|
Loading…
Reference in a new issue