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 FillDoWhile(int index, WrapperObject doObject) { WrapperObject doContentObject = new WrapperObject("DO_CONTENT"); index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index); index = this.FillFunctionContent(index, doContentObject); index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index); WrapperString whileCond = new WrapperString("WHILE_COND", string.Empty); index = RulesUtility.ValidateToken(this.TokenList[index], "while", "This needs is a valid \'while\'.", index); while (this.TokenList[index] != ")") { string lookAhead = this.TokenList[index + 1]; whileCond.Value += this.TokenList[index]; if (lookAhead != "." && lookAhead != "(" && lookAhead != ")" && lookAhead != "\'" && lookAhead != ";" && this.TokenList[index] != "." && this.TokenList[index] != "(" && this.TokenList[index] != ")" && this.TokenList[index] != "\"" && this.TokenList[index] != "\'") { whileCond.Value += " "; } index++; } index = RulesUtility.ValidateToken(this.TokenList[index], ")", "This needs is a valid \')\'.", index); whileCond.Value += ")"; index = RulesUtility.ValidateToken(this.TokenList[index], ";", "This needs is a valid \';\'.", index); whileCond.Value += ";"; doObject.Value.Add(doContentObject); doObject.Value.Add(whileCond); return(index); }
private int BuildEnumContent(int index, WrapperObject enumObject) { int times = 0; WrapperObject enumContent = new WrapperObject("ENUM_CONTENT"); while (this.TokenList[index] != "}") { WrapperString enumEntry = new WrapperString($"ENUM_VALUE_{times++}", string.Empty); while (this.TokenList[index] != "}" && this.TokenList[index] != ",") { enumEntry.Value += this.TokenList[index++]; } enumContent.Value.Add(enumEntry); if (this.TokenList[index] != "}") { index = RulesUtility.ValidateToken(this.TokenList[index], ",", $"{enumObject.WrapperName} enum object needs a valid divider.", index); } } enumObject.Value.Add(enumContent); return(index); }
private int FillTryCatch(int index, WrapperObject mainTryObject) { WrapperObject tryBlockObject = new WrapperObject("TRY_CONTENT"); index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index); index = this.FillFunctionContent(index, tryBlockObject); index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index); mainTryObject.Value.Add(tryBlockObject); if (this.TokenList[index] == "catch") { WrapperObject catchBlockObject = new WrapperObject("CATCH_CONTENT"); index = RulesUtility.ValidateToken(this.TokenList[index], "catch", "This needs is a valid \'catch\'.", index); if (this.TokenList[index] == "(") { string exStatement = string.Empty; while (this.TokenList[index] != ")") { string lookAhead = this.TokenList[index + 1]; exStatement += this.TokenList[index]; if (lookAhead != "." && lookAhead != "(" && lookAhead != ")" && lookAhead != "\'" && lookAhead != ";" && this.TokenList[index] != "." && this.TokenList[index] != "(" && this.TokenList[index] != ")" && this.TokenList[index] != "\"" && this.TokenList[index] != "\'") { exStatement += " "; } index++; } index = RulesUtility.ValidateToken(this.TokenList[index], ")", "This needs is a valid \')\'.", index); exStatement += ")"; catchBlockObject.Value.Add(new WrapperString("CATCH_COND", exStatement)); } index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index); index = this.FillFunctionContent(index, catchBlockObject); index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index); mainTryObject.Value.Add(catchBlockObject); } if (this.TokenList[index] == "finally") { WrapperObject finallyObject = new WrapperObject("FINALLY_CONTENT"); index = RulesUtility.ValidateToken(this.TokenList[index], "finally", "This needs is a valid \'finally\'.", index); index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index); index = this.FillFunctionContent(index, finallyObject); index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index); mainTryObject.Value.Add(finallyObject); } return(index); }
private int FillConditionalStatement(int index, WrapperObject wrapperObject) { string conditionStatement = string.Empty; var values = string.Empty; index = RulesUtility.ValidateToken(this.TokenList[index], "(", "This needs is a valid \'(\'.", index); conditionStatement += "("; while (this.TokenList[index] != ")") { string lookAhead = this.TokenList[index + 1]; values += this.TokenList[index]; if (lookAhead != "." && lookAhead != "(" && lookAhead != ")" && lookAhead != "\'" && lookAhead != ";" && this.TokenList[index] != "." && this.TokenList[index] != "(" && this.TokenList[index] != ")" && this.TokenList[index] != "\"" && this.TokenList[index] != "\'") { values += " "; } index++; } conditionStatement += values; index = RulesUtility.ValidateToken(this.TokenList[index], ")", "This needs is a valid \')\'.", index); conditionStatement += ")"; wrapperObject.Value.Add(new WrapperString("CONDITION_STATEMENT", conditionStatement)); return(index); }
private int AddClassLikeType(int index, WrapperObject wrapperObject, WrapperObject parentObject, string flag) { index = RulesUtility.ValidateToken(this.TokenList[index], flag, $"This is not an accurate {flag}.", index); while (this.TokenList[index] != "{") { wrapperObject.WrapperName += this.TokenList[index++]; } index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This is an invalid class opener.", index); switch (flag) { case "enum": index = BuildEnumContent(index, wrapperObject); break; case "class": index = BuildClassContent(index, wrapperObject); break; default: throw new Exception($"Unable to make a enum, struct, or class with this token {flag}."); } index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This is an invalid class closer.", index); parentObject.Value.Add(wrapperObject); return(index); }
private int ParseObject(int index, WrapperObject parentNode) { parentNode.Value = new List <WrapperType>(); while (this.TokenList[index] != "}") { string valueName = string.Empty; index = RulesUtility.ValidateToken(this.TokenList[index], "\"", "Invalid Token. Need first double quote for string value", index); valueName = this.TokenList[index++]; index = RulesUtility.ValidateToken(this.TokenList[index], "\"", "Invalid Token. Need first double quote for string value", index); index = RulesUtility.ValidateToken(this.TokenList[index], ":", "Invalid Token. Need \":\" for divider of value", index); index = ParseValue(index, valueName, parentNode); if (this.TokenList[index] == ",") { index++; } else if (this.TokenList[index] == "}") { // will cancel out } else { throw new Exception("Invalid Token. Need last double quote for name of value"); } } return(index); }
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 FillBracketStatement(int index, WrapperObject wrapperObject) { index = this.FillConditionalStatement(index, wrapperObject); index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index); index = this.FillFunctionContent(index, wrapperObject); index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index); return(index); }
private int BuildFunction(int index, WrapperObject functionObject, bool isStruct) { int holderValue = 1; WrapperObject parameters = new WrapperObject("PARAMETERS"); index = RulesUtility.ValidateToken(this.TokenList[index], "(", "This needs is a valid \'(\'.", index); while (this.TokenList[index] != ")") { WrapperObject parameter = new WrapperObject($"PARAMETER_{holderValue++}"); if (RulesUtility.IsValidType(this.ProgramTypeLanguage, this.TokenList[index])) { string valueName = this.TokenList[index++]; if (this.TokenList[index] == "[") { valueName += "[]"; index += 2; } parameter.Value.Add(new WrapperString("VALUE_TYPE", valueName)); parameter.Value.Add(new WrapperString("PARAM_NAME", this.TokenList[index++])); if (this.TokenList[index] == ")") { parameters.Value.Add(parameter); break; } index = RulesUtility.ValidateToken(this.TokenList[index], ",", "This needs is a valid \',\'.", index); } else { throw new Exception("This is an invalid parameter type."); } parameters.Value.Add(parameter); } if (isStruct && parameters.Value.Count < 0) { throw new Exception("You cannot have a default constructor for a struct object."); } else if (parameters.Value.Count > 0) { functionObject.Value.Add(parameters); } index = RulesUtility.ValidateToken(this.TokenList[index], ")", "This needs is a valid \')\'.", index); index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index); WrapperObject functionContent = new WrapperObject("FUNCTION_CONTENT"); index = this.FillFunctionContent(index, functionContent); functionObject.Value.Add(functionContent); index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index); 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 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 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 ParseArray(int index, WrapperArray parentNode) { parentNode.Value = new List <WrapperObject>(); int id = 0; while (this.TokenList[index] != "]") { index = RulesUtility.ValidateToken(this.TokenList[index], "{", "Need object for arrays", index); var actualValue = new WrapperObject(string.Format("ID-", id++), null); index = ParseObject(index, actualValue); index++; bool hasNoId = true; foreach (var new_id in actualValue.Value) { if (new_id.WrapperName.ToLower() == "id") { var tempNode = new_id as WrapperInt; actualValue.WrapperName = tempNode.WrapperName + "-" + tempNode.Value; hasNoId = false; break; } } if (hasNoId) { throw new Exception("Array entry has no valid id. Please place id value in Json."); } parentNode.Value.Add(actualValue); if (this.TokenList[index] == ",") { index++; } else if (this.TokenList[index] == "]") { // will cancel out } else { throw new Exception("Invalid Token. Need last double quote for name of value"); } } return(index); }
private int ParseObject(int index, WrapperObject parentNode) { parentNode.Value = new List <WrapperType>(); while (index < this.TokenList.Count) { index = RulesUtility.ValidateToken(this.TokenList[index], "<", "Invalid Token. Need \'<\' for name of value", index); if (this.TokenList[index] == $"/{parentNode.WrapperName}") { break; } string valueName = this.TokenList[index++]; index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need \'>\' for name of value", index); index = ParseValue(index, valueName, parentNode); } return(index - 1); }
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); }
public override void ParseFile() { Log.Info("Starting to Parse XML file."); WrapperType mainNode; int index = 0; index = VerifyHeader(index); if (this.TokenList[index] == "<") { index++; if (this.TokenList[index].Contains("Array")) { mainNode = new WrapperArray(this.TokenList[index++], null); index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need first double quote for name of value", index); index = ParseArray(index, mainNode as WrapperArray); index = RulesUtility.ValidateToken(this.TokenList[index], "<", "Invalid Token. Need \'<\' for name of value", index); index = RulesUtility.ValidateToken(this.TokenList[index], $"/{mainNode.WrapperName + "Array"}", $"Invalid Token. Need closing name {mainNode.WrapperName} for name of value", index); index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need \'>\' for name of value", index); } else { mainNode = new WrapperObject(this.TokenList[index++], null); index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need first double quote for name of value", index); index = ParseObject(index, mainNode as WrapperObject); index = RulesUtility.ValidateToken(this.TokenList[index], "<", "Invalid Token. Need \'<\' for name of value", index); index = RulesUtility.ValidateToken(this.TokenList[index], $"/{mainNode.WrapperName}", $"Invalid Token. Need closing name {mainNode.WrapperName} for name of value", index); index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need \'>\' for name of value", index); } } else { throw new Exception("Invalid start to XML Parsing."); } this.Structure.Add(mainNode); Log.Success("XML Parse Successfully Completed."); }
private int BuildAuxMethod(int index, WrapperObject auxObject, string variableName) { string flagName = auxObject.WrapperName.ToString().ToLower(); index = RulesUtility.ValidateToken(this.TokenList[index], flagName, $"This needs is a valid \'{flagName}\'.", index); WrapperObject functionContent = new WrapperObject("FUNCTION_CONTENT"); if (this.TokenList[index] == ";") { index = RulesUtility.ValidateToken(this.TokenList[index], ";", "This needs is a valid \';\'.", index); if (flagName == "get") { functionContent.Value.Add(new WrapperString("STATEMENT_1", $"return {variableName}")); } else if (flagName == "set") { functionContent.Value.Add(new WrapperString("STATEMENT_1", $"this.{variableName} = value")); } else { throw new Exception($"This flag name {flagName} is not valid for autoproperty getter/setter"); } } else if (this.TokenList[index] == "{") { index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index); index = this.FillFunctionContent(index, functionContent); index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index); } else { throw new Exception("This is not a valid set function of this auto property."); } auxObject.Value.Add(functionContent); return(index); }
private int ParseArray(int index, WrapperArray parentNode) { parentNode.Value = new List <WrapperObject>(); var testArray = parentNode.WrapperName.Split("Array"); string jsonName = string.Empty; for (int testIndex = 0; testIndex < testArray.Length - 1; testIndex++) { if (testArray[testIndex] == "") { jsonName += "Array"; } jsonName += testArray[testIndex]; } int id = 0; while (index < this.TokenList.Count) { index = RulesUtility.ValidateToken(this.TokenList[index], "<", "Invalid Token. Need \'<\' for name of value", index); if (this.TokenList[index] == $"/{parentNode.WrapperName}") { parentNode.WrapperName = jsonName; break; } index = RulesUtility.ValidateToken(this.TokenList[index], jsonName, $"Invalid Token. Need {jsonName} for name of value", index); index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need \'>\' for name of value", index); WrapperObject childNode = new WrapperObject(jsonName, null); index = ParseObject(index, childNode); childNode.Value.Add(new WrapperInt("id", id)); childNode.WrapperName = "ID-" + id++; parentNode.Value.Add(childNode); index = RulesUtility.ValidateToken(this.TokenList[index], "<", "Invalid Token. Need \'<\' for name of value", index); index = RulesUtility.ValidateToken(this.TokenList[index], $"/{jsonName}", "Invalid Token. Need \'<\' for name of value", index); index = RulesUtility.ValidateToken(this.TokenList[index], ">", "Invalid Token. Need \'>\' for name of value", index); } return(index - 1); }
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); }
public override void ScanFile() { var fileContents = File.ReadAllText(this.FullFile); bool isLocked = false; string hold = string.Empty; Log.Info("Scanning Json file."); for (int index = 0; index < fileContents.Length; index++) { if (isLocked) { if (fileContents[index] == '\"') { this.TokenList.Add(hold); this.TokenList.Add(fileContents[index].ToString()); hold = string.Empty; isLocked = false; continue; } hold += fileContents[index].ToString(); } else { if (fileContents[index] == ' ' || fileContents[index] == '\n' || fileContents[index] == '\r') { continue; } else if (fileContents[index] == '-' || char.IsDigit(fileContents[index])) { string number = fileContents[index++].ToString(); while (char.IsDigit(fileContents[index]) || fileContents[index] == '.') { number += fileContents[index++]; } this.TokenList.Add(number); index -= 1; continue; } else if (fileContents[index] == 't') { foreach (var character in "true") { index = RulesUtility.ValidateToken(fileContents[index].ToString(), character.ToString(), "not a valid true boolean.", index); } this.TokenList.Add("true"); index -= 1; } else if (fileContents[index] == 'f') { foreach (var character in "false") { index = RulesUtility.ValidateToken(fileContents[index].ToString(), character.ToString(), "not a valid false boolean.", index); } this.TokenList.Add("false"); index -= 1; } else { switch (fileContents[index]) { case '\"': isLocked = true; this.TokenList.Add(fileContents[index].ToString()); continue; case '{': case '}': case '[': case ']': case ':': case ',': this.TokenList.Add(fileContents[index].ToString()); continue; } } } } Log.Success("Scanning Json File Completed."); }
public override void ScanFile() { var fileContents = this.CleanSourceCode(); string hold = string.Empty; Log.Info("Scanning Java file."); for (int index = 0; index < fileContents.Length; index++) { if (fileContents[index] == ' ' || fileContents[index] == '\n' || fileContents[index] == '\r') { if (!string.IsNullOrEmpty(hold) && !string.IsNullOrWhiteSpace(hold)) { this.TokenList.Add(hold); hold = string.Empty; } continue; } else if (RulesUtility.ValidSymbol(this.ProgramTypeLanguage, fileContents[index])) { if (fileContents[index] == '\"') { this.TokenList.Add(fileContents[index].ToString()); int subIndex = index + 1; string content = string.Empty; while (fileContents[subIndex] != '\"') { content += fileContents[subIndex++].ToString(); } this.TokenList.Add(content); index = subIndex; } else if (!string.IsNullOrEmpty(hold) && !string.IsNullOrWhiteSpace(hold)) { this.TokenList.Add(hold); hold = string.Empty; } this.TokenList.Add(fileContents[index].ToString()); continue; } else if (fileContents[index] == ';') { if (!string.IsNullOrEmpty(hold) && !string.IsNullOrWhiteSpace(hold)) { this.TokenList.Add(hold); } this.TokenList.Add(fileContents[index].ToString()); hold = string.Empty; continue; } hold += fileContents[index]; if (this.IsValidKeyword(hold.ToLower()) && !(char.IsLetter(fileContents[index + 1]) || char.IsDigit(fileContents[index + 1]))) { this.LogValidKeyword(hold.ToLower()); if (!string.IsNullOrEmpty(hold) && !string.IsNullOrWhiteSpace(hold)) { this.TokenList.Add(hold); hold = string.Empty; } continue; } } Log.Success("Scanning Java file is Completed."); }
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); }
private int FillSwitchStatement(int index, WrapperObject wrapperObject) { WrapperObject cases = new WrapperObject("CASES"); int caseCount = 1; index = this.FillConditionalStatement(index, wrapperObject); index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index); while (this.TokenList[index] != "}") { switch (this.TokenList[index]) { case "case": List <WrapperType> instantCases = new List <WrapperType>(); WrapperObject thisCase = new WrapperObject($"CASE_{caseCount++}"); WrapperObject caseContent = new WrapperObject("CASE_CONTENT"); index = RulesUtility.ValidateToken(this.TokenList[index], "case", "This needs is a valid \'case\'.", index); string caseValue = string.Empty; while (this.TokenList[index] != ":") { caseValue += this.TokenList[index++]; } thisCase.Value.Add(new WrapperString("CASE_VALUE", caseValue)); index = RulesUtility.ValidateToken(this.TokenList[index], ":", "This needs is a valid \':\'.", index); instantCases.Add(thisCase); while (this.TokenList[index] == "case") { WrapperObject otherCase = new WrapperObject($"CASE_{caseCount++}"); index = RulesUtility.ValidateToken(this.TokenList[index], "case", "This needs is a valid \'case\'.", index); string multiCaseValue = string.Empty; while (this.TokenList[index] != ":") { multiCaseValue += this.TokenList[index++]; } otherCase.Value.Add(new WrapperString("CASE_VALUE", multiCaseValue)); index = RulesUtility.ValidateToken(this.TokenList[index], ":", "This needs is a valid \':\'.", index); instantCases.Add(otherCase); } index = this.FillFunctionContent(index, caseContent, false); index = RulesUtility.ValidateToken(this.TokenList[index], "break", "This needs is a valid \'break\'.", index); index = RulesUtility.ValidateToken(this.TokenList[index], ";", "This needs is a valid \';\'.", index); foreach (var inst in instantCases) { (inst as WrapperObject).Value.Add(caseContent); cases.Value.Add(inst); } break; case "default": WrapperObject defaultCase = new WrapperObject($"DEFAULT"); WrapperObject defaultContent = new WrapperObject("DEFAULT_CONTENT"); index = RulesUtility.ValidateToken(this.TokenList[index], "default", "This needs is a valid \'default\'.", index); index = RulesUtility.ValidateToken(this.TokenList[index], ":", "This needs is a valid \':\'.", index); index = this.FillFunctionContent(index, defaultContent, false); index = RulesUtility.ValidateToken(this.TokenList[index], "break", "This needs is a valid \'break\'.", index); index = RulesUtility.ValidateToken(this.TokenList[index], ";", "This needs is a valid \';\'.", index); defaultCase.Value.Add(defaultContent); cases.Value.Add(defaultCase); break; default: throw new Exception("No valid case or default for switch statement"); } } index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index); return(index); }
private int FillFunctionContent(int index, WrapperObject functionContent, bool isNormalStatement = true) { int counter = 1; int whileLoopCount = 1; int forLoopCount = 1; int ifCount = 1; int ifElseCount = 1; int elseCount = 1; int switchCount = 1; int doCount = 1; int tryCount = 1; string endingToken = isNormalStatement ? "}" : "break"; while (this.TokenList[index] != endingToken) { var values = string.Empty; string flag = this.TokenList[index].ToLower(); switch (flag) { case "for": index = RulesUtility.ValidateToken(this.TokenList[index], "for", "This needs is a valid \'for\'.", index); WrapperObject forObject = new WrapperObject($"FOR_{forLoopCount++}"); index = this.FillBracketStatement(index, forObject); functionContent.Value.Add(forObject); break; case "while": index = RulesUtility.ValidateToken(this.TokenList[index], "while", "This needs is a valid \'while\'.", index); WrapperObject whileObject = new WrapperObject($"WHILE_{whileLoopCount++}"); index = this.FillBracketStatement(index, whileObject); functionContent.Value.Add(whileObject); break; case "if": index = RulesUtility.ValidateToken(this.TokenList[index], "if", "This needs is a valid \'if\'.", index); WrapperObject ifObject = new WrapperObject($"IF_{ifCount++}"); index = this.FillBracketStatement(index, ifObject); functionContent.Value.Add(ifObject); break; case "else": index = RulesUtility.ValidateToken(this.TokenList[index], "else", "This needs is a valid \'else\'.", index); if (this.TokenList[index].ToLower() == "if") { index = RulesUtility.ValidateToken(this.TokenList[index], "if", "This needs is a valid \'if\'.", index); WrapperObject elseIfObject = new WrapperObject($"ELSE_IF_{ifElseCount++}"); index = this.FillBracketStatement(index, elseIfObject); functionContent.Value.Add(elseIfObject); } else { WrapperObject elseObject = new WrapperObject($"ELSE_{elseCount++}"); index = RulesUtility.ValidateToken(this.TokenList[index], "{", "This needs is a valid \'{\'.", index); index = this.FillFunctionContent(index, elseObject); index = RulesUtility.ValidateToken(this.TokenList[index], "}", "This needs is a valid \'}\'.", index); functionContent.Value.Add(elseObject); } break; case "switch": index = RulesUtility.ValidateToken(this.TokenList[index], "switch", "This needs is a valid \'switch\'.", index); WrapperObject switchObject = new WrapperObject($"SWITCH_{switchCount++}"); index = this.FillSwitchStatement(index, switchObject); functionContent.Value.Add(switchObject); break; case "do": index = RulesUtility.ValidateToken(this.TokenList[index], "do", "This needs is a valid \'do\'.", index); WrapperObject doObject = new WrapperObject($"DO_{doCount++}"); index = this.FillDoWhile(index, doObject); functionContent.Value.Add(doObject); break; case "try": index = RulesUtility.ValidateToken(this.TokenList[index], "try", "This needs is a valid \'try\'.", index); WrapperObject tryObject = new WrapperObject($"TRY_{tryCount++}"); index = this.FillTryCatch(index, tryObject); functionContent.Value.Add(tryObject); break; default: while (this.TokenList[index] != ";") { string lookAhead = this.TokenList[index + 1]; values += this.TokenList[index]; if (lookAhead != "." && lookAhead != "(" && lookAhead != ")" && lookAhead != "\'" && lookAhead != ";" && this.TokenList[index] != "." && this.TokenList[index] != "(" && this.TokenList[index] != ")" && this.TokenList[index] != "\"" && this.TokenList[index] != "\'") { values += " "; } index++; } index = RulesUtility.ValidateToken(this.TokenList[index], ";", "This needs is a valid \';\'.", index); values += ";"; functionContent.Value.Add(new WrapperString($"STATEMENT_{counter++}", values)); break; } } return(index); }