Something went wrong. Try again.
Actually just three programming languages in a trenchcoat
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785use super::*;use crate::{Parser, Spanned, token_pattern::TokenPattern};use become_expression::BecomeExpression;use trilogy_scanner::TokenType::{self, *};
/// The many kinds of expressions in a Trilogy program.#[derive(Clone, Debug, Spanned, PrettyPrintSExpr)]pub enum Expression { Number(Box<NumberLiteral>), Character(Box<CharacterLiteral>), String(Box<StringLiteral>), Bits(Box<BitsLiteral>), Boolean(Box<BooleanLiteral>), Unit(Box<UnitLiteral>), Atom(Box<AtomLiteral>), Struct(Box<StructLiteral>), Array(Box<ArrayLiteral>), Set(Box<SetLiteral>), Record(Box<RecordLiteral>), ArrayComprehension(Box<ArrayComprehension>), SetComprehension(Box<SetComprehension>), RecordComprehension(Box<RecordComprehension>), Reference(Box<super::Identifier>), Keyword(Box<KeywordReference>), Application(Box<Application>), Call(Box<CallExpression>), Binary(Box<BinaryOperation>), Unary(Box<UnaryOperation>), Let(Box<LetExpression>), IfElse(Box<IfElseExpression>), Match(Box<MatchExpression>), Is(Box<IsExpression>), End(Box<EndExpression>), Exit(Box<ExitExpression>), Resume(Box<ResumeExpression>), Become(Box<BecomeExpression>), Cancel(Box<CancelExpression>), Return(Box<ReturnExpression>), Break(Box<BreakExpression>), Continue(Box<ContinueExpression>), Fn(Box<FnExpression>), Do(Box<DoExpression>), Qy(Box<QyExpression>), Template(Box<Template>), Handled(Box<HandledExpression>), Parenthesized(Box<ParenthesizedExpression>), ModuleAccess(Box<ModuleAccess>),}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]pub(crate) enum Precedence { None, Sequence, Continuation, Or, And, Equality, Comparison, Pipe, RPipe, Cons, Glue, BitwiseOr, BitwiseXor, BitwiseShift, BitwiseAnd, Term, Factor, Exponent, RCompose, Compose, Path, Application, Unary, Call, Access,}
enum ExpressionResult { Continue(Expression), Done(Expression), Pattern(Pattern),}
impl Expression { pub(crate) const PREFIX: [TokenType; 33] = [ Numeric, String, Bits, KwTrue, KwFalse, Atom, Character, KwUnit, OBrack, OBrackPipe, OBracePipe, OpBang, OpTilde, KwYield, KwIf, KwIs, KwMatch, KwEnd, KwExit, KwReturn, KwResume, KwBreak, KwContinue, KwCancel, KwLet, Identifier, KwWith, KwFn, KwDo, KwQy, OpDollar, TemplateStart, OParen, ];
fn binary(parser: &mut Parser, lhs: Expression) -> SyntaxResult<ExpressionResult> { let binary = BinaryOperation::parse(parser, lhs)?; match binary { Ok(binary) => Ok(ExpressionResult::Continue(Self::Binary(Box::new(binary)))), Err(pattern) => Ok(ExpressionResult::Pattern(pattern)), } }
fn parse_follow( parser: &mut Parser, precedence: Precedence, lhs: Expression, no_seq: bool, ) -> SyntaxResult<ExpressionResult> { // A bit of strangeness here because `peek()` takes a mutable reference, // so we can't use the fields afterwards... but we need their value after // and I'd really rather not clone every token of every expression, so // instead we peek first, then do a force peek after (to skip an extra chomp). parser.peek(); let is_spaced = parser.is_spaced; let is_line_start = parser.is_line_start; let token = parser.force_peek();
use ExpressionResult::{Continue, Done};
match token.token_type { OpDot if precedence < Precedence::Access => Self::binary(parser, lhs), OpAmpAmp if precedence < Precedence::And => Self::binary(parser, lhs), OpPipePipe if precedence < Precedence::Or => Self::binary(parser, lhs), OpPlus | OpMinus if precedence < Precedence::Term => Self::binary(parser, lhs), OpStar | OpSlash | OpPercent | OpSlashSlash if precedence < Precedence::Factor => { Self::binary(parser, lhs) } OpStarStar if precedence <= Precedence::Exponent => Self::binary(parser, lhs), OpLt | OpGt | OpLtEq | OpGtEq if precedence == Precedence::Comparison => { let expr = Self::binary(parser, lhs); if let Ok(Continue(expr)) = &expr { parser.error(SyntaxError::new( expr.span(), "comparison operators cannot be chained, use parentheses to disambiguate", )); } expr } OpLt | OpGt | OpLtEq | OpGtEq if precedence < Precedence::Comparison => { Self::binary(parser, lhs) } OpEqEq | OpEqEqEq if precedence == Precedence::Equality => { let expr = Self::binary(parser, lhs); if let Ok(Continue(expr)) = &expr { parser.error(SyntaxError::new( expr.span(), "equality operators cannot be chained, use parentheses to disambiguate", )); } expr } OpBangEq | OpBangEqEq | OpEqEq | OpEqEqEq if precedence < Precedence::Equality => { Self::binary(parser, lhs) } OpAmp if precedence < Precedence::BitwiseAnd => Self::binary(parser, lhs), OpPipe if precedence < Precedence::BitwiseOr => Self::binary(parser, lhs), OpCaret if precedence < Precedence::BitwiseXor => Self::binary(parser, lhs), OpShr | OpShl | OpShrEx | OpShlEx | OpShrCon | OpShlCon if precedence < Precedence::BitwiseShift => { Self::binary(parser, lhs) } OpColonColon if precedence < Precedence::Path => Ok(Continue(Self::ModuleAccess( Box::new(ModuleAccess::parse(parser, lhs)?), ))), OpColon if precedence <= Precedence::Cons => Self::binary(parser, lhs), OpLtLt if precedence < Precedence::Compose => Self::binary(parser, lhs), OpGtGt if precedence < Precedence::RCompose => Self::binary(parser, lhs), OpPipeGt if precedence < Precedence::Pipe => Self::binary(parser, lhs), OpLtPipe if precedence <= Precedence::RPipe => Self::binary(parser, lhs), OpGlue if precedence < Precedence::Glue => Self::binary(parser, lhs), OpBang if precedence < Precedence::Call && !is_spaced => Ok(Continue(Self::Call( Box::new(CallExpression::parse(parser, lhs)?), ))), OpSemi if precedence <= Precedence::Sequence && !no_seq => Self::binary(parser, lhs),
// NOTE: despite and/or being allowed in patterns, we can't accept them here because // they are also allowed in queries, in which case an expression was never an option, // unless that expression was the start of a lookup, in which case the and/or is not // permitted, so... if we're parsing as maybe expression or pattern, we aren't // expecting and/or... KwAnd | KwOr => Ok(Done(lhs)), // Unary operators and keywords are not permitted here. They must be parenthesized // to be considered an argument to an application. It messes with handler parsing // otherwise, while also being confusing in terms of precedence rules. KwYield | KwResume | KwCancel | KwReturn | KwContinue | KwBreak | KwBecome => { Ok(Done(lhs)) }
// A function application never spans across two lines. Furthermore, // the application requires a space, even when the parse would be // otherwise unambiguous. // // Sadly, the list of things that can follow, for an application, is // anything prefix (except unary operators) so this becomes a very long list. _ if Expression::PREFIX.matches(token) && precedence < Precedence::Application && !is_line_start && is_spaced => { Ok(Continue(Self::Application(Box::new(Application::parse( parser, lhs, )?)))) } // If nothing matched, it must be the end of the expression _ => Ok(Done(lhs)), } }
fn parse_prefix(parser: &mut Parser) -> SyntaxResult<Result<Self, Pattern>> { let token = parser.peek(); match token.token_type { Numeric => Ok(Ok(Self::Number(Box::new(NumberLiteral::parse(parser)?)))), String => Ok(Ok(Self::String(Box::new(StringLiteral::parse(parser)?)))), Bits => Ok(Ok(Self::Bits(Box::new(BitsLiteral::parse(parser)?)))), KwTrue | KwFalse => Ok(Ok(Self::Boolean(Box::new(BooleanLiteral::parse(parser)?)))), Atom => { let atom = AtomLiteral::parse(parser)?; if parser.check(OParen).is_ok() { let result = StructLiteral::parse(parser, atom)?; match result { Ok(expr) => Ok(Ok(Self::Struct(Box::new(expr)))), Err(patt) => Ok(Err(Pattern::Struct(Box::new(patt)))), } } else { Ok(Ok(Self::Atom(Box::new(atom)))) } } Character => Ok(Ok(Self::Character(Box::new(CharacterLiteral::parse( parser, )?)))), KwUnit => Ok(Ok(Self::Unit(Box::new(UnitLiteral::parse(parser)?)))), OBrack => { let start = parser.expect(OBrack).unwrap(); if let Ok(end) = parser.expect(CBrack) { return Ok(Ok(Self::Array(Box::new(ArrayLiteral::new_empty( start, end, ))))); } match ArrayElement::parse(parser)? { Ok(ArrayElement::Element(expression)) if parser.check(KwFor).is_ok() => { Ok(Ok(Self::ArrayComprehension(Box::new( ArrayComprehension::parse_rest(parser, start, expression)?, )))) } Ok(element) => match ArrayLiteral::parse_rest(parser, start, element)? { Ok(expr) => Ok(Ok(Self::Array(Box::new(expr)))), Err(patt) => Ok(Err(Pattern::Array(Box::new(patt)))), }, Err(next) => Ok(Err(Pattern::Array(Box::new( ArrayPattern::parse_from_expression( parser, start, Punctuated::new(), next, )?, )))), } } OBrackPipe => { let start = parser.expect(OBrackPipe).unwrap(); if let Ok(end) = parser.expect(CBrackPipe) { return Ok(Ok(Self::Set(Box::new(SetLiteral::new_empty(start, end))))); } match SetElement::parse(parser)? { Ok(SetElement::Element(expression)) if parser.expect(KwFor).is_ok() => { Ok(Ok(Self::SetComprehension(Box::new( SetComprehension::parse_rest(parser, start, expression)?, )))) } Ok(element) => { let result = SetLiteral::parse_rest(parser, start, element)?; match result { Ok(expr) => Ok(Ok(Self::Set(Box::new(expr)))), Err(patt) => Ok(Err(Pattern::Set(Box::new(patt)))), } } Err(next) => Ok(Err(Pattern::Set(Box::new( SetPattern::parse_from_expression(parser, start, vec![], next)?, )))), } } OBracePipe => { let start = parser.expect(OBracePipe).unwrap(); if let Ok(end) = parser.expect(CBracePipe) { return Ok(Ok(Self::Record(Box::new(RecordLiteral::new_empty( start, end, ))))); } match RecordElement::parse(parser)? { Ok(RecordElement::Element(key, value)) if parser.expect(KwFor).is_ok() => { Ok(Ok(Self::RecordComprehension(Box::new( RecordComprehension::parse_rest(parser, start, key, value)?, )))) } Ok(element) => { let result = RecordLiteral::parse_rest(parser, start, element)?; match result { Ok(literal) => Ok(Ok(Self::Record(Box::new(literal)))), Err(pattern) => Ok(Err(Pattern::Record(Box::new(pattern)))), } } Err(next) => Ok(Err(Pattern::Record(Box::new( RecordPattern::parse_from_expression(parser, start, vec![], next)?, )))), } } OpBang | OpMinus | OpTilde | KwYield | KwTypeof => match UnaryOperation::parse(parser)? { Ok(expr) => Ok(Ok(Self::Unary(Box::new(expr)))), Err(patt) => Ok(Err(patt)), }, KwIf => { let expr = IfElseExpression::parse(parser)?; if !expr.is_strict_expression() { parser.error(ErrorKind::IfExpressionRestriction.at(expr.span())); } Ok(Ok(Self::IfElse(Box::new(expr)))) } KwMatch => Ok(Ok(Self::Match(Box::new( MatchExpression::parse(parser)?.strict_expression()?, )))), KwEnd => Ok(Ok(Self::End(Box::new(EndExpression::parse(parser)?)))), KwExit => Ok(Ok(Self::Exit(Box::new(ExitExpression::parse(parser)?)))), KwReturn => Ok(Ok(Self::Return(Box::new(ReturnExpression::parse(parser)?)))), KwResume => Ok(Ok(Self::Resume(Box::new(ResumeExpression::parse(parser)?)))), KwBecome => Ok(Ok(Self::Become(Box::new(BecomeExpression::parse(parser)?)))), KwBreak => Ok(Ok(Self::Break(Box::new(BreakExpression::parse(parser)?)))), KwContinue => Ok(Ok(Self::Continue(Box::new(ContinueExpression::parse( parser, )?)))), KwCancel => Ok(Ok(Self::Cancel(Box::new(CancelExpression::parse(parser)?)))), KwLet => Ok(Ok(Self::Let(Box::new(LetExpression::parse(parser)?)))), Identifier => Ok(Ok(Self::Reference(Box::new(super::Identifier::parse( parser, )?)))), KwWith => Ok(Ok(Self::Handled(Box::new(HandledExpression::parse( parser, )?)))), KwFn => Ok(Ok(Self::Fn(Box::new(FnExpression::parse(parser)?)))), KwDo => Ok(Ok(Self::Do(Box::new(DoExpression::parse(parser)?)))), KwQy => Ok(Ok(Self::Qy(Box::new(QyExpression::parse(parser)?)))), OpDollar => Ok(Ok(Self::Template(Box::new(Template::parse_tagged( parser, )?)))), TemplateStart => Ok(Ok(Self::Template(Box::new(Template::parse_bare(parser)?)))), OParen => match KeywordReference::try_parse(parser) { Some(keyword) => Ok(Ok(Self::Keyword(Box::new(keyword)))), None => match ParenthesizedExpression::parse(parser)? { Ok(expression) => Ok(Ok(Self::Parenthesized(Box::new(expression)))), Err(pattern) => Ok(Err(Pattern::Parenthesized(Box::new(pattern)))), }, }, KwIs => Ok(Ok(Self::Is(Box::new(IsExpression::parse(parser)?)))), KwMut | Discard | OpCaret => Ok(Err(Pattern::parse(parser)?)),
// Invalid stuff, but we can do better error messages by handling some specifically KwNot => { let error = ErrorKind::KwNotInExpression.at(token.span); parser.error(error.clone()); Err(error) } _ => { let error = SyntaxError::new( token.span, format!("unexpected token {:?} in expression", token.token_type), ); parser.error(error.clone()); Err(error) } } }
fn parse_suffix( parser: &mut Parser, precedence: Precedence, no_seq: bool, mut expr: Expression, ) -> SyntaxResult<Result<Self, Pattern>> { loop { match Self::parse_follow(parser, precedence, expr, no_seq)? { ExpressionResult::Continue(updated) => expr = updated, ExpressionResult::Done(expr) => return Ok(Ok(expr)), ExpressionResult::Pattern(patt) => return Ok(Err(patt)), } } }
fn parse_precedence_inner( parser: &mut Parser, precedence: Precedence, no_seq: bool, ) -> SyntaxResult<Result<Self, Pattern>> { match Self::parse_prefix(parser)? { Ok(expr) => Self::parse_suffix(parser, precedence, no_seq, expr), Err(patt) => Ok(Err(Pattern::parse_suffix( parser, pattern::Precedence::None, patt, )?)), } }
pub(crate) fn parse_or_pattern_precedence( parser: &mut Parser, precedence: Precedence, ) -> SyntaxResult<Result<Self, Pattern>> { Self::parse_precedence_inner(parser, precedence, false) }
pub(crate) fn parse_precedence( parser: &mut Parser, precedence: Precedence, ) -> SyntaxResult<Self> { Self::parse_or_pattern_precedence(parser, precedence)?.map_err(|patt| { SyntaxError::new( patt.span(), "expected an expression in parameter list, but found a pattern", ) }) }
pub(crate) fn parse_parameter_list(parser: &mut Parser) -> SyntaxResult<Result<Self, Pattern>> { Self::parse_precedence_inner(parser, Precedence::None, true) }
pub(crate) fn parse_or_pattern(parser: &mut Parser) -> SyntaxResult<Result<Self, Pattern>> { Self::parse_or_pattern_precedence(parser, Precedence::None) }
pub(crate) fn parse(parser: &mut Parser) -> SyntaxResult<Self> { Self::parse_precedence(parser, Precedence::None) }
pub(crate) fn parse_no_seq(parser: &mut Parser) -> SyntaxResult<Self> { Self::parse_precedence_inner(parser, Precedence::None, true)?.map_err(|patt| { SyntaxError::new(patt.span(), "expected an expression but found a pattern") }) }
pub(crate) fn is_lvalue(&self) -> bool { match self { Self::Binary(op) if matches!(op.operator, BinaryOperator::Access(..)) => true, _ => self.is_pattern(), } }
pub(crate) fn is_pattern(&self) -> bool { match self { Self::Reference(..) => true, Self::Atom(..) => true, Self::Number(..) => true, Self::Boolean(..) => true, Self::Unit(..) => true, Self::Bits(..) => true, Self::String(..) => true, Self::Character(..) => true, Self::Unary(op) if matches!(op.operator, UnaryOperator::Negate(..)) => { op.operand.is_pattern() } Self::Binary(op) if matches!( op.operator, BinaryOperator::Glue(..) | BinaryOperator::Cons(..) ) => { op.lhs.is_pattern() && op.rhs.is_pattern() } Self::Struct(inner) => inner.value.is_pattern(), Self::Array(array) => { array.elements.iter().all(|element| match element { ArrayElement::Element(element) => element.is_pattern(), ArrayElement::Spread(_, element) => element.is_pattern(), }) && array .elements .iter() .filter(|element| matches!(element, ArrayElement::Spread(..))) .count() <= 1 } Self::Set(set) => set.elements.iter().all(|element| match element { SetElement::Element(element) => element.is_pattern(), SetElement::Spread(_, spread) if std::ptr::eq(element, set.elements.last().unwrap()) => { spread.is_pattern() } _ => false, }), Self::Record(record) => record.elements.iter().all(|element| match element { RecordElement::Element(key, value) => key.is_pattern() && value.is_pattern(), RecordElement::Spread(_, spread) if std::ptr::eq(element, record.elements.last().unwrap()) => { spread.is_pattern() } _ => false, }), Self::Parenthesized(paren) => paren.expression.is_pattern(), _ => false, } }}
#[cfg(test)]mod test { use super::*;
test_parse!(expr_prec_boolean: "!true && false || true && !false" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Unary _) (BinaryOperator::And _) _)) (BinaryOperator::Or _) (Expression::Binary (BinaryOperation _ (BinaryOperator::And _) (Expression::Unary _)))))"); test_parse!(expr_prec_arithmetic: "- 1 / 2 + 3 ** e - 4 * 5" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Unary _) (BinaryOperator::Divide _) _)) (BinaryOperator::Add _) (Expression::Binary (BinaryOperation _ (BinaryOperator::Power _) _)))) (BinaryOperator::Subtract _) (Expression::Binary (BinaryOperation _ (BinaryOperator::Multiply _) _))))"); test_parse!(expr_prec_factor: "1 / 2 % 3 // 4 * 5" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation _ (BinaryOperator::Divide _) _)) (BinaryOperator::Remainder _) _)) (BinaryOperator::IntDivide _) _)) (BinaryOperator::Multiply _) _))"); test_parse!(expr_prec_bitwise: "~x & y <~ 4 | x ^ y ~> 3" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Unary _) (BinaryOperator::BitwiseAnd _) _)) (BinaryOperator::LeftShift _) _)) (BinaryOperator::BitwiseOr _) (Expression::Binary (BinaryOperation _ (BinaryOperator::BitwiseXor _) (Expression::Binary (BinaryOperation _ (BinaryOperator::RightShift _) _))))))"); test_parse!(expr_prec_app_pipe: "f x |> map (fn y. 2 * y) |> print" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Application _) (BinaryOperator::Pipe _) (Expression::Application _))) (BinaryOperator::Pipe _) (Expression::Reference _)))"); test_parse!(expr_prec_pipe_rpipe: "x |> f <| g <| y |> h" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Reference _) (BinaryOperator::Pipe _) (Expression::Binary (BinaryOperation (Expression::Reference _) (BinaryOperator::RPipe _) (Expression::Binary (BinaryOperation (Expression::Reference _) (BinaryOperator::RPipe _) (Expression::Reference _))))))) (BinaryOperator::Pipe _) (Expression::Reference _)))"); test_parse!(expr_prec_compose_rcompose: "x >> f << g << y >> h" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Reference _) (BinaryOperator::RCompose _) (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Reference _) (BinaryOperator::Compose _) (Expression::Reference _))) (BinaryOperator::Compose _) (Expression::Reference _))))) (BinaryOperator::RCompose _) (Expression::Reference _)))"); test_parse!(expr_prec_application: "x - f y + f y <| -z" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Reference _) (BinaryOperator::Subtract _) (Expression::Application _))) (BinaryOperator::Add _) (Expression::Application _))) (BinaryOperator::RPipe _) (Expression::Unary _)))"); test_parse!(expr_prec_if_else: "if true then 5 + 6 else 7 + 8" => Expression::parse => " (Expression::IfElse (IfElseExpression _ (Expression::Boolean _) (IfBody::Then _ _) (ElseClause _ _)))");
test_parse_error!(expr_eq_without_parens: "x == y == z" => Expression::parse => "equality operators cannot be chained, use parentheses to disambiguate"); test_parse_error!(expr_cmp_without_parens: "x <= y <= z" => Expression::parse => "comparison operators cannot be chained, use parentheses to disambiguate"); test_parse!(expr_prec_cmp_eq: "x < y == y > z" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Binary _) (BinaryOperator::StructuralEquality _) (Expression::Binary _)))");
test_parse_error!(expr_multiline_application: "f\nx" => Expression::parse); test_parse_error!(expr_application_no_space: "f(x)" => Expression::parse); test_parse!(expr_multiline_operators: "f\n<| x" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Reference _) (BinaryOperator::RPipe _) (Expression::Reference _)))");
test_parse!(expr_is: "true && is check(y) and also(z) && false" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Boolean _) (BinaryOperator::And _) (Expression::Is _))) (BinaryOperator::And _) (Expression::Boolean _)))"); test_parse!(expr_is_prec: "false || is x = y && z" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Boolean _) (BinaryOperator::Or _) (Expression::Is _)))");
test_parse!(expr_prec_glue_cons: "\"hello\" : \"hello\" <> \"world\" : 3 + 3 : \"world\"" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::String _) (BinaryOperator::Cons _) (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::String _) (BinaryOperator::Glue _) (Expression::String _))) (BinaryOperator::Cons _) (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Number _) (BinaryOperator::Add _) (Expression::Number _))) (BinaryOperator::Cons _) (Expression::String _)))))))");
test_parse!(expr_prec_call: "a + b!() + c!()" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Binary (BinaryOperation (Expression::Reference _) (BinaryOperator::Add _) (Expression::Call _))) (BinaryOperator::Add _) (Expression::Call _)))");
test_parse!(expr_prec_access: "a.1!() + b.'hello 3" => Expression::parse => " (Expression::Binary (BinaryOperation (Expression::Call (CallExpression (Expression::Binary (BinaryOperation (Expression::Reference _) (BinaryOperator::Access _) (Expression::Number _))) _ _ [] _)) (BinaryOperator::Add _) (Expression::Application (Application (Expression::Binary (BinaryOperation (Expression::Reference _) (BinaryOperator::Access _) (Expression::Atom _))) (Expression::Number _)))))"); test_parse!(expr_let_seq: "b; let a = b, a; b" => Expression::parse => " (Expression::Binary (BinaryOperation _ (BinaryOperator::Sequence _) (Expression::Binary (BinaryOperation (Expression::Let _) (BinaryOperator::Sequence _) _))))"); test_parse!(expr_mod_access: "mod1::mod2::member" => Expression::parse => " (Expression::ModuleAccess (ModuleAccess (Expression::ModuleAccess (ModuleAccess (Expression::Reference _) _ (Identifier))) _ (Identifier)))"); test_parse!(expr_prec_paths: "a b::c d::e f" => Expression::parse => " (Expression::Application (Application (Expression::ModuleAccess (ModuleAccess (Expression::Application (Application (Expression::ModuleAccess _) (Expression::Reference _))) _ (Identifier))) (Expression::Reference _))) ");}