From 55602727c8adfa12c026a8c7881a8bc57fba9db8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 1 Jan 2018 23:22:01 +0300 Subject: Parser: first struct :-) --- src/parser/event_parser/grammar.rs | 7 ++++++- src/parser/event_parser/parser.rs | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs index 0896506fb..be61483ec 100644 --- a/src/parser/event_parser/grammar.rs +++ b/src/parser/event_parser/grammar.rs @@ -43,13 +43,18 @@ fn item(p: &mut Parser) -> Result { if p.current_is(STRUCT_KW) { p.start(STRUCT_ITEM); p.bump(); + let _ = struct_item(p); p.finish(); return OK; } ERR } - +fn struct_item(p: &mut Parser) -> Result{ + p.expect(IDENT)?; + p.expect(L_CURLY)?; + p.expect(R_CURLY) +} // Paths, types, attributes, and stuff // diff --git a/src/parser/event_parser/parser.rs b/src/parser/event_parser/parser.rs index 2d5418a29..36452ef67 100644 --- a/src/parser/event_parser/parser.rs +++ b/src/parser/event_parser/parser.rs @@ -69,6 +69,15 @@ impl<'t> Parser<'t> { Some(kind) } + pub(crate) fn expect(&mut self, kind: SyntaxKind) -> Result<(), ()> { + if kind == self.current().ok_or(())? { + self.bump(); + Ok(()) + } else { + Err(()) + } + } + fn event(&mut self, event: Event) { self.events.push(event) } -- cgit v1.2.3