示例#1
0
        public static string parseFirstBlockNode(string program, out BlockNode node)
        {
            int    firstBlockStart = int.MaxValue;
            int    firstBlockEnd   = int.MaxValue;
            String firstBlock      = "";
            //Get the next block op name
            String opName = program.Trim().Split(BLOCK_NAME_SPLIT, StringSplitOptions.RemoveEmptyEntries)[0].Trim();

            if (allBlockNodes.ContainsKey(opName))
            {
                BlockNode foundNode = allBlockNodes[opName];

                int    startLocation, endLocation;
                String block =
                    BlockNode.getFullStartAndEndLocations
                        (program, foundNode.getOpName(), out startLocation, out endLocation);
                if (firstBlockStart > startLocation)
                {
                    firstBlockStart = startLocation;
                    firstBlockEnd   = endLocation;
                    firstBlock      = block;
                }
                //store the program in the list
                node = loadBlockProgram(firstBlock);
            }
            else
            {
                node = null;
                addError("Could not find block node with Op Name: " + opName);
            }

            String strippedProgram = program.Substring(firstBlockEnd);

            return(strippedProgram);
        }
示例#2
0
        public static BlockNode loadBlockProgram(String parsedBlock)
        {
            //TODO search for nested programs.
            String    firstLine = parsedBlock.Split(OP_SPLIT, StringSplitOptions.RemoveEmptyEntries)[0];
            String    nodeName  = firstLine.Replace(BlockNode.START, "").Trim();
            BlockNode node;

            if (allBlockNodes.TryGetValue(nodeName, out node))
            {
                BlockNode createdNode   = node.createInstance();
                String    internalBlock = BlockNode.getInternalBlockText(createdNode.getOpName(), parsedBlock);
                createdNode.parseBlocks(internalBlock);
                //nodes.Add(createdNode);
                return(createdNode);
            }
            else
            {
                //Throw Error
                errors += "Failed to parse line: " + firstLine;
                return(null);
            }
        }
示例#3
0
 public static void addAllNode(BlockNode node)
 {
     allBlockNodes.Add(node.getOpName(), node);
     allProgramNodeInterfaces.Add(node);
 }