v2: enum fields separated by commas
parent
5b990078f9
commit
9bb1b5d1bb
|
@ -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()
|
||||||
|
@ -71,13 +70,13 @@ pub fn parse_file(path string, table &table.Table, comments_mode scanner.Comment
|
||||||
table: table
|
table: table
|
||||||
file_name: path
|
file_name: path
|
||||||
pref: pref // &pref.Preferences{}
|
pref: pref // &pref.Preferences{}
|
||||||
|
|
||||||
scope: &ast.Scope{
|
scope: &ast.Scope{
|
||||||
start_pos: 0
|
start_pos: 0
|
||||||
parent: 0
|
parent: 0
|
||||||
}
|
}
|
||||||
// comments_mode: comments_mode
|
// comments_mode: comments_mode
|
||||||
|
|
||||||
}
|
}
|
||||||
p.read_first_token()
|
p.read_first_token()
|
||||||
// p.scope = &ast.Scope{start_pos: p.tok.position(), parent: 0}
|
// p.scope = &ast.Scope{start_pos: p.tok.position(), parent: 0}
|
||||||
|
@ -270,7 +269,7 @@ pub fn (p mut Parser) top_stmt() ast.Stmt {
|
||||||
p.error('wrong pub keyword usage')
|
p.error('wrong pub keyword usage')
|
||||||
return ast.Stmt{}
|
return ast.Stmt{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.lsbr {
|
.lsbr {
|
||||||
return p.attribute()
|
return p.attribute()
|
||||||
|
@ -691,7 +690,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
|
||||||
p.expr_mod = ''
|
p.expr_mod = ''
|
||||||
return ast.EnumVal{
|
return ast.EnumVal{
|
||||||
enum_name: enum_name // lp.prepend_mod(enum_name)
|
enum_name: enum_name // lp.prepend_mod(enum_name)
|
||||||
|
|
||||||
val: val
|
val: val
|
||||||
pos: p.tok.position()
|
pos: p.tok.position()
|
||||||
mod: mod
|
mod: mod
|
||||||
|
@ -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{
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue