1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: support for 'enum Color {red = 31 yellow green blue}'

This commit is contained in:
Delyan Angelov 2019-10-21 14:00:41 +03:00 committed by Alexander Medvednikov
parent a52cb315cb
commit cd8b0d04bb

View File

@ -22,6 +22,18 @@ fn (p mut Parser) enum_decl(_enum_name string) {
fields << field
p.fgenln('')
name := '${mod_gen_name(p.mod)}__${enum_name}_$field'
if p.tok == .assign {
mut enum_assign_tidx := p.cur_tok_index()
if p.peek() == .number {
p.next()
val = p.lit.int()
p.next()
}else{
p.next()
enum_assign_tidx = p.cur_tok_index()
p.error_with_token_index('only numbers are allowed in enum initializations', enum_assign_tidx)
}
}
if p.pass == .main {
p.cgen.consts << '#define $name $val'
}