mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 15:03:46 +00:00
Rename RemoveSpaces->Normalize
This commit is contained in:
parent
6835041a61
commit
2d9aa00771
6 changed files with 527 additions and 577 deletions
|
@ -9,7 +9,7 @@ use roc_fmt::header::fmt_header;
|
|||
use roc_fmt::Buf;
|
||||
use roc_parse::ast::{FullAst, SpacesBefore};
|
||||
use roc_parse::header::parse_module_defs;
|
||||
use roc_parse::remove_spaces::RemoveSpaces;
|
||||
use roc_parse::normalize::Normalize;
|
||||
use roc_parse::{header, parser::SyntaxError, state::State};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
@ -200,8 +200,8 @@ pub fn format_src(arena: &Bump, src: &str) -> Result<String, FormatProblem> {
|
|||
}
|
||||
};
|
||||
|
||||
let ast_normalized = ast.remove_spaces(arena);
|
||||
let reparsed_ast_normalized = reparsed_ast.remove_spaces(arena);
|
||||
let ast_normalized = ast.normalize(arena);
|
||||
let reparsed_ast_normalized = reparsed_ast.normalize(arena);
|
||||
|
||||
// HACK!
|
||||
// We compare the debug format strings of the ASTs, because I'm finding in practice that _somewhere_ deep inside the ast,
|
||||
|
|
|
@ -13,10 +13,10 @@ pub mod header;
|
|||
pub mod highlight;
|
||||
pub mod ident;
|
||||
pub mod keyword;
|
||||
pub mod normalize;
|
||||
pub mod number_literal;
|
||||
pub mod pattern;
|
||||
pub mod problems;
|
||||
pub mod remove_spaces;
|
||||
pub mod src64;
|
||||
pub mod state;
|
||||
pub mod string_literal;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -7,7 +7,7 @@
|
|||
|
||||
use crate::test_helpers::{Input, InputKind};
|
||||
use bumpalo::Bump;
|
||||
use roc_parse::{ast::Malformed, remove_spaces::RemoveSpaces};
|
||||
use roc_parse::{ast::Malformed, normalize::Normalize};
|
||||
|
||||
pub fn print_minimizations(text: &str, kind: InputKind) {
|
||||
let Some(original_error) = round_trip_once_and_extract_error(text, kind) else {
|
||||
|
@ -81,12 +81,7 @@ fn round_trip_once(input: Input<'_>) -> Option<String> {
|
|||
|
||||
let actual = match input.parse_in(&arena) {
|
||||
Ok(a) => a,
|
||||
Err(e) => {
|
||||
return Some(format!(
|
||||
"Initial parse failed: {:?}",
|
||||
e.remove_spaces(&arena)
|
||||
))
|
||||
}
|
||||
Err(e) => return Some(format!("Initial parse failed: {:?}", e.normalize(&arena))),
|
||||
};
|
||||
|
||||
if actual.is_malformed() {
|
||||
|
@ -97,11 +92,11 @@ fn round_trip_once(input: Input<'_>) -> Option<String> {
|
|||
|
||||
let reparsed_ast = match output.as_ref().parse_in(&arena) {
|
||||
Ok(r) => r,
|
||||
Err(e) => return Some(format!("Reparse failed: {:?}", e.remove_spaces(&arena))),
|
||||
Err(e) => return Some(format!("Reparse failed: {:?}", e.normalize(&arena))),
|
||||
};
|
||||
|
||||
let ast_normalized = actual.remove_spaces(&arena);
|
||||
let reparsed_ast_normalized = reparsed_ast.remove_spaces(&arena);
|
||||
let ast_normalized = actual.normalize(&arena);
|
||||
let reparsed_ast_normalized = reparsed_ast.normalize(&arena);
|
||||
|
||||
if format!("{ast_normalized:?}") != format!("{reparsed_ast_normalized:?}") {
|
||||
return Some("Different ast".to_string());
|
||||
|
|
|
@ -3,8 +3,8 @@ use roc_fmt::{annotation::Formattable, header::fmt_header};
|
|||
use roc_parse::{
|
||||
ast::{Defs, Expr, FullAst, Header, Malformed, SpacesBefore},
|
||||
header::parse_module_defs,
|
||||
normalize::Normalize,
|
||||
parser::{Parser, SyntaxError},
|
||||
remove_spaces::RemoveSpaces,
|
||||
state::State,
|
||||
test_helpers::{parse_defs_with, parse_expr_with, parse_header_with},
|
||||
};
|
||||
|
@ -128,13 +128,13 @@ impl<'a> Malformed for Output<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> RemoveSpaces<'a> for Output<'a> {
|
||||
fn remove_spaces(&self, arena: &'a Bump) -> Self {
|
||||
impl<'a> Normalize<'a> for Output<'a> {
|
||||
fn normalize(&self, arena: &'a Bump) -> Self {
|
||||
match self {
|
||||
Output::Header(header) => Output::Header(header.remove_spaces(arena)),
|
||||
Output::ModuleDefs(defs) => Output::ModuleDefs(defs.remove_spaces(arena)),
|
||||
Output::Expr(expr) => Output::Expr(expr.remove_spaces(arena)),
|
||||
Output::Full(full) => Output::Full(full.remove_spaces(arena)),
|
||||
Output::Header(header) => Output::Header(header.normalize(arena)),
|
||||
Output::ModuleDefs(defs) => Output::ModuleDefs(defs.normalize(arena)),
|
||||
Output::Expr(expr) => Output::Expr(expr.normalize(arena)),
|
||||
Output::Full(full) => Output::Full(full.normalize(arena)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -221,8 +221,8 @@ impl<'a> Input<'a> {
|
|||
);
|
||||
});
|
||||
|
||||
let ast_normalized = actual.remove_spaces(&arena);
|
||||
let reparsed_ast_normalized = reparsed_ast.remove_spaces(&arena);
|
||||
let ast_normalized = actual.normalize(&arena);
|
||||
let reparsed_ast_normalized = reparsed_ast.normalize(&arena);
|
||||
|
||||
// HACK!
|
||||
// We compare the debug format strings of the ASTs, because I'm finding in practice that _somewhere_ deep inside the ast,
|
||||
|
|
|
@ -63,7 +63,7 @@ mod test_fmt {
|
|||
|
||||
match header::parse_header(&arena, State::new(src.as_bytes())) {
|
||||
Ok((actual, state)) => {
|
||||
use roc_parse::remove_spaces::RemoveSpaces;
|
||||
use roc_parse::normalize::Normalize;
|
||||
|
||||
let mut buf = Buf::new_in(&arena);
|
||||
|
||||
|
@ -77,8 +77,8 @@ mod test_fmt {
|
|||
);
|
||||
});
|
||||
|
||||
let ast_normalized = actual.remove_spaces(&arena);
|
||||
let reparsed_ast_normalized = reparsed_ast.remove_spaces(&arena);
|
||||
let ast_normalized = actual.normalize(&arena);
|
||||
let reparsed_ast_normalized = reparsed_ast.normalize(&arena);
|
||||
|
||||
// HACK!
|
||||
// We compare the debug format strings of the ASTs, because I'm finding in practice that _somewhere_ deep inside the ast,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue