Clean up main.rs, stdout, some compile warnings
This commit is contained in:
@@ -86,22 +86,6 @@ pub fn parse_stat_labels(stat: &Stat) -> ParsedStat {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn print_labels(b: &Stat) {
|
||||
let code = &b.code;
|
||||
let mut parser = ParseState::new(code);
|
||||
assert!(
|
||||
grammar::program(&mut parser),
|
||||
"Couldn't parse code: {:?}",
|
||||
code
|
||||
);
|
||||
|
||||
for capture in parser.captures() {
|
||||
if capture.kind() == Tag::Label {
|
||||
println!("- {}", capture.text());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod grammar {
|
||||
use peg_macro::grammar;
|
||||
|
||||
|
||||
+3
-22
@@ -5,7 +5,7 @@ mod preprocess;
|
||||
mod world;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use labels::{parse::print_labels, process::process_labels};
|
||||
use labels::process::process_labels;
|
||||
use preprocess::eval::Context;
|
||||
use std::{env, error::Error, fs, path::PathBuf, process::exit};
|
||||
use world::World;
|
||||
@@ -28,33 +28,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
.ok_or(anyhow!("Couldn't get world's directory"))?;
|
||||
let eval_context = Context::new(&world_dir);
|
||||
|
||||
println!("num boards: {}", &world.boards.len());
|
||||
// Codegen: Evaluate all macros
|
||||
for board in &mut world.boards {
|
||||
println!("board: {}", board.name);
|
||||
for stat in &mut board.stats {
|
||||
// Print some of the data parsed.
|
||||
let (x, y) = (stat.x as usize, stat.y as usize);
|
||||
let terrain = if x < 1 || x > 60 || y < 1 || y > 25 {
|
||||
None
|
||||
} else {
|
||||
let terrain_index = (x - 1) + (y - 1) * 60;
|
||||
Some(board.terrain[terrain_index])
|
||||
};
|
||||
println!(" stat at ({}, {}): {:?}, {:?}", x, y, terrain, stat.code);
|
||||
|
||||
// Evaluate macros
|
||||
stat.code = eval_context.eval_program(&stat.code)?;
|
||||
}
|
||||
board.name.push_str(" (♪)");
|
||||
}
|
||||
|
||||
for board in &world.boards {
|
||||
println!("# Board: {}", board.name);
|
||||
for stat in &board.stats {
|
||||
print_labels(stat);
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve labels to proper ZZT-OOP
|
||||
for mut board in &mut world.boards {
|
||||
process_labels(&mut board);
|
||||
}
|
||||
|
||||
@@ -21,9 +21,6 @@ trait FileLoaderTrait {
|
||||
struct FileLoader {
|
||||
working_dir: PathBuf,
|
||||
}
|
||||
struct MockFileLoader {
|
||||
content: String,
|
||||
}
|
||||
|
||||
impl FileLoaderTrait for FileLoader {
|
||||
fn load(&self, path: &Path) -> Result<String> {
|
||||
@@ -34,6 +31,12 @@ impl FileLoaderTrait for FileLoader {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
struct MockFileLoader {
|
||||
content: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl FileLoaderTrait for MockFileLoader {
|
||||
fn load(&self, _path: &Path) -> Result<String> {
|
||||
Ok(self.content.clone())
|
||||
|
||||
Reference in New Issue
Block a user