Rename ArgName::{Discard,NamedLabeled} as ArgName::{Discarded,Named}

Now that the other variants are gone, this is clearer.
This commit is contained in:
KtorZ 2022-12-22 09:35:39 +01:00
parent 8ab05509b1
commit 7ad8babf17
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
6 changed files with 36 additions and 41 deletions

View File

@ -406,12 +406,12 @@ impl<A> Arg<A> {
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum ArgName { pub enum ArgName {
Discard { Discarded {
name: String, name: String,
label: String, label: String,
location: Span, location: Span,
}, },
NamedLabeled { Named {
name: String, name: String,
label: String, label: String,
location: Span, location: Span,
@ -421,15 +421,15 @@ pub enum ArgName {
impl ArgName { impl ArgName {
pub fn get_variable_name(&self) -> Option<&str> { pub fn get_variable_name(&self) -> Option<&str> {
match self { match self {
ArgName::Discard { .. } => None, ArgName::Discarded { .. } => None,
ArgName::NamedLabeled { name, .. } => Some(name), ArgName::Named { name, .. } => Some(name),
} }
} }
pub fn get_label(&self) -> String { pub fn get_label(&self) -> String {
match self { match self {
ArgName::Discard { label, .. } => label.to_string(), ArgName::Discarded { label, .. } => label.to_string(),
ArgName::NamedLabeled { label, .. } => label.to_string(), ArgName::Named { label, .. } => label.to_string(),
} }
} }
} }

View File

@ -1330,8 +1330,8 @@ impl<'comments> Formatter<'comments> {
fn docs_fn_arg_name<'a>(&mut self, arg_name: &'a ArgName) -> Document<'a> { fn docs_fn_arg_name<'a>(&mut self, arg_name: &'a ArgName) -> Document<'a> {
match arg_name { match arg_name {
ArgName::Discard { .. } => "".to_doc(), ArgName::Discarded { .. } => "".to_doc(),
ArgName::NamedLabeled { label, .. } => label.to_doc().append(": "), ArgName::Named { label, .. } => label.to_doc().append(": "),
} }
} }
@ -1589,8 +1589,7 @@ impl<'comments> Formatter<'comments> {
impl<'a> Documentable<'a> for &'a ArgName { impl<'a> Documentable<'a> for &'a ArgName {
fn to_doc(self) -> Document<'a> { fn to_doc(self) -> Document<'a> {
match self { match self {
ArgName::Discard { name, .. } => name.to_doc(), ArgName::Discarded { label, name, .. } | ArgName::Named { label, name, .. } => {
ArgName::NamedLabeled { label, name, .. } => {
if label == name { if label == name {
name.to_doc() name.to_doc()
} else { } else {

View File

@ -496,13 +496,13 @@ pub fn fn_param_parser() -> impl Parser<Token, ast::UntypedArg, Error = ParseErr
choice(( choice((
select! {Token::Name {name} => name} select! {Token::Name {name} => name}
.then(select! {Token::DiscardName {name} => name}) .then(select! {Token::DiscardName {name} => name})
.map_with_span(|(label, name), span| ast::ArgName::Discard { .map_with_span(|(label, name), span| ast::ArgName::Discarded {
label, label,
name, name,
location: span, location: span,
}), }),
select! {Token::DiscardName {name} => name}.map_with_span(|name, span| { select! {Token::DiscardName {name} => name}.map_with_span(|name, span| {
ast::ArgName::Discard { ast::ArgName::Discarded {
label: name.clone(), label: name.clone(),
name, name,
location: span, location: span,
@ -510,17 +510,15 @@ pub fn fn_param_parser() -> impl Parser<Token, ast::UntypedArg, Error = ParseErr
}), }),
select! {Token::Name {name} => name} select! {Token::Name {name} => name}
.then(select! {Token::Name {name} => name}) .then(select! {Token::Name {name} => name})
.map_with_span(|(label, name), span| ast::ArgName::NamedLabeled { .map_with_span(|(label, name), span| ast::ArgName::Named {
label, label,
name, name,
location: span, location: span,
}), }),
select! {Token::Name {name} => name}.map_with_span(|name, span| { select! {Token::Name {name} => name}.map_with_span(|name, span| ast::ArgName::Named {
ast::ArgName::NamedLabeled {
label: name.clone(), label: name.clone(),
name, name,
location: span, location: span,
}
}), }),
)) ))
.then(just(Token::Colon).ignore_then(type_parser()).or_not()) .then(just(Token::Colon).ignore_then(type_parser()).or_not())
@ -536,18 +534,16 @@ pub fn anon_fn_param_parser() -> impl Parser<Token, ast::UntypedArg, Error = Par
// TODO: return a better error when a label is provided `UnexpectedLabel` // TODO: return a better error when a label is provided `UnexpectedLabel`
choice(( choice((
select! {Token::DiscardName {name} => name}.map_with_span(|name, span| { select! {Token::DiscardName {name} => name}.map_with_span(|name, span| {
ast::ArgName::Discard { ast::ArgName::Discarded {
label: name.clone(), label: name.clone(),
name, name,
location: span, location: span,
} }
}), }),
select! {Token::Name {name} => name}.map_with_span(|name, span| { select! {Token::Name {name} => name}.map_with_span(|name, span| ast::ArgName::Named {
ast::ArgName::NamedLabeled {
label: name.clone(), label: name.clone(),
name, name,
location: span, location: span,
}
}), }),
)) ))
.then(just(Token::Colon).ignore_then(type_parser()).or_not()) .then(just(Token::Colon).ignore_then(type_parser()).or_not())
@ -1160,7 +1156,7 @@ pub fn expr_parser(
holes.push(ast::Arg { holes.push(ast::Arg {
location: Span::empty(), location: Span::empty(),
annotation: None, annotation: None,
arg_name: ast::ArgName::NamedLabeled { arg_name: ast::ArgName::Named {
label: name.clone(), label: name.clone(),
name, name,
location: Span::empty(), location: Span::empty(),

View File

@ -320,7 +320,7 @@ fn plus_binop() {
code, code,
ast::UntypedDefinition::Fn(Function { ast::UntypedDefinition::Fn(Function {
arguments: vec![ast::Arg { arguments: vec![ast::Arg {
arg_name: ast::ArgName::NamedLabeled { arg_name: ast::ArgName::Named {
label: "a".to_string(), label: "a".to_string(),
name: "a".to_string(), name: "a".to_string(),
location: Span::new((), 15..16), location: Span::new((), 15..16),
@ -371,7 +371,7 @@ fn pipeline() {
code, code,
ast::UntypedDefinition::Fn(Function { ast::UntypedDefinition::Fn(Function {
arguments: vec![ast::Arg { arguments: vec![ast::Arg {
arg_name: ast::ArgName::NamedLabeled { arg_name: ast::ArgName::Named {
name: "a".to_string(), name: "a".to_string(),
label: "thing".to_string(), label: "thing".to_string(),
location: Span::new((), 13..20), location: Span::new((), 13..20),
@ -538,7 +538,7 @@ fn let_bindings() {
code, code,
ast::UntypedDefinition::Fn(Function { ast::UntypedDefinition::Fn(Function {
arguments: vec![ast::Arg { arguments: vec![ast::Arg {
arg_name: ast::ArgName::NamedLabeled { arg_name: ast::ArgName::Named {
label: "a".to_string(), label: "a".to_string(),
name: "a".to_string(), name: "a".to_string(),
location: Span::new((), 11..12), location: Span::new((), 11..12),
@ -663,7 +663,7 @@ fn block() {
code, code,
ast::UntypedDefinition::Fn(Function { ast::UntypedDefinition::Fn(Function {
arguments: vec![ast::Arg { arguments: vec![ast::Arg {
arg_name: ast::ArgName::NamedLabeled { arg_name: ast::ArgName::Named {
label: "a".to_string(), label: "a".to_string(),
name: "a".to_string(), name: "a".to_string(),
location: Span::new((), 12..13), location: Span::new((), 12..13),
@ -757,7 +757,7 @@ fn when() {
code, code,
ast::UntypedDefinition::Fn(Function { ast::UntypedDefinition::Fn(Function {
arguments: vec![ast::Arg { arguments: vec![ast::Arg {
arg_name: ast::ArgName::NamedLabeled { arg_name: ast::ArgName::Named {
label: "a".to_string(), label: "a".to_string(),
name: "a".to_string(), name: "a".to_string(),
location: Span::new((), 12..13), location: Span::new((), 12..13),
@ -905,7 +905,7 @@ fn anonymous_function() {
location: Span::new((), 39..67), location: Span::new((), 39..67),
is_capture: false, is_capture: false,
arguments: vec![ast::Arg { arguments: vec![ast::Arg {
arg_name: ast::ArgName::NamedLabeled { arg_name: ast::ArgName::Named {
label: "a".to_string(), label: "a".to_string(),
name: "a".to_string(), name: "a".to_string(),
location: Span::new((), 43..44), location: Span::new((), 43..44),
@ -987,7 +987,7 @@ fn field_access() {
code, code,
ast::UntypedDefinition::Fn(Function { ast::UntypedDefinition::Fn(Function {
arguments: vec![ast::Arg { arguments: vec![ast::Arg {
arg_name: ast::ArgName::NamedLabeled { arg_name: ast::ArgName::Named {
label: "user".to_string(), label: "user".to_string(),
name: "user".to_string(), name: "user".to_string(),
location: Span::new((), 8..12), location: Span::new((), 8..12),
@ -1069,7 +1069,7 @@ fn call() {
location: Span::new((), 61..82), location: Span::new((), 61..82),
is_capture: true, is_capture: true,
arguments: vec![ast::Arg { arguments: vec![ast::Arg {
arg_name: ast::ArgName::NamedLabeled { arg_name: ast::ArgName::Named {
label: "_capture__0".to_string(), label: "_capture__0".to_string(),
name: "_capture__0".to_string(), name: "_capture__0".to_string(),
location: Span::new((), 0..0), location: Span::new((), 0..0),
@ -1095,7 +1095,7 @@ fn call() {
location: Span::new((), 65..81), location: Span::new((), 65..81),
is_capture: false, is_capture: false,
arguments: vec![ast::Arg { arguments: vec![ast::Arg {
arg_name: ast::ArgName::NamedLabeled { arg_name: ast::ArgName::Named {
label: "y".to_string(), label: "y".to_string(),
name: "y".to_string(), name: "y".to_string(),
location: Span::new((), 69..70), location: Span::new((), 69..70),
@ -1194,7 +1194,7 @@ fn record_update() {
ast::UntypedDefinition::Fn(Function { ast::UntypedDefinition::Fn(Function {
arguments: vec![ arguments: vec![
ast::Arg { ast::Arg {
arg_name: ast::ArgName::NamedLabeled { arg_name: ast::ArgName::Named {
label: "user".to_string(), label: "user".to_string(),
name: "user".to_string(), name: "user".to_string(),
location: Span::new((), 15..19), location: Span::new((), 15..19),
@ -1209,7 +1209,7 @@ fn record_update() {
tipo: (), tipo: (),
}, },
ast::Arg { ast::Arg {
arg_name: ast::ArgName::NamedLabeled { arg_name: ast::ArgName::Named {
label: "name".to_string(), label: "name".to_string(),
name: "name".to_string(), name: "name".to_string(),
location: Span::new((), 27..31), location: Span::new((), 27..31),

View File

@ -1544,7 +1544,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
let (body_rigid_names, body_infer) = self.in_new_scope(|body_typer| { let (body_rigid_names, body_infer) = self.in_new_scope(|body_typer| {
for (arg, t) in args.iter().zip(args.iter().map(|arg| arg.tipo.clone())) { for (arg, t) in args.iter().zip(args.iter().map(|arg| arg.tipo.clone())) {
match &arg.arg_name { match &arg.arg_name {
ArgName::NamedLabeled { name, .. } => { ArgName::Named { name, .. } => {
body_typer.environment.insert_variable( body_typer.environment.insert_variable(
name.to_string(), name.to_string(),
ValueConstructorVariant::LocalVariable { ValueConstructorVariant::LocalVariable {
@ -1559,7 +1559,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
arg.location, arg.location,
); );
} }
ArgName::Discard { .. } => (), ArgName::Discarded { .. } => (),
}; };
} }

View File

@ -1851,7 +1851,7 @@ impl<'a> CodeGenerator<'a> {
for arg in function.arguments.iter() { for arg in function.arguments.iter() {
match &arg.arg_name { match &arg.arg_name {
ArgName::NamedLabeled { name, .. } => { ArgName::Named { name, .. } => {
args.push(name.clone()); args.push(name.clone());
} }
_ => { _ => {