aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: f064d397f5d98e733c52bdb97be725fea573386f (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
#![feature(test, let_chains)]
#![warn(
    clippy::wildcard_imports,
    clippy::string_add,
    clippy::string_add_assign,
    clippy::manual_ok_or,
    unused_lifetimes
)]

pub mod ast;
pub mod lexer;

use ast::{Expression, Operation, Value};
use lexer::Lexer;

use crate::ast::Statement;

const SOURCE: &str = r#"

val variable = 5;

if variable <= 7 {
    print "Hello World";
}

"#;

fn main() {
    let lexer = Lexer::new(SOURCE);
    for token in lexer {
        print!("{} ", token.lexeme);
    }

    println!("-------");

    let a = Expression::Literal(Value(7));
    let b = Expression::Binary {
        operation: Operation::Add,
        lhs: &Expression::Literal(Value(5)),
        rhs: &a,
    };

    let stmt = Statement::Expression { expr: &b };

    println!("{stmt}");
}