mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
cast expr
This commit is contained in:
parent
66bd1ffa32
commit
498098a5d9
@ -162,6 +162,7 @@ Grammar(
|
||||
"METHOD_CALL_EXPR",
|
||||
"FIELD_EXPR",
|
||||
"TRY_EXPR",
|
||||
"CAST_EXPR",
|
||||
|
||||
// unary
|
||||
"REF_EXPR",
|
||||
|
@ -183,6 +183,7 @@ fn postfix_expr(p: &mut Parser, mut lhs: CompletedMarker) -> CompletedMarker {
|
||||
m.complete(p, RANGE_EXPR)
|
||||
}
|
||||
QUESTION => try_expr(p, lhs),
|
||||
AS_KW => cast_expr(p, lhs),
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
@ -260,6 +261,18 @@ fn try_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
||||
m.complete(p, TRY_EXPR)
|
||||
}
|
||||
|
||||
// test cast_expr
|
||||
// fn foo() {
|
||||
// 82 as i32;
|
||||
// }
|
||||
fn cast_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
||||
assert!(p.at(AS_KW));
|
||||
let m = lhs.precede(p);
|
||||
p.bump();
|
||||
types::type_(p);
|
||||
m.complete(p, CAST_EXPR)
|
||||
}
|
||||
|
||||
fn arg_list(p: &mut Parser) {
|
||||
assert!(p.at(L_PAREN));
|
||||
let m = p.start();
|
||||
|
@ -150,6 +150,7 @@ pub enum SyntaxKind {
|
||||
METHOD_CALL_EXPR,
|
||||
FIELD_EXPR,
|
||||
TRY_EXPR,
|
||||
CAST_EXPR,
|
||||
REF_EXPR,
|
||||
DEREF_EXPR,
|
||||
NOT_EXPR,
|
||||
@ -383,6 +384,7 @@ impl SyntaxKind {
|
||||
METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" },
|
||||
FIELD_EXPR => &SyntaxInfo { name: "FIELD_EXPR" },
|
||||
TRY_EXPR => &SyntaxInfo { name: "TRY_EXPR" },
|
||||
CAST_EXPR => &SyntaxInfo { name: "CAST_EXPR" },
|
||||
REF_EXPR => &SyntaxInfo { name: "REF_EXPR" },
|
||||
DEREF_EXPR => &SyntaxInfo { name: "DEREF_EXPR" },
|
||||
NOT_EXPR => &SyntaxInfo { name: "NOT_EXPR" },
|
||||
|
3
tests/data/parser/inline/0087_cast_expr.rs
Normal file
3
tests/data/parser/inline/0087_cast_expr.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn foo() {
|
||||
82 as i32;
|
||||
}
|
29
tests/data/parser/inline/0087_cast_expr.txt
Normal file
29
tests/data/parser/inline/0087_cast_expr.txt
Normal file
@ -0,0 +1,29 @@
|
||||
FILE@[0; 28)
|
||||
FN_ITEM@[0; 27)
|
||||
FN_KW@[0; 2)
|
||||
WHITESPACE@[2; 3)
|
||||
NAME@[3; 6)
|
||||
IDENT@[3; 6) "foo"
|
||||
PARAM_LIST@[6; 8)
|
||||
L_PAREN@[6; 7)
|
||||
R_PAREN@[7; 8)
|
||||
WHITESPACE@[8; 9)
|
||||
BLOCK_EXPR@[9; 27)
|
||||
L_CURLY@[9; 10)
|
||||
WHITESPACE@[10; 15)
|
||||
EXPR_STMT@[15; 25)
|
||||
CAST_EXPR@[15; 24)
|
||||
LITERAL@[15; 17)
|
||||
INT_NUMBER@[15; 17) "82"
|
||||
WHITESPACE@[17; 18)
|
||||
AS_KW@[18; 20)
|
||||
WHITESPACE@[20; 21)
|
||||
PATH_TYPE@[21; 24)
|
||||
PATH@[21; 24)
|
||||
PATH_SEGMENT@[21; 24)
|
||||
NAME_REF@[21; 24)
|
||||
IDENT@[21; 24) "i32"
|
||||
SEMI@[24; 25)
|
||||
WHITESPACE@[25; 26)
|
||||
R_CURLY@[26; 27)
|
||||
WHITESPACE@[27; 28)
|
Loading…
Reference in New Issue
Block a user