v2: enum fields separated by commas

pull/4174/head
Major Taylor 2020-04-01 06:11:00 -04:00 committed by GitHub
parent 5b990078f9
commit 9bb1b5d1bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 9 deletions

View File

@ -52,7 +52,6 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
pref: &pref.Preferences{} pref: &pref.Preferences{}
scope: scope scope: scope
// scope: &ast.Scope{start_pos: 0, parent: 0} // scope: &ast.Scope{start_pos: 0, parent: 0}
} }
p.init_parse_fns() p.init_parse_fns()
p.read_first_token() p.read_first_token()
@ -781,7 +780,6 @@ pub fn (p mut Parser) expr(precedence int) ast.Expr {
node = ast.SizeOf{ node = ast.SizeOf{
typ: sizeof_type typ: sizeof_type
// type_name: type_name // type_name: type_name
} }
} }
.key_typeof { .key_typeof {
@ -1052,7 +1050,6 @@ fn (p mut Parser) infix_expr(left ast.Expr) ast.Expr {
left: left left: left
right: right right: right
// right_type: typ // right_type: typ
op: op op: op
pos: pos pos: pos
} }
@ -1457,7 +1454,6 @@ fn (p mut Parser) const_decl() ast.ConstDecl {
fields << ast.Field{ fields << ast.Field{
name: name name: name
// typ: typ // typ: typ
} }
exprs << expr exprs << expr
// TODO: once consts are fixed reg here & update in checker // TODO: once consts are fixed reg here & update in checker
@ -1851,6 +1847,13 @@ fn (p mut Parser) enum_decl() ast.EnumDecl {
p.next() p.next()
default_exprs << p.expr(0) default_exprs << p.expr(0)
} }
// Allow commas after enum, helpful for
// enum Color {
// r,g,b
// }
if p.tok.kind == .comma {
p.next()
}
} }
p.check(.rcbr) p.check(.rcbr)
p.table.register_type_symbol(table.TypeSymbol{ p.table.register_type_symbol(table.TypeSymbol{

View File

@ -25,7 +25,7 @@ fn test_match_integers() {
assert match 0 { assert match 0 {
1 { 2 } 1 { 2 }
2 { 3 } 2 { 3 }
else 5 else { 5 }
} == 5 } == 5
assert match 1 { assert match 1 {