From e87f0c81b36fb4d44127a146b666e30369e94352 Mon Sep 17 00:00:00 2001 From: Kira Malinova Date: Sat, 14 Sep 2024 11:25:44 +0300 Subject: [PATCH] add pipe operator --- crates/ide/src/ide/syntax_highlighting.rs | 2 +- crates/ide/src/ty/infer.rs | 2 +- crates/syntax/src/ast.rs | 3 +++ crates/syntax/src/kind.rs | 1 + crates/syntax/src/lexer.rs | 1 + crates/syntax/src/parser.rs | 1 + 6 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/ide/src/ide/syntax_highlighting.rs b/crates/ide/src/ide/syntax_highlighting.rs index 6647f29..8410807 100644 --- a/crates/ide/src/ide/syntax_highlighting.rs +++ b/crates/ide/src/ide/syntax_highlighting.rs @@ -160,7 +160,7 @@ pub(crate) fn highlight( HlTag::Operator(HlOperator::Comparison) } T![+] | T![-] | T![*] | T![/] => HlTag::Operator(HlOperator::Arithmetic), - T![++] | T!["//"] => HlTag::Operator(HlOperator::Aggregation), + T![++] | T![|>] | T!["//"] => HlTag::Operator(HlOperator::Aggregation), T!['{'] | T!['}'] | T!["${"] => HlTag::Punct(HlPunct::Brace), T!['['] | T![']'] => HlTag::Punct(HlPunct::Bracket), T!['('] | T![')'] => HlTag::Punct(HlPunct::Paren), diff --git a/crates/ide/src/ty/infer.rs b/crates/ide/src/ty/infer.rs index 09a4a51..85e3440 100644 --- a/crates/ide/src/ty/infer.rs +++ b/crates/ide/src/ty/infer.rs @@ -250,7 +250,7 @@ impl<'db> InferCtx<'db> { self.unify_var(lhs_ty, rhs_ty); lhs_ty } - BinaryOpKind::Concat => { + BinaryOpKind::Concat | BinaryOpKind::Pipe => { let ret_ty = Ty::List(self.new_ty_var()).intern(self); self.unify_var(lhs_ty, ret_ty); self.unify_var(rhs_ty, ret_ty); diff --git a/crates/syntax/src/ast.rs b/crates/syntax/src/ast.rs index 1e17027..9700660 100644 --- a/crates/syntax/src/ast.rs +++ b/crates/syntax/src/ast.rs @@ -10,6 +10,7 @@ pub enum BinaryOpKind { Imply, Or, And, + Pipe, Equal, NotEqual, @@ -276,6 +277,7 @@ impl Expr { BinaryOpKind::Imply => 1, BinaryOpKind::Or => 3, BinaryOpKind::And => 5, + BinaryOpKind::Pipe => 6, BinaryOpKind::Equal | BinaryOpKind::NotEqual => 7, BinaryOpKind::Less | BinaryOpKind::Greater @@ -382,6 +384,7 @@ asts! { let op = match tok.kind() { T![->] => BinaryOpKind::Imply, T![&&] => BinaryOpKind::And, + T![|>] => BinaryOpKind::Pipe, T![||] => BinaryOpKind::Or, T![==] => BinaryOpKind::Equal, T![!=] => BinaryOpKind::NotEqual, diff --git a/crates/syntax/src/kind.rs b/crates/syntax/src/kind.rs index f8c31d9..86386a3 100644 --- a/crates/syntax/src/kind.rs +++ b/crates/syntax/src/kind.rs @@ -113,6 +113,7 @@ def! { LT_EQ = [<=], MINUS_GT = [->], NOT_EQ = [!=], + PIPE = [|>], OR2 = [||], PLUS2 = [++], QUOTE2 = ["''"], diff --git a/crates/syntax/src/lexer.rs b/crates/syntax/src/lexer.rs index 8fd0a48..62a53d1 100644 --- a/crates/syntax/src/lexer.rs +++ b/crates/syntax/src/lexer.rs @@ -110,6 +110,7 @@ regex_dfa! { DOT3 = r"\.\.\.", MINUS_GT = r"->", + PIPE = r"\|>", OR2 = r"\|\|", AND2 = r"&&", EQ2 = r"==", diff --git a/crates/syntax/src/parser.rs b/crates/syntax/src/parser.rs index 324918f..70d856e 100644 --- a/crates/syntax/src/parser.rs +++ b/crates/syntax/src/parser.rs @@ -884,6 +884,7 @@ impl SyntaxKind { T![*] | T![/] => (17, 18), T![++] => (20, 19), + T![|>] => (21, 22), // Postfix `?` => 21 // Prefix `-` => 23 _ if self.can_start_atom_expr() => (25, 26), // APPLY