2018-08-04 19:18:53 +00:00
|
|
|
import 'package:source_span/source_span.dart';
|
|
|
|
import '../token.dart';
|
2019-08-08 01:48:12 +00:00
|
|
|
import 'input_value.dart';
|
2018-08-04 19:18:53 +00:00
|
|
|
import 'node.dart';
|
|
|
|
|
2019-08-08 01:48:12 +00:00
|
|
|
class NullValueContext extends InputValueContext<Null> {
|
2018-08-04 19:18:53 +00:00
|
|
|
final Token NULL;
|
|
|
|
|
|
|
|
NullValueContext(this.NULL);
|
|
|
|
|
|
|
|
@override
|
|
|
|
FileSpan get span => NULL.span;
|
|
|
|
|
|
|
|
@override
|
2019-08-08 01:48:12 +00:00
|
|
|
Null computeValue(Map<String, dynamic> variables) => null;
|
2018-08-04 19:18:53 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 01:48:12 +00:00
|
|
|
class EnumValueContext extends InputValueContext<String> {
|
2018-08-04 19:18:53 +00:00
|
|
|
final Token NAME;
|
|
|
|
|
|
|
|
EnumValueContext(this.NAME);
|
|
|
|
|
|
|
|
@override
|
|
|
|
FileSpan get span => NAME.span;
|
|
|
|
|
|
|
|
@override
|
2019-08-08 01:48:12 +00:00
|
|
|
String computeValue(Map<String, dynamic> variables) => NAME.span.text;
|
2018-08-04 19:18:53 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 01:48:12 +00:00
|
|
|
class ObjectValueContext extends InputValueContext<Map<String, dynamic>> {
|
2018-08-04 19:18:53 +00:00
|
|
|
final Token LBRACE;
|
|
|
|
final List<ObjectFieldContext> fields;
|
|
|
|
final Token RBRACE;
|
|
|
|
|
|
|
|
ObjectValueContext(this.LBRACE, this.fields, this.RBRACE);
|
|
|
|
|
|
|
|
@override
|
|
|
|
FileSpan get span {
|
|
|
|
var left = LBRACE.span;
|
|
|
|
|
|
|
|
for (var field in fields) {
|
|
|
|
left = left.expand(field.span);
|
|
|
|
}
|
|
|
|
|
|
|
|
return left.expand(RBRACE.span);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2019-08-08 01:48:12 +00:00
|
|
|
Map<String, dynamic> computeValue(Map<String, dynamic> variables) {
|
2018-08-04 19:18:53 +00:00
|
|
|
if (fields.isEmpty) {
|
|
|
|
return <String, dynamic>{};
|
|
|
|
} else {
|
|
|
|
return fields.fold<Map<String, dynamic>>(<String, dynamic>{},
|
|
|
|
(map, field) {
|
2019-08-08 01:48:12 +00:00
|
|
|
return map..[field.NAME.text] = field.value.computeValue(variables);
|
2018-08-04 19:18:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ObjectFieldContext extends Node {
|
|
|
|
final Token NAME;
|
|
|
|
final Token COLON;
|
2019-08-08 01:48:12 +00:00
|
|
|
final InputValueContext value;
|
2018-08-04 19:18:53 +00:00
|
|
|
|
|
|
|
ObjectFieldContext(this.NAME, this.COLON, this.value);
|
|
|
|
|
|
|
|
@override
|
|
|
|
FileSpan get span => NAME.span.expand(COLON.span).expand(value.span);
|
|
|
|
}
|