58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/cel/encoder.rb', line 58
def decode(enc)
case enc
in ["group", stmt]
Group.new(decode(stmt))
in ["inv", var, ::String => func, *args]
args = if func == "[]" && args.size == 1
decode(args.first)
elsif args.empty?
nil
else
args.map(&method(:decode))
end
Invoke.new(func: func, var: decode(var), args: args)
in ["inv", ::String => func, *args]
args = nil if args.empty?
Invoke.new(func: func, args: args.map(&method(:decode)))
in ["op", ::String => op, *args]
Operation.new(op, args.map(&method(:decode)))
in ["cond", f, th, el]
Condition.new(decode(f), decode(th), decode(el))
in ["id", ::String => type, ::String => val]
id = Identifier.new(val)
id.type = TYPES[type.to_sym]
id
in ["lit", "list", *items]
list = List.new(items.map(&method(:decode)))
list
in ["lit", "map", items]
Map.new(items.map(&method(:decode)).each_slice(2))
in ["lit", /\Aint|uint|double\z/ => type, Integer => val]
Number.new(type.to_sym, val)
in ["lit", "bool", val]
Bool.new(val)
in ["lit", "string", val]
String.new(val)
in ["lit", "bytes", val]
Bytes.new(val)
in ["lit", "null"]
Null.new
in ["lit", "type", type]
TYPES[type.to_sym]
end
end
|