cast expr

This commit is contained in:
Aleksey Kladov 2018-08-07 03:55:16 +03:00
parent 66bd1ffa32
commit 498098a5d9
5 changed files with 48 additions and 0 deletions

View File

@ -162,6 +162,7 @@ Grammar(
"METHOD_CALL_EXPR",
"FIELD_EXPR",
"TRY_EXPR",
"CAST_EXPR",
// unary
"REF_EXPR",

View File

@ -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();

View File

@ -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" },

View File

@ -0,0 +1,3 @@
fn foo() {
82 as i32;
}

View 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)