[Genie] Allow enums to have methods
@astavale
Submitted by Al Thomas Link to original bug (#776835)
Description
The following Vala code works fine:
void main () { print (Test.ONE.pretty_print () + "\n"); } enum Test { ONE;
public string pretty_print () {
return @"The value of this enum is $this";
}
}
The following Genie code:
init print( Test.ONE.pretty_print() ) enum Test ONE def pretty_print():string return @"The value of this enum is $this"
produces the error:
test.gs:5.3-5.5: error: syntax error, expected end of line but got def' with previous
tab indent'
def pretty_print():string
Vala allows a function to be defined after the enum values are listed. If this was to be implemented in Genie then a similar scheme is probably best. It would mean adding some additional code to the end of parse_enum_declaration () n the Genie parser. Vala uses the semi-colon to denotes the end of the list of values, but it would be more Genie like to use a new block, i.e. an indent.
One test would be to convert https://git.gnome.org/browse/vala/tree/vala/valagenietokentype.vala to Genie, although this couldn't go in mainline because it would only build with the most recent versions of Vala.