rust/src/parser/event_parser/grammar.rs

81 lines
1.3 KiB
Rust
Raw Normal View History

2018-01-01 07:05:46 -06:00
use super::Event;
use super::parser::Parser;
use syntax_kinds::*;
2018-01-01 09:58:46 -06:00
// Items //
2018-01-01 08:21:53 -06:00
pub fn file(p: &mut Parser) {
2018-01-01 07:05:46 -06:00
p.start(FILE);
2018-01-01 09:58:46 -06:00
shebang(p);
inner_attributes(p);
mod_items(p);
p.finish();
}
type Result = ::std::result::Result<(), ()>;
const OK: Result = Ok(());
const ERR: Result = Err(());
fn shebang(_: &mut Parser) {
//TODO
}
fn inner_attributes(_: &mut Parser) {
//TODO
}
fn mod_items(p: &mut Parser) {
loop {
skip_until_item(p);
if p.is_eof() {
return;
}
if item(p).is_err() {
skip_one_token(p);
}
}
}
fn item(p: &mut Parser) -> Result {
outer_attributes(p)?;
visibility(p)?;
2018-01-01 13:13:04 -06:00
if p.current_is(STRUCT_KW) {
p.start(STRUCT_ITEM);
p.bump();
2018-01-01 14:22:01 -06:00
let _ = struct_item(p);
2018-01-01 13:13:04 -06:00
p.finish();
return OK;
}
2018-01-01 09:58:46 -06:00
ERR
}
2018-01-01 14:22:01 -06:00
fn struct_item(p: &mut Parser) -> Result{
p.expect(IDENT)?;
p.expect(L_CURLY)?;
p.expect(R_CURLY)
}
2018-01-01 09:58:46 -06:00
// Paths, types, attributes, and stuff //
fn outer_attributes(_: &mut Parser) -> Result {
OK
}
fn visibility(_: &mut Parser) -> Result {
OK
}
// Expressions //
// Error recovery and high-order utils //
fn skip_until_item(_: &mut Parser) {
//TODO
}
fn skip_one_token(p: &mut Parser) {
p.start(ERROR);
p.bump().unwrap();
2018-01-01 07:05:46 -06:00
p.finish();
}