Remove Named & DiscardLabeled, now unused

And unify everything into either 'Discard' or 'NamedLabeled'
This commit is contained in:
KtorZ 2022-12-22 09:30:58 +01:00
parent 18acd0e65f
commit 8ab05509b1
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
7 changed files with 37 additions and 36 deletions

View File

@ -408,15 +408,7 @@ impl<A> Arg<A> {
pub enum ArgName { pub enum ArgName {
Discard { Discard {
name: String, name: String,
location: Span,
},
LabeledDiscard {
label: String, label: String,
name: String,
location: Span,
},
Named {
name: String,
location: Span, location: Span,
}, },
NamedLabeled { NamedLabeled {
@ -429,8 +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 { .. } | ArgName::LabeledDiscard { .. } => None, ArgName::Discard { .. } => None,
ArgName::NamedLabeled { name, .. } | ArgName::Named { name, .. } => Some(name), ArgName::NamedLabeled { name, .. } => Some(name),
}
}
pub fn get_label(&self) -> String {
match self {
ArgName::Discard { label, .. } => label.to_string(),
ArgName::NamedLabeled { label, .. } => label.to_string(),
} }
} }
} }

View File

@ -1330,10 +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::Named { .. } | ArgName::Discard { .. } => "".to_doc(), ArgName::Discard { .. } => "".to_doc(),
ArgName::LabeledDiscard { label, .. } | ArgName::NamedLabeled { label, .. } => { ArgName::NamedLabeled { label, .. } => label.to_doc().append(": "),
label.to_doc().append(": ")
}
} }
} }
@ -1591,9 +1589,8 @@ 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::Named { name, .. } | ArgName::Discard { name, .. } => name.to_doc(), ArgName::Discard { name, .. } => name.to_doc(),
ArgName::LabeledDiscard { label, name, .. } ArgName::NamedLabeled { 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,14 @@ 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::LabeledDiscard { .map_with_span(|(label, name), span| ast::ArgName::Discard {
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::Discard {
label: name.clone(),
name, name,
location: span, location: span,
} }
@ -536,13 +537,17 @@ pub fn anon_fn_param_parser() -> impl Parser<Token, ast::UntypedArg, Error = Par
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::Discard {
label: name.clone(),
name, name,
location: span, location: span,
} }
}), }),
select! {Token::Name {name} => name}.map_with_span(|name, span| ast::ArgName::Named { select! {Token::Name {name} => name}.map_with_span(|name, span| {
ast::ArgName::NamedLabeled {
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())
@ -1151,11 +1156,13 @@ pub fn expr_parser(
.map(|(index, a)| match a { .map(|(index, a)| match a {
ParserArg::Arg(arg) => *arg, ParserArg::Arg(arg) => *arg,
ParserArg::Hole { location, label } => { ParserArg::Hole { location, label } => {
let name = format!("{}__{}", CAPTURE_VARIABLE, index);
holes.push(ast::Arg { holes.push(ast::Arg {
location: Span::empty(), location: Span::empty(),
annotation: None, annotation: None,
arg_name: ast::ArgName::Named { arg_name: ast::ArgName::NamedLabeled {
name: format!("{}__{}", CAPTURE_VARIABLE, index), label: name.clone(),
name,
location: Span::empty(), location: Span::empty(),
}, },
tipo: (), tipo: (),

View File

@ -905,7 +905,8 @@ 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::Named { arg_name: ast::ArgName::NamedLabeled {
label: "a".to_string(),
name: "a".to_string(), name: "a".to_string(),
location: Span::new((), 43..44), location: Span::new((), 43..44),
}, },
@ -1068,7 +1069,8 @@ 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::Named { arg_name: ast::ArgName::NamedLabeled {
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),
}, },
@ -1093,7 +1095,8 @@ 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::Named { arg_name: ast::ArgName::NamedLabeled {
label: "y".to_string(),
name: "y".to_string(), name: "y".to_string(),
location: Span::new((), 69..70), location: Span::new((), 69..70),
}, },

View File

@ -8,7 +8,7 @@ use itertools::Itertools;
use crate::{ use crate::{
ast::{ ast::{
Annotation, ArgName, CallArg, DataType, Definition, Function, ModuleConstant, Pattern, Annotation, CallArg, DataType, Definition, Function, ModuleConstant, Pattern,
RecordConstructor, RecordConstructorArg, Span, TypeAlias, TypedDefinition, RecordConstructor, RecordConstructorArg, Span, TypeAlias, TypedDefinition,
UnqualifiedImport, UntypedDefinition, Use, PIPE_VARIABLE, UnqualifiedImport, UntypedDefinition, Use, PIPE_VARIABLE,
}, },
@ -1012,11 +1012,7 @@ impl<'a> Environment<'a> {
let mut field_map = FieldMap::new(args.len()); let mut field_map = FieldMap::new(args.len());
for (i, arg) in args.iter().enumerate() { for (i, arg) in args.iter().enumerate() {
if let ArgName::NamedLabeled { label, .. } field_map.insert(arg.arg_name.get_label().clone(), i, location)?;
| ArgName::LabeledDiscard { label, .. } = &arg.arg_name
{
field_map.insert(label.clone(), i, location)?;
}
} }
let field_map = field_map.into_option(); let field_map = field_map.into_option();

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::Named { name, .. } | ArgName::NamedLabeled { name, .. } => { ArgName::NamedLabeled { 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::LabeledDiscard { .. } => (), ArgName::Discard { .. } => (),
}; };
} }

View File

@ -1851,8 +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::Named { name, .. } ArgName::NamedLabeled { name, .. } => {
| ArgName::NamedLabeled { name, .. } => {
args.push(name.clone()); args.push(name.clone());
} }
_ => { _ => {