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

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