1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-09 18:06:35 +03:00
mal/impls/cs/printer.cs
Joel Martin 8a19f60386 Move implementations into impls/ dir
- 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.
2020-02-10 23:50:16 -06:00

50 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Mal;
using MalVal = Mal.types.MalVal;
using MalList = Mal.types.MalList;
namespace Mal {
public class printer {
public static string join(List<MalVal> value,
string delim, bool print_readably) {
List<string> strs = new List<string>();
foreach (MalVal mv in value) {
strs.Add(mv.ToString(print_readably));
}
return String.Join(delim, strs.ToArray());
}
public static string join(Dictionary<string,MalVal> value,
string delim, bool print_readably) {
List<string> strs = new List<string>();
foreach (KeyValuePair<string, MalVal> entry in value) {
if (entry.Key.Length > 0 && entry.Key[0] == '\u029e') {
strs.Add(":" + entry.Key.Substring(1));
} else if (print_readably) {
strs.Add("\"" + entry.Key.ToString() + "\"");
} else {
strs.Add(entry.Key.ToString());
}
strs.Add(entry.Value.ToString(print_readably));
}
return String.Join(delim, strs.ToArray());
}
public static string _pr_str(MalVal mv, bool print_readably) {
return mv.ToString(print_readably);
}
public static string _pr_str_args(MalList args, String sep,
bool print_readably) {
return join(args.getValue(), sep, print_readably);
}
public static string escapeString(string str) {
return Regex.Escape(str);
}
}
}