1
- # TODO use traits for hasmethod checks
1
+ using Tricks: compat_hasmethod
2
+ # TODO use traits for compat_hasmethod checks
2
3
3
4
# Scalar parsers
4
5
@@ -17,9 +18,9 @@ function nodeparse(type::Type, content::String)
17
18
# https://julialang.slack.com/archives/C6A044SQH/p1578442480438100
18
19
if hasmethod (type, Tuple{String}) && Core. Compiler. return_type (type, Tuple{Node})=== Union{}
19
20
return type (content)
20
- elseif hasmethod (convert, Tuple{String, type})
21
+ elseif compat_hasmethod (convert, Tuple{String, type})
21
22
return convert (type, content)
22
- elseif hasmethod (parse, Tuple{type, String})
23
+ elseif compat_hasmethod (parse, Tuple{type, String})
23
24
return parse (type, content)
24
25
else
25
26
error (" Could not parse a String as type $type " )
@@ -32,9 +33,9 @@ function nodeparse(type::Type, elm::Node)
32
33
content = elm. content
33
34
if hasmethod (type, Tuple{String}) && Core. Compiler. return_type (type, Tuple{Node})=== Union{}
34
35
return type (content)
35
- elseif hasmethod (convert, Tuple{String, type})
36
+ elseif compat_hasmethod (convert, Tuple{String, type})
36
37
return convert (type, content)
37
- elseif hasmethod (parse, Tuple{type, String})
38
+ elseif compat_hasmethod (parse, Tuple{type, String})
38
39
return parse (type, content)
39
40
else
40
41
# should be the last to avoid invoking generic methods
58
59
function nodeparse (:: Type{T} , contents:: Vector{String} ) where {T}
59
60
elms_typed = Vector {T} (undef, length (contents))
60
61
i = 1
62
+ # TODO https://github.com/oxinabox/Tricks.jl/issues/2#issuecomment-630450764
61
63
if hasmethod (type, Tuple{String}) && Core. Compiler. return_type (type, Tuple{Node})=== Union{}
62
64
for content in contents
63
65
elms_typed[i] = type (content)
64
66
i+= 1
65
67
end
66
- elseif hasmethod (convert, Tuple{String, type})
68
+ elseif compat_hasmethod (convert, Tuple{String, type})
67
69
for content in contents
68
70
elms_typed[i] = convert (type, content)
69
71
i+= 1
70
72
end
71
- elseif hasmethod (parse, Tuple{type, String})
73
+ elseif compat_hasmethod (parse, Tuple{type, String})
72
74
for content in contents
73
75
elms_typed[i] = parse (type, content)
74
76
i+= 1
82
84
function nodeparse (type:: Type{T} , elms:: Vector{Node} ) where {T}
83
85
elms_typed = Vector {T} (undef, length (elms))
84
86
i = 1
87
+ # TODO https://github.com/oxinabox/Tricks.jl/issues/2#issuecomment-630450764
85
88
if hasmethod (type, Tuple{String}) && Core. Compiler. return_type (type, Tuple{Node})=== Union{}
86
89
for elm in elms
87
90
elms_typed[i] = type (elm. content)
88
91
i+= 1
89
92
end
90
- elseif hasmethod (convert, Tuple{String, type})
93
+ elseif compat_hasmethod (convert, Tuple{String, type})
91
94
for elm in elms
92
95
elms_typed[i] = convert (type, elm. content)
93
96
i+= 1
94
97
end
95
- elseif hasmethod (parse, Tuple{type, String})
98
+ elseif compat_hasmethod (parse, Tuple{type, String})
96
99
for elm in elms
97
100
elms_typed[i] = parse (type, elm. content)
98
101
i+= 1
0 commit comments