From d0900b3ca7be669418e185c0eea0d92550d83d4d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 6 Jan 2018 17:16:00 +0300 Subject: G: struct fields --- src/parser/event_parser/grammar.rs | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'src/parser/event_parser/grammar.rs') diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs index be61483ec..77596fea6 100644 --- a/src/parser/event_parser/grammar.rs +++ b/src/parser/event_parser/grammar.rs @@ -1,4 +1,3 @@ -use super::Event; use super::parser::Parser; use syntax_kinds::*; @@ -50,10 +49,26 @@ fn item(p: &mut Parser) -> Result { ERR } -fn struct_item(p: &mut Parser) -> Result{ +fn struct_item(p: &mut Parser) -> Result { p.expect(IDENT)?; - p.expect(L_CURLY)?; - p.expect(R_CURLY) + p.curly_block(|p| { + comma_list(p, struct_field) + }) +} + +fn struct_field(p: &mut Parser) -> Result { + if !p.current_is(IDENT) { + return ERR; + } + p.start(STRUCT_FIELD); + p.bump(); + ignore_errors(|| { + p.expect(COLON)?; + p.expect(IDENT)?; + OK + }); + p.finish(); + OK } // Paths, types, attributes, and stuff // @@ -78,4 +93,19 @@ fn skip_one_token(p: &mut Parser) { p.start(ERROR); p.bump().unwrap(); p.finish(); +} + +fn ignore_errors Result>(f: F) { + drop(f()); +} + +fn comma_list Result>(p: &mut Parser, element: F) { + loop { + if element(p).is_err() { + return + } + if p.expect(COMMA).is_err() { + return + } + } } \ No newline at end of file -- cgit v1.2.3