mirror of
https://github.com/kanaka/mal.git
synced 2024-08-17 09:40:21 +03:00
- Reorder README to have implementation list after "learning tool" bullet. - This also moves tests/ and libs/ into impls. It would be preferrable to have these directories at the top level. However, this causes difficulties with the wasm implementations which need pre-open directories and have trouble with paths starting with "../../". So in lieu of that, symlink those directories to the top-level. - Move the run_argv_test.sh script into the tests directory for general hygiene.
48 lines
1.6 KiB
Dart
48 lines
1.6 KiB
Dart
import 'types.dart';
|
|
|
|
String pr_str(MalType data, {bool print_readably: true}) {
|
|
if (data is MalSymbol) {
|
|
return data.value;
|
|
} else if (data is MalInt) {
|
|
return '${data.value}';
|
|
} else if (data is MalList) {
|
|
var printedElements =
|
|
data.elements.map((e) => pr_str(e, print_readably: print_readably));
|
|
return '(${printedElements.join(" ")})';
|
|
} else if (data is MalVector) {
|
|
var printedElements =
|
|
data.elements.map((e) => pr_str(e, print_readably: print_readably));
|
|
return '[${printedElements.join(" ")}]';
|
|
} else if (data is MalHashMap) {
|
|
var printedElements = <String>[];
|
|
data.value.forEach((key, value) {
|
|
printedElements.add(pr_str(key, print_readably: print_readably));
|
|
printedElements.add(pr_str(value, print_readably: print_readably));
|
|
});
|
|
return '{${printedElements.join(" ")}}';
|
|
} else if (data is MalString) {
|
|
if (print_readably) {
|
|
var readableValue = data.value
|
|
.replaceAll('\\', r'\\')
|
|
.replaceAll('\n', r'\n')
|
|
.replaceAll('\"', r'\"');
|
|
return '"$readableValue"';
|
|
} else {
|
|
return '${data.value}';
|
|
}
|
|
} else if (data is MalKeyword) {
|
|
return ':${data.value}';
|
|
} else if (data is MalBool) {
|
|
return '${data.value}';
|
|
} else if (data is MalNil) {
|
|
return 'nil';
|
|
} else if (data is MalBuiltin) {
|
|
return '#<built in function>';
|
|
} else if (data is MalClosure) {
|
|
return '#<function>';
|
|
} else if (data is MalAtom) {
|
|
return "(atom ${pr_str(data.value, print_readably: print_readably)})";
|
|
}
|
|
throw new ArgumentError("Unrecognized type: ${data.runtimeType}");
|
|
}
|