Exemplo n.º 1
0
        // Parse the declaration and returns index of parts after declaration
        public int Parse(string[] parts, int start)
        {
            // If doesn't start with keyword
            if (parts[start] != "desig")
            {
                throw new Exception("Desig starts with '" + parts[start] + "' not 'desig'!");
            }
            // If the name is already taken
            else if (Reserved.Exists(parts[start + 1], true))
            {
                throw new Exception("Name " + parts[start + 1] + " already exists!");
            }
            // Declaration doesn't end with ;
            else if (parts[start + 3] != ";")
            {
                throw new Exception("Desig declaration doesn't end in ';'!");
            }
            else
            {
                // Save desig name
                desigName = parts[start + 1];
                criteria  = parts[start + 2];
                Reserved.dEx.Add(this);

                // Return index after desig
                return(start + 4);
            }
        }
Exemplo n.º 2
0
        public void CreateFunction(string directory)
        {
            string filepath = directory + funcName + ".mcfunction";

            if (File.Exists(filepath))
            {
                throw new Exception("Function '" + funcName + "'s .mcfunction already exists!");
            }
            else
            {
                string alldo = "";
                // There is a load rule, and the load function is this function
                if (Ruling.hasLoad && IntoAST.maintodo.Exists(x => x is LoadFuncRuling lf && lf.function == funcName))
                {
                    // Begin with the initialization
                    alldo = Reserved.InitializeDeclarationString();
                }

                // Open the file to the function
                StreamWriter sw = File.CreateText(filepath);

                foreach (IChildFunctionDeclaration icdf in todo)
                {
                    alldo += icdf.GetLine() + "\n";
                }

                // Write to file as text
                sw.Write(alldo);

                sw.Close();

                {}
            }
        }
Exemplo n.º 3
0
        // Parse the declaration and returns index of parts after declaration
        public int Parse(string[] parts, int start)
        {
            // If doesn't start with keyword
            if (parts[start] != "var")
            {
                throw new Exception("Var starts with '" + parts[start] + "' not 'var'!");
            }
            // If the name is already taken
            else if (Reserved.Exists(parts[start + 1], true))
            {
                throw new Exception("Name " + parts[start + 1] + " already exists!");
            }
            // Declaration doesn't end with ;
            else if (parts[start + 2] != ";")
            {
                throw new Exception("Var declaration doesn't end in ';'!");
            }
            else
            {
                // Save var name
                varName = parts[start + 1];
                Reserved.vEx.Add(this);

                // Return index after var
                return(start + 3);
            }
        }
Exemplo n.º 4
0
        // Parse into function
        public int Parse(string[] parts, int start)
        {
            // Set compilation time context
            string currContext = context;

            // If doesn't start with keyword func
            if (parts[start] != "func")
            {
                throw new Exception("Func starts with '" + parts[start] + "' not 'func'!");
            }
            // If the name is already taken
            else if (Reserved.Exists(parts[start + 1], true))
            {
                throw new Exception("Name " + parts[start + 1] + " already exists!");
            }
            else if (parts[start + 2] != "{")
            {
                throw new Exception("Expected { not " + parts[start + 2]);
            }
            else
            {
                // Save function name
                funcName = parts[start + 1];
                Reserved.fEx.Add(this);

                // Skip to first expression
                start += 3;

                // Keep identifying expression until end of function declaration
                while (start < parts.Length)
                {
                    if (parts[start] == "}")
                    {
                        return(start + 1);
                    }

                    // Identify from function context
                    IntoAST.IdentifyResponse ir = IntoAST.Identify("function", currContext, parts, start);

                    // Move to next statement and add function child to todo
                    start = ir.next;
                    if (ir.IChild is IChildFunctionDeclaration icfd)
                    {
                        todo.Add(icfd);
                    }
                    else
                    {
                        throw new Exception("Function child '" + ir.IChild + "' cannot follow function '" + funcName + "'");
                    }
                }

                // Didn't find end of function
                throw new Exception("No } found for function " + funcName);
            }
        }
Exemplo n.º 5
0
        // Apply each type
        public void CreateFiles(string masterDir)
        {
            if (maintodo == null || maintodo.Count == 0)
            {
                throw new Exception("Cannot create files; Nothing specified/compiled");
            }
            else
            {
                // If no name is ruled
                if (!Ruling.hasName)
                {
                    throw new Exception("Name ruling has to be made !");
                }

                // Made a load tag function
                bool madeLoadTagFunc = false;
                // Made a description
                bool madeDesc = false;

                foreach (IChildMainFile icmf in maintodo)
                {
                    if (icmf is FunctionDeclaration fd)
                    {
                        fd.CreateFunction(masterDir + "data\\" + IntoAST.nameSpace + "\\functions\\");
                    }
                    else if (icmf is DescriptionRuling dr)
                    {
                        StreamWriter sw = new StreamWriter(masterDir + "pack.mcmeta");
                        sw.Write("{\n\t\"pack\": {\n\t\t\"pack_format\": 5,\n\t\t\"description\":\"" + dr.description + "\"\n\t}\n}");
                        sw.Close();

                        madeDesc = true;
                    }
                    //else if (icmf is DatapackNameRuling dr)
                    // Nothing is done, name ruling is for all the function's namespace
                    //else if (icmf is VariableDeclaration vd)
                    //else if (icmf is DesigDeclaration dd)
                    // Nothing is done, taken care of in the load ruling or after all IChildMainFile is taken care of
                    else if (icmf is LoadFuncRuling lf)
                    {
                        // Create load tag
                        string initString = "{\n\t\"replace\":false,\n\t\"values\":\n\t[\n\t\t\"" + IntoAST.nameSpace + ":" + lf.function + "\"\n\t]\n}";

                        StreamWriter sw = File.CreateText(masterDir + "data\\minecraft\\tags\\functions\\load.json");

                        sw.Write(initString);

                        sw.Close();

                        // Has a load tagged function
                        madeLoadTagFunc = true;
                    }
                    else if (icmf is TickFuncRuling tf)
                    {
                        // Create tick tag
                        string initString = "{\n\t\"replace\":false,\n\t\"values\":\n\t[\n\t\t\"" + IntoAST.nameSpace + ":" + tf.function + "\"\n\t]\n}";

                        StreamWriter sw = File.CreateText(masterDir + "data\\minecraft\\tags\\functions\\tick.json");

                        sw.Write(initString);

                        sw.Close();
                    }
                }

                // If didn't make a load tag function
                if (!madeLoadTagFunc)
                {
                    // Get commands to initialize variables and desigs
                    string initString = Reserved.InitializeDeclarationString();

                    // Create load function initall.mcfunction
                    StreamWriter sw = File.CreateText(masterDir + "data\\" + IntoAST.nameSpace + "\\functions\\initall.mcfunction");

                    sw.Write(initString);

                    sw.Close();

                    // Create load tag
                    initString = "{\n\t\"replace\":false,\n\t\"values\":\n\t[\n\t\t\"" + IntoAST.nameSpace + ":initall\"\n\t]\n}";

                    sw = File.CreateText(masterDir + "data\\minecraft\\tags\\functions\\load.json");

                    sw.Write(initString);

                    sw.Close();
                }

                // If didn't make a description
                if (!madeDesc)
                {
                    StreamWriter sw = new StreamWriter(masterDir + "pack.mcmeta");
                    sw.Write("{\n\t\"pack\": {\n\t\t\"pack_format\": 5,\n\t\t\"description\":\"generated\"\n\t}\n}");
                    sw.Close();
                }
            }
        }