// ENUM_VAL_INITIALIZER -> INTEGER_LITERAL | ENUM_VALUE_REF // ENUM_VALUE_REF -> IDENTIFIER {{that resolves to a declared enum value}} func (p *Parser) parseEnumValueInitializer(mojoEnum *mojom.MojomEnum) mojom.ValueRef { if !p.OK() { return nil } p.pushChildNode("enumValueInitializer") defer p.popNode() // We need to manufacture an instance of Type to act as the "assigneeType" // for the new ValueSpec we are creating. This is because unlike // other types of value assignment, an enum value initializer is not // preceded by a type reference for the assignee. Rather the type of // the assignee is implicit in the scope. enumType := mojom.NewResolvedUserTypeRef(mojoEnum.FullyQualifiedName(), mojoEnum) valueToken := p.peekNextToken("Parsing an enum value initializer type.") valueRef := p.parseValue(enumType) if valueRef == nil { return nil } if !valueRef.MarkUsedAsEnumValueInitializer() { message := fmt.Sprintf("Illegal value: %s at %s. An enum value may "+ "only be initialized by an integer or another enum value.", valueToken, valueToken.LongLocationString()) p.err = &ParseError{ParserErrorCodeUnexpectedToken, message} return nil } return valueRef }