aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser/grammar.rs
blob: 0896506fb1b1eb0185be09e918973c619f48be72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use super::Event;
use super::parser::Parser;

use syntax_kinds::*;

// Items //

pub fn file(p: &mut Parser) {
    p.start(FILE);
    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)?;
    if p.current_is(STRUCT_KW) {
        p.start(STRUCT_ITEM);
        p.bump();
        p.finish();
        return OK;
    }
    ERR
}



// 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();
    p.finish();
}