-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
94 lines (76 loc) · 2.14 KB
/
main.rs
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#![allow(dead_code)]
#![allow(unused)]
mod rain;
use colored::*;
use serde::Deserialize;
use core::panic;
use std::{collections::HashMap, env, fs, process::{self, exit}};
use rain::lexer::*;
#[derive(Debug, Deserialize)]
struct Config {
project: Project,
droplets: HashMap<String, String>,
}
#[derive(Debug, Deserialize)]
struct Project {
name: String,
version: String,
author: Vec<String>,
description: String,
raindrop: i32,
out: String,
}
#[derive(Debug, Deserialize)]
struct Droplet {
name: String,
version: String,
}
fn main() {
let args: Vec<String> = env::args().collect();
// ###### For storm, but right now just for reading the version file
let file: String = match fs::read_to_string("rain.toml") {
Ok(x) => x,
Err(x) => panic!("Error reading rain.toml file: {}", x),
};
let config: Config = match toml::from_str(&file) {
Ok(x) => x,
Err(x) => panic!("Error parsing rain.toml file: {}", x),
};
let droplets: Vec<Droplet> = config
.droplets
.iter()
.map(|droplet| Droplet {
name: droplet.0.clone(),
version: droplet.1.clone(),
})
.collect();
// println!("{:#?}", droplets);
// ###### END - For storm, but right now just for reading the version file
let file: String = if args.len() >= 2 {
if !args[1].ends_with(".rain") {
eprintln!("Invalid file extension. File extension must be .rain");
exit(0x1)
}
match fs::read_to_string(args[1].clone()) {
Ok(x) => x,
Err(x) => panic!("Error reading \"{}\": {}", args[1], x),
}
} else {
println!(
"{}",
format!("Rain Lang Compiler - {}", config.project.version.as_str()).blue()
);
println!("{}", "\nUsage: rain <source file>.rain".cyan());
process::exit(0);
};
let mut _lexer = Lexer::new(file.as_str()).clone();
_lexer.lex();
let _tokens = _lexer.tokens;
for token in _tokens {
println!("{:#?}", token);
}
// let idents = _lexer.idents;
// for ident in &idents {
// println!("{:#?}", ident);
// }
}