-
Notifications
You must be signed in to change notification settings - Fork 0
/
native_undefined.go
33 lines (29 loc) · 1.02 KB
/
native_undefined.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
package joeson
// Some parsers (namedly Not, Pattern, Sequence, Existential) need
// a value different from `nil` (which represents parsing failure).
//
// NativeUndefined need both to
// - implement Parser
// - get instantiated fast
type NativeUndefined struct {
*Attr
*rule
}
func NewNativeUndefined() NativeUndefined {
nu := NativeUndefined{newAttr(), newRule()}
return nu
}
func (nu NativeUndefined) assertNode() {}
func (nu NativeUndefined) String() string { return "<NativeUndefined>" }
func (nu NativeUndefined) parse(ctx *ParseContext) Ast { return nu }
func (nu NativeUndefined) getRule() *rule { return nu.rule }
func (nu NativeUndefined) prepare() {}
func (nu NativeUndefined) handlesChildLabel() bool { return false }
func (nu NativeUndefined) forEachChild(f func(Parser) Parser) Parser { return nu }
func IsUndefined(x Ast) bool {
if x == nil {
return true
}
_, isUndefined := x.(NativeUndefined)
return isUndefined
}