diff options
-rw-r--r-- | src/grammar.ron | 3 | ||||
-rw-r--r-- | src/grammar/expressions/atom.rs | 13 | ||||
-rw-r--r-- | src/grammar/expressions/mod.rs | 25 | ||||
-rw-r--r-- | src/syntax_kinds/generated.rs | 8 | ||||
-rw-r--r-- | tests/data/parser/inline/0079_compound_ops.rs | 5 |
5 files changed, 40 insertions, 14 deletions
diff --git a/src/grammar.ron b/src/grammar.ron index 9e122091b..d5bdb206c 100644 --- a/src/grammar.ron +++ b/src/grammar.ron | |||
@@ -41,6 +41,8 @@ Grammar( | |||
41 | [">=", "GTEQ"], | 41 | [">=", "GTEQ"], |
42 | ["+=", "PLUSEQ"], | 42 | ["+=", "PLUSEQ"], |
43 | ["-=", "MINUSEQ"], | 43 | ["-=", "MINUSEQ"], |
44 | ["&&", "AMPERSANDAMPERSAND"], | ||
45 | ["||", "PIPEPIPE"], | ||
44 | ], | 46 | ], |
45 | keywords: [ | 47 | keywords: [ |
46 | "use", | 48 | "use", |
@@ -143,6 +145,7 @@ Grammar( | |||
143 | "LAMBDA_EXPR", | 145 | "LAMBDA_EXPR", |
144 | "IF_EXPR", | 146 | "IF_EXPR", |
145 | "WHILE_EXPR", | 147 | "WHILE_EXPR", |
148 | "LOOP_EXPR", | ||
146 | "BLOCK_EXPR", | 149 | "BLOCK_EXPR", |
147 | "RETURN_EXPR", | 150 | "RETURN_EXPR", |
148 | "MATCH_EXPR", | 151 | "MATCH_EXPR", |
diff --git a/src/grammar/expressions/atom.rs b/src/grammar/expressions/atom.rs index 4eb638c3c..65b9e5ef0 100644 --- a/src/grammar/expressions/atom.rs +++ b/src/grammar/expressions/atom.rs | |||
@@ -48,6 +48,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark | |||
48 | MOVE_KW if la == PIPE => lambda_expr(p), | 48 | MOVE_KW if la == PIPE => lambda_expr(p), |
49 | IF_KW => if_expr(p), | 49 | IF_KW => if_expr(p), |
50 | WHILE_KW => while_expr(p), | 50 | WHILE_KW => while_expr(p), |
51 | LOOP_KW => loop_expr(p), | ||
51 | MATCH_KW => match_expr(p), | 52 | MATCH_KW => match_expr(p), |
52 | UNSAFE_KW if la == L_CURLY => block_expr(p), | 53 | UNSAFE_KW if la == L_CURLY => block_expr(p), |
53 | L_CURLY => block_expr(p), | 54 | L_CURLY => block_expr(p), |
@@ -143,6 +144,18 @@ fn while_expr(p: &mut Parser) -> CompletedMarker { | |||
143 | m.complete(p, WHILE_EXPR) | 144 | m.complete(p, WHILE_EXPR) |
144 | } | 145 | } |
145 | 146 | ||
147 | // test loop_expr | ||
148 | // fn foo() { | ||
149 | // loop {}; | ||
150 | // } | ||
151 | fn loop_expr(p: &mut Parser) -> CompletedMarker { | ||
152 | assert!(p.at(LOOP_KW)); | ||
153 | let m = p.start(); | ||
154 | p.bump(); | ||
155 | block(p); | ||
156 | m.complete(p, LOOP_EXPR) | ||
157 | } | ||
158 | |||
146 | // test cond | 159 | // test cond |
147 | // fn foo() { if let Some(_) = None {} } | 160 | // fn foo() { if let Some(_) = None {} } |
148 | fn cond(p: &mut Parser) { | 161 | fn cond(p: &mut Parser) { |
diff --git a/src/grammar/expressions/mod.rs b/src/grammar/expressions/mod.rs index 0312a757a..18e3f5798 100644 --- a/src/grammar/expressions/mod.rs +++ b/src/grammar/expressions/mod.rs | |||
@@ -56,27 +56,34 @@ enum Op { | |||
56 | // x += 1; | 56 | // x += 1; |
57 | // 1 + 1 <= 2 * 3; | 57 | // 1 + 1 <= 2 * 3; |
58 | // z -= 3 >= 0; | 58 | // z -= 3 >= 0; |
59 | // true || true && false; | ||
59 | // } | 60 | // } |
60 | fn current_op(p: &Parser) -> (u8, Op) { | 61 | fn current_op(p: &Parser) -> (u8, Op) { |
61 | if p.at_compound2(L_ANGLE, EQ) { | ||
62 | return (3, Op::Composite(LTEQ, 2)); | ||
63 | } | ||
64 | if p.at_compound2(R_ANGLE, EQ) { | ||
65 | return (3, Op::Composite(GTEQ, 2)); | ||
66 | } | ||
67 | if p.at_compound2(PLUS, EQ) { | 62 | if p.at_compound2(PLUS, EQ) { |
68 | return (1, Op::Composite(PLUSEQ, 2)); | 63 | return (1, Op::Composite(PLUSEQ, 2)); |
69 | } | 64 | } |
70 | if p.at_compound2(MINUS, EQ) { | 65 | if p.at_compound2(MINUS, EQ) { |
71 | return (1, Op::Composite(MINUSEQ, 2)); | 66 | return (1, Op::Composite(MINUSEQ, 2)); |
72 | } | 67 | } |
68 | if p.at_compound2(PIPE, PIPE) { | ||
69 | return (3, Op::Composite(PIPEPIPE, 2)); | ||
70 | } | ||
71 | if p.at_compound2(AMPERSAND, AMPERSAND) { | ||
72 | return (4, Op::Composite(AMPERSANDAMPERSAND, 2)); | ||
73 | } | ||
74 | if p.at_compound2(L_ANGLE, EQ) { | ||
75 | return (5, Op::Composite(LTEQ, 2)); | ||
76 | } | ||
77 | if p.at_compound2(R_ANGLE, EQ) { | ||
78 | return (5, Op::Composite(GTEQ, 2)); | ||
79 | } | ||
73 | 80 | ||
74 | let bp = match p.current() { | 81 | let bp = match p.current() { |
75 | EQ => 1, | 82 | EQ => 1, |
76 | DOTDOT => 2, | 83 | DOTDOT => 2, |
77 | EQEQ | NEQ => 3, | 84 | EQEQ | NEQ => 5, |
78 | MINUS | PLUS => 4, | 85 | MINUS | PLUS => 6, |
79 | STAR | SLASH => 5, | 86 | STAR | SLASH => 7, |
80 | _ => 0, | 87 | _ => 0, |
81 | }; | 88 | }; |
82 | (bp, Op::Simple) | 89 | (bp, Op::Simple) |
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs index 8db006e54..20f01c505 100644 --- a/src/syntax_kinds/generated.rs +++ b/src/syntax_kinds/generated.rs | |||
@@ -44,6 +44,8 @@ pub enum SyntaxKind { | |||
44 | GTEQ, | 44 | GTEQ, |
45 | PLUSEQ, | 45 | PLUSEQ, |
46 | MINUSEQ, | 46 | MINUSEQ, |
47 | AMPERSANDAMPERSAND, | ||
48 | PIPEPIPE, | ||
47 | USE_KW, | 49 | USE_KW, |
48 | FN_KW, | 50 | FN_KW, |
49 | STRUCT_KW, | 51 | STRUCT_KW, |
@@ -133,6 +135,7 @@ pub enum SyntaxKind { | |||
133 | LAMBDA_EXPR, | 135 | LAMBDA_EXPR, |
134 | IF_EXPR, | 136 | IF_EXPR, |
135 | WHILE_EXPR, | 137 | WHILE_EXPR, |
138 | LOOP_EXPR, | ||
136 | BLOCK_EXPR, | 139 | BLOCK_EXPR, |
137 | RETURN_EXPR, | 140 | RETURN_EXPR, |
138 | MATCH_EXPR, | 141 | MATCH_EXPR, |
@@ -272,6 +275,8 @@ impl SyntaxKind { | |||
272 | GTEQ => &SyntaxInfo { name: "GTEQ" }, | 275 | GTEQ => &SyntaxInfo { name: "GTEQ" }, |
273 | PLUSEQ => &SyntaxInfo { name: "PLUSEQ" }, | 276 | PLUSEQ => &SyntaxInfo { name: "PLUSEQ" }, |
274 | MINUSEQ => &SyntaxInfo { name: "MINUSEQ" }, | 277 | MINUSEQ => &SyntaxInfo { name: "MINUSEQ" }, |
278 | AMPERSANDAMPERSAND => &SyntaxInfo { name: "AMPERSANDAMPERSAND" }, | ||
279 | PIPEPIPE => &SyntaxInfo { name: "PIPEPIPE" }, | ||
275 | USE_KW => &SyntaxInfo { name: "USE_KW" }, | 280 | USE_KW => &SyntaxInfo { name: "USE_KW" }, |
276 | FN_KW => &SyntaxInfo { name: "FN_KW" }, | 281 | FN_KW => &SyntaxInfo { name: "FN_KW" }, |
277 | STRUCT_KW => &SyntaxInfo { name: "STRUCT_KW" }, | 282 | STRUCT_KW => &SyntaxInfo { name: "STRUCT_KW" }, |
@@ -361,6 +366,7 @@ impl SyntaxKind { | |||
361 | LAMBDA_EXPR => &SyntaxInfo { name: "LAMBDA_EXPR" }, | 366 | LAMBDA_EXPR => &SyntaxInfo { name: "LAMBDA_EXPR" }, |
362 | IF_EXPR => &SyntaxInfo { name: "IF_EXPR" }, | 367 | IF_EXPR => &SyntaxInfo { name: "IF_EXPR" }, |
363 | WHILE_EXPR => &SyntaxInfo { name: "WHILE_EXPR" }, | 368 | WHILE_EXPR => &SyntaxInfo { name: "WHILE_EXPR" }, |
369 | LOOP_EXPR => &SyntaxInfo { name: "LOOP_EXPR" }, | ||
364 | BLOCK_EXPR => &SyntaxInfo { name: "BLOCK_EXPR" }, | 370 | BLOCK_EXPR => &SyntaxInfo { name: "BLOCK_EXPR" }, |
365 | RETURN_EXPR => &SyntaxInfo { name: "RETURN_EXPR" }, | 371 | RETURN_EXPR => &SyntaxInfo { name: "RETURN_EXPR" }, |
366 | MATCH_EXPR => &SyntaxInfo { name: "MATCH_EXPR" }, | 372 | MATCH_EXPR => &SyntaxInfo { name: "MATCH_EXPR" }, |
@@ -520,6 +526,8 @@ impl SyntaxKind { | |||
520 | GTEQ => ">=", | 526 | GTEQ => ">=", |
521 | PLUSEQ => "+=", | 527 | PLUSEQ => "+=", |
522 | MINUSEQ => "-=", | 528 | MINUSEQ => "-=", |
529 | AMPERSANDAMPERSAND => "&&", | ||
530 | PIPEPIPE => "||", | ||
523 | 531 | ||
524 | USE_KW => "use", | 532 | USE_KW => "use", |
525 | FN_KW => "fn", | 533 | FN_KW => "fn", |
diff --git a/tests/data/parser/inline/0079_compound_ops.rs b/tests/data/parser/inline/0079_compound_ops.rs deleted file mode 100644 index 48be5aebe..000000000 --- a/tests/data/parser/inline/0079_compound_ops.rs +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | fn foo() { | ||
2 | x += 1; | ||
3 | 1 + 1 <= 2 * 3; | ||
4 | z -= 3 >= 0; | ||
5 | } | ||