This commit is contained in:
Aleksey Kladov 2018-08-01 00:19:04 +03:00
parent a750135a0a
commit 2bbd4c510d
5 changed files with 49 additions and 5 deletions

View File

@ -132,6 +132,7 @@ Grammar(
"FIELD_EXPR",
"REF_EXPR",
"DEREF_EXPR",
"NOT_EXPR",
"LAMBDA_EXPR",
"STRUCT_LIT",
"STRUCT_LIT_FIELD",

View File

@ -103,11 +103,13 @@ fn let_stmt(p: &mut Parser) {
}
fn prefix_expr(p: &mut Parser) -> Option<CompletedMarker> {
match p.current() {
AMPERSAND => Some(ref_expr(p)),
STAR => Some(deref_expr(p)),
_ => atom_expr(p),
}
let done = match p.current() {
AMPERSAND => ref_expr(p),
STAR => deref_expr(p),
EXCL => not_expr(p),
_ => return atom_expr(p),
};
Some(done)
}
// test ref_expr
@ -136,6 +138,18 @@ fn deref_expr(p: &mut Parser) -> CompletedMarker {
m.complete(p, DEREF_EXPR)
}
// test not_expr
// fn foo() {
// !!true;
// }
fn not_expr(p: &mut Parser) -> CompletedMarker {
assert!(p.at(EXCL));
let m = p.start();
p.bump();
expr(p);
m.complete(p, NOT_EXPR)
}
fn atom_expr(p: &mut Parser) -> Option<CompletedMarker> {
match literal(p) {
Some(m) => return Some(m),

View File

@ -123,6 +123,7 @@ pub enum SyntaxKind {
FIELD_EXPR,
REF_EXPR,
DEREF_EXPR,
NOT_EXPR,
LAMBDA_EXPR,
STRUCT_LIT,
STRUCT_LIT_FIELD,
@ -287,6 +288,7 @@ pub(crate) fn info(self) -> &'static SyntaxInfo {
FIELD_EXPR => &SyntaxInfo { name: "FIELD_EXPR" },
REF_EXPR => &SyntaxInfo { name: "REF_EXPR" },
DEREF_EXPR => &SyntaxInfo { name: "DEREF_EXPR" },
NOT_EXPR => &SyntaxInfo { name: "NOT_EXPR" },
LAMBDA_EXPR => &SyntaxInfo { name: "LAMBDA_EXPR" },
STRUCT_LIT => &SyntaxInfo { name: "STRUCT_LIT" },
STRUCT_LIT_FIELD => &SyntaxInfo { name: "STRUCT_LIT_FIELD" },

View File

@ -0,0 +1,3 @@
fn foo() {
!!true;
}

View File

@ -0,0 +1,24 @@
FILE@[0; 25)
FN_ITEM@[0; 25)
FN_KW@[0; 2)
NAME@[2; 6)
WHITESPACE@[2; 3)
IDENT@[3; 6) "foo"
PARAM_LIST@[6; 9)
L_PAREN@[6; 7)
R_PAREN@[7; 8)
WHITESPACE@[8; 9)
BLOCK@[9; 25)
L_CURLY@[9; 10)
EXPR_STMT@[10; 23)
NOT_EXPR@[10; 21)
WHITESPACE@[10; 15)
EXCL@[15; 16)
NOT_EXPR@[16; 21)
EXCL@[16; 17)
LITERAL@[17; 21)
TRUE_KW@[17; 21)
SEMI@[21; 22)
WHITESPACE@[22; 23)
R_CURLY@[23; 24)
WHITESPACE@[24; 25)