Parser: first struct :-)

This commit is contained in:
Aleksey Kladov 2018-01-01 23:22:01 +03:00
parent 46422f722b
commit 55602727c8
3 changed files with 16 additions and 5 deletions

View file

@ -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 //

View file

@ -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)
}

View file

@ -1,12 +1,9 @@
FILE@[0; 13)
STRUCT_ITEM@[0; 7)
STRUCT_ITEM@[0; 13)
STRUCT_KW@[0; 6)
WHITESPACE@[6; 7)
ERROR@[7; 9)
IDENT@[7; 8)
WHITESPACE@[8; 9)
ERROR@[9; 12)
L_CURLY@[9; 10)
WHITESPACE@[10; 12)
ERROR@[12; 13)
R_CURLY@[12; 13)