示例#1
0
        public void ParseWasteDeclarationBlock()
        {
            JSProgram program = new JSProgram();

            program.AddWasteDeclarationBlock("z");
            TestTools.ExecuteJS(program);

            XmlNode    node       = TestTools.GetWorkspace();
            ParserInfo parserInfo = new ParserInfo();

            parserInfo.EnterDFG();
            WasteDeclaration heater = (WasteDeclaration)XmlParser.ParseBlock(node, null, parserInfo, true);

            Assert.AreEqual(0, parserInfo.ParseExceptions.Count, parserInfo.ParseExceptions.FirstOrDefault()?.Message);
        }
示例#2
0
        public static Block ParseBlock(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo, bool allowDeclarationBlocks = false, bool canBeScheduled = true)
        {
            string id        = node.GetAttributeValue(Block.ID_FIELD_NAME);
            string blockType = node.GetAttributeValue(Block.TYPE_FIELD_NAME);

            switch (blockType)
            {
            case ArithOP.XML_TYPE_NAME:
                return(ArithOP.Parse(node, dfg, parserInfo, canBeScheduled));

            case Constant.XML_TYPE_NAME:
                return(Constant.Parse(node, parserInfo, canBeScheduled));

            case FluidArray.XML_TYPE_NAME:
                return(FluidArray.Parse(node, dfg, parserInfo));

            case SetArrayFluid.XML_TYPE_NAME:
                return(SetArrayFluid.Parse(node, dfg, parserInfo));

            case Fluid.XML_TYPE_NAME:
                return(Fluid.Parse(node, dfg, parserInfo));

            case InputDeclaration.XML_TYPE_NAME:
                if (!allowDeclarationBlocks)
                {
                    parserInfo.ParseExceptions.Add(new ParseException(id, "Declaration blocks has to be at the top of the program."));
                }
                return(InputDeclaration.Parse(node, parserInfo));

            case OutputDeclaration.XML_TYPE_NAME:
                if (!allowDeclarationBlocks)
                {
                    parserInfo.ParseExceptions.Add(new ParseException(id, "Declaration blocks has to be at the top of the program."));
                }
                return(OutputDeclaration.Parse(node, parserInfo));

            case WasteDeclaration.XML_TYPE_NAME:
                if (!allowDeclarationBlocks)
                {
                    parserInfo.ParseExceptions.Add(new ParseException(id, "Declaration blocks has to be at the top of the program."));
                }
                return(WasteDeclaration.Parse(node, parserInfo));

            case HeaterDeclaration.XML_TYPE_NAME:
                if (!allowDeclarationBlocks)
                {
                    parserInfo.ParseExceptions.Add(new ParseException(id, "Declaration blocks has to be at the top of the program."));
                }
                return(HeaterDeclaration.Parse(node, parserInfo));

            case OutputUsage.XML_TYPE_NAME:
                return(OutputUsage.Parse(node, dfg, parserInfo));

            case WasteUsage.XML_TYPE_NAME:
                return(WasteUsage.Parse(node, dfg, parserInfo));

            case DropletDeclaration.XML_TYPE_NAME:
                return(DropletDeclaration.Parse(node, parserInfo));

            case BoolOP.XML_TYPE_NAME:
                return(BoolOP.Parse(node, dfg, parserInfo, canBeScheduled));

            //case Sensor.XmlTypeName:
            //    return Sensor.Parse(node);
            case GetNumberVariable.XML_TYPE_NAME:
                return(GetNumberVariable.Parse(node, parserInfo, canBeScheduled));

            case SetNumberVariable.XML_TYPE_NAME:
                return(SetNumberVariable.Parse(node, dfg, parserInfo));

            case GetDropletCount.XML_TYPE_NAME:
                return(GetDropletCount.Parser(node, parserInfo, canBeScheduled));

            case GetArrayLength.XML_TYPE_NAME:
                return(GetArrayLength.Parse(node, parserInfo, canBeScheduled));

            case ImportVariable.XML_TYPE_NAME:
                return(ImportVariable.Parse(node, parserInfo, canBeScheduled));

            case NumberArray.XML_TYPE_NAME:
                return(NumberArray.Parse(node, dfg, parserInfo));

            case GetArrayNumber.XML_TYPE_NAME:
                return(GetArrayNumber.Parse(node, dfg, parserInfo, canBeScheduled));

            case SetArrayNumber.XML_TYPE_NAME:
                return(SetArrayNumber.Parse(node, dfg, parserInfo, canBeScheduled));

            case RoundOP.XML_TYPE_NAME:
                return(RoundOP.Parse(node, dfg, parserInfo, canBeScheduled));

            default:
                throw new UnknownBlockException(id);
            }
        }