mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Parser: first struct :-)
This commit is contained in:
parent
46422f722b
commit
55602727c8
3 changed files with 16 additions and 5 deletions
|
@ -43,13 +43,18 @@ fn item(p: &mut Parser) -> Result {
|
||||||
if p.current_is(STRUCT_KW) {
|
if p.current_is(STRUCT_KW) {
|
||||||
p.start(STRUCT_ITEM);
|
p.start(STRUCT_ITEM);
|
||||||
p.bump();
|
p.bump();
|
||||||
|
let _ = struct_item(p);
|
||||||
p.finish();
|
p.finish();
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
ERR
|
ERR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn struct_item(p: &mut Parser) -> Result{
|
||||||
|
p.expect(IDENT)?;
|
||||||
|
p.expect(L_CURLY)?;
|
||||||
|
p.expect(R_CURLY)
|
||||||
|
}
|
||||||
|
|
||||||
// Paths, types, attributes, and stuff //
|
// Paths, types, attributes, and stuff //
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,15 @@ impl<'t> Parser<'t> {
|
||||||
Some(kind)
|
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) {
|
fn event(&mut self, event: Event) {
|
||||||
self.events.push(event)
|
self.events.push(event)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
FILE@[0; 13)
|
FILE@[0; 13)
|
||||||
STRUCT_ITEM@[0; 7)
|
STRUCT_ITEM@[0; 13)
|
||||||
STRUCT_KW@[0; 6)
|
STRUCT_KW@[0; 6)
|
||||||
WHITESPACE@[6; 7)
|
WHITESPACE@[6; 7)
|
||||||
ERROR@[7; 9)
|
|
||||||
IDENT@[7; 8)
|
IDENT@[7; 8)
|
||||||
WHITESPACE@[8; 9)
|
WHITESPACE@[8; 9)
|
||||||
ERROR@[9; 12)
|
|
||||||
L_CURLY@[9; 10)
|
L_CURLY@[9; 10)
|
||||||
WHITESPACE@[10; 12)
|
WHITESPACE@[10; 12)
|
||||||
ERROR@[12; 13)
|
|
||||||
R_CURLY@[12; 13)
|
R_CURLY@[12; 13)
|
||||||
|
|
Loading…
Reference in a new issue