diff options
author | Aleksey Kladov <[email protected]> | 2018-08-05 16:16:52 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-05 16:16:52 +0100 |
commit | 720861bcff4b9f67ca4def66e2996015811fa90b (patch) | |
tree | 9bed19490f802860e0c17532eaed853dfeb548bb /src/grammar | |
parent | b0291cd8c2ec1d6d164caaa743f7484416e9b3f5 (diff) |
Lopps && logical ops
Diffstat (limited to 'src/grammar')
-rw-r--r-- | src/grammar/expressions/atom.rs | 13 | ||||
-rw-r--r-- | src/grammar/expressions/mod.rs | 25 |
2 files changed, 29 insertions, 9 deletions
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) |