aboutsummaryrefslogtreecommitdiff
path: root/src/parser/grammar/expressions.rs
blob: 40f41535e6d66ced46166903c39f2c80bb550f06 (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
use super::*;

// test expr_literals
// fn foo() {
//     let _ = 92;
// }
pub(super) fn literal(p: &mut Parser) -> bool {
    match p.current() {
        TRUE_KW | FALSE_KW | INT_NUMBER | FLOAT_NUMBER | BYTE | CHAR | STRING | RAW_STRING
        | BYTE_STRING | RAW_BYTE_STRING => {
            let lit = p.start();
            p.bump();
            lit.complete(p, LITERAL);
            true
        }
        _ => false,
    }
}

pub(super) fn expr(p: &mut Parser) {
    if literal(p) {
        return;
    }

    match p.current() {
        L_PAREN => tuple_expr(p),
        _ => p.error("expected expression"),
    }
}

fn tuple_expr(p: &mut Parser) {
    assert!(p.at(L_PAREN));
    let m = p.start();
    p.expect(L_PAREN);
    p.expect(R_PAREN);
    m.complete(p, TUPLE_EXPR);
}