public override string Interpret(ref XmlToPythonContext context) { base.Interpret(ref context); string value = string.Empty, unit = string.Empty; var nodes = context.currentNode.ChildNodes; foreach (XmlNode node in nodes) { context.currentNode = node; switch (node.Name) { case "field": unit = new Field().Interpret(ref context); if (!Enum.GetNames(typeof(TemperatureUnit)).Contains(unit)) { throw new Exception("Unknown unit of temperature:" + unit); } break; case "value": value = new Values.Number().Interpret(ref context); break; default: throw new Exception("unexpected xml node name"); } } var result = string.Format(LiteralsPython.FunctionCall, LiteralsPython.Temperature, value + ",\"" + unit + "\""); return(result); }
/// <summary> /// Interpret context as <see cref="Lamp"/> /// </summary> /// <param name="context">Context to interpret</param> /// <returns>Python code</returns> public override string Interpret(ref XmlToPythonContext context) { base.Interpret(ref context); context.NextNode(); var result = (new Blocks.Lamp()).Interpret(ref context); context.ParentNode(); return(result); }
/// <summary> /// Interpret context as <see cref="Number"/> /// </summary> /// <param name="context">Context to interpret</param> /// <returns>Python code</returns> public override string Interpret(ref XmlToPythonContext context) { base.Interpret(ref context); context.NextNode(); var result = new Field().Interpret(ref context); context.ParentNode(); return(result); }
/// <summary> /// Interpret context as <see cref="Event"/> /// </summary> /// <param name="context">Context to interpret</param> /// <returns>Python code</returns> public override string Interpret(ref XmlToPythonContext context) { base.Interpret(ref context); context.NextNode(); var result = EventStarters[context.currentNode.Attributes["type"].Value].Interpret(ref context); context.ParentNode(); return(result); }
/// <summary> /// Interpret context as <see cref="FunctionCallBlock{InputValueType}"/> /// </summary> /// <param name="context">Context to interpret</param> /// <returns>Python code</returns> public override string Interpret(ref XmlToPythonContext context) { base.Interpret(ref context); context.NextNode(); var result = string.Format(LiteralsPython.FunctionCall, FunctionLiteral, (new InputValueType()).Interpret(ref context)); context.ParentNode(); return(result); }
public override string Interpret(ref XmlToPythonContext context) { base.Interpret(ref context); var nodes = context.currentNode.ChildNodes; string OP = string.Empty; string A = string.Empty; string B = string.Empty; foreach (XmlNode n in nodes) { context.currentNode = n; switch (n.Attributes["name"].Value) { case "OP": OP = new Field().Interpret(ref context); break; //TODO: add attribute for comparables case "A": context.NextNode(); if (OP == "EQ" || OP == "NEQ") { A = EqBlocks[context.currentNode.Attributes["type"].Value] .Interpret(ref context); } else { A = ComBlocks[context.currentNode.Attributes["type"].Value] .Interpret(ref context); } break; case "B": context.NextNode(); if (OP == "EQ" || OP == "NEQ") { B = EqBlocks[context.currentNode.Attributes["type"].Value] .Interpret(ref context); } else { B = ComBlocks[context.currentNode.Attributes["type"].Value] .Interpret(ref context); } break; default: throw new System.Exception(); } } //TODO: error handling var result = "(" + A + Operations[OP] + B + ")"; context.ParentNode(); return(result); }
public override string Interpret(ref XmlToPythonContext context) { base.Interpret(ref context); //TODO: create finder attribute for numbers, that are not just math_number context.NextNode(); var result = (new Blocks.Math.Number()).Interpret(ref context); context.ParentNode(); return(result); }
/// <summary> /// Interpret context as <see cref="MethodCallBlock{InputValueType}"/> /// </summary> /// <param name="context">Context to interpret</param> /// <returns>Python code</returns> public override string Interpret(ref XmlToPythonContext context) { base.Interpret(ref context); context.NextNode(); var result = string.Format(LiteralsPython.MethodCall, (new InputValueType()).Interpret(ref context), FunctionLiteral); context.ParentNode(); if (NeedNextCheck) { context.NextCheck(); } return(result); }
/// <summary> /// Interpret context as <see cref="Body"/> /// </summary> /// <param name="context">Context to interpret</param> /// <returns>Python code</returns> public override string Interpret(ref XmlToPythonContext context) { base.Interpret(ref context); context.tabCount = 1; var result = string.Empty; context.NextNode(); XmlNode prev; do { prev = context.currentNode; result += BlocklyTransformer.AddSpaces(context.tabCount) + (Blocks[context.currentNode.Attributes["type"].Value]).Interpret(ref context) + '\n'; } while (prev != context.currentNode); return(result); }
/// <summary> /// Interpret context as <see cref="Value"/> /// </summary> /// <param name="context">Context to interpret</param> /// <returns>Python code</returns> public override string Interpret(ref XmlToPythonContext context) { System.Diagnostics.Debug.Assert(context.currentNode.Name == "value"); return(null); }
/// <summary> /// Interpret some context /// </summary> /// <param name="context">Context to interpret</param> /// <returns>Code in Python</returns> public abstract string Interpret(ref XmlToPythonContext context);
/// <summary> /// Interpret context as <see cref="Script"/> /// </summary> /// <param name="context">Context to interpret</param> /// <returns>Python code</returns> public override string Interpret(ref XmlToPythonContext context) { base.Interpret(ref context); var node = context.currentNode; //add imports string result = string.Format(LiteralsPython.Import, LiteralsPython.PackageName) + '\n'; string ev = string.Empty; string body = string.Empty; string name = "None"; foreach (XmlNode item in node.ChildNodes) { context.currentNode = item; switch (item.Attributes["name"].Value) { //name of script case "NAME": name = (new Values.Name()).Interpret(ref context); break; //event of script case "EVENT": ev = (new Values.Event()).Interpret(ref context); break; //body of script case "BODY": body = (new Statements.Body()).Interpret(ref context); break; } } //declare event of script result += '\n'; result += LiteralsPython.Event + "\n" + BlocklyTransformer.AddSpaces(1) + LiteralsPython.EventStart; if (string.IsNullOrEmpty(ev)) { result += LiteralsPython.EmptyEvent; } else { result += ev; } //declare body of script result += "\n\n"; result += LiteralsPython.Body + "\n"; if (string.IsNullOrEmpty(body)) { result += BlocklyTransformer.AddSpaces(1) + LiteralsPython.EmptyBody; } else { result += body; } //declare script with name, event and body result += '\n'; result += string.Format(LiteralsPython.AddScript, name); return(result); }
/// <summary> /// Interpret context as <see cref="Field"/> /// </summary> /// <param name="context">Context to interpret</param> /// <returns>Python code</returns> public override string Interpret(ref XmlToPythonContext context) { System.Diagnostics.Debug.Assert(context.currentNode.Name == "field"); return(context.currentNode.InnerText); }