/
listempty.go
49 lines (42 loc) · 1.1 KB
/
listempty.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package pnml
import (
"encoding/xml"
"errors"
"fmt"
"log"
)
type ListEmpty struct {
XMLName xml.Name `xml:"emptylist"`
Sort *HLSort `xml:",any"`
Terms []HLSubterm `xml:"subterm"`
}
func (l *ListEmpty) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type listempty ListEmpty
var ll listempty
if err := d.DecodeElement(&ll, &start); err != nil {
return err
}
line, col := d.InputPos()
if ll.Sort == nil {
msg := fmt.Sprint(modelPath, " at line ", line, ", col ", col, ", emptylist without sort")
return errors.New(msg)
}
if len(ll.Terms) != 0 {
msg := fmt.Sprint(modelPath, " at line ", line, ", col ", col, ", emptylist with ", len(ll.Terms), " subterm elements (should be 0)")
if panicIfNotPnmlCompliant {
return errors.New(msg)
}
log.Print("Pinimili: ", msg)
}
*l = ListEmpty(ll)
return nil
}
func (l ListEmpty) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
type tmpL struct {
XMLName xml.Name `xml:"emptylist"`
Sort interface{}
Terms []HLSubterm `xml:"subterm"`
}
t := tmpL{l.XMLName, l.Sort.Value, l.Terms}
return e.Encode(t)
}