Enum members are now ordered

pull/8/head
Sasha Koshka 5 months ago
parent a5477717eb
commit 0d366964ca

@ -11,10 +11,7 @@ func (parser *ParsingOperation) parseEnumSection () (
err = parser.expect(lexer.TokenKindName)
if err != nil { return }
section = &EnumSection {
location: parser.token.Location(),
members: make(map[string] Argument),
}
section = &EnumSection { location: parser.token.Location() }
// get permission
err = parser.nextToken(lexer.TokenKindPermission)
@ -63,26 +60,28 @@ func (parser *ParsingOperation) parseEnumMembers (
// if we've left the block, stop parsing
if !parser.token.Is(lexer.TokenKindIndent) { return }
if parser.token.Value().(int) != 1 { return }
member := EnumMember { }
// get name
err = parser.nextToken(lexer.TokenKindName)
if err != nil { return }
name := parser.token.Value().(string)
member.location = parser.token.Location()
member.name = parser.token.Value().(string)
err = parser.nextToken()
if err != nil { return }
// parse default value
var argument Argument
if parser.token.Is(lexer.TokenKindNewline) {
err = parser.nextToken()
if err != nil { return }
argument, err = parser.parseInitializationValues(1)
into.members[name] = argument
member.value, err = parser.parseInitializationValues(1)
into.members = append(into.members, member)
if err != nil { return }
} else {
argument, err = parser.parseArgument()
into.members[name] = argument
member.value, err = parser.parseArgument()
into.members = append(into.members, member)
if err != nil { return }
err = parser.expect(lexer.TokenKindNewline)

@ -179,17 +179,17 @@ enum ro AffrontToGod:{Int 4}
3
4
enum ro NamedColor:U32
blue 255
green 65280
red 16711680
green 65280
blue 255
enum ro Weekday:Int
friday
monday
saturday
sunday
thursday
monday
tuesday
wednesday
thursday
friday
saturday
`, test)
}

@ -337,22 +337,20 @@ func (section *EnumSection) ToString (indent int) (output string) {
section.name, ":",
section.what.ToString(), "\n")
for _, name := range sortMapKeysAlphabetically(section.members) {
output += doIndent(indent + 1, name)
defaultValue := section.members[name]
for _, member := range section.members {
output += doIndent(indent + 1, member.name)
isComplexInitialization :=
defaultValue.kind == ArgumentKindObjectInitializationValues ||
defaultValue.kind == ArgumentKindArrayInitializationValues
member.value.kind == ArgumentKindObjectInitializationValues ||
member.value.kind == ArgumentKindArrayInitializationValues
if defaultValue.value == nil {
if member.value.value == nil {
output += "\n"
} else if isComplexInitialization {
output += "\n"
output += defaultValue.ToString(indent + 2, true)
output += member.value.ToString(indent + 2, true)
} else {
output += " " + defaultValue.ToString(0, false)
output += " " + member.value.ToString(0, false)
output += "\n"
}
}

@ -191,9 +191,17 @@ type ObjtSection struct {
inherits Type
permission types.Permission
// TODO: order matters here we need to store these in an array
// TODO: add bitfield support (:n)
members map[string] ObjtMember
}
type EnumMember struct {
location file.Location
name string
value Argument
}
// EnumSection represents an enumerated type section.
type EnumSection struct {
location file.Location
@ -201,8 +209,7 @@ type EnumSection struct {
what Type
permission types.Permission
// TODO: order matters here we need to store these in an array
members map[string] Argument
members []EnumMember
}
// FaceBehavior represents a behavior of an interface section.