Simplifying PR per reviewers request
This commit is contained in:
parent
d39dbd6697
commit
ff4ddfbe1b
|
@ -1814,6 +1814,7 @@ pub enum TraceKind {
|
|||
Trace,
|
||||
Todo,
|
||||
Error,
|
||||
Emit,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
|
|
@ -550,12 +550,6 @@ pub enum UntypedExpr {
|
|||
text: Box<Self>,
|
||||
},
|
||||
|
||||
Emit {
|
||||
location: Span,
|
||||
then: Box<Self>,
|
||||
text: Box<Self>,
|
||||
},
|
||||
|
||||
TraceIfFalse {
|
||||
location: Span,
|
||||
value: Box<Self>,
|
||||
|
@ -1267,7 +1261,6 @@ impl UntypedExpr {
|
|||
match self {
|
||||
Self::PipeLine { expressions, .. } => expressions.last().location(),
|
||||
Self::Trace { then, .. } => then.location(),
|
||||
Self::Emit { then, .. } => then.location(),
|
||||
Self::TraceIfFalse { location, .. }
|
||||
| Self::Fn { location, .. }
|
||||
| Self::Var { location, .. }
|
||||
|
@ -1307,9 +1300,7 @@ impl UntypedExpr {
|
|||
.map(|e| e.start_byte_index())
|
||||
.unwrap_or(location.start),
|
||||
Self::PipeLine { expressions, .. } => expressions.first().start_byte_index(),
|
||||
Self::Trace { location, .. }
|
||||
| Self::Emit { location, .. }
|
||||
| Self::Assignment { location, .. } => location.start,
|
||||
Self::Trace { location, .. } | Self::Assignment { location, .. } => location.start,
|
||||
_ => self.location().start,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -639,7 +639,7 @@ impl<'comments> Formatter<'comments> {
|
|||
) -> Document<'a> {
|
||||
let args = wrap_args(args.iter().map(|e| (self.fn_arg(e), false))).group();
|
||||
let body = match body {
|
||||
UntypedExpr::Trace { .. } | UntypedExpr::Emit { .. } | UntypedExpr::When { .. } => {
|
||||
UntypedExpr::Trace { .. } | UntypedExpr::When { .. } => {
|
||||
self.expr(body, true).force_break()
|
||||
}
|
||||
_ => self.expr(body, true),
|
||||
|
@ -957,8 +957,6 @@ impl<'comments> Formatter<'comments> {
|
|||
kind, text, then, ..
|
||||
} => self.trace(kind, text, then),
|
||||
|
||||
UntypedExpr::Emit { text, then, .. } => self.emit(text, then),
|
||||
|
||||
UntypedExpr::When {
|
||||
subject, clauses, ..
|
||||
} => self.when(subject, clauses),
|
||||
|
@ -1022,6 +1020,7 @@ impl<'comments> Formatter<'comments> {
|
|||
TraceKind::Trace => ("trace", None),
|
||||
TraceKind::Error => ("fail", Some(DEFAULT_ERROR_STR.to_string())),
|
||||
TraceKind::Todo => ("todo", Some(DEFAULT_TODO_STR.to_string())),
|
||||
TraceKind::Emit => ("emit", None),
|
||||
};
|
||||
|
||||
let body = match text {
|
||||
|
@ -1037,7 +1036,7 @@ impl<'comments> Formatter<'comments> {
|
|||
|
||||
match kind {
|
||||
TraceKind::Error | TraceKind::Todo => body,
|
||||
TraceKind::Trace => body
|
||||
TraceKind::Trace | TraceKind::Emit => body
|
||||
.append(if self.pop_empty_lines(then.start_byte_index()) {
|
||||
lines(2)
|
||||
} else {
|
||||
|
@ -1047,20 +1046,6 @@ impl<'comments> Formatter<'comments> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn emit<'a>(&mut self, text: &'a UntypedExpr, then: &'a UntypedExpr) -> Document<'a> {
|
||||
let body = "emit"
|
||||
.to_doc()
|
||||
.append(" ")
|
||||
.append(self.wrap_expr(text))
|
||||
.group();
|
||||
body.append(if self.pop_empty_lines(then.start_byte_index()) {
|
||||
lines(2)
|
||||
} else {
|
||||
line()
|
||||
})
|
||||
.append(self.expr(then, true))
|
||||
}
|
||||
|
||||
pub fn pattern_constructor<'a>(
|
||||
&mut self,
|
||||
name: &'a str,
|
||||
|
@ -1675,7 +1660,6 @@ impl<'comments> Formatter<'comments> {
|
|||
kind: TraceKind::Trace,
|
||||
..
|
||||
}
|
||||
| UntypedExpr::Emit { .. }
|
||||
| UntypedExpr::Sequence { .. }
|
||||
| UntypedExpr::Assignment { .. } => "{"
|
||||
.to_doc()
|
||||
|
@ -1718,7 +1702,6 @@ impl<'comments> Formatter<'comments> {
|
|||
kind: TraceKind::Trace,
|
||||
..
|
||||
}
|
||||
| UntypedExpr::Emit { .. }
|
||||
| UntypedExpr::Sequence { .. }
|
||||
| UntypedExpr::Assignment { .. } => " {"
|
||||
.to_doc()
|
||||
|
|
|
@ -354,11 +354,6 @@ pub enum AirTree {
|
|||
msg: Box<AirTree>,
|
||||
then: Box<AirTree>,
|
||||
},
|
||||
Emit {
|
||||
tipo: Rc<Type>,
|
||||
msg: Box<AirTree>,
|
||||
then: Box<AirTree>,
|
||||
},
|
||||
// End Expressions
|
||||
}
|
||||
|
||||
|
@ -836,7 +831,7 @@ impl AirTree {
|
|||
}
|
||||
}
|
||||
pub fn emit(msg: AirTree, tipo: Rc<Type>, then: AirTree) -> AirTree {
|
||||
AirTree::Emit {
|
||||
AirTree::Trace {
|
||||
tipo,
|
||||
msg: msg.into(),
|
||||
then: then.into(),
|
||||
|
@ -1391,11 +1386,6 @@ impl AirTree {
|
|||
msg.create_air_vec(air_vec);
|
||||
then.create_air_vec(air_vec);
|
||||
}
|
||||
AirTree::Emit { tipo, msg, then } => {
|
||||
air_vec.push(Air::Emit { tipo: tipo.clone() });
|
||||
msg.create_air_vec(air_vec);
|
||||
then.create_air_vec(air_vec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1417,8 +1407,7 @@ impl AirTree {
|
|||
| AirTree::Constr { tipo, .. }
|
||||
| AirTree::RecordUpdate { tipo, .. }
|
||||
| AirTree::ErrorTerm { tipo, .. }
|
||||
| AirTree::Trace { tipo, .. }
|
||||
| AirTree::Emit { tipo, .. } => tipo.clone(),
|
||||
| AirTree::Trace { tipo, .. } => tipo.clone(),
|
||||
AirTree::Void => void(),
|
||||
AirTree::Var { constructor, .. } => constructor.tipo.clone(),
|
||||
AirTree::Fn { func_body, .. } => func_body.return_type(),
|
||||
|
@ -1474,8 +1463,7 @@ impl AirTree {
|
|||
| AirTree::If { tipo, .. }
|
||||
| AirTree::Constr { tipo, .. }
|
||||
| AirTree::ErrorTerm { tipo, .. }
|
||||
| AirTree::Trace { tipo, .. }
|
||||
| AirTree::Emit { tipo, .. } => vec![tipo],
|
||||
| AirTree::Trace { tipo, .. } => vec![tipo],
|
||||
AirTree::Var { constructor, .. } => {
|
||||
vec![constructor.tipo.borrow_mut()]
|
||||
}
|
||||
|
@ -1959,23 +1947,6 @@ impl AirTree {
|
|||
apply_with_func_last,
|
||||
);
|
||||
}
|
||||
AirTree::Emit { msg, then, .. } => {
|
||||
msg.do_traverse_tree_with(
|
||||
tree_path,
|
||||
current_depth + 1,
|
||||
index_count.next_number(),
|
||||
with,
|
||||
apply_with_func_last,
|
||||
);
|
||||
|
||||
then.do_traverse_tree_with(
|
||||
tree_path,
|
||||
current_depth + 1,
|
||||
index_count.next_number(),
|
||||
with,
|
||||
apply_with_func_last,
|
||||
);
|
||||
}
|
||||
AirTree::DefineFunc {
|
||||
func_body, then, ..
|
||||
} => {
|
||||
|
@ -2320,15 +2291,6 @@ impl AirTree {
|
|||
panic!("Tree Path index outside tree children nodes")
|
||||
}
|
||||
}
|
||||
AirTree::Emit { msg, then, .. } => {
|
||||
if *index == 0 {
|
||||
msg.as_mut().do_find_air_tree_node(tree_path_iter)
|
||||
} else if *index == 1 {
|
||||
then.as_mut().do_find_air_tree_node(tree_path_iter)
|
||||
} else {
|
||||
panic!("Tree Path index outside tree children nodes")
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
panic!("A tree node with no children was encountered with a longer tree path.")
|
||||
}
|
||||
|
|
|
@ -39,7 +39,8 @@ pub fn parser<'a>(
|
|||
just(Token::Emit)
|
||||
.ignore_then(choice((string::hybrid(), expression.clone())))
|
||||
.then(sequence.clone().or_not())
|
||||
.map_with_span(|(text, then_), span| UntypedExpr::Emit {
|
||||
.map_with_span(|(text, then_), span| UntypedExpr::Trace {
|
||||
kind: TraceKind::Emit,
|
||||
location: span,
|
||||
then: Box::new(then_.unwrap_or_else(|| UntypedExpr::todo(None, span))),
|
||||
text: Box::new(text),
|
||||
|
|
|
@ -281,22 +281,6 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
|||
kind,
|
||||
} => self.infer_trace(kind, *then, location, *text),
|
||||
|
||||
UntypedExpr::Emit {
|
||||
location,
|
||||
then,
|
||||
text,
|
||||
} => {
|
||||
let text = self.infer(*text)?;
|
||||
self.unify(string(), text.tipo(), text.location(), false)?;
|
||||
let then = self.infer(*then)?;
|
||||
Ok(TypedExpr::Emit {
|
||||
location,
|
||||
tipo: then.tipo(),
|
||||
then: Box::new(then),
|
||||
text: Box::new(text),
|
||||
})
|
||||
}
|
||||
|
||||
UntypedExpr::When {
|
||||
location,
|
||||
subject,
|
||||
|
@ -2340,9 +2324,7 @@ fn assert_no_assignment(expr: &UntypedExpr) -> Result<(), Error> {
|
|||
location: expr.location(),
|
||||
expr: *value.clone(),
|
||||
}),
|
||||
UntypedExpr::Trace { then, .. } | UntypedExpr::Emit { then, .. } => {
|
||||
assert_no_assignment(then)
|
||||
}
|
||||
UntypedExpr::Trace { then, .. } => assert_no_assignment(then),
|
||||
UntypedExpr::Fn { .. }
|
||||
| UntypedExpr::BinOp { .. }
|
||||
| UntypedExpr::ByteArray { .. }
|
||||
|
|
Loading…
Reference in New Issue