mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Extract spacing from parse::header::* items into explicit Spaced enum
This commit is contained in:
parent
86c8764012
commit
0786e554c6
11 changed files with 378 additions and 470 deletions
|
@ -7,11 +7,11 @@ use roc_fmt::module::fmt_module;
|
|||
use roc_fmt::Buf;
|
||||
use roc_module::called_via::{BinOp, UnaryOp};
|
||||
use roc_parse::ast::{
|
||||
AssignedField, Collection, Expr, Pattern, StrLiteral, StrSegment, Tag, TypeAnnotation,
|
||||
AssignedField, Collection, Expr, Pattern, Spaced, StrLiteral, StrSegment, Tag, TypeAnnotation,
|
||||
WhenBranch,
|
||||
};
|
||||
use roc_parse::header::{
|
||||
AppHeader, Effects, ExposesEntry, ImportsEntry, InterfaceHeader, ModuleName, PackageEntry,
|
||||
AppHeader, Effects, ExposedName, ImportsEntry, InterfaceHeader, ModuleName, PackageEntry,
|
||||
PackageName, PackageOrPath, PlatformHeader, PlatformRequires, PlatformRigid, To, TypedIdent,
|
||||
};
|
||||
use roc_parse::{
|
||||
|
@ -228,16 +228,22 @@ impl<'a> RemoveSpaces<'a> for &'a str {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: RemoveSpaces<'a> + Copy> RemoveSpaces<'a> for ExposesEntry<'a, T> {
|
||||
impl<'a, T: RemoveSpaces<'a> + Copy> RemoveSpaces<'a> for Spaced<'a, T> {
|
||||
fn remove_spaces(&self, arena: &'a Bump) -> Self {
|
||||
match *self {
|
||||
ExposesEntry::Exposed(a) => ExposesEntry::Exposed(a.remove_spaces(arena)),
|
||||
ExposesEntry::SpaceBefore(a, _) => a.remove_spaces(arena),
|
||||
ExposesEntry::SpaceAfter(a, _) => a.remove_spaces(arena),
|
||||
Spaced::Item(a) => Spaced::Item(a.remove_spaces(arena)),
|
||||
Spaced::SpaceBefore(a, _) => a.remove_spaces(arena),
|
||||
Spaced::SpaceAfter(a, _) => a.remove_spaces(arena),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RemoveSpaces<'a> for ExposedName<'a> {
|
||||
fn remove_spaces(&self, _arena: &'a Bump) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RemoveSpaces<'a> for ModuleName<'a> {
|
||||
fn remove_spaces(&self, _arena: &'a Bump) -> Self {
|
||||
*self
|
||||
|
@ -261,18 +267,10 @@ impl<'a> RemoveSpaces<'a> for To<'a> {
|
|||
|
||||
impl<'a> RemoveSpaces<'a> for TypedIdent<'a> {
|
||||
fn remove_spaces(&self, arena: &'a Bump) -> Self {
|
||||
match *self {
|
||||
TypedIdent::Entry {
|
||||
ident,
|
||||
spaces_before_colon: _,
|
||||
ann,
|
||||
} => TypedIdent::Entry {
|
||||
ident: ident.remove_spaces(arena),
|
||||
spaces_before_colon: &[],
|
||||
ann: ann.remove_spaces(arena),
|
||||
},
|
||||
TypedIdent::SpaceBefore(a, _) => a.remove_spaces(arena),
|
||||
TypedIdent::SpaceAfter(a, _) => a.remove_spaces(arena),
|
||||
TypedIdent {
|
||||
ident: self.ident.remove_spaces(arena),
|
||||
spaces_before_colon: &[],
|
||||
ann: self.ann.remove_spaces(arena),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -287,29 +285,17 @@ impl<'a> RemoveSpaces<'a> for PlatformRequires<'a> {
|
|||
}
|
||||
|
||||
impl<'a> RemoveSpaces<'a> for PlatformRigid<'a> {
|
||||
fn remove_spaces(&self, arena: &'a Bump) -> Self {
|
||||
match *self {
|
||||
PlatformRigid::Entry { rigid, alias } => PlatformRigid::Entry { rigid, alias },
|
||||
PlatformRigid::SpaceBefore(a, _) => a.remove_spaces(arena),
|
||||
PlatformRigid::SpaceAfter(a, _) => a.remove_spaces(arena),
|
||||
}
|
||||
fn remove_spaces(&self, _arena: &'a Bump) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RemoveSpaces<'a> for PackageEntry<'a> {
|
||||
fn remove_spaces(&self, arena: &'a Bump) -> Self {
|
||||
match *self {
|
||||
PackageEntry::Entry {
|
||||
shorthand,
|
||||
spaces_after_shorthand: _,
|
||||
package_or_path,
|
||||
} => PackageEntry::Entry {
|
||||
shorthand,
|
||||
spaces_after_shorthand: &[],
|
||||
package_or_path: package_or_path.remove_spaces(arena),
|
||||
},
|
||||
PackageEntry::SpaceBefore(a, _) => a.remove_spaces(arena),
|
||||
PackageEntry::SpaceAfter(a, _) => a.remove_spaces(arena),
|
||||
PackageEntry {
|
||||
shorthand: self.shorthand,
|
||||
spaces_after_shorthand: &[],
|
||||
package_or_path: self.package_or_path.remove_spaces(arena),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -328,8 +314,6 @@ impl<'a> RemoveSpaces<'a> for ImportsEntry<'a> {
|
|||
match *self {
|
||||
ImportsEntry::Module(a, b) => ImportsEntry::Module(a, b.remove_spaces(arena)),
|
||||
ImportsEntry::Package(a, b, c) => ImportsEntry::Package(a, b, c.remove_spaces(arena)),
|
||||
ImportsEntry::SpaceBefore(a, _) => a.remove_spaces(arena),
|
||||
ImportsEntry::SpaceAfter(a, _) => a.remove_spaces(arena),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue