Skip to content

Commit

Permalink
fix(whitespaces): do not strip whitespaces when removing previous tok…
Browse files Browse the repository at this point in the history
…en (#15)
  • Loading branch information
pinbraerts authored Dec 15, 2024
1 parent 78e745f commit 22ebad2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Parser {
return result;
}
let mut tokens = vec![Token::new(lexem, std::mem::take(&mut self.whitespace))];
while let Some(token) = tokens.pop() {
while let Some(mut token) = tokens.pop() {
match validate(
self.states.last().cloned().unwrap_or_default(),
token.lexem.clone(),
Expand Down Expand Up @@ -164,8 +164,9 @@ impl Parser {
Validate::DropBefore => {
self.states.pop();
if let Some(t) = std::mem::take(&mut self.delay) {
self.whitespace = t.whitespace_before + &self.whitespace;
token.whitespace_before = t.whitespace_before + &token.whitespace_before;
}
tokens.push(token);
continue;
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/input/preserve_whitespaces.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[ 1, 2,
3 ]
3 , ]


0 comments on commit 22ebad2

Please sign in to comment.