Fix block structure in enums

This commit is contained in:
Aleksey Kladov
2018-09-08 10:55:09 +03:00
parent 749907d330
commit f48b9d9be7
5 changed files with 274 additions and 25 deletions

View File

@@ -1,11 +1,11 @@
mod consts;
mod structs;
mod nominal;
mod traits;
mod use_item;
use super::*;
pub(crate) use self::structs::named_field_def_list;
pub(crate) use self::nominal::named_field_def_list;
// test mod_contents
// fn foo() {}
@@ -176,7 +176,7 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> {
MODULE
}
STRUCT_KW => {
structs::struct_def(p);
nominal::struct_def(p);
if p.at(SEMI) {
p.err_and_bump(
"expected item, found `;`\n\
@@ -186,7 +186,7 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> {
STRUCT_DEF
}
ENUM_KW => {
structs::enum_def(p);
nominal::enum_def(p);
ENUM_DEF
}
USE_KW => {

View File

@@ -91,6 +91,10 @@ pub(crate) fn named_field_def_list(p: &mut Parser) {
let m = p.start();
p.bump();
while !p.at(R_CURLY) && !p.at(EOF) {
if p.at(L_CURLY) {
error_block(p, "expected field");
continue;
}
named_field_def(p);
if !p.at(R_CURLY) {
p.expect(COMMA);
@@ -127,10 +131,15 @@ fn pos_field_list(p: &mut Parser) {
return;
}
while !p.at(R_PAREN) && !p.at(EOF) {
let pos_field = p.start();
let m = p.start();
opt_visibility(p);
if !p.at_ts(types::TYPE_FIRST) {
p.error("expected a type");
m.complete(p, ERROR);
break;
}
types::type_(p);
pos_field.complete(p, POS_FIELD);
m.complete(p, POS_FIELD);
if !p.at(R_PAREN) {
p.expect(COMMA);