From 498098a5d968f06f08fa093f1fd5a43a9a61ecf3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 7 Aug 2018 03:55:16 +0300 Subject: cast expr --- src/grammar.ron | 1 + src/grammar/expressions/mod.rs | 13 +++++++++++++ src/syntax_kinds/generated.rs | 2 ++ 3 files changed, 16 insertions(+) (limited to 'src') diff --git a/src/grammar.ron b/src/grammar.ron index ca37eb80b..b525476c2 100644 --- a/src/grammar.ron +++ b/src/grammar.ron @@ -162,6 +162,7 @@ Grammar( "METHOD_CALL_EXPR", "FIELD_EXPR", "TRY_EXPR", + "CAST_EXPR", // unary "REF_EXPR", diff --git a/src/grammar/expressions/mod.rs b/src/grammar/expressions/mod.rs index e0b4ced74..c137fe654 100644 --- a/src/grammar/expressions/mod.rs +++ b/src/grammar/expressions/mod.rs @@ -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(); diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs index 3c5071126..005f4a9dc 100644 --- a/src/syntax_kinds/generated.rs +++ b/src/syntax_kinds/generated.rs @@ -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" }, -- cgit v1.2.3