-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocinst.go
More file actions
73 lines (61 loc) · 2.03 KB
/
procinst.go
File metadata and controls
73 lines (61 loc) · 2.03 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package risorxml
import (
"github.com/risor-io/risor/object"
"github.com/risor-io/risor/op"
"github.com/speedata/goxml"
)
// XMLProcInst represents an XML processing instruction in the Risor XML module.
type XMLProcInst struct {
Value *goxml.ProcInst
}
// Type of the object.
func (pi *XMLProcInst) Type() object.Type {
return "xml.procinst"
}
// Inspect returns a string representation of the given object.
func (pi *XMLProcInst) Inspect() string {
return pi.Value.Target + " " + string(pi.Value.Inst)
}
// Interface converts the given object to a native Go value.
func (pi *XMLProcInst) Interface() interface{} {
return pi.Value
}
// Equals returns True if the given object is equal to this object.
func (pi *XMLProcInst) Equals(other object.Object) object.Object {
return object.NewBool(pi.Value == other.(*XMLProcInst).Value)
}
// GetAttr returns the attribute with the given name from this object.
func (pi *XMLProcInst) GetAttr(name string) (object.Object, bool) {
switch name {
case "is_element":
return object.False, true
case "is_text":
return object.False, true
case "is_comment":
return object.False, true
case "is_procinst":
return object.True, true
case "text":
return object.NewString(string(pi.Value.Inst)), true
case "target":
return object.NewString(pi.Value.Target), true
}
return nil, false
}
// SetAttr sets the attribute with the given name on this object.
func (pi *XMLProcInst) SetAttr(name string, value object.Object) error {
return object.Errorf("xml.procinst: cannot set attribute %s", name)
}
// IsTruthy returns true if the object is considered "truthy".
func (pi *XMLProcInst) IsTruthy() bool {
return string(pi.Value.Inst) != ""
}
// RunOperation runs an operation on this object with the given
// right-hand side object.
func (pi *XMLProcInst) RunOperation(opType op.BinaryOpType, right object.Object) object.Object {
return object.Errorf("xml.procinst: operation %s not supported", opType)
}
// Cost returns the incremental processing cost of this object.
func (pi *XMLProcInst) Cost() int {
return 0
}