/// <summary> /// /// </summary> /// <param name="args"></param> public override LispObject execute(LispObject[] args) { if (args[0] is Condition) { Condition cond = (Condition)args[0]; String s = "DESC:\r\n" + cond.getDescription().princToString() + "\r\nMESG:\r\n" + cond.getMessage() + "\r\nRPRT:\r\n" + cond.getConditionReport() + "\r\n"; DLRConsole.DebugWriteLine(s); // if (true) return previous.execute(args); if (args[0] is UndefinedFunction) { UndefinedFunction u = (UndefinedFunction)args[0]; return(ABCLInterpreter.COMMON_ABCLInterpreter.makeFunction(u.getCellName())); } if (args[0] is UnboundVariable) { UnboundVariable u = (UnboundVariable)args[0]; return(ABCLInterpreter.COMMON_ABCLInterpreter.makeVariable(u.getCellName())); } lock (ABCLInterpreter.SubThreadInDebugMutex) { bool wasDebugging = ABCLInterpreter.IsSubThreadInDebug; try { ABCLInterpreter.IsSubThreadInDebug = true; previous.execute(args); //throw new ConditionThrowable(cond); } finally { ABCLInterpreter.IsSubThreadInDebug = wasDebugging; } } } throw new MissingMethodException(Lisp.javaString(args[0])); } // method: execute
public void StringLength() { LispAssert.EvaluatesTo(Lisp.Constant(4), Lisp.List(Lisp.Symbol("string-length"), Lisp.Constant("test"))); LispAssert.EvaluatesTo(Lisp.Constant(0), Lisp.List(Lisp.Symbol("string-length"), Lisp.Constant(""))); }
public void Parse(Lisp.Parser parser) { int d = parser.Depth; while(parser.Parse() && parser.Depth >= d) { if(parser.Depth == d+1) { if(parser.Type != Parser.LispType.SYMBOL) throw new Exception("expected SYMBOL at supertux-tiles level, but got \"" + parser.StringValue + "\""); string symbol = parser.SymbolValue; parser.Parse(); switch(symbol) { case "name": Name = parser.StringValue; break; case "tiles": do { Tiles.Add(parser.IntegerValue); } while(parser.Parse() && parser.Type == Parser.LispType.INTEGER); break; default: Console.WriteLine("Unknown section " + symbol); break; } } } }
public void ListToString() { LispAssert.EvaluatesTo(Lisp.Constant("test"), Lisp.List(Lisp.Symbol("list->string"), Lisp.Quote(Lisp.List(Lisp.Constant('t'), Lisp.Constant('e'), Lisp.Constant('s'), Lisp.Constant('t'))))); LispAssert.EvaluatesTo(Lisp.Constant(""), Lisp.List(Lisp.Symbol("list->string"), Lisp.Nil)); }
public void Can_import_into_global_symbols() { var SExprs = Lisp.Parse("(fib 10)"); var lispCtx = Lisp.CreateInterpreter(); try { lispCtx.Eval(SExprs); Assert.Fail("should throw"); } catch (LispEvalException e) {} Lisp.Import(@" (defun fib (n) (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2)) ) )) "); lispCtx = Lisp.CreateInterpreter(); Assert.That(lispCtx.Eval(SExprs), Is.EqualTo(89)); Lisp.Reset(); lispCtx = Lisp.CreateInterpreter(); try { lispCtx.Eval(SExprs); Assert.Fail("should throw"); } catch (LispEvalException e) {} }
public override object GetSymbol(string eventName) { eventName = eventName.ToLower(); Symbol s = Lisp.getCurrentPackage().findAccessibleSymbol(eventName); return(s); }
public void TestTreeToList() { var tree = Lisp.Parse("((cons 0) ((cons ((cons 0) ((cons ((cons 0) nil)) ((cons 0) ((cons nil) nil))))) ((cons ((cons ((cons ((cons -1) -3)) ((cons ((cons 0) -3)) ((cons ((cons 1) -3)) ((cons ((cons 2) -2)) ((cons ((cons -2) -1)) ((cons ((cons -1) -1)) ((cons ((cons 0) -1)) ((cons ((cons 3) -1)) ((cons ((cons -3) 0)) ((cons ((cons -1) 0)) ((cons ((cons 1) 0)) ((cons ((cons 3) 0)) ((cons ((cons -3) 1)) ((cons ((cons 0) 1)) ((cons ((cons 1) 1)) ((cons ((cons 2) 1)) ((cons ((cons -2) 2)) ((cons ((cons -1) 3)) ((cons ((cons 0) 3)) ((cons ((cons 1) 3)) nil))))))))))))))))))))) ((cons ((cons ((cons -7) -3)) ((cons ((cons -8) -2)) nil))) ((cons nil) nil)))) nil)))").Children.First(); //var tree = Program.Parse("ap ap cons 42 nil"); //var tree = Program.Parse("ap ap cons 42 ap ap cons ap ap cons 13 ap ap cons 101 nil nil"); //Console.WriteLine(Program.TreeToJson(tree)); }
public async Task TestDefaultStartingParams() { var startingParams = new LispNode() { new LispNode(1), new LispNode(0), new LispNode(0), new LispNode(1), }; var create = Common.Flatten(await Common.Send(Common.Unflatten(Lisp.Parse("(1 6)")[0]))); var playerKey = create[1][0][1]; var tasks = new List <Task <LispNode> >(); tasks.Add(Common.Send(Common.Unflatten(new LispNode() { new LispNode(2), create[1][0][1], new LispNode() }))); //tasks.Add(Common.Send(Common.Unflatten(new LispNode() { new LispNode(2), playerKey, new LispNode() }))); Task.WaitAll(tasks.ToArray()); var join = Common.Flatten(tasks[0].Result); var start = Common.Flatten(await Common.Send(Common.Unflatten(new LispNode() { new LispNode(3), playerKey, startingParams }))); }
public void Can_eval_fib_lisp() { var lisp = @" (defun fib (n) (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2)) ) )) "; try { var lispCtx = Lisp.CreateInterpreter(); var sExpressions = Lisp.Parse(lisp); var x = lispCtx.Eval(sExpressions); $"{x}".Print(); sExpressions = Lisp.Parse("(fib 15)"); x = lispCtx.Eval(sExpressions); $"{x}".Print(); Assert.That((int)x, Is.EqualTo(987)); } catch (Exception e) { Console.WriteLine(e); throw; } }
public void ProperListToString() { ILispValue properList = Lisp.List(Lisp.Symbol("test"), Lisp.Constant(1), Lisp.Constant("foo"), Lisp.List(Lisp.Constant(1), Lisp.Constant(2), Lisp.Constant(3)), Lisp.Constant(true)); Assert.IsInstanceOfType(properList, typeof(ConsBox)); Assert.AreEqual("(test 1 \"foo\" (1 2 3) #t)", properList.ToString()); }
public void StringToList() { LispAssert.EvaluatesTo(Lisp.List(Lisp.Constant('t'), Lisp.Constant('e'), Lisp.Constant('s'), Lisp.Constant('t')), Lisp.List(Lisp.Symbol("string->list"), Lisp.Constant("test"))); LispAssert.EvaluatesTo(Lisp.Nil, Lisp.List(Lisp.Symbol("string->list"), Lisp.Constant(""))); }
public void If() { ILispEnvironment environment = new GlobalEnvironment(); environment.Set(new Symbol("kablooey"), new NativeLambda { Body = parameters => { throw new LispException("kablooey!"); } }); // Ensure only the "then" clause is evaluated on a true condition. LispAssert.EvaluatesTo(Lisp.Constant(1), Lisp.List(Lisp.Symbol("if"), Lisp.Constant(true), Lisp.Constant(1), Lisp.List(Lisp.Symbol("kablooey"))), environment); LispAssert.ThrowsWhenEvaluated( Lisp.List(Lisp.Symbol("if"), Lisp.Constant(true), Lisp.List(Lisp.Symbol("kablooey")), Lisp.Constant(1)), environment); // Ensure only the "else" clause is evaluated on a false condition. LispAssert.EvaluatesTo(Lisp.Constant(1), Lisp.List(Lisp.Symbol("if"), Lisp.Constant(false), Lisp.List(Lisp.Symbol("kablooey")), Lisp.Constant(1)), environment); LispAssert.ThrowsWhenEvaluated( Lisp.List(Lisp.Symbol("if"), Lisp.Constant(false), Lisp.Constant(1), Lisp.List(Lisp.Symbol("kablooey"))), environment); // Ensure the test condition clause is evaluated. In this case, a non-empty list would be true if not // evaluated, but evaluating the expression will produce false. LispAssert.EvaluatesTo(Lisp.Constant(2), Lisp.List(Lisp.Symbol("if"), Lisp.List(Lisp.Symbol("number?"), Lisp.Symbol("car")), Lisp.Constant(1), Lisp.Constant(2))); // Test truth / falsiness of non-boolean - only #f and () should count as false. LispAssert.EvaluatesTo(Lisp.Constant(2), Lisp.List(Lisp.Symbol("if"), Lisp.Nil, Lisp.Constant(1), Lisp.Constant(2))); LispAssert.EvaluatesTo(Lisp.Constant(1), Lisp.List(Lisp.Symbol("if"), Lisp.Quote(Lisp.List(Lisp.Constant(false))), Lisp.Constant(1), Lisp.Constant(2))); LispAssert.EvaluatesTo(Lisp.Constant(1), Lisp.List(Lisp.Symbol("if"), Lisp.Constant(""), Lisp.Constant(1), Lisp.Constant(2))); LispAssert.EvaluatesTo(Lisp.Constant(1), Lisp.List(Lisp.Symbol("if"), Lisp.Symbol("cdr"), Lisp.Constant(1), Lisp.Constant(2))); }
public void ImproperListToString() { ConsBox improperList = new ConsBox { Head = Lisp.Symbol("test"), Tail = Lisp.Constant(1) }; Assert.AreEqual("(test . 1)", improperList.ToString()); }
internal LispObject Evaluate(string command) { getInterpreter(); LispObject cmd = Lisp.readObjectFromString(command); LispObject result = Lisp.eval(cmd); return(result); }
public void List() { LispAssert.EvaluatesTo(Lisp.Nil, Lisp.List(Lisp.Symbol("list"))); LispAssert.EvaluatesTo(Lisp.List(Lisp.Constant(1)), Lisp.List(Lisp.Symbol("list"), Lisp.Constant(1))); LispAssert.EvaluatesTo(Lisp.List(Lisp.Constant(1), Lisp.Constant(2)), Lisp.List(Lisp.Symbol("list"), Lisp.Constant(1), Lisp.Constant(2))); }
public void Cons() { LispAssert.EvaluatesTo(Lisp.List(Lisp.Constant(1)), Lisp.List(Lisp.Symbol("cons"), Lisp.Constant(1), Lisp.Nil)); LispAssert.EvaluatesTo(Lisp.List(Lisp.Constant(1), Lisp.Constant(2)), Lisp.List(Lisp.Symbol("cons"), Lisp.Constant(1), Lisp.Quote(Lisp.List(Lisp.Constant(2))))); LispAssert.EvaluatesTo(Lisp.Cons(Lisp.Constant(1), Lisp.Constant(2)), Lisp.List(Lisp.Symbol("cons"), Lisp.Constant(1), Lisp.Constant(2))); }
public void MakeString() { LispAssert.EvaluatesTo(Lisp.Constant("xxxxxxxxxx"), Lisp.List(Lisp.Symbol("make-string"), Lisp.Constant(10), Lisp.Constant('x'))); LispAssert.ThrowsWhenEvaluated( Lisp.List(Lisp.Symbol("make-string"), Lisp.Constant(9.3m), Lisp.Constant('x'))); LispAssert.EvaluatesTo(Lisp.Constant(8), Lisp.List(Lisp.Symbol("string-length"), Lisp.List(Lisp.Symbol("make-string"), Lisp.Constant(8)))); }
public void Length() { LispAssert.EvaluatesTo(Lisp.Constant(0), Lisp.List(Lisp.Symbol("length"), Lisp.Nil)); LispAssert.EvaluatesTo(Lisp.Constant(1), Lisp.List(Lisp.Symbol("length"), Lisp.Quote(Lisp.List(Lisp.Constant(1))))); LispAssert.EvaluatesTo(Lisp.Constant(2), Lisp.List(Lisp.Symbol("length"), Lisp.Quote(Lisp.List(Lisp.Constant(1), Lisp.Constant(2))))); LispAssert.EvaluatesTo(Lisp.Constant(5), Lisp.List(Lisp.Symbol("length"), Lisp.Quote(Lisp.List(Lisp.Constant(1), Lisp.Constant(2), Lisp.Constant(3), Lisp.Constant(4), Lisp.Constant(5))))); }
public void Reverse() { LispAssert.EvaluatesTo(Lisp.Nil, Lisp.List(Lisp.Symbol("reverse"), Lisp.Nil)); LispAssert.EvaluatesTo(Lisp.List(Lisp.Constant(1)), Lisp.List(Lisp.Symbol("reverse"), Lisp.Quote(Lisp.List(Lisp.Constant(1))))); LispAssert.EvaluatesTo(Lisp.List(Lisp.Constant(2), Lisp.Constant(1)), Lisp.List(Lisp.Symbol("reverse"), Lisp.Quote(Lisp.List(Lisp.Constant(1), Lisp.Constant(2))))); LispAssert.EvaluatesTo(Lisp.List(Lisp.Constant(5), Lisp.Constant(4), Lisp.Constant(3), Lisp.Constant(2), Lisp.Constant(1)), Lisp.List(Lisp.Symbol("reverse"), Lisp.Quote(Lisp.List(Lisp.Constant(1), Lisp.Constant(2), Lisp.Constant(3), Lisp.Constant(4), Lisp.Constant(5))))); }
public void StringP() { LispAssert.EvaluatesTo(Lisp.Constant(true), Lisp.List(Lisp.Symbol("string?"), Lisp.Constant("test"))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("string?"), Lisp.Constant(true))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("string?"), Lisp.Constant('x'))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("string?"), Nil.Instance)); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("string?"), Lisp.Constant(5))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("string?"), Lisp.Quote(Lisp.Symbol("test")))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("string?"), new UndefinedValue())); }
public override bool IsSubscriberOf(string eventName) { eventName = eventName.ToUpper(); Symbol s = Lisp.getCurrentPackage().findAccessibleSymbol(eventName); LispObject fun = s.getSymbolFunction(); if (fun == null || fun == Lisp.NIL) { return(false); } return(true); }
public void ListP() { LispAssert.EvaluatesTo(Lisp.Constant(true), Lisp.List(Lisp.Symbol("list?"), Lisp.Nil)); LispAssert.EvaluatesTo(Lisp.Constant(true), Lisp.List(Lisp.Symbol("list?"), Lisp.Quote(Lisp.List(Lisp.Constant(1), Lisp.Symbol("a"))))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("list?"), Lisp.Constant(true))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("list?"), Lisp.Constant('x'))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("list?"), Lisp.Constant(5))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("list?"), Lisp.Constant("test"))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("list?"), Lisp.Quote(Lisp.Symbol("test")))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("list?"), new UndefinedValue())); }
public void NumberP() { LispAssert.EvaluatesTo(Lisp.Constant(true), Lisp.List(Lisp.Symbol("number?"), Lisp.Constant(5))); LispAssert.EvaluatesTo(Lisp.Constant(true), Lisp.List(Lisp.Symbol("number?"), Lisp.Constant(9.95m))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("number?"), Lisp.Constant(true))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("number?"), Lisp.Constant('x'))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("number?"), Nil.Instance)); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("number?"), Lisp.Constant("test"))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("number?"), Lisp.Quote(Lisp.Symbol("test")))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("number?"), new UndefinedValue())); }
public void LambdaP() { LispAssert.EvaluatesTo(Lisp.Constant(true), Lisp.List(Lisp.Symbol("lambda?"), Lisp.Symbol("lambda?"))); // TODO: add test for user-defined function LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("lambda?"), Lisp.Constant(true))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("lambda?"), Lisp.Constant('x'))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("lambda?"), Nil.Instance)); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("lambda?"), Lisp.Constant(5))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("lambda?"), Lisp.Constant("test"))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("lambda?"), Lisp.Quote(Lisp.Symbol("test")))); LispAssert.EvaluatesTo(Lisp.Constant(false), Lisp.List(Lisp.Symbol("lambda?"), new UndefinedValue())); }
public void Can_min_max_int_long_double_values() { var lispCtx = Lisp.CreateInterpreter(); Assert.That((int)lispCtx.Eval(Lisp.Parse("(min 1 2)")), Is.EqualTo(1)); Assert.That((int)lispCtx.Eval(Lisp.Parse("(max 1 2)")), Is.EqualTo(2)); Assert.That((double)lispCtx.Eval(Lisp.Parse("(min 1.0 2.0)")), Is.EqualTo(1.0)); Assert.That((double)lispCtx.Eval(Lisp.Parse("(max 1.0 2.0)")), Is.EqualTo(2.0)); Assert.That((long)lispCtx.Eval(Lisp.Parse($"(min {int.MaxValue + 1L} {int.MaxValue + 2L})")), Is.EqualTo(int.MaxValue + 1L)); Assert.That((long)lispCtx.Eval(Lisp.Parse($"(max {int.MaxValue + 1L} {int.MaxValue + 2L})")), Is.EqualTo(int.MaxValue + 2L)); }
public void Cdr() { LispAssert.EvaluatesTo(Lisp.List(Lisp.Constant(2), Lisp.Constant(3)), Lisp.List(Lisp.Symbol("cdr"), Lisp.Quote(Lisp.List(Lisp.Constant(1), Lisp.Constant(2), Lisp.Constant(3))))); LispAssert.EvaluatesTo(Lisp.Nil, Lisp.List(Lisp.Symbol("cdr"), Lisp.Quote(Lisp.List(Lisp.Constant(1))))); LispAssert.EvaluatesTo(Lisp.Constant(2), Lisp.List(Lisp.Symbol("cdr"), Lisp.Quote(Lisp.Cons(Lisp.Constant(1), Lisp.Constant(2))))); LispAssert.ThrowsWhenEvaluated(Lisp.List(Lisp.Symbol("cdr"), Lisp.Nil)); LispAssert.ThrowsWhenEvaluated <TypeMismatchException>(Lisp.List(Lisp.Symbol("cdr"), Lisp.Constant(3))); LispAssert.ThrowsWhenEvaluated <SignatureMismatchException>(Lisp.List(Lisp.Symbol("cdr"))); }
public override object Read(string p, TextReader stringCodeReader, OutputDelegate WriteLine) { try { getInterpreter(); return(Lisp.readObjectFromString(stringCodeReader.ReadToEnd())); } catch (Exception e) { WriteLine(e.ToString()); return(Lisp.EOF); } }
public void StringRef() { LispAssert.EvaluatesTo(Lisp.Constant('t'), Lisp.List(Lisp.Symbol("string-ref"), Lisp.Constant("test"), Lisp.Constant(0))); LispAssert.EvaluatesTo(Lisp.Constant('s'), Lisp.List(Lisp.Symbol("string-ref"), Lisp.Constant("test test test"), Lisp.Constant(12))); LispAssert.ThrowsWhenEvaluated( Lisp.List(Lisp.Symbol("string-ref"), Lisp.Constant("test"), Lisp.Constant(-1))); LispAssert.ThrowsWhenEvaluated( Lisp.List(Lisp.Symbol("string-ref"), Lisp.Constant("test"), Lisp.Constant(4))); LispAssert.ThrowsWhenEvaluated( Lisp.List(Lisp.Symbol("string-ref"), Lisp.Constant("test"), Lisp.Constant(2.2m))); }
static void ExecuteFuelScript(string script) { var model = new TestModel("fuel"); // create a dictionary with name <--> object pairs // the objects will be registered under the name in the fuel interpreter var nativeItems = new Dictionary <string, object>(); nativeItems["model"] = model; LispVariant result = Lisp.Eval(script, nativeItems: nativeItems); Console.WriteLine("Script result={0}", result); }
public void ProperListConstruction() { ILispValue helperConstructedList = Lisp.List( Lisp.Symbol("test"), Lisp.Constant(1), Lisp.Constant("foo"), Lisp.List(Lisp.Constant(1), Lisp.Constant(2), Lisp.Constant(3)), Lisp.Constant(true)); ILispValue manuallyConstructedList = new ConsBox { Head = Lisp.Symbol("test"), Tail = new ConsBox { Head = Lisp.Constant(1), Tail = new ConsBox { Head = Lisp.Constant("foo"), Tail = new ConsBox { Head = new ConsBox { Head = Lisp.Constant(1), Tail = new ConsBox { Head = Lisp.Constant(2), Tail = new ConsBox { Head = Lisp.Constant(3), Tail = Nil.Instance } } }, Tail = new ConsBox { Head = Lisp.Constant(true), Tail = Nil.Instance } } } } }; // Do not use Assert.AreEqual here since it doesn't use IEquatable. LispAssert.AreEqual(manuallyConstructedList, helperConstructedList); }
public void Subtract() { LispAssert.EvaluatesTo(Lisp.Constant(-1), Lisp.List(Lisp.Symbol("-"), Lisp.Constant(1))); LispAssert.EvaluatesTo(Lisp.Constant(-1), Lisp.List(Lisp.Symbol("-"), Lisp.Constant(1), Lisp.Constant(2))); LispAssert.EvaluatesTo(Lisp.Constant(-4), Lisp.List(Lisp.Symbol("-"), Lisp.Constant(1), Lisp.Constant(2), Lisp.Constant(3))); LispAssert.EvaluatesTo(Lisp.Constant(-0.1m), Lisp.List(Lisp.Symbol("-"), Lisp.Constant(3.1m), Lisp.Constant(2.1m), Lisp.Constant(1.1m))); LispAssert.EvaluatesTo(Lisp.Constant(0.1m), Lisp.List(Lisp.Symbol("-"), Lisp.Constant(3.1m), Lisp.Constant(2), Lisp.Constant(1))); LispAssert.EvaluatesTo(Lisp.Constant(-0.1m), Lisp.List(Lisp.Symbol("-"), Lisp.Constant(3), Lisp.Constant(2.1m), Lisp.Constant(1))); LispAssert.EvaluatesTo(Lisp.Constant(-0.1m), Lisp.List(Lisp.Symbol("-"), Lisp.Constant(3), Lisp.Constant(2), Lisp.Constant(1.1m))); }
public Tilemap(Tileset Tileset, Lisp.List Data) { this.Tileset = Tileset; Properties Props = new Properties(Data); uint Width = 0; uint Height = 0; Props.Get("width", ref Width); Props.Get("height", ref Height); if(Width == 0 || Height == 0) throw new Exception("Width or Height of Tilemap invalid"); List<uint> Tiles = new List<uint>(); Props.GetUIntList("tiles", Tiles); if(Tiles.Count != (int) (Width * Height)) throw new Exception("TileCount != Width*Height"); Props.Get("solid", ref Solid); Props.PrintUnusedWarnings(); Field = new Field<uint>(Tiles, Width, Height); }
public void Parse(Lisp.Parser parser) { int d = parser.Depth; while(parser.Parse() && parser.Depth >= d) { if(parser.Depth == d+1) { if(parser.Type != Parser.LispType.SYMBOL) throw new Exception("expected SYMBOL"); string symbol = parser.SymbolValue; parser.Parse(); switch(symbol) { case "id": ID = parser.IntegerValue; break; case "images": ParseTileImages(parser); break; case "editor-images": EditorImage = parser.StringValue; break; case "solid": Solid = parser.BoolValue; break; case "unisolid": UniSolid = parser.BoolValue; break; case "ice": Ice = parser.BoolValue; break; case "water": Water = parser.BoolValue; break; case "slope-type": Slope = true; Data = parser.IntegerValue; break; case "anim-fps": AnimFps = parser.FloatValue; break; case "hurts": Hurts = parser.BoolValue; break; case "hidden": Hidden = parser.BoolValue; break; case "data": Data = parser.IntegerValue; break; case "next-tile": NextTile = parser.IntegerValue; break; case "brick": Brick = parser.BoolValue; break; case "fullbox": FullBox = parser.BoolValue; break; case "coin": Coin = parser.BoolValue; break; case "goal": Goal = parser.BoolValue; break; default: Console.WriteLine("Unknown tile element " + symbol); break; } } } }
public void ParseTiles(Lisp.Parser parser) { isNew = false; int d = parser.Depth; while(parser.Parse() && parser.Depth >= d) { if(parser.Depth == d && parser.Type != Parser.LispType.START_LIST) { Console.WriteLine("non-cons type in list..."); continue; } if(parser.Depth == d+1) { if(parser.Type != Parser.LispType.SYMBOL) { throw new Exception("Expected symbol in list element"); } switch(parser.SymbolValue) { case "properties": SkipList(parser); break; case "tilegroup": TileGroup tilegroup = new TileGroup(); tilegroup.Parse(parser); TileGroups.Add(tilegroup); break; case "tile": Tile tile = new Tile(); tile.Parse(parser); while(tile.ID >= Tiles.Count) Tiles.Add(null); Tiles[tile.ID] = tile; break; case "tiles": ParseMoreTiles(parser); isNew = true; break; default: throw new Exception("Unexpected listentry: " + parser.SymbolValue); } } } }
public void ParseMoreTiles(Lisp.Parser parser) { int blockWidth = 0; int blockHeight = 0; List<int> ids = new List<int>(); List<int> attributes = new List<int>(); List<int> datas = new List<int>(); List<string> imageNames = new List<string>(); float animFps = 0; int d = parser.Depth; while(parser.Parse() && parser.Depth >= d) { if(parser.Depth == d+1) { if(parser.Type != Parser.LispType.SYMBOL) throw new Exception("expected SYMBOL at supertux-tiles---tiles level, but got \"" + parser.StringValue + "\""); string symbol = parser.SymbolValue; parser.Parse(); switch(symbol) { case "width": blockWidth = parser.IntegerValue; break; case "height": blockHeight = parser.IntegerValue; break; case "ids": Parser.ParseIntList(parser, ids); break; case "attributes": Parser.ParseIntList(parser, attributes); break; case "datas": Parser.ParseIntList(parser, datas); break; case "anim-fps": animFps = parser.FloatValue; break; case "image": int subDepth = parser.Depth; while(parser.Depth >= subDepth) { imageNames.Add(parser.StringValue); parser.Parse(); } break; default: Console.WriteLine("Unknown tiles element " + symbol); break; } } } if(ids.Count != blockWidth * blockHeight) throw new ApplicationException("Must have width*height ids in tiles block, but found " + ids.Count.ToString()); if((attributes.Count != blockWidth * blockHeight) && attributes.Count > 0) //missing atributes == all-are-0-attributes throw new ApplicationException("Must have width*height attributes in tiles block"); if((datas.Count != blockWidth * blockHeight) && datas.Count > 0) //missing DATAs == all-are-0-DATAs throw new ApplicationException("Must have width*height DATAs in tiles block"); int id = 0; for(int y = 0; y < blockHeight; ++y) { for(int x = 0; x < blockWidth; ++x) { if (ids[id] != 0) { Tile tile = new Tile(); tile.Images = new ArrayList(); foreach (string str in imageNames) { ImageRegion region = new ImageRegion(); region.ImageFile = str; region.Region.X = x * TILE_WIDTH; region.Region.Y = y * TILE_HEIGHT; region.Region.Width = TILE_WIDTH; region.Region.Height = TILE_HEIGHT; tile.Images.Add(region); } tile.ID = ids[id]; tile.Attributes = (attributes.Count > 0)?attributes[id]:0; //missing atributes == all-are-0-attributes tile.Data = (datas.Count > 0)?datas[id]:0; //missing DATAs == all-are-0-DATAs tile.AnimFps = animFps; while(Tiles.Count <= tile.ID) Tiles.Add(null); Tiles[tile.ID] = tile; } id++; } } }
public PathNode(Lisp.Parser parser) { int d = parser.Depth; while (parser.Parse() && parser.Depth >= d) { if (parser.Depth == d + 1) { if (parser.Type != Lisp.Parser.LispType.SYMBOL) throw new Exception("expected SYMBOL"); string symbol = parser.SymbolValue; parser.Parse(); switch (symbol) { case "x": this.x = parser.FloatValue; break; case "y": this.x = parser.FloatValue; break; case "time": this.x = parser.FloatValue; break; default: throw new Exception("Unknown Token in Path Node"); } } } }
private void ParseImageRegion(Lisp.Parser parser, ImageRegion region) { parser.Parse(); if(parser.Type != Parser.LispType.SYMBOL) throw new Exception("expected symbol"); if(parser.SymbolValue != "region") throw new Exception("expected region symbol"); parser.Parse(); if(parser.Type != Parser.LispType.STRING) throw new Exception("expected string"); region.ImageFile = parser.StringValue; parser.Parse(); if(parser.Type != Parser.LispType.INTEGER) throw new Exception("expected integer"); region.Region.X = parser.IntegerValue; parser.Parse(); if(parser.Type != Parser.LispType.INTEGER) throw new Exception("expected integer"); region.Region.Y = parser.IntegerValue; parser.Parse(); if(parser.Type != Parser.LispType.INTEGER) throw new Exception("expected integer"); region.Region.Width = parser.IntegerValue; parser.Parse(); if(parser.Type != Parser.LispType.INTEGER) throw new Exception("expected integer"); region.Region.Height = parser.IntegerValue; parser.Parse(); if(parser.Type != Parser.LispType.END_LIST) throw new Exception("expected END_LIST"); }
private void SkipList(Lisp.Parser parser) { int d = parser.Depth; while(parser.Parse() && parser.Depth >= d) ; }
protected override bool tryParse(string symbol, Lisp.Parser parser) { switch (symbol) { case "name": this.name = parser.StringValue; return true; case "node": this.pathNodes.Add(new PathNode(parser)); return true; default: return base.tryParse(symbol, parser); } }
public void Parse(Lisp.Parser parser) { int d = parser.Depth; while(parser.Parse() && parser.Depth >= d) { if(parser.Depth == d+1) { if(parser.Type != Parser.LispType.SYMBOL) throw new Exception("expected SYMBOL at single tile deserialization level, but found \"" + parser.StringValue + "\""); string symbol = parser.SymbolValue; parser.Parse(); switch(symbol) { case "id": ID = parser.IntegerValue; break; case "images": ParseTileImages(parser, Images); break; case "editor-images": ParseTileImages(parser, EditorImages); break; case "anim-fps": AnimFps = parser.FloatValue; break; case "one-way": OneWayString = parser.StringValue; break; case "data": Data = parser.IntegerValue; break; case "next-tile": NextTile = parser.IntegerValue; break; case "hidden": Hidden = parser.BoolValue; break; case "solid": SetAttribute(Attribute.SOLID, parser.BoolValue); break; case "unisolid": SetAttribute(Attribute.UNISOLID, parser.BoolValue); break; case "ice": SetAttribute(Attribute.ICE, parser.BoolValue); break; case "water": SetAttribute(Attribute.WATER, parser.BoolValue); break; case "slope-type": SetAttribute(Attribute.SLOPE, true); Data = parser.IntegerValue; break; case "hurts": SetAttribute(Attribute.HURTS, parser.BoolValue); break; case "fire": SetAttribute(Attribute.FIRE, parser.BoolValue); break; case "brick": SetAttribute(Attribute.BRICK, parser.BoolValue); break; case "fullbox": SetAttribute(Attribute.FULLBOX, parser.BoolValue); break; case "coin": SetAttribute(Attribute.COIN, parser.BoolValue); break; case "goal": SetAttribute(Attribute.GOAL, parser.BoolValue); break; //Worldmap attributes section - these are stored in Data case "north": SetWMAttribute(Attribute.WORLDMAP_NORTH, parser.BoolValue); break; case "south": SetWMAttribute(Attribute.WORLDMAP_SOUTH, parser.BoolValue); break; case "west": SetWMAttribute(Attribute.WORLDMAP_WEST, parser.BoolValue); break; case "east": SetWMAttribute(Attribute.WORLDMAP_EAST, parser.BoolValue); break; case "stop": SetWMAttribute(Attribute.WORLDMAP_STOP, parser.BoolValue); break; default: Console.WriteLine("Unknown tile element " + symbol); break; } } } }
public override GameObject ParseAsThis(string name, Lisp.Parser parser) { return new SpatialGameObject(name, parser); }
private void ParseTileImages(Lisp.Parser parser, ArrayList ImagesList) { if(parser.Type == Parser.LispType.END_LIST) return; int d = parser.Depth; do { ImageRegion region = new ImageRegion(); if(parser.Type == Parser.LispType.STRING) { region.ImageFile = parser.StringValue; } else if(parser.Type == Parser.LispType.START_LIST) { ParseImageRegion(parser, region); } else { throw new Exception("unexpected lisp data: " + parser.Type); } ImagesList.Add(region); } while(parser.Parse() && parser.Depth >= d); }
public Path(string name, Lisp.Parser parser) : base(name, parser) { }