cl-ast: Overhaul pretty-printing using std::fmt::Write adapters.
Now you don't have to import cl_ast::format::*!!!
This commit is contained in:
@@ -12,6 +12,7 @@ const STDLIB: &str = include_str!("../../stdlib/lib.cl");
|
||||
const C_MAIN: &str = "\x1b[30m";
|
||||
const C_RESV: &str = "\x1b[35m";
|
||||
const C_CODE: &str = "\x1b[36m";
|
||||
const C_LISTING: &str = "\x1b[38;5;117m";
|
||||
|
||||
/// A home for immutable intermediate ASTs
|
||||
///
|
||||
@@ -144,12 +145,15 @@ fn list_types(prj: &mut Project) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
fn pretty_def(def: &Def, id: impl Into<usize>) {
|
||||
let id = id.into();
|
||||
let Def { vis, name, kind, module, meta, source: _ } = def;
|
||||
let Def { vis, name, kind, module, meta, source } = def;
|
||||
for meta in *meta {
|
||||
println!("#[{meta}]")
|
||||
}
|
||||
println!("{vis}{name} [id: {id}] = {kind}");
|
||||
println!("Module:\n\x1b[97m{module}\x1b[0m");
|
||||
if let Some(source) = source {
|
||||
println!("Source:\n{C_LISTING}{source}\x1b[0m");
|
||||
}
|
||||
println!("\x1b[90m{module}\x1b[0m");
|
||||
}
|
||||
|
||||
fn clear() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
@@ -85,11 +85,11 @@ pub mod program {
|
||||
env::Environment, error::IResult, interpret::Interpret, temp_type_impl::ConValue,
|
||||
};
|
||||
|
||||
use cl_ast::{self as ast, format::*};
|
||||
use cl_ast as ast;
|
||||
use cl_lexer::Lexer;
|
||||
use cl_parser::{error::PResult, Parser};
|
||||
// use conlang::resolver::{error::TyResult, Resolver};
|
||||
use std::{fmt::Display, io::Write};
|
||||
use std::fmt::Display;
|
||||
|
||||
pub struct Parsable;
|
||||
|
||||
@@ -136,13 +136,11 @@ pub mod program {
|
||||
}
|
||||
}
|
||||
pub fn print(&self) {
|
||||
let mut f = std::io::stdout().pretty();
|
||||
let _ = match &self.data {
|
||||
Parsed::File(v) => writeln!(f, "{v}"),
|
||||
Parsed::Stmt(v) => writeln!(f, "{v}"),
|
||||
Parsed::Expr(v) => writeln!(f, "{v}"),
|
||||
match &self.data {
|
||||
Parsed::File(v) => println!("{v}"),
|
||||
Parsed::Stmt(v) => println!("{v}"),
|
||||
Parsed::Expr(v) => println!("{v}"),
|
||||
};
|
||||
// println!("{self}")
|
||||
}
|
||||
|
||||
pub fn run(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
|
||||
Reference in New Issue
Block a user