forked from Orchid/orchid
Lexer test mode works
This commit is contained in:
@@ -6,3 +6,8 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
camino = "1.1.7"
|
||||
clap = { version = "=4.5.4", features = ["derive"] }
|
||||
itertools = "0.13.0"
|
||||
orchid-base = { version = "0.1.0", path = "../orchid-base" }
|
||||
orchid-host = { version = "0.1.0", path = "../orchid-host" }
|
||||
|
||||
@@ -1,3 +1,43 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::{fs::File, io::Read, process::Command};
|
||||
|
||||
use camino::Utf8PathBuf;
|
||||
use clap::{Parser, Subcommand};
|
||||
use itertools::Itertools;
|
||||
use orchid_base::{interner::intern, logging::{LogStrategy, Logger}};
|
||||
use orchid_host::{extension::{init_systems, Extension}, lex::lex, tree::fmt_tt_v};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about)]
|
||||
pub struct Args {
|
||||
#[arg(short, long)]
|
||||
extension: Vec<Utf8PathBuf>,
|
||||
#[arg(short, long)]
|
||||
system: Vec<String>,
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
pub enum Commands {
|
||||
Lex{
|
||||
#[arg(short, long)]
|
||||
file: Utf8PathBuf
|
||||
},
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
match args.command {
|
||||
Commands::Lex { file } => {
|
||||
let extensions = (args.extension.iter())
|
||||
.map(|f| Extension::new(Command::new(f.as_os_str()), Logger::new(LogStrategy::StdErr)).unwrap())
|
||||
.collect_vec();
|
||||
let systems = init_systems(&args.system, &extensions).unwrap();
|
||||
let mut file = File::open(file.as_std_path()).unwrap();
|
||||
let mut buf = String::new();
|
||||
file.read_to_string(&mut buf).unwrap();
|
||||
let lexemes = lex(intern(&buf), &systems).unwrap();
|
||||
println!("{}", fmt_tt_v(&lexemes))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user