ast: formatting; main: explicit verbosity
This commit is contained in:
@@ -438,7 +438,7 @@ impl<A: Annotation> Display for Expr<A> {
|
|||||||
Self::Op(Op::Tuple, exprs) => f.delimit("(", ")").list(exprs, ", "),
|
Self::Op(Op::Tuple, exprs) => f.delimit("(", ")").list(exprs, ", "),
|
||||||
Self::Op(Op::Group, exprs) => f.list(exprs, ", "),
|
Self::Op(Op::Group, exprs) => f.list(exprs, ", "),
|
||||||
Self::Op(Op::Meta, exprs) => match exprs.as_slice() {
|
Self::Op(Op::Meta, exprs) => match exprs.as_slice() {
|
||||||
[meta, expr @ ..] => f.delimit(fmt!("#[{meta}]\n"), "").list(expr, ","),
|
[meta, expr @ ..] => f.delimit(fmt!("#[{meta}] "), "").list(expr, ","),
|
||||||
[] => write!(f, "#[]"),
|
[] => write!(f, "#[]"),
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -465,7 +465,7 @@ impl<A: Annotation> Display for Expr<A> {
|
|||||||
impl Display for Op {
|
impl Display for Op {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.write_str(match self {
|
f.write_str(match self {
|
||||||
Op::Do => "; ",
|
Op::Do => ";\n",
|
||||||
Op::As => " as ",
|
Op::As => " as ",
|
||||||
Op::Macro => "macro ",
|
Op::Macro => "macro ",
|
||||||
Op::Block => "{}",
|
Op::Block => "{}",
|
||||||
|
|||||||
@@ -205,7 +205,10 @@ fn subst() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
fn parse(document: &str) {
|
fn parse(document: &str) {
|
||||||
let mut parser = Parser::new(Lexer::new(document));
|
let mut parser = Parser::new(Lexer::new(document));
|
||||||
let isatty = std::io::stdin().is_terminal();
|
let verbose = !matches!(
|
||||||
|
std::env::var("DOUGHLANG_VERBOSE").as_deref(),
|
||||||
|
Ok("false" | "0" | "no")
|
||||||
|
);
|
||||||
for idx in 0.. {
|
for idx in 0.. {
|
||||||
match parser.parse::<Expr>(0) {
|
match parser.parse::<Expr>(0) {
|
||||||
Err(e @ ParseError::EOF(s)) if s.tail == document.len() as _ => {
|
Err(e @ ParseError::EOF(s)) if s.tail == document.len() as _ => {
|
||||||
@@ -220,7 +223,7 @@ fn parse(document: &str) {
|
|||||||
println!("\x1b[91m{e}\x1b[0m");
|
println!("\x1b[91m{e}\x1b[0m");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ok(v) if isatty => {
|
Ok(v) if verbose => {
|
||||||
println!("\x1b[{}m{v}", (idx + 5) % 6 + 31);
|
println!("\x1b[{}m{v}", (idx + 5) % 6 + 31);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
Reference in New Issue
Block a user