mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
commit
5e7504b978
7 changed files with 81 additions and 9 deletions
|
@ -21,7 +21,10 @@ Grammar(
|
|||
"loop",
|
||||
"while",
|
||||
"if",
|
||||
"match"
|
||||
"match",
|
||||
"const",
|
||||
"static",
|
||||
"mut",
|
||||
],
|
||||
tokens: [
|
||||
"ERROR",
|
||||
|
@ -85,6 +88,7 @@ Grammar(
|
|||
"EXTERN_CRATE_ITEM",
|
||||
"MOD_ITEM",
|
||||
"USE_ITEM",
|
||||
"STATIC_ITEM",
|
||||
|
||||
"EXTERN_BLOCK",
|
||||
"ENUM_VARIANT",
|
||||
|
|
|
@ -46,6 +46,10 @@ fn item(p: &mut Parser) {
|
|||
}
|
||||
}
|
||||
}
|
||||
STATIC_KW => {
|
||||
static_item(p);
|
||||
STATIC_ITEM
|
||||
}
|
||||
MOD_KW => {
|
||||
mod_item(p);
|
||||
MOD_ITEM
|
||||
|
@ -92,6 +96,24 @@ fn extern_crate_item(p: &mut Parser) {
|
|||
p.expect(IDENT) && alias(p) && p.expect(SEMI);
|
||||
}
|
||||
|
||||
fn extern_block(p: &mut Parser) {
|
||||
assert!(p.at(L_CURLY));
|
||||
p.bump();
|
||||
p.expect(R_CURLY);
|
||||
}
|
||||
|
||||
fn static_item(p: &mut Parser) {
|
||||
assert!(p.at(STATIC_KW));
|
||||
p.bump();
|
||||
p.eat(MUT_KW);
|
||||
p.expect(IDENT);
|
||||
p.expect(COLON);
|
||||
types::type_ref(p);
|
||||
p.expect(EQ);
|
||||
expressions::expr(p);
|
||||
p.expect(SEMI);
|
||||
}
|
||||
|
||||
fn mod_item(p: &mut Parser) {
|
||||
assert!(p.at(MOD_KW));
|
||||
p.bump();
|
||||
|
@ -104,12 +126,6 @@ fn mod_item(p: &mut Parser) {
|
|||
}
|
||||
}
|
||||
|
||||
fn extern_block(p: &mut Parser) {
|
||||
assert!(p.at(L_CURLY));
|
||||
p.bump();
|
||||
p.expect(R_CURLY);
|
||||
}
|
||||
|
||||
fn abi(p: &mut Parser) {
|
||||
assert!(p.at(EXTERN_KW));
|
||||
let abi = p.start();
|
||||
|
|
|
@ -28,6 +28,9 @@ pub enum SyntaxKind {
|
|||
WHILE_KW,
|
||||
IF_KW,
|
||||
MATCH_KW,
|
||||
CONST_KW,
|
||||
STATIC_KW,
|
||||
MUT_KW,
|
||||
ERROR,
|
||||
IDENT,
|
||||
UNDERSCORE,
|
||||
|
@ -86,6 +89,7 @@ pub enum SyntaxKind {
|
|||
EXTERN_CRATE_ITEM,
|
||||
MOD_ITEM,
|
||||
USE_ITEM,
|
||||
STATIC_ITEM,
|
||||
EXTERN_BLOCK,
|
||||
ENUM_VARIANT,
|
||||
NAMED_FIELD,
|
||||
|
@ -137,6 +141,9 @@ impl SyntaxKind {
|
|||
WHILE_KW => &SyntaxInfo { name: "WHILE_KW" },
|
||||
IF_KW => &SyntaxInfo { name: "IF_KW" },
|
||||
MATCH_KW => &SyntaxInfo { name: "MATCH_KW" },
|
||||
CONST_KW => &SyntaxInfo { name: "CONST_KW" },
|
||||
STATIC_KW => &SyntaxInfo { name: "STATIC_KW" },
|
||||
MUT_KW => &SyntaxInfo { name: "MUT_KW" },
|
||||
ERROR => &SyntaxInfo { name: "ERROR" },
|
||||
IDENT => &SyntaxInfo { name: "IDENT" },
|
||||
UNDERSCORE => &SyntaxInfo { name: "UNDERSCORE" },
|
||||
|
@ -195,6 +202,7 @@ impl SyntaxKind {
|
|||
EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" },
|
||||
MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" },
|
||||
USE_ITEM => &SyntaxInfo { name: "USE_ITEM" },
|
||||
STATIC_ITEM => &SyntaxInfo { name: "STATIC_ITEM" },
|
||||
EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" },
|
||||
ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" },
|
||||
NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
|
||||
|
@ -242,6 +250,9 @@ pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> {
|
|||
"while" => Some(WHILE_KW),
|
||||
"if" => Some(IF_KW),
|
||||
"match" => Some(MATCH_KW),
|
||||
"const" => Some(CONST_KW),
|
||||
"static" => Some(STATIC_KW),
|
||||
"mut" => Some(MUT_KW),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
fn use struct trait enum impl true false as extern crate mod pub self super in where for loop while if match
|
||||
fn use struct trait enum impl true false as extern crate
|
||||
mod pub self super in where for loop while if match const
|
||||
static mut
|
||||
|
|
|
@ -19,7 +19,7 @@ WHITESPACE 1 " "
|
|||
EXTERN_KW 6 "extern"
|
||||
WHITESPACE 1 " "
|
||||
CRATE_KW 5 "crate"
|
||||
WHITESPACE 1 " "
|
||||
WHITESPACE 1 "\n"
|
||||
MOD_KW 3 "mod"
|
||||
WHITESPACE 1 " "
|
||||
PUB_KW 3 "pub"
|
||||
|
@ -41,4 +41,10 @@ WHITESPACE 1 " "
|
|||
IF_KW 2 "if"
|
||||
WHITESPACE 1 " "
|
||||
MATCH_KW 5 "match"
|
||||
WHITESPACE 1 " "
|
||||
CONST_KW 5 "const"
|
||||
WHITESPACE 1 "\n"
|
||||
STATIC_KW 6 "static"
|
||||
WHITESPACE 1 " "
|
||||
MUT_KW 3 "mut"
|
||||
WHITESPACE 1 "\n"
|
||||
|
|
2
tests/data/parser/ok/0023_static_items.rs
Normal file
2
tests/data/parser/ok/0023_static_items.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
static FOO: u32 = 1;
|
||||
static mut BAR: i32 = 92;
|
31
tests/data/parser/ok/0023_static_items.txt
Normal file
31
tests/data/parser/ok/0023_static_items.txt
Normal file
|
@ -0,0 +1,31 @@
|
|||
FILE@[0; 47)
|
||||
STATIC_ITEM@[0; 21)
|
||||
STATIC_KW@[0; 6)
|
||||
WHITESPACE@[6; 7)
|
||||
IDENT@[7; 10) "FOO"
|
||||
COLON@[10; 11)
|
||||
WHITESPACE@[11; 12)
|
||||
IDENT@[12; 15) "u32"
|
||||
WHITESPACE@[15; 16)
|
||||
EQ@[16; 17)
|
||||
LITERAL@[17; 19)
|
||||
WHITESPACE@[17; 18)
|
||||
INT_NUMBER@[18; 19)
|
||||
SEMI@[19; 20)
|
||||
WHITESPACE@[20; 21)
|
||||
STATIC_ITEM@[21; 47)
|
||||
STATIC_KW@[21; 27)
|
||||
WHITESPACE@[27; 28)
|
||||
MUT_KW@[28; 31)
|
||||
WHITESPACE@[31; 32)
|
||||
IDENT@[32; 35) "BAR"
|
||||
COLON@[35; 36)
|
||||
WHITESPACE@[36; 37)
|
||||
IDENT@[37; 40) "i32"
|
||||
WHITESPACE@[40; 41)
|
||||
EQ@[41; 42)
|
||||
LITERAL@[42; 45)
|
||||
WHITESPACE@[42; 43)
|
||||
INT_NUMBER@[43; 45)
|
||||
SEMI@[45; 46)
|
||||
WHITESPACE@[46; 47)
|
Loading…
Reference in a new issue