Пример #1
0
        public static void parseVariable(ObservableCollection <Block> variables, EditorDragDropTarget page)
        {
            ReadOnlyObservableCollection <Block> list = page.getTreeList();

            indent(true);

            foreach (Block b in variables)
            {
                string s = "";
                foreach (String str in indentCount)
                {
                    s = s + str;
                }
                s = s + "vardecl";
                foreach (string str in b.metadataList)
                {
                    //catching caps in var declaration and setting them to lowercase
                    if (str.Contains("INT") || str.Contains("BOOL") || str.Contains("STRING"))
                    {
                        s += " " + str.ToLower();
                    }
                    else
                    {
                        s = s + " " + str;
                    }
                }
                s = s + ";";
                if (SocketReader.checkCustoms(list, b) > 0)
                {
                    writeToFile(s);
                }
            }
        }
Пример #2
0
        //method to read socket values and place them into parentheses
        public static String readSocket(Block source)
        {
            if (source.flag_hasSocks)
            {
                String  plaintext = "";                         //string that will become the output
                ListBox socket;                                 //listbox to be checked for values
                bool    parenCheck  = checkLocation(source);    //bool to see if socket needs parentheses
                bool    specialLoop = checkSpecialLoop(source); //bool to see if socket is in for/wait for loops, which have special outputs

                //adding opening bracket or paren if necessary
                if (source.ToString().Equals("ASSIGNMENT") || source.ToString().Equals("RETURN"))
                {
                    plaintext = " ";
                }
                else if (parenCheck || source.flag_isCustom)
                {
                    plaintext = " ( ";
                }
                else
                {
                    plaintext = "[ ";
                }


                //getting all sockets in the block
                List <int> locations = socketFinder(source);

                foreach (int i in locations)
                {
                    socket = socketMole(source, i);

                    //ensuring that the socket contains a block
                    if (socket.Items.Count > 0)
                    {
                        Block infoCube = (Block)socket.Items.ElementAt(0);
                        //handling nested conditions, logic statements, and methods since they have unique styles
                        if (infoCube.flag_transformer)
                        {
                            if (infoCube.flag_isCustom)
                            {
                                plaintext += "method " + infoCube.metadataList[1] + readSocket(infoCube);
                            }
                            else
                            {
                                plaintext += readSocket(infoCube) + " ";
                            }
                        }
                        //handling blocks with text
                        else if (infoCube.flag_isConstant && infoCube.flag_hasSocks && !infoCube.flag_robotOnly)
                        {
                            plaintext += (infoCube.ToString()).ToLower();
                            int slot = textFinder(infoCube);
                            //general case
                            if (!specialLoop)
                            {
                                //handling string blocks
                                if (infoCube.ToString().Contains("STRING"))
                                {
                                    plaintext += (" \"" + textReader(infoCube, slot) + "\" ").ToLower();
                                }
                                //handling other, numerical blocks
                                else
                                {
                                    plaintext += (" " + textReader(infoCube, slot) + " ").ToLower();
                                }
                            }
                            //case of for/wait for
                            else
                            {
                                if (source.ToString().Contains("WAIT"))
                                {
                                    return(" " + textReader(infoCube, slot) + ";");
                                }
                                else
                                {
                                    return(" " + textReader(infoCube, slot));
                                }
                            }
                        }
                        //handling robot functions and constants
                        else if (infoCube.flag_robotOnly && (infoCube.flag_hasSocks || infoCube.ToString().Contains("GETBEARING")))
                        {
                            plaintext += translateRobotFunctions(infoCube);
                        }
                        //handling blocks with comboboxes or non-text constants
                        else if ((infoCube.flag_isRobotConstant || infoCube.flag_isConstant) && !infoCube.flag_hasSocks)
                        {
                            //infinity block case, to be placed into for/wait for
                            if (specialLoop)
                            {
                                return(" -1");
                            }
                            //handling any combobox blocks
                            else
                            {
                                ComboBox cb = (ComboBox)infoCube.innerPane.Children.ElementAt(1);
                                //differentiating between the combobox types since bearing/range, direction, and others have different processes
                                if (infoCube.ToString().Contains("BEARING") || source.ToString().Contains("RANGE"))
                                {
                                    plaintext += SocketReader.translateDistanceInputs(cb);
                                }
                                else if (infoCube.ToString().Contains("DIRECTION"))
                                {
                                    plaintext += SocketReader.translateDriveInputs(infoCube);
                                }
                                else
                                {
                                    plaintext += (((TextBlock)cb.SelectionBoxItem).Text + " ").ToLower();
                                }
                            }
                        }
                        //handling variables, since they require 2 strings for identification
                        else if (infoCube.flag_isCustom)
                        {
                            //accounting for using var in front of variable names...except in assign for some reason, which doesn't use it
                            if (source.ToString().Contains("ASSIGN"))
                            {
                                plaintext += infoCube.metadataList[1] + " ";
                            }
                            else
                            {
                                plaintext += "var " + infoCube.metadataList[1] + " ";
                            }
                            plaintext += readSocket(infoCube);
                        }
                        //all other blocks
                        else
                        {
                            plaintext += (infoCube.metadataList[0] + " ").ToLower();
                            plaintext += readSocket(infoCube);
                        }
                        //adding the operator after the first comparator, if necessary
                        if (i == 0 && !source.flag_isCustom)
                        {
                            plaintext += " " + translateComparisons(source) + " ";
                        }
                        //adding the comma needed in parameters
                        else if (source.flag_isCustom && i != locations.ElementAt(locations.Count() - 1))
                        {
                            plaintext += ", ";
                        }
                        //accounting for the equal sign needed in assign
                        else if (i == 2 && locations.Contains(4))
                        {
                            plaintext += " = ";
                        }
                    }
                }

                //adding closing brackets and parens
                if (source.ToString().Equals("ASSIGNMENT") || source.ToString().Equals("RETURN"))
                {
                    //removing the extra space at the end
                    if (plaintext[plaintext.Length - 1] != ')')
                    {
                        plaintext = plaintext.Substring(0, plaintext.Length - 1);
                    }
                }
                else if (parenCheck || source.flag_isCustom)
                {
                    plaintext += ")";
                }
                else
                {
                    plaintext += "]";
                }

                return(plaintext);
            }
            else
            {
                return("");
            }
        }
Пример #3
0
        public static void parseCode(EditorDragDropTarget page)
        {
            ReadOnlyObservableCollection <Block> list = page.getTreeList();

            foreach (Block b in list)
            {
                string s = "";
                if (b.flag_endIndent)
                {
                    indent(false);
                    foreach (String str in indentCount)
                    {
                        s = s + str;
                    }
                    s += "}";
                    writeToFile(s);
                }
                else
                {
                    foreach (String str in indentCount)
                    {
                        s = s + str;
                    }
                    //checks to see if the block should use name or contents to print into code
                    if (b.flag_printLiteral)
                    {
                        s += (b.ToString()).ToLower() + SocketReader.readSocket(b);
                        //s = s.ToLower();
                    }
                    else if (b.flag_robotOnly)
                    {
                        s += SocketReader.translateRobotFunctions(b) + ";";
                    }
                    else if (b.flag_isCustom && b.flag_transformer)
                    {
                        s += (b.metadataList[0]).ToLower() + " " + b.metadataList[1];
                        s += SocketReader.readSocket(b);
                        if (s[s.Length - 1] != ')')
                        {
                            s += " ()";
                        }
                        s += ";";
                    }
                    else
                    {
                        s += (b.metadataList[0]).ToLower();
                        s += SocketReader.readSocket(b);
                    }

                    if (b.metadataList[0].Equals("ASSIGN") || b.metadataList[0].Equals("WAIT UNTIL") || b.metadataList[0].Equals("RETURN"))
                    {
                        s += ";";
                    }

                    writeToFile(s);
                    if (b.flag_beginIndent)
                    {
                        s = "";
                        foreach (String str in indentCount)
                        {
                            s = s + str;
                        }
                        s += "{";
                        writeToFile(s);
                        indent(true);
                    }
                }
            }
            indent(false);
        }