private int BuildClassProperty(int index, WrapperObject contentObject) { if (this.TokenList[index] == ";") { index = RulesUtility.ValidateToken(this.TokenList[index], ";", "This needs is a valid \';\'.", index); return(index); } var type = (WrapperString)contentObject.GetValue("VALUE_TYPE"); string statement = $"{type.Value} {contentObject.WrapperName} "; while (this.TokenList[index] != ";") { string lookAhead = this.TokenList[index + 1]; statement += this.TokenList[index]; if (lookAhead != "." && lookAhead != "(" && lookAhead != ")" && lookAhead != "\'" && lookAhead != ";" && this.TokenList[index] != "." && this.TokenList[index] != "(" && this.TokenList[index] != ")" && this.TokenList[index] != "\"" && this.TokenList[index] != "\'") { statement += " "; } index++; } index = RulesUtility.ValidateToken(this.TokenList[index], ";", "This needs is a valid \';\'.", index); contentObject.Value.Add(new WrapperString("STATEMENT_1", statement)); return(index); }
private int BuildAutoProperty(int index, WrapperObject contentObject, WrapperObject parentObject) { index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index); WrapperObject setObject = new WrapperObject("SET"); WrapperObject getObject = new WrapperObject("GET"); contentObject.CopyData(getObject); contentObject.CopyData(setObject); string compVariableName = "_" + char.ToLower(contentObject.WrapperName[0]).ToString() + contentObject.WrapperName.Substring(1); string holdOlderName = contentObject.WrapperName; if (!parentObject.GetKeys().Contains(compVariableName)) { contentObject.WrapperName = compVariableName; contentObject.UpdateStringValue("ACCESS_MOD", "private"); parentObject.Value.Add(contentObject); } WrapperString valueType = setObject.GetValue("VALUE_TYPE") as WrapperString; WrapperObject parameters = new WrapperObject("PARAMETERS"); WrapperObject parameter = new WrapperObject($"PARAMETER_1"); parameter.Value.Add(new WrapperString("VALUE_TYPE", valueType.Value)); parameter.Value.Add(new WrapperString("PARAM_NAME", "value")); setObject.UpdateStringValue("VALUE_TYPE", "void"); parameters.Value.Add(parameter); setObject.Value.Add(parameters); if (this.TokenList[index] == "get") { index = this.BuildAuxMethod(index, getObject, compVariableName); index = this.BuildAuxMethod(index, setObject, compVariableName); } else if (this.TokenList[index] == "set") { index = this.BuildAuxMethod(index, setObject, compVariableName); index = this.BuildAuxMethod(index, getObject, compVariableName); } else { throw new Exception("This auto property needs an explicet get and set keywords."); } index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index); getObject.WrapperName = $"Get{holdOlderName}"; setObject.WrapperName = $"Set{holdOlderName}"; parentObject.Value.Add(getObject); parentObject.Value.Add(setObject); this._autoPropertyList.Add(holdOlderName); this._autoPropertyList.Add($"this.{holdOlderName}"); 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); }