Beispiel #1
0
        private int ParseValue(int index, string valueName, WrapperObject parentNode)
        {
            WrapperType actualValue;

            if (this.TokenList[index].Contains("."))
            {
                var proposedDouble = this.TokenList[index].Split(".");
                if (int.TryParse(proposedDouble[0], out _) && int.TryParse(proposedDouble[1], out _))
                {
                    actualValue = new WrapperDouble(valueName, double.Parse(this.TokenList[index++]));
                }
                else
                {
                    actualValue = new WrapperString(valueName, this.TokenList[index++]);
                }
            }
            else if (int.TryParse(this.TokenList[index], out _))
            {
                actualValue = new WrapperInt(valueName, int.Parse(this.TokenList[index++]));
            }
            else if (this.TokenList[index].ToLower() == "true" || this.TokenList[index].ToLower() == "false")
            {
                bool boolVal = bool.Parse(this.TokenList[index++]);
                actualValue = new WrapperBool(valueName, boolVal);
            }
            else if (this.TokenList[index] == "<")
            {
                if (valueName.ToLower().Contains("array"))
                {
                    actualValue = new WrapperArray(valueName, null);
                    index       = ParseArray(index, actualValue as WrapperArray);
                }
                else
                {
                    actualValue = new WrapperObject(valueName, null);
                    index       = ParseObject(index, actualValue as WrapperObject);
                }
            }
            else
            {
                actualValue = new WrapperString(valueName, this.TokenList[index++]);
            }

            index = RulesUtility.ValidateToken(this.TokenList[index], "<", "Invalid Token. Need \'<\' for name of value", index);
            if (valueName.ToLower().Contains("array"))
            {
                index = RulesUtility.ValidateToken(this.TokenList[index], $"/{valueName.ToLower()}", $"Invalid Token. Need closing name {valueName} for name of value", index);
            }
            else
            {
                index = RulesUtility.ValidateToken(this.TokenList[index], $"/{valueName}", $"Invalid Token. Need closing name {valueName} for name of value", index);
            }
            index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need \'>\' for name of value", index);

            parentNode.Value.Add(actualValue);
            return(index);
        }
        private int ParseValue(int index, string valueName, WrapperObject parentNode)
        {
            WrapperType actualValue = null;

            if (this.TokenList[index].Contains("\""))
            {
                index = RulesUtility.ValidateToken(this.TokenList[index], "\"", "Invalid Token. Need first double quote for string value", index);

                actualValue = new WrapperString(valueName, this.TokenList[index++]);

                index = RulesUtility.ValidateToken(this.TokenList[index], "\"", "Invalid Token. Need first double quote for string value", index);
            }
            else if (this.TokenList[index].Contains("."))
            {
                var proposedDouble = this.TokenList[index].Split(".");
                if (int.TryParse(proposedDouble[0], out _) && int.TryParse(proposedDouble[1], out _))
                {
                    actualValue = new WrapperDouble(valueName, double.Parse(this.TokenList[index++]));
                }
                else
                {
                    throw new Exception("This is an invlid Double Value");
                }
            }
            else if (int.TryParse(this.TokenList[index], out _))
            {
                actualValue = new WrapperInt(valueName, int.Parse(this.TokenList[index++]));
            }
            else if (this.TokenList[index] == "true" || this.TokenList[index] == "false")
            {
                bool boolVal = bool.Parse(this.TokenList[index++]);
                actualValue = new WrapperBool(valueName, boolVal);
            }
            else if (this.TokenList[index] == "{")
            {
                index++;
                actualValue = new WrapperObject(valueName, null);
                index       = ParseObject(index, actualValue as WrapperObject);
                index++;
            }
            else if (this.TokenList[index] == "[")
            {
                index++;
                actualValue = new WrapperArray(valueName, null);
                index       = ParseArray(index, actualValue as WrapperArray);
                index++;
            }

            parentNode.Value.Add(actualValue);
            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);
        }