From fb0140746543c811e51326cfeb061171e165962e Mon Sep 17 00:00:00 2001 From: mlokr Date: Fri, 19 Jul 2024 13:38:30 +0200 Subject: [PATCH] k --- hblang/src/parser.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hblang/src/parser.rs b/hblang/src/parser.rs index 0648393..1c72364 100644 --- a/hblang/src/parser.rs +++ b/hblang/src/parser.rs @@ -2,7 +2,7 @@ use { crate::{ codegen, ident::{self, Ident}, - lexer::{Lexer, LineMap, Token, TokenKind}, + lexer::{self, Lexer, LineMap, Token, TokenKind}, log, }, std::{ @@ -874,8 +874,8 @@ impl<'a> std::fmt::Display for Expr<'a> { Consecutive => Expr::UnOp { .. }, } + let source = unsafe { &*FMT_SOURCE.with(|s| s.get()) }; { - let source = unsafe { &*FMT_SOURCE.with(|s| s.get()) }; let pos = self.pos(); if let Some(before) = source.get(..pos as usize) { @@ -959,11 +959,17 @@ impl<'a> std::fmt::Display for Expr<'a> { writeln!(f)?; INDENT.with(|i| i.set(i.get() + 1)); let res = (|| { - for stmt in stmts { + for (i, stmt) in stmts.iter().enumerate() { for _ in 0..INDENT.with(|i| i.get()) { write!(f, "\t")?; } - writeln!(f, "{stmt};")?; + write!(f, "{stmt}")?; + if let Some(expr) = stmts.get(i + 1) + && let Some(rest) = source.get(expr.pos() as usize..) + && lexer::Lexer::new(rest).next().kind.precedence().is_some() + { + write!(f, ";")?; + } } Ok(()) })();