2018-01-07 19:46:10 +01:00
|
|
|
use super::*;
|
|
|
|
|
2018-07-30 15:16:58 +02:00
|
|
|
// test expr_literals
|
|
|
|
// fn foo() {
|
2018-07-30 16:02:51 +02:00
|
|
|
// let _ = true;
|
|
|
|
// let _ = false;
|
|
|
|
// let _ = 1;
|
|
|
|
// let _ = 2.0;
|
|
|
|
// let _ = b'a';
|
|
|
|
// let _ = 'b';
|
|
|
|
// let _ = "c";
|
|
|
|
// let _ = r"d";
|
|
|
|
// let _ = b"e";
|
|
|
|
// let _ = br"f";
|
2018-07-30 15:16:58 +02:00
|
|
|
// }
|
2018-01-07 19:46:10 +01:00
|
|
|
pub(super) fn literal(p: &mut Parser) -> bool {
|
2018-01-20 19:49:58 +01:00
|
|
|
match p.current() {
|
2018-01-28 00:31:23 +01:00
|
|
|
TRUE_KW | FALSE_KW | INT_NUMBER | FLOAT_NUMBER | BYTE | CHAR | STRING | RAW_STRING
|
|
|
|
| BYTE_STRING | RAW_BYTE_STRING => {
|
2018-01-20 21:25:34 +01:00
|
|
|
let lit = p.start();
|
2018-01-20 19:49:58 +01:00
|
|
|
p.bump();
|
2018-01-20 21:25:34 +01:00
|
|
|
lit.complete(p, LITERAL);
|
2018-01-20 19:49:58 +01:00
|
|
|
true
|
|
|
|
}
|
2018-01-28 00:31:23 +01:00
|
|
|
_ => false,
|
2018-01-20 19:49:58 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-28 20:59:18 +01:00
|
|
|
|
|
|
|
pub(super) fn expr(p: &mut Parser) {
|
2018-02-17 23:06:48 +01:00
|
|
|
if literal(p) {
|
|
|
|
return;
|
2018-01-28 20:59:18 +01:00
|
|
|
}
|
2018-07-30 16:02:51 +02:00
|
|
|
if paths::is_path_start(p) {
|
|
|
|
return path_expr(p);
|
|
|
|
}
|
2018-02-17 23:06:48 +01:00
|
|
|
|
|
|
|
match p.current() {
|
|
|
|
L_PAREN => tuple_expr(p),
|
|
|
|
_ => p.error("expected expression"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tuple_expr(p: &mut Parser) {
|
|
|
|
assert!(p.at(L_PAREN));
|
|
|
|
let m = p.start();
|
|
|
|
p.expect(L_PAREN);
|
|
|
|
p.expect(R_PAREN);
|
|
|
|
m.complete(p, TUPLE_EXPR);
|
2018-01-28 20:59:18 +01:00
|
|
|
}
|
2018-07-30 16:02:51 +02:00
|
|
|
|
|
|
|
// test path_expr
|
|
|
|
// fn foo() {
|
|
|
|
// let _ = a;
|
|
|
|
// let _ = a::b;
|
|
|
|
// let _ = ::a::<b>;
|
|
|
|
// }
|
|
|
|
fn path_expr(p: &mut Parser) {
|
|
|
|
assert!(paths::is_path_start(p));
|
|
|
|
let m = p.start();
|
|
|
|
paths::expr_path(p);
|
|
|
|
m.complete(p, PATH_EXPR);
|
|
|
|
}
|