Fix a few places non-0 Located slipped by RemoveSpaces

This commit is contained in:
Joshua Warner 2021-11-26 19:49:04 -08:00
parent 0a58d6e60e
commit 54317f4c0c

View file

@ -5,10 +5,13 @@ use bumpalo::Bump;
use roc_fmt::def::fmt_def; use roc_fmt::def::fmt_def;
use roc_fmt::module::fmt_module; use roc_fmt::module::fmt_module;
use roc_module::called_via::{BinOp, UnaryOp}; use roc_module::called_via::{BinOp, UnaryOp};
use roc_parse::ast::{AssignedField, Collection, Expr, Pattern, Tag, TypeAnnotation, WhenBranch}; use roc_parse::ast::{
AssignedField, Collection, Expr, Pattern, StrLiteral, StrSegment, Tag, TypeAnnotation,
WhenBranch,
};
use roc_parse::header::{ use roc_parse::header::{
AppHeader, Effects, ExposesEntry, ImportsEntry, InterfaceHeader, ModuleName, PackageEntry, AppHeader, Effects, ExposesEntry, ImportsEntry, InterfaceHeader, ModuleName, PackageEntry,
PlatformHeader, PlatformRequires, PlatformRigid, TypedIdent, PackageName, PackageOrPath, PlatformHeader, PlatformRequires, PlatformRigid, To, TypedIdent,
}; };
use roc_parse::{ use roc_parse::{
ast::{Def, Module}, ast::{Def, Module},
@ -117,7 +120,7 @@ impl<'a> RemoveSpaces<'a> for Module<'a> {
match self { match self {
Module::Interface { header } => Module::Interface { Module::Interface { header } => Module::Interface {
header: InterfaceHeader { header: InterfaceHeader {
name: header.name, name: header.name.remove_spaces(arena),
exposes: header.exposes.remove_spaces(arena), exposes: header.exposes.remove_spaces(arena),
imports: header.imports.remove_spaces(arena), imports: header.imports.remove_spaces(arena),
before_header: &[], before_header: &[],
@ -130,11 +133,11 @@ impl<'a> RemoveSpaces<'a> for Module<'a> {
}, },
Module::App { header } => Module::App { Module::App { header } => Module::App {
header: AppHeader { header: AppHeader {
name: header.name, name: header.name.remove_spaces(arena),
packages: header.packages.remove_spaces(arena), packages: header.packages.remove_spaces(arena),
imports: header.imports.remove_spaces(arena), imports: header.imports.remove_spaces(arena),
provides: header.provides.remove_spaces(arena), provides: header.provides.remove_spaces(arena),
to: header.to, to: header.to.remove_spaces(arena),
before_header: &[], before_header: &[],
after_app_keyword: &[], after_app_keyword: &[],
before_packages: &[], before_packages: &[],
@ -149,7 +152,7 @@ impl<'a> RemoveSpaces<'a> for Module<'a> {
}, },
Module::Platform { header } => Module::Platform { Module::Platform { header } => Module::Platform {
header: PlatformHeader { header: PlatformHeader {
name: header.name, name: header.name.remove_spaces(arena),
requires: header.requires.remove_spaces(arena), requires: header.requires.remove_spaces(arena),
exposes: header.exposes.remove_spaces(arena), exposes: header.exposes.remove_spaces(arena),
packages: header.packages.remove_spaces(arena), packages: header.packages.remove_spaces(arena),
@ -203,6 +206,21 @@ impl<'a> RemoveSpaces<'a> for ModuleName<'a> {
} }
} }
impl<'a> RemoveSpaces<'a> for PackageName<'a> {
fn remove_spaces(&self, _arena: &'a Bump) -> Self {
*self
}
}
impl<'a> RemoveSpaces<'a> for To<'a> {
fn remove_spaces(&self, arena: &'a Bump) -> Self {
match *self {
To::ExistingPackage(a) => To::ExistingPackage(a),
To::NewPackage(a) => To::NewPackage(a.remove_spaces(arena)),
}
}
}
impl<'a> RemoveSpaces<'a> for TypedIdent<'a> { impl<'a> RemoveSpaces<'a> for TypedIdent<'a> {
fn remove_spaces(&self, arena: &'a Bump) -> Self { fn remove_spaces(&self, arena: &'a Bump) -> Self {
match *self { match *self {
@ -250,7 +268,7 @@ impl<'a> RemoveSpaces<'a> for PackageEntry<'a> {
} => PackageEntry::Entry { } => PackageEntry::Entry {
shorthand, shorthand,
spaces_after_shorthand: &[], spaces_after_shorthand: &[],
package_or_path, package_or_path: package_or_path.remove_spaces(arena),
}, },
PackageEntry::SpaceBefore(a, _) => a.remove_spaces(arena), PackageEntry::SpaceBefore(a, _) => a.remove_spaces(arena),
PackageEntry::SpaceAfter(a, _) => a.remove_spaces(arena), PackageEntry::SpaceAfter(a, _) => a.remove_spaces(arena),
@ -258,6 +276,15 @@ impl<'a> RemoveSpaces<'a> for PackageEntry<'a> {
} }
} }
impl<'a> RemoveSpaces<'a> for PackageOrPath<'a> {
fn remove_spaces(&self, arena: &'a Bump) -> Self {
match *self {
PackageOrPath::Package(a, b) => PackageOrPath::Package(a, b),
PackageOrPath::Path(p) => PackageOrPath::Path(p.remove_spaces(arena)),
}
}
}
impl<'a> RemoveSpaces<'a> for ImportsEntry<'a> { impl<'a> RemoveSpaces<'a> for ImportsEntry<'a> {
fn remove_spaces(&self, arena: &'a Bump) -> Self { fn remove_spaces(&self, arena: &'a Bump) -> Self {
match *self { match *self {
@ -393,6 +420,27 @@ impl<'a, T: RemoveSpaces<'a> + Copy + std::fmt::Debug> RemoveSpaces<'a> for Assi
} }
} }
impl<'a> RemoveSpaces<'a> for StrLiteral<'a> {
fn remove_spaces(&self, arena: &'a Bump) -> Self {
match *self {
StrLiteral::PlainLine(t) => StrLiteral::PlainLine(t),
StrLiteral::Line(t) => StrLiteral::Line(t.remove_spaces(arena)),
StrLiteral::Block(t) => StrLiteral::Block(t.remove_spaces(arena)),
}
}
}
impl<'a> RemoveSpaces<'a> for StrSegment<'a> {
fn remove_spaces(&self, arena: &'a Bump) -> Self {
match *self {
StrSegment::Plaintext(t) => StrSegment::Plaintext(t),
StrSegment::Unicode(t) => StrSegment::Unicode(t.remove_spaces(arena)),
StrSegment::EscapedChar(c) => StrSegment::EscapedChar(c),
StrSegment::Interpolated(t) => StrSegment::Interpolated(t.remove_spaces(arena)),
}
}
}
impl<'a> RemoveSpaces<'a> for Expr<'a> { impl<'a> RemoveSpaces<'a> for Expr<'a> {
fn remove_spaces(&self, arena: &'a Bump) -> Self { fn remove_spaces(&self, arena: &'a Bump) -> Self {
match *self { match *self {
@ -407,7 +455,7 @@ impl<'a> RemoveSpaces<'a> for Expr<'a> {
base, base,
is_negative, is_negative,
}, },
Expr::Str(a) => Expr::Str(a), Expr::Str(a) => Expr::Str(a.remove_spaces(arena)),
Expr::Access(a, b) => Expr::Access(arena.alloc(a.remove_spaces(arena)), b), Expr::Access(a, b) => Expr::Access(arena.alloc(a.remove_spaces(arena)), b),
Expr::AccessorFunction(a) => Expr::AccessorFunction(a), Expr::AccessorFunction(a) => Expr::AccessorFunction(a),
Expr::List(a) => Expr::List(a.remove_spaces(arena)), Expr::List(a) => Expr::List(a.remove_spaces(arena)),