Skip to content

Commit

Permalink
Apply different method of indentation to AST.
Browse files Browse the repository at this point in the history
Applies indent by a `number_of_spaces` rather than a tab. This allows for more customization (if wanted) in the `asphalt.toml` if a user wishes to configure their indentation size.
  • Loading branch information
bibi-reden committed Apr 25, 2024
1 parent ca0bc60 commit fb27208
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) enum ASTTarget {
}

pub(crate) struct ASTStream<'a, 'b> {
number_of_spaces: usize,
indents: usize,
is_start_of_line: bool,
writer: &'a mut (dyn Write),
Expand All @@ -36,6 +37,7 @@ pub(crate) struct ASTStream<'a, 'b> {
impl<'a, 'b> ASTStream<'a, 'b> {
pub fn new(writer: &'a mut (dyn fmt::Write + 'a), target: &'b ASTTarget) -> Self {
Self {
number_of_spaces: 4,
indents: 0,
is_start_of_line: true,
writer,
Expand Down Expand Up @@ -73,8 +75,11 @@ impl Write for ASTStream<'_, '_> {
if !line.is_empty() {
if self.is_start_of_line {
self.is_start_of_line = false;
let indentation = "\t".repeat(self.indents);
self.writer.write_str(&indentation)?;
self.writer.write_str(&format!(
"{: >1$}",
"",
self.number_of_spaces * self.indents
))?;
}

self.writer.write_str(line)?;
Expand Down

0 comments on commit fb27208

Please sign in to comment.