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:
parent
a52cb315cb
commit
cd8b0d04bb
@ -22,6 +22,18 @@ fn (p mut Parser) enum_decl(_enum_name string) {
|
|||||||
fields << field
|
fields << field
|
||||||
p.fgenln('')
|
p.fgenln('')
|
||||||
name := '${mod_gen_name(p.mod)}__${enum_name}_$field'
|
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 {
|
if p.pass == .main {
|
||||||
p.cgen.consts << '#define $name $val'
|
p.cgen.consts << '#define $name $val'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user