Remove the 'trace/try' keyword, use builtin.trace
I am not entirely sure what the intent was for that keyword, but nothing really matched between the parser, the formatter and the uplc code gen. I don't think there's any need for a keyword here, trace is already readily available from the builtins.
This commit is contained in:
parent
5d459b25bd
commit
f26737ecb4
|
@ -91,12 +91,6 @@ pub enum TypedExpr {
|
|||
kind: AssignmentKind,
|
||||
},
|
||||
|
||||
Trace {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
then: Box<Self>,
|
||||
},
|
||||
|
||||
When {
|
||||
location: Span,
|
||||
tipo: Arc<Type>,
|
||||
|
@ -164,7 +158,6 @@ impl TypedExpr {
|
|||
match self {
|
||||
Self::Negate { .. } => bool(),
|
||||
Self::Var { constructor, .. } => constructor.tipo.clone(),
|
||||
Self::Trace { then, .. } => then.tipo(),
|
||||
Self::Fn { tipo, .. }
|
||||
| Self::Int { tipo, .. }
|
||||
| Self::Todo { tipo, .. }
|
||||
|
@ -207,7 +200,6 @@ impl TypedExpr {
|
|||
match self {
|
||||
TypedExpr::Fn { .. }
|
||||
| TypedExpr::Int { .. }
|
||||
| TypedExpr::Trace { .. }
|
||||
| TypedExpr::List { .. }
|
||||
| TypedExpr::Call { .. }
|
||||
| TypedExpr::When { .. }
|
||||
|
@ -247,7 +239,6 @@ impl TypedExpr {
|
|||
match self {
|
||||
Self::Fn { location, .. }
|
||||
| Self::Int { location, .. }
|
||||
| Self::Trace { location, .. }
|
||||
| Self::Var { location, .. }
|
||||
| Self::Todo { location, .. }
|
||||
| Self::When { location, .. }
|
||||
|
@ -284,7 +275,6 @@ impl TypedExpr {
|
|||
pub fn location(&self) -> Span {
|
||||
match self {
|
||||
Self::Fn { location, .. }
|
||||
| Self::Trace { location, .. }
|
||||
| Self::Int { location, .. }
|
||||
| Self::Var { location, .. }
|
||||
| Self::Todo { location, .. }
|
||||
|
@ -374,12 +364,6 @@ pub enum UntypedExpr {
|
|||
annotation: Option<Annotation>,
|
||||
},
|
||||
|
||||
Trace {
|
||||
location: Span,
|
||||
then: Box<Self>,
|
||||
text: Option<String>,
|
||||
},
|
||||
|
||||
When {
|
||||
location: Span,
|
||||
subjects: Vec<Self>,
|
||||
|
@ -477,7 +461,6 @@ impl UntypedExpr {
|
|||
|
||||
pub fn location(&self) -> Span {
|
||||
match self {
|
||||
Self::Trace { then, .. } => then.location(),
|
||||
Self::PipeLine { expressions, .. } => expressions.last().location(),
|
||||
Self::Fn { location, .. }
|
||||
| Self::Var { location, .. }
|
||||
|
@ -515,7 +498,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::Assignment { location, .. } => location.start,
|
||||
Self::Assignment { location, .. } => location.start,
|
||||
_ => self.location().start,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -751,29 +751,6 @@ impl<'comments> Formatter<'comments> {
|
|||
..
|
||||
} => self.assignment(pattern, value, None, Some(*kind), annotation),
|
||||
|
||||
UntypedExpr::Trace {
|
||||
text: None, then, ..
|
||||
} => "trace"
|
||||
.to_doc()
|
||||
.append(if self.pop_empty_lines(then.start_byte_index()) {
|
||||
lines(2)
|
||||
} else {
|
||||
line()
|
||||
})
|
||||
.append(self.expr(then)),
|
||||
|
||||
UntypedExpr::Trace {
|
||||
text: Some(l),
|
||||
then,
|
||||
..
|
||||
} => docvec!["trace(\"", l, "\")"]
|
||||
.append(if self.pop_empty_lines(then.start_byte_index()) {
|
||||
lines(2)
|
||||
} else {
|
||||
line()
|
||||
})
|
||||
.append(self.expr(then)),
|
||||
|
||||
UntypedExpr::When {
|
||||
subjects, clauses, ..
|
||||
} => self.when(subjects, clauses),
|
||||
|
@ -1342,9 +1319,7 @@ impl<'comments> Formatter<'comments> {
|
|||
|
||||
fn wrap_expr<'a>(&mut self, expr: &'a UntypedExpr) -> Document<'a> {
|
||||
match expr {
|
||||
UntypedExpr::Sequence { .. }
|
||||
| UntypedExpr::Assignment { .. }
|
||||
| UntypedExpr::Trace { .. } => "{"
|
||||
UntypedExpr::Sequence { .. } | UntypedExpr::Assignment { .. } => "{"
|
||||
.to_doc()
|
||||
.append(line().append(self.expr(expr)).nest(INDENT))
|
||||
.append(line())
|
||||
|
@ -1381,9 +1356,7 @@ impl<'comments> Formatter<'comments> {
|
|||
|
||||
fn case_clause_value<'a>(&mut self, expr: &'a UntypedExpr) -> Document<'a> {
|
||||
match expr {
|
||||
UntypedExpr::Trace { .. }
|
||||
| UntypedExpr::Sequence { .. }
|
||||
| UntypedExpr::Assignment { .. } => " {"
|
||||
UntypedExpr::Sequence { .. } | UntypedExpr::Assignment { .. } => " {"
|
||||
.to_doc()
|
||||
.append(line().append(self.expr(expr)).nest(INDENT).group())
|
||||
.append(line())
|
||||
|
|
|
@ -553,23 +553,9 @@ pub fn anon_fn_param_parser() -> impl Parser<Token, ast::UntypedArg, Error = Par
|
|||
|
||||
pub fn expr_seq_parser() -> impl Parser<Token, expr::UntypedExpr, Error = ParseError> {
|
||||
recursive(|r| {
|
||||
choice((
|
||||
just(Token::Trace)
|
||||
.ignore_then(
|
||||
select! {Token::String {value} => value}
|
||||
.delimited_by(just(Token::LeftParen), just(Token::RightParen))
|
||||
.or_not(),
|
||||
)
|
||||
.then(r.clone())
|
||||
.map_with_span(|(text, then_), span| expr::UntypedExpr::Trace {
|
||||
location: span,
|
||||
then: Box::new(then_),
|
||||
text,
|
||||
}),
|
||||
expr_parser(r.clone())
|
||||
.then(r.repeated())
|
||||
.foldl(|current, next| current.append_in_sequence(next)),
|
||||
))
|
||||
.foldl(|current, next| current.append_in_sequence(next))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,6 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
|
|||
"pub" => Token::Pub,
|
||||
"use" => Token::Use,
|
||||
"todo" => Token::Todo,
|
||||
"trace" => Token::Trace,
|
||||
"type" => Token::Type,
|
||||
"when" => Token::When,
|
||||
_ => {
|
||||
|
|
|
@ -71,7 +71,6 @@ pub enum Token {
|
|||
Use,
|
||||
Test,
|
||||
Todo,
|
||||
Trace,
|
||||
Type,
|
||||
When,
|
||||
}
|
||||
|
@ -81,7 +80,6 @@ impl fmt::Display for Token {
|
|||
let s = match self {
|
||||
Token::Error(c) => {
|
||||
write!(f, "\"{}\"", c)?;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
Token::Name { name } => name,
|
||||
|
@ -146,7 +144,6 @@ impl fmt::Display for Token {
|
|||
Token::Opaque => "opaque",
|
||||
Token::Pub => "pub",
|
||||
Token::Todo => "todo",
|
||||
Token::Trace => "try",
|
||||
Token::Type => "type",
|
||||
Token::Test => "test",
|
||||
};
|
||||
|
|
|
@ -279,8 +279,6 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
|||
..
|
||||
} => self.infer_assignment(pattern, *value, kind, &annotation, location),
|
||||
|
||||
UntypedExpr::Trace { location, then, .. } => self.infer_trace(*then, location),
|
||||
|
||||
UntypedExpr::When {
|
||||
location,
|
||||
subjects,
|
||||
|
@ -1713,19 +1711,6 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
|||
}
|
||||
}
|
||||
|
||||
fn infer_trace(&mut self, then: UntypedExpr, location: Span) -> Result<TypedExpr, Error> {
|
||||
// Check the type of the following code
|
||||
let then = self.infer(then)?;
|
||||
|
||||
let tipo = then.tipo();
|
||||
|
||||
Ok(TypedExpr::Trace {
|
||||
location,
|
||||
tipo,
|
||||
then: Box::new(then),
|
||||
})
|
||||
}
|
||||
|
||||
fn infer_value_constructor(
|
||||
&mut self,
|
||||
module: &Option<String>,
|
||||
|
|
|
@ -474,7 +474,6 @@ fn str_to_keyword(word: &str) -> Option<Token> {
|
|||
"opaque" => Some(Token::Opaque),
|
||||
"pub" => Some(Token::Pub),
|
||||
"todo" => Some(Token::Todo),
|
||||
"try" => Some(Token::Trace),
|
||||
"type" => Some(Token::Type),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
@ -283,7 +283,6 @@ impl<'a> CodeGenerator<'a> {
|
|||
ir_stack.append(&mut define_vec);
|
||||
ir_stack.append(&mut pattern_vec);
|
||||
}
|
||||
TypedExpr::Trace { .. } => todo!(),
|
||||
TypedExpr::When {
|
||||
subjects, clauses, ..
|
||||
} => {
|
||||
|
|
Loading…
Reference in New Issue