本文整理汇总了C#中Reader.ReadFirstForm方法的典型用法代码示例。如果您正苦于以下问题:C# Reader.ReadFirstForm方法的具体用法?C# Reader.ReadFirstForm怎么用?C# Reader.ReadFirstForm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reader
的用法示例。
在下文中一共展示了Reader.ReadFirstForm方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestVector
public void TestVector()
{
Reader rdr = new Reader();
NLVector vec = (NLVector)rdr.ReadFirstForm("[]");
Assert.IsNotNull(vec);
Assert.AreEqual(0, vec.Contents.Length);
vec = (NLVector) rdr.ReadFirstForm("[1]");
Assert.IsNotNull(vec);
Assert.AreEqual(1, vec.Contents.Length);
long ival = (long)vec.Contents[0];
Assert.AreEqual(1, ival);
vec = (NLVector)rdr.ReadFirstForm("[ 1, 2]");
Assert.IsNotNull(vec);
Assert.AreEqual(2, vec.Contents.Length);
ival = (long)vec.Contents[0];
Assert.AreEqual(1, ival);
ival = (long)vec.Contents[1];
Assert.AreEqual(2, ival);
vec = (NLVector)rdr.ReadFirstForm(" [ [, 42 ] \"a\" ]");
Assert.IsNotNull(vec);
Assert.AreEqual(2, vec.Contents.Length);
NLVector vval = (NLVector)vec.Contents[0];
Assert.AreEqual(42, (long)vval.Contents[0]);
string sval = (string)vec.Contents[1];
Assert.AreEqual("a", sval);
}
示例2: Main
public static void Main()
{
Reader arr = new Reader();
Evaluator eval = new Evaluator();
Greet();
do {
Console.Write("nihil> ");
string str = Console.ReadLine().Trim();
// FIXME: the really annoying echo problem
if (str.Length == 0) {
// Why yes, this *is* the hard way of printing an empty line.
str = "(System.Console.WriteLine)";
}
try {
object form = arr.ReadFirstForm(str.Trim());
if (form == null) {
throw new Exception("uh, couldn't read " + str);
}
form = eval.Evaluate(form);
if (form != null) {
Console.WriteLine(PrettyPrinter.Reformat(form));
}
} catch (ReaderException rex) {
Console.WriteLine("Reader exception: " + rex.Message);
Console.WriteLine(rex.StackTrace);
} catch (EvaluatorException eex) {
Console.WriteLine("Evaluator exception: " + eex.Message);
Console.WriteLine(eex.StackTrace);
} catch (Exception ex) {
Console.WriteLine("UNEXPECTED exception: " + ex.Message);
Console.WriteLine(ex.StackTrace);
}
} while (true);
}
示例3: TestMap
public void TestMap()
{
Reader rdr = new Reader();
NLMap map = (NLMap)rdr.ReadFirstForm("{}");
Assert.AreEqual(0, map.Contents.Length);
map = (NLMap)rdr.ReadFirstForm("{ 42 \"everything\" }");
Assert.AreEqual(2, map.Contents.Length);
Assert.AreEqual(42, (long)map.Contents[0]);
Assert.AreEqual("everything", (string)map.Contents[1]);
map = (NLMap)rdr.ReadFirstForm("{ [0], :foo }");
Assert.AreEqual(2, map.Contents.Length);
Assert.AreEqual(0, (long)((NLVector)map.Contents[0]).Contents[0]);
Assert.AreEqual(":foo", ((NLKeyword)map.Contents[1]).ToString());
// Form equivalence not trivial
// NLMap map = (NLMap)form;
// Assert.AreEqual("everything", map.Get(NLInteger.Create("42")));
}
示例4: TestSymbol
public void TestSymbol()
{
Reader rdr = new Reader();
NLSymbol sym = (NLSymbol)rdr.ReadFirstForm("foo");
Assert.AreEqual("foo", sym.ToString());
sym = (NLSymbol)rdr.ReadFirstForm("foo.bar");
Assert.AreEqual("foo", sym.Namespace);
Assert.AreEqual("bar", sym.FunctionName);
}
示例5: TestList
public void TestList()
{
Reader rdr = new Reader();
NLList list = (NLList)rdr.ReadFirstForm("( )");
Assert.IsNotNull(list);
Assert.AreEqual(0, list.Contents.Length);
list = (NLList)rdr.ReadFirstForm("(1)");
Assert.IsNotNull(list);
Assert.AreEqual(1, list.Contents.Length);
long ival = (long)list.Contents[0];
Assert.AreEqual(1, ival);
list = (NLList)rdr.ReadFirstForm("( 1, 2)");
Assert.IsNotNull(list);
Assert.AreEqual(2, list.Contents.Length);
ival = (long)list.Contents[0];
Assert.AreEqual(1, ival);
ival = (long)list.Contents[1];
Assert.AreEqual(2, ival);
list = (NLList)rdr.ReadFirstForm(" ( [, 42 ] \"a\" )");
Assert.IsNotNull(list);
Assert.AreEqual(2, list.Contents.Length);
NLVector vval = (NLVector)list.Contents[0];
Assert.AreEqual(42, (long)vval.Contents[0]);
string sval = (string)list.Contents[1];
Assert.AreEqual("a", sval);
}