mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-11 18:58:24 +03:00
Parse module params loc and rename to pattern
This commit is contained in:
parent
c6e42ecf0c
commit
7ac72159e9
@ -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,
|
||||
|
@ -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(¶ms.params) {
|
||||
if is_collection_multiline(¶ms.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("->");
|
||||
|
@ -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: &[],
|
||||
}
|
||||
|
@ -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>],
|
||||
}
|
||||
|
@ -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))
|
||||
|
@ -5,7 +5,7 @@ Module {
|
||||
after_keyword: [],
|
||||
params: Some(
|
||||
ModuleParams {
|
||||
params: [
|
||||
pattern: @7-45 [
|
||||
@8-12 Identifier {
|
||||
ident: "echo",
|
||||
},
|
||||
|
@ -5,7 +5,7 @@ Module {
|
||||
after_keyword: [],
|
||||
params: Some(
|
||||
ModuleParams {
|
||||
params: [
|
||||
pattern: @7-20 [
|
||||
@9-10 Identifier {
|
||||
ident: "x",
|
||||
},
|
||||
|
@ -5,7 +5,7 @@ Module {
|
||||
after_keyword: [],
|
||||
params: Some(
|
||||
ModuleParams {
|
||||
params: [
|
||||
pattern: @7-20 [
|
||||
@8-12 Identifier {
|
||||
ident: "echo",
|
||||
},
|
||||
|
@ -5,7 +5,7 @@ Module {
|
||||
after_keyword: [],
|
||||
params: Some(
|
||||
ModuleParams {
|
||||
params: [
|
||||
pattern: @7-20 [
|
||||
@8-12 Identifier {
|
||||
ident: "echo",
|
||||
},
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user