mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 14:43:24 +00:00
Lopps && logical ops
This commit is contained in:
parent
b0291cd8c2
commit
720861bcff
@ -41,6 +41,8 @@ Grammar(
|
||||
[">=", "GTEQ"],
|
||||
["+=", "PLUSEQ"],
|
||||
["-=", "MINUSEQ"],
|
||||
["&&", "AMPERSANDAMPERSAND"],
|
||||
["||", "PIPEPIPE"],
|
||||
],
|
||||
keywords: [
|
||||
"use",
|
||||
@ -143,6 +145,7 @@ Grammar(
|
||||
"LAMBDA_EXPR",
|
||||
"IF_EXPR",
|
||||
"WHILE_EXPR",
|
||||
"LOOP_EXPR",
|
||||
"BLOCK_EXPR",
|
||||
"RETURN_EXPR",
|
||||
"MATCH_EXPR",
|
||||
|
@ -48,6 +48,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark
|
||||
MOVE_KW if la == PIPE => lambda_expr(p),
|
||||
IF_KW => if_expr(p),
|
||||
WHILE_KW => while_expr(p),
|
||||
LOOP_KW => loop_expr(p),
|
||||
MATCH_KW => match_expr(p),
|
||||
UNSAFE_KW if la == L_CURLY => block_expr(p),
|
||||
L_CURLY => block_expr(p),
|
||||
@ -143,6 +144,18 @@ fn while_expr(p: &mut Parser) -> CompletedMarker {
|
||||
m.complete(p, WHILE_EXPR)
|
||||
}
|
||||
|
||||
// test loop_expr
|
||||
// fn foo() {
|
||||
// loop {};
|
||||
// }
|
||||
fn loop_expr(p: &mut Parser) -> CompletedMarker {
|
||||
assert!(p.at(LOOP_KW));
|
||||
let m = p.start();
|
||||
p.bump();
|
||||
block(p);
|
||||
m.complete(p, LOOP_EXPR)
|
||||
}
|
||||
|
||||
// test cond
|
||||
// fn foo() { if let Some(_) = None {} }
|
||||
fn cond(p: &mut Parser) {
|
||||
|
@ -56,27 +56,34 @@ enum Op {
|
||||
// x += 1;
|
||||
// 1 + 1 <= 2 * 3;
|
||||
// z -= 3 >= 0;
|
||||
// true || true && false;
|
||||
// }
|
||||
fn current_op(p: &Parser) -> (u8, Op) {
|
||||
if p.at_compound2(L_ANGLE, EQ) {
|
||||
return (3, Op::Composite(LTEQ, 2));
|
||||
}
|
||||
if p.at_compound2(R_ANGLE, EQ) {
|
||||
return (3, Op::Composite(GTEQ, 2));
|
||||
}
|
||||
if p.at_compound2(PLUS, EQ) {
|
||||
return (1, Op::Composite(PLUSEQ, 2));
|
||||
}
|
||||
if p.at_compound2(MINUS, EQ) {
|
||||
return (1, Op::Composite(MINUSEQ, 2));
|
||||
}
|
||||
if p.at_compound2(PIPE, PIPE) {
|
||||
return (3, Op::Composite(PIPEPIPE, 2));
|
||||
}
|
||||
if p.at_compound2(AMPERSAND, AMPERSAND) {
|
||||
return (4, Op::Composite(AMPERSANDAMPERSAND, 2));
|
||||
}
|
||||
if p.at_compound2(L_ANGLE, EQ) {
|
||||
return (5, Op::Composite(LTEQ, 2));
|
||||
}
|
||||
if p.at_compound2(R_ANGLE, EQ) {
|
||||
return (5, Op::Composite(GTEQ, 2));
|
||||
}
|
||||
|
||||
let bp = match p.current() {
|
||||
EQ => 1,
|
||||
DOTDOT => 2,
|
||||
EQEQ | NEQ => 3,
|
||||
MINUS | PLUS => 4,
|
||||
STAR | SLASH => 5,
|
||||
EQEQ | NEQ => 5,
|
||||
MINUS | PLUS => 6,
|
||||
STAR | SLASH => 7,
|
||||
_ => 0,
|
||||
};
|
||||
(bp, Op::Simple)
|
||||
|
@ -44,6 +44,8 @@ pub enum SyntaxKind {
|
||||
GTEQ,
|
||||
PLUSEQ,
|
||||
MINUSEQ,
|
||||
AMPERSANDAMPERSAND,
|
||||
PIPEPIPE,
|
||||
USE_KW,
|
||||
FN_KW,
|
||||
STRUCT_KW,
|
||||
@ -133,6 +135,7 @@ pub enum SyntaxKind {
|
||||
LAMBDA_EXPR,
|
||||
IF_EXPR,
|
||||
WHILE_EXPR,
|
||||
LOOP_EXPR,
|
||||
BLOCK_EXPR,
|
||||
RETURN_EXPR,
|
||||
MATCH_EXPR,
|
||||
@ -272,6 +275,8 @@ impl SyntaxKind {
|
||||
GTEQ => &SyntaxInfo { name: "GTEQ" },
|
||||
PLUSEQ => &SyntaxInfo { name: "PLUSEQ" },
|
||||
MINUSEQ => &SyntaxInfo { name: "MINUSEQ" },
|
||||
AMPERSANDAMPERSAND => &SyntaxInfo { name: "AMPERSANDAMPERSAND" },
|
||||
PIPEPIPE => &SyntaxInfo { name: "PIPEPIPE" },
|
||||
USE_KW => &SyntaxInfo { name: "USE_KW" },
|
||||
FN_KW => &SyntaxInfo { name: "FN_KW" },
|
||||
STRUCT_KW => &SyntaxInfo { name: "STRUCT_KW" },
|
||||
@ -361,6 +366,7 @@ impl SyntaxKind {
|
||||
LAMBDA_EXPR => &SyntaxInfo { name: "LAMBDA_EXPR" },
|
||||
IF_EXPR => &SyntaxInfo { name: "IF_EXPR" },
|
||||
WHILE_EXPR => &SyntaxInfo { name: "WHILE_EXPR" },
|
||||
LOOP_EXPR => &SyntaxInfo { name: "LOOP_EXPR" },
|
||||
BLOCK_EXPR => &SyntaxInfo { name: "BLOCK_EXPR" },
|
||||
RETURN_EXPR => &SyntaxInfo { name: "RETURN_EXPR" },
|
||||
MATCH_EXPR => &SyntaxInfo { name: "MATCH_EXPR" },
|
||||
@ -520,6 +526,8 @@ impl SyntaxKind {
|
||||
GTEQ => ">=",
|
||||
PLUSEQ => "+=",
|
||||
MINUSEQ => "-=",
|
||||
AMPERSANDAMPERSAND => "&&",
|
||||
PIPEPIPE => "||",
|
||||
|
||||
USE_KW => "use",
|
||||
FN_KW => "fn",
|
||||
|
@ -1,5 +0,0 @@
|
||||
fn foo() {
|
||||
x += 1;
|
||||
1 + 1 <= 2 * 3;
|
||||
z -= 3 >= 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user