diff --git a/grammar.ron b/grammar.ron index 18af8d1238..9beb7f7aa2 100644 --- a/grammar.ron +++ b/grammar.ron @@ -64,5 +64,6 @@ Grammar( "FILE", "STRUCT_ITEM", "STRUCT_FIELD", + "FN_ITEM", ] ) \ No newline at end of file diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs index f26cbc4f66..09b2f02b2d 100644 --- a/src/parser/event_parser/grammar.rs +++ b/src/parser/event_parser/grammar.rs @@ -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) { diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 4a27b0eae6..6099cd6e0d 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs @@ -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 { diff --git a/tests/data/parser/ok/0005_fn_item.rs b/tests/data/parser/ok/0005_fn_item.rs new file mode 100644 index 0000000000..03210551cb --- /dev/null +++ b/tests/data/parser/ok/0005_fn_item.rs @@ -0,0 +1,2 @@ +fn foo() { +} diff --git a/tests/data/parser/ok/0005_fn_item.txt b/tests/data/parser/ok/0005_fn_item.txt new file mode 100644 index 0000000000..e37129ff15 --- /dev/null +++ b/tests/data/parser/ok/0005_fn_item.txt @@ -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)