aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast.rs52
-rw-r--r--crates/ra_syntax/src/ast/generated.rs35
-rw-r--r--crates/ra_syntax/src/grammar.ron14
3 files changed, 76 insertions, 25 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index c10169d90..9df8ec663 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -489,6 +489,58 @@ impl<'a> PrefixExpr<'a> {
489} 489}
490 490
491#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] 491#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
492pub enum BinOp {
493 /// The `||` operator for boolean OR
494 BooleanOr,
495 /// The `&&` operator for boolean AND
496 BooleanAnd,
497 /// The `==` operator for equality testing
498 EqualityTest,
499 /// The `<=` operator for lesser-equal testing
500 LesserEqualTest,
501 /// The `>=` operator for greater-equal testing
502 GreaterEqualTest,
503 /// The `<` operator for comparison
504 LesserTest,
505 /// The `>` operator for comparison
506 GreaterTest,
507 // TODO: lots of others
508}
509
510impl<'a> BinExpr<'a> {
511 pub fn op(&self) -> Option<BinOp> {
512 self.syntax()
513 .children()
514 .filter_map(|c| match c.kind() {
515 PIPEPIPE => Some(BinOp::BooleanOr),
516 AMPAMP => Some(BinOp::BooleanAnd),
517 EQEQ => Some(BinOp::EqualityTest),
518 LTEQ => Some(BinOp::LesserEqualTest),
519 GTEQ => Some(BinOp::GreaterEqualTest),
520 L_ANGLE => Some(BinOp::LesserTest),
521 R_ANGLE => Some(BinOp::GreaterTest),
522 _ => None,
523 })
524 .next()
525 }
526
527 pub fn lhs(self) -> Option<Expr<'a>> {
528 children(self).nth(0)
529 }
530
531 pub fn rhs(self) -> Option<Expr<'a>> {
532 children(self).nth(1)
533 }
534
535 pub fn sub_exprs(self) -> (Option<Expr<'a>>, Option<Expr<'a>>) {
536 let mut children = children(self);
537 let first = children.next();
538 let second = children.next();
539 (first, second)
540 }
541}
542
543#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
492pub enum SelfParamFlavor { 544pub enum SelfParamFlavor {
493 /// self 545 /// self
494 Owned, 546 Owned,
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 7df6a9c46..24f72393a 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -378,7 +378,11 @@ impl<R: TreeRoot<RaTypes>> BreakExprNode<R> {
378} 378}
379 379
380 380
381impl<'a> BreakExpr<'a> {} 381impl<'a> BreakExpr<'a> {
382 pub fn expr(self) -> Option<Expr<'a>> {
383 super::child_opt(self)
384 }
385}
382 386
383// Byte 387// Byte
384#[derive(Debug, Clone, Copy,)] 388#[derive(Debug, Clone, Copy,)]
@@ -923,12 +927,7 @@ pub enum Expr<'a> {
923 BlockExpr(BlockExpr<'a>), 927 BlockExpr(BlockExpr<'a>),
924 ReturnExpr(ReturnExpr<'a>), 928 ReturnExpr(ReturnExpr<'a>),
925 MatchExpr(MatchExpr<'a>), 929 MatchExpr(MatchExpr<'a>),
926 MatchArmList(MatchArmList<'a>),
927 MatchArm(MatchArm<'a>),
928 MatchGuard(MatchGuard<'a>),
929 StructLit(StructLit<'a>), 930 StructLit(StructLit<'a>),
930 NamedFieldList(NamedFieldList<'a>),
931 NamedField(NamedField<'a>),
932 CallExpr(CallExpr<'a>), 931 CallExpr(CallExpr<'a>),
933 IndexExpr(IndexExpr<'a>), 932 IndexExpr(IndexExpr<'a>),
934 MethodCallExpr(MethodCallExpr<'a>), 933 MethodCallExpr(MethodCallExpr<'a>),
@@ -960,12 +959,7 @@ impl<'a> AstNode<'a> for Expr<'a> {
960 BLOCK_EXPR => Some(Expr::BlockExpr(BlockExpr { syntax })), 959 BLOCK_EXPR => Some(Expr::BlockExpr(BlockExpr { syntax })),
961 RETURN_EXPR => Some(Expr::ReturnExpr(ReturnExpr { syntax })), 960 RETURN_EXPR => Some(Expr::ReturnExpr(ReturnExpr { syntax })),
962 MATCH_EXPR => Some(Expr::MatchExpr(MatchExpr { syntax })), 961 MATCH_EXPR => Some(Expr::MatchExpr(MatchExpr { syntax })),
963 MATCH_ARM_LIST => Some(Expr::MatchArmList(MatchArmList { syntax })),
964 MATCH_ARM => Some(Expr::MatchArm(MatchArm { syntax })),
965 MATCH_GUARD => Some(Expr::MatchGuard(MatchGuard { syntax })),
966 STRUCT_LIT => Some(Expr::StructLit(StructLit { syntax })), 962 STRUCT_LIT => Some(Expr::StructLit(StructLit { syntax })),
967 NAMED_FIELD_LIST => Some(Expr::NamedFieldList(NamedFieldList { syntax })),
968 NAMED_FIELD => Some(Expr::NamedField(NamedField { syntax })),
969 CALL_EXPR => Some(Expr::CallExpr(CallExpr { syntax })), 963 CALL_EXPR => Some(Expr::CallExpr(CallExpr { syntax })),
970 INDEX_EXPR => Some(Expr::IndexExpr(IndexExpr { syntax })), 964 INDEX_EXPR => Some(Expr::IndexExpr(IndexExpr { syntax })),
971 METHOD_CALL_EXPR => Some(Expr::MethodCallExpr(MethodCallExpr { syntax })), 965 METHOD_CALL_EXPR => Some(Expr::MethodCallExpr(MethodCallExpr { syntax })),
@@ -997,12 +991,7 @@ impl<'a> AstNode<'a> for Expr<'a> {
997 Expr::BlockExpr(inner) => inner.syntax(), 991 Expr::BlockExpr(inner) => inner.syntax(),
998 Expr::ReturnExpr(inner) => inner.syntax(), 992 Expr::ReturnExpr(inner) => inner.syntax(),
999 Expr::MatchExpr(inner) => inner.syntax(), 993 Expr::MatchExpr(inner) => inner.syntax(),
1000 Expr::MatchArmList(inner) => inner.syntax(),
1001 Expr::MatchArm(inner) => inner.syntax(),
1002 Expr::MatchGuard(inner) => inner.syntax(),
1003 Expr::StructLit(inner) => inner.syntax(), 994 Expr::StructLit(inner) => inner.syntax(),
1004 Expr::NamedFieldList(inner) => inner.syntax(),
1005 Expr::NamedField(inner) => inner.syntax(),
1006 Expr::CallExpr(inner) => inner.syntax(), 995 Expr::CallExpr(inner) => inner.syntax(),
1007 Expr::IndexExpr(inner) => inner.syntax(), 996 Expr::IndexExpr(inner) => inner.syntax(),
1008 Expr::MethodCallExpr(inner) => inner.syntax(), 997 Expr::MethodCallExpr(inner) => inner.syntax(),
@@ -3880,6 +3869,10 @@ impl<'a> StructLit<'a> {
3880 pub fn named_field_list(self) -> Option<NamedFieldList<'a>> { 3869 pub fn named_field_list(self) -> Option<NamedFieldList<'a>> {
3881 super::child_opt(self) 3870 super::child_opt(self)
3882 } 3871 }
3872
3873 pub fn spread(self) -> Option<Expr<'a>> {
3874 super::child_opt(self)
3875 }
3883} 3876}
3884 3877
3885// StructPat 3878// StructPat
@@ -4147,7 +4140,15 @@ impl<R: TreeRoot<RaTypes>> TupleStructPatNode<R> {
4147} 4140}
4148 4141
4149 4142
4150impl<'a> TupleStructPat<'a> {} 4143impl<'a> TupleStructPat<'a> {
4144 pub fn args(self) -> impl Iterator<Item = Pat<'a>> + 'a {
4145 super::children(self)
4146 }
4147
4148 pub fn path(self) -> Option<Path<'a>> {
4149 super::child_opt(self)
4150 }
4151}
4151 4152
4152// TupleType 4153// TupleType
4153#[derive(Debug, Clone, Copy,)] 4154#[derive(Debug, Clone, Copy,)]
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index c55e9e07a..3c640ed47 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -384,7 +384,7 @@ Grammar(
384 options: [ "Condition" ] 384 options: [ "Condition" ]
385 ), 385 ),
386 "ContinueExpr": (), 386 "ContinueExpr": (),
387 "BreakExpr": (), 387 "BreakExpr": (options: ["Expr"]),
388 "Label": (), 388 "Label": (),
389 "BlockExpr": ( 389 "BlockExpr": (
390 options: [ "Block" ] 390 options: [ "Block" ]
@@ -404,7 +404,7 @@ Grammar(
404 collections: [ [ "pats", "Pat" ] ] 404 collections: [ [ "pats", "Pat" ] ]
405 ), 405 ),
406 "MatchGuard": (), 406 "MatchGuard": (),
407 "StructLit": (options: ["Path", "NamedFieldList"]), 407 "StructLit": (options: ["Path", "NamedFieldList", ["spread", "Expr"]]),
408 "NamedFieldList": (collections: [ ["fields", "NamedField"] ]), 408 "NamedFieldList": (collections: [ ["fields", "NamedField"] ]),
409 "NamedField": (options: ["NameRef", "Expr"]), 409 "NamedField": (options: ["NameRef", "Expr"]),
410 "CallExpr": ( 410 "CallExpr": (
@@ -446,12 +446,7 @@ Grammar(
446 "BlockExpr", 446 "BlockExpr",
447 "ReturnExpr", 447 "ReturnExpr",
448 "MatchExpr", 448 "MatchExpr",
449 "MatchArmList",
450 "MatchArm",
451 "MatchGuard",
452 "StructLit", 449 "StructLit",
453 "NamedFieldList",
454 "NamedField",
455 "CallExpr", 450 "CallExpr",
456 "IndexExpr", 451 "IndexExpr",
457 "MethodCallExpr", 452 "MethodCallExpr",
@@ -472,7 +467,10 @@ Grammar(
472 "PathPat": (), 467 "PathPat": (),
473 "StructPat": (), 468 "StructPat": (),
474 "FieldPatList": (), 469 "FieldPatList": (),
475 "TupleStructPat": (), 470 "TupleStructPat": (
471 options: ["Path"],
472 collections: [["args", "Pat"]],
473 ),
476 "TuplePat": (), 474 "TuplePat": (),
477 "SlicePat": (), 475 "SlicePat": (),
478 "RangePat": (), 476 "RangePat": (),