11import Common
2- import TOMLKit
32
43struct PerMonitorValue < Value: Equatable > : Equatable {
54 let description : MonitorDescription
@@ -33,15 +32,15 @@ extension DynamicConfigValue {
3332}
3433
3534func parseDynamicValue< T> (
36- _ raw: TOMLValueConvertible ,
35+ _ raw: Json ,
3736 _ valueType: T . Type ,
3837 _ fallback: T ,
3938 _ backtrace: ConfigBacktrace ,
4039 _ errors: inout [ ConfigParseError ] ,
4140) -> DynamicConfigValue < T > {
4241 if let simpleValue = parseSimpleType ( raw) as T ? {
4342 return . constant( simpleValue)
44- } else if let array = raw. array {
43+ } else if let array = raw. asArrayOrNil {
4544 if array. isEmpty {
4645 errors. append ( . semantic( backtrace, " The array must not be empty " ) )
4746 return . constant( fallback)
@@ -57,17 +56,17 @@ func parseDynamicValue<T>(
5756 return . constant( fallback)
5857 }
5958
60- let rules : [ PerMonitorValue < T > ] = parsePerMonitorValues ( TOMLArray ( array. dropLast ( ) ) , backtrace, & errors)
59+ let rules : [ PerMonitorValue < T > ] = parsePerMonitorValues ( array. dropLast ( ) , backtrace, & errors)
6160
6261 return . perMonitor( rules, default: defaultValue)
6362 } else {
64- errors. append ( . semantic( backtrace, " Unsupported type: \( raw. type ) , expected: \( valueType) or array " ) )
63+ errors. append ( . semantic( backtrace, " Unsupported type: \( raw. tomlType ) , expected: \( valueType) or array " ) )
6564 return . constant( fallback)
6665 }
6766}
6867
69- func parsePerMonitorValues< T> ( _ array: TOMLArray , _ backtrace: ConfigBacktrace , _ errors: inout [ ConfigParseError ] ) -> [ PerMonitorValue < T > ] {
70- array. enumerated ( ) . compactMap { ( index: Int , raw: TOMLValueConvertible ) -> PerMonitorValue < T > ? in
68+ func parsePerMonitorValues< T> ( _ array: Json . JsonArray , _ backtrace: ConfigBacktrace , _ errors: inout [ ConfigParseError ] ) -> [ PerMonitorValue < T > ] {
69+ array. enumerated ( ) . compactMap { ( index: Int , raw: Json ) -> PerMonitorValue < T > ? in
7170 var backtrace = backtrace + . index( index)
7271
7372 guard let ( key, value) = raw. unwrapTableWithSingleKey ( expectedKey: " monitor " , & backtrace)
@@ -77,12 +76,12 @@ func parsePerMonitorValues<T>(_ array: TOMLArray, _ backtrace: ConfigBacktrace,
7776 return nil
7877 }
7978
80- let monitorDescriptionResult = parseMonitorDescription ( key, backtrace)
79+ let monitorDescriptionResult = parseMonitorDescription ( . string ( key) , backtrace)
8180
8281 guard let monitorDescription = monitorDescriptionResult. getOrNil ( appendErrorTo: & errors) else { return nil }
8382
8483 guard let value = parseSimpleType ( value) as T ? else {
85- errors. append ( . semantic( backtrace, " Expected type is ' \( T . self) '. But actual type is ' \( value. type ) ' " ) )
84+ errors. append ( . semantic( backtrace, " Expected type is ' \( T . self) '. But actual type is ' \( value. tomlType ) ' " ) )
8685 return nil
8786 }
8887
0 commit comments