private int Start(int index)
        {
            WrapperObject wholeFile = new WrapperObject("WHOLE_FILE");

            while (index < this.TokenList.Count)
            {
                WrapperObject potentialObject = new WrapperObject();

                if (RulesUtility.ValidAccessModifiers(this.ProgramTypeLanguage, this.TokenList[index]))
                {
                    potentialObject.Value.Add(new WrapperString("ACCESS_MOD", this.TokenList[index++].ToLower()));
                }
                else
                {
                    potentialObject.Value.Add(new WrapperString("ACCESS_MOD", "public"));
                }

                if (this.TokenList[index].ToLower() == "static")
                {
                    potentialObject.Value.Add(new WrapperBool("IS_STATIC", true));
                    index++;
                }
                else if (this.TokenList[index].ToLower() == "enum")
                {
                    index = this.AddClassLikeType(index, potentialObject, wholeFile, "enum");
                    continue;
                }
                else
                {
                    potentialObject.Value.Add(new WrapperBool("IS_STATIC", false));
                }

                if (this._isOneClass)
                {
                    throw new Exception("Java does not allow multiple classes. Please seperate classes into individual files.");
                }
                else
                {
                    this._isOneClass = true;
                }

                index = this.AddClassLikeType(index, potentialObject, wholeFile, "class");
            }

            this.Structure.Add(wholeFile);

            this._isOneClass = false;

            return(index);
        }
        private int AddHeader(int index)
        {
            var otherHeaders = new WrapperObject("HEADERS");

            // TODO: make sure to implement this while multi file task
            while ((this.TokenList[index].ToLower() != "class" && this.TokenList[index].ToLower() != "enum") &&
                   !RulesUtility.ValidAccessModifiers(this.ProgramTypeLanguage, this.TokenList[index]))
            {
                if (this.TokenList[index].ToLower() == "import")
                {
                    index++;
                    if (this.TokenList[index].ToLower() == "java")
                    {
                        while (this.TokenList[index] != ";")
                        {
                            index++;
                        }
                    }
                    else
                    {
                        string location = string.Empty;
                        while (this.TokenList[index] != ";")
                        {
                            location += this.TokenList[index++];
                        }
                        otherHeaders.Value.Add(new WrapperString("IMPORT", location));
                    }
                }
                else if (this.TokenList[index].ToLower() == "package")
                {
                    index = RulesUtility.ValidateToken(this.TokenList[index], "package", "This is not an accurate package.", index);
                    string packageName = string.Empty;
                    while (this.TokenList[index] != ";")
                    {
                        packageName += this.TokenList[index++];
                    }
                    otherHeaders.Value.Add(new WrapperString("PACKAGE", packageName));
                }
                index++;
            }

            this.Structure.Add(otherHeaders);

            return(index);
        }
        private int BuildClassContent(int index, WrapperObject classObject)
        {
            WrapperObject classContent = new WrapperObject("OBJECT_CONTENT");

            while (this.TokenList[index] != "}")
            {
                WrapperObject contentObject = new WrapperObject();

                if (RulesUtility.ValidAccessModifiers(this.ProgramTypeLanguage, this.TokenList[index]))
                {
                    contentObject.Value.Add(new WrapperString("ACCESS_MOD", this.TokenList[index++].ToLower()));
                }
                else
                {
                    var classObjectAccessMod = (WrapperString)classObject.GetValue("ACCESS_MOD");
                    contentObject.Value.Add(new WrapperString("ACCESS_MOD", classObjectAccessMod.Value));
                }

                if (this.TokenList[index].ToLower() == "static")
                {
                    contentObject.Value.Add(new WrapperBool("IS_STATIC", true));
                    index++;
                }
                else if (this.TokenList[index].ToLower() == "enum")
                {
                    index = this.AddClassLikeType(index, contentObject, classContent, "enum");
                    continue;
                }
                else
                {
                    contentObject.Value.Add(new WrapperBool("IS_STATIC", false));
                }

                if (this.TokenList[index].ToLower() == "final")
                {
                    contentObject.Value.Add(new WrapperBool("IS_CONST", true));
                    index++;
                }
                else
                {
                    contentObject.Value.Add(new WrapperBool("IS_CONST", false));
                }

                if (this.TokenList[index] == "class")
                {
                    index = this.AddClassLikeType(index, contentObject, classContent, "class");
                    continue;
                }

                if (this.TokenList[index + 1] != "(")
                {
                    if (RulesUtility.IsValidType(this.ProgramTypeLanguage, this.TokenList[index]))
                    {
                        string valueType = this.TokenList[index++];
                        if (this.TokenList[index] == "<")
                        {
                            while (this.TokenList[index] != ">")
                            {
                                valueType += this.TokenList[index++];
                            }
                            valueType += this.TokenList[index++];
                        }
                        contentObject.Value.Add(new WrapperString("VALUE_TYPE", valueType));
                    }
                    else
                    {
                        throw new Exception("This is an invalid return/set type.");
                    }
                }

                if (this.TokenList[index].ToUpper() == this.TokenList[index])
                {
                    string constName = string.Empty;
                    while (this.TokenList[index] != "=")
                    {
                        constName += this.TokenList[index++];
                    }
                    contentObject.WrapperName = constName;
                    index--;
                }
                else
                {
                    contentObject.WrapperName = this.TokenList[index];
                }

                if (this.TokenList[index][0] == '_' || (this.TokenList[index][0] >= 'A' && this.TokenList[index][0] <= 'Z' && this.TokenList[index + 1] != "{" && this.TokenList[index + 1] != "("))
                {
                    contentObject.WrapperName = this.TokenList[index++];
                    index = this.BuildClassProperty(index, contentObject);
                }
                else
                {
                    index++;
                    WrapperBool isConst = (WrapperBool)contentObject.GetValue("IS_CONST");
                    if (isConst.Value)
                    {
                        throw new Exception("This cannot use constant for auto property and function.");
                    }
                    index = this.BuildFunction(index, contentObject);
                }

                classContent.Value.Add(contentObject);
            }

            classObject.Value.Add(classContent);

            return(index);
        }
Beispiel #4
0
        private int AddNamespace(int index)
        {
            // TODO: FIGURE THIS WITH CLASS AND STRUCTURE AND SHIT
            var namespaceObject = new WrapperObject();

            index = RulesUtility.ValidateToken(this.TokenList[index], "namespace", "This is not an accurate namespace.", index);

            while (this.TokenList[index] != "{")
            {
                namespaceObject.WrapperName += this.TokenList[index++];
            }

            index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This is an invalid class opener.", index);

            while (this.TokenList[index] != "}")
            {
                var potentialObject = new WrapperObject();

                if (RulesUtility.ValidAccessModifiers(this.ProgramTypeLanguage, this.TokenList[index]))
                {
                    potentialObject.Value.Add(new WrapperString("ACCESS_MOD", this.TokenList[index++].ToLower()));
                }
                else
                {
                    potentialObject.Value.Add(new WrapperString("ACCESS_MOD", "public"));
                }

                if (this.TokenList[index].ToLower() == "abstract" ||
                    this.TokenList[index].ToLower() == "override" ||
                    this.TokenList[index].ToLower() == "virtual")
                {
                    potentialObject.Value.Add(new WrapperString("UNIQUE_MOD", this.TokenList[index++].ToLower()));
                }

                if (this.TokenList[index].ToLower() == "static")
                {
                    potentialObject.Value.Add(new WrapperBool("IS_STATIC", true));
                    index++;
                }
                else if (this.TokenList[index].ToLower() == "struct")
                {
                    index = this.AddClassLikeType(index, potentialObject, namespaceObject, "struct");
                    continue;
                }
                else if (this.TokenList[index].ToLower() == "enum")
                {
                    index = this.AddClassLikeType(index, potentialObject, namespaceObject, "enum");
                    continue;
                }
                else
                {
                    potentialObject.Value.Add(new WrapperBool("IS_STATIC", false));
                }

                index = this.AddClassLikeType(index, potentialObject, namespaceObject, "class");
            }

            index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This is an invalid class closer.", index);

            this.Structure.Add(namespaceObject);

            return(index);
        }