From 66182ed5d5e43962a46492ea41f19f9adeccc9e5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 31 Jul 2018 12:51:00 +0300 Subject: Ref exprs --- src/parser/grammar/expressions.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/parser/grammar') diff --git a/src/parser/grammar/expressions.rs b/src/parser/grammar/expressions.rs index 7991b1921..4861536f8 100644 --- a/src/parser/grammar/expressions.rs +++ b/src/parser/grammar/expressions.rs @@ -26,7 +26,7 @@ pub(super) fn literal(p: &mut Parser) -> Option { } pub(super) fn expr(p: &mut Parser) { - let mut lhs = atom_expr(p); + let mut lhs = prefix_expr(p); while let Some(m) = lhs { match p.current() { @@ -36,6 +36,27 @@ pub(super) fn expr(p: &mut Parser) { } } +fn prefix_expr(p: &mut Parser) -> Option { + match p.current() { + AMPERSAND => Some(ref_expr(p)), + _ => atom_expr(p) + } +} + +// test ref_expr +// fn foo() { +// let _ = &1; +// let _ = &mut &f(); +// } +fn ref_expr(p: &mut Parser) -> CompletedMarker { + assert!(p.at(AMPERSAND)); + let m = p.start(); + p.bump(); + p.eat(MUT_KW); + expr(p); + m.complete(p, REF_EXPR) +} + fn atom_expr(p: &mut Parser) -> Option { match literal(p) { Some(m) => return Some(m), -- cgit v1.2.3