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
|
/*
Copyright 2023-2024 Gabriel Bjørnager Jensen.
This file is part of eAS.
eAS is free software: you can redistribute it
and/or modify it under the terms of the GNU
General Public License as published by the Free
Software Foundation, either version 3 of the
License, or (at your option) any later version.
eAS is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU
General Public License along with eAS. If not,
see <https://www.gnu.org/licenses/>.
*/
use crate::app::App;
use crate::error::Error;
use crate::node::Node;
use crate::source_location::SourceLocation;
use crate::token::Token;
use std::fs::read_to_string;
impl App {
#[must_use]
pub fn run(self) -> Result<(), Error> {
if cfg!(debug_assertions) {
println!("\u{1B}[1mSettings\u{1B}[0m:");
println!("\u{B7} input \u{1B}[3m\"{}\"\u{1B}[0m", self.input);
println!("\u{B7} output \u{1B}[3m\"{}\"\u{1B}[0m", self.output);
println!();
println!("\u{B7} encoding \u{1B}[3m{}\u{1B}[0m", self.encoding);
println!("\u{B7} processor \u{1B}[3m{}\u{1B}[0m", self.processor);
println!("\u{B7} format \u{1B}[3m{}\u{1B}[0m", self.format);
println!();
}
let input = match read_to_string(&self.input) {
Ok(content) => content,
_ => return Err(Error::AccessDenied(self.input.clone())),
};
let tokens = Token::tokenise(&input, &mut SourceLocation::new(&self.input))?;
if cfg!(debug_assertions) {
eprintln!("\u{1B}[1mTokens\u{1B}[0m:");
for (location, token) in &tokens {
eprintln!("\u{B7} {location}: {token:?}");
}
}
let nodes = Node::parse(&tokens)?;
if cfg!(debug_assertions) {
eprintln!("\u{1B}[1mNodes\u{1B}[0m:");
for node in &nodes {
eprintln!("\u{B7} {node:?}");
}
}
return Ok(());
}
}
|