parameter parsing does not destroy blocks

This commit is contained in:
Aleksey Kladov
2018-08-24 20:50:37 +03:00
parent b0aac1ca98
commit f104458d45
10 changed files with 70 additions and 4 deletions

View File

@@ -13,7 +13,7 @@ use super::*;
// let _ = b"e";
// let _ = br"f";
// }
const LITERAL_FIRST: TokenSet =
pub(crate) const LITERAL_FIRST: TokenSet =
token_set![TRUE_KW, FALSE_KW, INT_NUMBER, FLOAT_NUMBER, BYTE, CHAR,
STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING];

View File

@@ -1,7 +1,7 @@
mod atom;
use super::*;
pub(super) use self::atom::literal;
pub(super) use self::atom::{literal, LITERAL_FIRST};
const EXPR_FIRST: TokenSet = LHS_FIRST;

View File

@@ -250,8 +250,10 @@ fn function(p: &mut Parser, flavor: ItemFlavor) {
// test fn_decl
// trait T { fn foo(); }
if !p.eat(SEMI) {
if p.at(L_CURLY) {
expressions::block(p);
} else {
p.expect(SEMI);
}
}

View File

@@ -48,6 +48,10 @@ fn list_(p: &mut Parser, flavor: Flavor) {
opt_self_param(p);
}
while !p.at(EOF) && !p.at(ket) {
if !VALUE_PARAMETER_FIRST.contains(p.current()) {
p.error("expected value parameter");
break;
}
value_parameter(p, flavor);
if !p.at(ket) {
p.expect(COMMA);
@@ -57,6 +61,13 @@ fn list_(p: &mut Parser, flavor: Flavor) {
m.complete(p, PARAM_LIST);
}
const VALUE_PARAMETER_FIRST: TokenSet =
token_set_union![
patterns::PATTERN_FIRST,
types::TYPE_FIRST,
];
fn value_parameter(p: &mut Parser, flavor: Flavor) {
let m = p.start();
match flavor {

View File

@@ -1,5 +1,8 @@
use super::*;
pub(super) const PATH_FIRST: TokenSet =
token_set![IDENT, SELF_KW, SUPER_KW, COLONCOLON, L_ANGLE];
pub(super) fn is_path_start(p: &Parser) -> bool {
match p.current() {
IDENT | SELF_KW | SUPER_KW | COLONCOLON => true,

View File

@@ -1,5 +1,12 @@
use super::*;
pub(super) const PATTERN_FIRST: TokenSet =
token_set_union![
token_set![REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP],
expressions::LITERAL_FIRST,
paths::PATH_FIRST,
];
pub(super) fn pattern(p: &mut Parser) {
if let Some(lhs) = atom_pat(p) {
// test range_pat

View File

@@ -1,5 +1,13 @@
use super::*;
pub(super) const TYPE_FIRST: TokenSet =
token_set_union![
token_set![
L_PAREN, EXCL, STAR, L_BRACK, AMP, UNDERSCORE, FN_KW, UNSAFE_KW, EXTERN_KW, FOR_KW, IMPL_KW, DYN_KW, L_ANGLE,
],
paths::PATH_FIRST,
];
pub(super) fn type_(p: &mut Parser) {
match p.current() {
L_PAREN => paren_or_tuple_type(p),