mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
G: function item
This commit is contained in:
parent
7c6f0f9128
commit
b5034410c8
5 changed files with 32 additions and 4 deletions
|
@ -64,5 +64,6 @@ Grammar(
|
|||
"FILE",
|
||||
"STRUCT_ITEM",
|
||||
"STRUCT_FIELD",
|
||||
"FN_ITEM",
|
||||
]
|
||||
)
|
|
@ -22,8 +22,12 @@ fn inner_attributes(_: &mut Parser) {
|
|||
}
|
||||
|
||||
fn item_first(p: &Parser) -> bool {
|
||||
match p.current() {
|
||||
Some(STRUCT_KW) => true,
|
||||
let current = match p.current() {
|
||||
Some(c) => c,
|
||||
None => return false,
|
||||
};
|
||||
match current {
|
||||
STRUCT_KW | FN_KW => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +35,8 @@ fn item_first(p: &Parser) -> bool {
|
|||
fn item(p: &mut Parser) {
|
||||
outer_attributes(p);
|
||||
visibility(p);
|
||||
node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item);
|
||||
node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item)
|
||||
|| node_if(p, FN_KW, FN_ITEM, fn_item);
|
||||
}
|
||||
|
||||
fn struct_item(p: &mut Parser) {
|
||||
|
@ -45,6 +50,12 @@ fn struct_field(p: &mut Parser) -> bool {
|
|||
})
|
||||
}
|
||||
|
||||
fn fn_item(p: &mut Parser) {
|
||||
p.expect(IDENT) && p.expect(L_PAREN) && p.expect(R_PAREN)
|
||||
&& p.curly_block(|p| ());
|
||||
}
|
||||
|
||||
|
||||
// Paths, types, attributes, and stuff //
|
||||
|
||||
fn outer_attributes(_: &mut Parser) {
|
||||
|
|
|
@ -61,8 +61,9 @@ pub const SHEBANG: SyntaxKind = SyntaxKind(56);
|
|||
pub const FILE: SyntaxKind = SyntaxKind(57);
|
||||
pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(58);
|
||||
pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(59);
|
||||
pub const FN_ITEM: SyntaxKind = SyntaxKind(60);
|
||||
|
||||
static INFOS: [SyntaxInfo; 60] = [
|
||||
static INFOS: [SyntaxInfo; 61] = [
|
||||
SyntaxInfo { name: "USE_KW" },
|
||||
SyntaxInfo { name: "FN_KW" },
|
||||
SyntaxInfo { name: "STRUCT_KW" },
|
||||
|
@ -123,6 +124,7 @@ static INFOS: [SyntaxInfo; 60] = [
|
|||
SyntaxInfo { name: "FILE" },
|
||||
SyntaxInfo { name: "STRUCT_ITEM" },
|
||||
SyntaxInfo { name: "STRUCT_FIELD" },
|
||||
SyntaxInfo { name: "FN_ITEM" },
|
||||
];
|
||||
|
||||
pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo {
|
||||
|
|
2
tests/data/parser/ok/0005_fn_item.rs
Normal file
2
tests/data/parser/ok/0005_fn_item.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
fn foo() {
|
||||
}
|
12
tests/data/parser/ok/0005_fn_item.txt
Normal file
12
tests/data/parser/ok/0005_fn_item.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
FILE@[0; 13)
|
||||
FN_ITEM@[0; 13)
|
||||
FN_KW@[0; 2)
|
||||
WHITESPACE@[2; 3)
|
||||
IDENT@[3; 6)
|
||||
L_PAREN@[6; 7)
|
||||
R_PAREN@[7; 8)
|
||||
WHITESPACE@[8; 9)
|
||||
L_CURLY@[9; 10)
|
||||
WHITESPACE@[10; 11)
|
||||
R_CURLY@[11; 12)
|
||||
WHITESPACE@[12; 13)
|
Loading…
Reference in a new issue