-
Notifications
You must be signed in to change notification settings - Fork 46
/
resolver.jl
90 lines (67 loc) · 2.13 KB
/
resolver.jl
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# TODO:
# This is a punt for now. It does not handle any sort of custom resolving tags,
# only matching default implicits.
const DEFAULT_SCALAR_TAG = "tag:yaml.org,2002:str"
const DEFAULT_SEQUENCE_TAG = "tag:yaml.org,2002:seq"
const DEFAULT_MAPPING_TAG = "tag:yaml.org,2002:map"
const default_implicit_resolvers =
[
("tag:yaml.org,2002:bool",
r"^(?:true|True|TRUE|false|False|FALSE)$"x),
("tag:yaml.org,2002:int",
r"^(?:[-+]?0b[0-1_]+
|[-+]? [0-9]+
|0o [0-7]+
|0x [0-9a-fA-F]+)$"x),
("tag:yaml.org,2002:float",
r"^(?:[-+]? ( \. [0-9]+ | [0-9]+ ( \. [0-9]* )? ) ( [eE] [-+]? [0-9]+ )?
|[-+]? (?: \.inf | \.Inf | \.INF )
|\.nan | \.NaN | \.NAN)$"x),
("tag:yaml.org,2002:merge",
r"^(?:<<)$"),
("tag:yaml.org,2002:null",
r"^(?:~|null|Null|NULL|)$"x),
("tag:yaml.org,2002:timestamp",
r"^(\d{4})- (?# year)
(\d\d?)- (?# month)
(\d\d?) (?# day)
(?:
(?:[Tt]|[ \t]+)
(\d\d?): (?# hour)
(\d\d): (?# minute)
(\d\d) (?# second)
(?:\.(\d*))? (?# fraction)
(?:
[ \t]*(Z|([+\-])(\d\d?)
(?:
:(\d\d)
)?)
)?
)?$"x),
("tag:yaml.org,2002:value",
r"^(?:=)$"),
("tag:yaml.org,2002:yaml",
r"^(?:!|&|\*)$")
]
type Resolver
implicit_resolvers::Vector
function Resolver()
new(copy(default_implicit_resolvers))
end
end
function resolve(resolver::Resolver, ::Type{ScalarNode}, value, implicit)
if implicit[1]
for (tag, pat) in resolver.implicit_resolvers
if ismatch(pat, value)
return tag
end
end
end
DEFAULT_SCALAR_TAG
end
function resolve(resolver::Resolver, ::Type{SequenceNode}, value, implicit)
DEFAULT_SEQUENCE_TAG
end
function resolve(resolver::Resolver, ::Type{MappingNode}, value, implicit)
DEFAULT_MAPPING_TAG
end