From b5034410c8e5aabf809d2665e38017ef79d05601 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 7 Jan 2018 16:01:30 +0300 Subject: G: function item --- src/parser/event_parser/grammar.rs | 17 ++++++++++++++--- src/syntax_kinds.rs | 4 +++- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs index f26cbc4f6..09b2f02b2 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 4a27b0eae..6099cd6e0 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 { -- cgit v1.2.3