Parse module params loc and rename to pattern

This commit is contained in:
Agus Zubiaga 2024-06-27 16:14:56 -03:00
parent c6e42ecf0c
commit 7ac72159e9
No known key found for this signature in database
10 changed files with 20 additions and 14 deletions

View File

@ -389,10 +389,10 @@ pub fn canonicalize_module_defs<'a>(
let mut param_patterns = Vec::new();
if let Some(ModuleParams { params, .. }) = header_type.get_params() {
param_patterns.reserve_exact(params.len());
if let Some(ModuleParams { pattern, .. }) = header_type.get_params() {
param_patterns.reserve_exact(pattern.value.len());
for param in params.iter() {
for param in pattern.value.iter() {
let pattern = canonicalize_pattern(
&mut env,
var_store,

View File

@ -182,11 +182,17 @@ pub fn fmt_module_header<'a>(buf: &mut Buf, header: &'a ModuleHeader<'a>) {
let mut indent = fmt_spaces_with_outdent(buf, header.after_keyword, 0);
if let Some(params) = &header.params {
if is_collection_multiline(&params.params) {
if is_collection_multiline(&params.pattern.value) {
indent = INDENT;
}
fmt_collection(buf, indent, Braces::Curly, params.params, Newlines::Yes);
fmt_collection(
buf,
indent,
Braces::Curly,
params.pattern.value,
Newlines::Yes,
);
indent = fmt_spaces_with_outdent(buf, params.before_arrow, indent);
buf.push_str("->");

View File

@ -342,7 +342,7 @@ impl<'a> RemoveSpaces<'a> for Module<'a> {
impl<'a> RemoveSpaces<'a> for ModuleParams<'a> {
fn remove_spaces(&self, arena: &'a Bump) -> Self {
ModuleParams {
params: self.params.remove_spaces(arena),
pattern: self.pattern.remove_spaces(arena),
before_arrow: &[],
after_arrow: &[],
}

View File

@ -302,7 +302,7 @@ pub struct ModuleHeader<'a> {
#[derive(Clone, Debug, PartialEq)]
pub struct ModuleParams<'a> {
pub params: Collection<'a, Loc<Pattern<'a>>>,
pub pattern: Loc<Collection<'a, Loc<Pattern<'a>>>>,
pub before_arrow: &'a [CommentOrNewline<'a>],
pub after_arrow: &'a [CommentOrNewline<'a>],
}

View File

@ -123,7 +123,7 @@ fn module_header<'a>() -> impl Parser<'a, ModuleHeader<'a>, EHeader<'a>> {
fn module_params<'a>() -> impl Parser<'a, ModuleParams<'a>, EParams<'a>> {
record!(ModuleParams {
params: specialize_err(EParams::Pattern, record_pattern_fields()),
pattern: specialize_err(EParams::Pattern, loc(record_pattern_fields())),
before_arrow: skip_second(
space0_e(EParams::BeforeArrow),
loc(two_bytes(b'-', b'>', EParams::Arrow))

View File

@ -5,7 +5,7 @@ Module {
after_keyword: [],
params: Some(
ModuleParams {
params: [
pattern: @7-45 [
@8-12 Identifier {
ident: "echo",
},

View File

@ -5,7 +5,7 @@ Module {
after_keyword: [],
params: Some(
ModuleParams {
params: [
pattern: @7-20 [
@9-10 Identifier {
ident: "x",
},

View File

@ -5,7 +5,7 @@ Module {
after_keyword: [],
params: Some(
ModuleParams {
params: [
pattern: @7-20 [
@8-12 Identifier {
ident: "echo",
},

View File

@ -5,7 +5,7 @@ Module {
after_keyword: [],
params: Some(
ModuleParams {
params: [
pattern: @7-20 [
@8-12 Identifier {
ident: "echo",
},

View File

@ -243,12 +243,12 @@ where
impl IterTokens for ModuleParams<'_> {
fn iter_tokens<'a>(&self, arena: &'a Bump) -> BumpVec<'a, Loc<Token>> {
let Self {
params,
pattern,
before_arrow: _,
after_arrow: _,
} = self;
params.iter_tokens(arena)
pattern.value.iter_tokens(arena)
}
}