diff --git a/jdr/sheet.go b/jdr/sheet.go index 277fcfa..e3bf370 100644 --- a/jdr/sheet.go +++ b/jdr/sheet.go @@ -158,12 +158,18 @@ func (n *xmlNode) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { return d.DecodeElement((*node)(n), &start) } +// The parseVariable function parses a Variable value from a XML node. +// The variable type is inferred from the "type" attribute of the node. +// If this attribute is omitted, the type of the variable must be given through the +// "defaults" parameter to avoid a parsing error. +// If this attribute is specified, the "defaults" parameter will be unused and may be nil func parseVariable(root xmlNode, sheet *CharacterSheet, defaults *Variable) (*Variable, error) { ret := &Variable{} typeOk := false nameOk := false + //parsing default values if defaults != nil { switch defaults.Type.(type) { case *VariableType_badType: @@ -174,6 +180,7 @@ func parseVariable(root xmlNode, sheet *CharacterSheet, defaults *Variable) (*Va } } + //iterating on the attributes for i := 0; i < len(root.Attrs); i++ { attrName := root.Attrs[i].Name.Local attrVal := root.Attrs[i].Value @@ -192,6 +199,7 @@ func parseVariable(root xmlNode, sheet *CharacterSheet, defaults *Variable) (*Va } } + //check if no parse error if !nameOk { return nil, errors.New("Unnamed variable") }