public override void ModifyFileParser(FileParser fileParser) { if (string.IsNullOrEmpty(Value)) { NeoDoc.WriteErrors("Invalid param argument format", new List <string> { "In '@" + GetName() + "' param" }, fileParser.relPath, fileParser.CurrentLineCount + 1, (int)NeoDoc.ERROR_CODES.INVALID_PARAM_ARGS_FORMAT); } base.ModifyFileParser(fileParser); }
// merges 2 sections together. Used by a wrapper to merge same sections of different files public void Merge(SectionParam sectionParam) { foreach (KeyValuePair <string, List <DataStructure> > keyValuePair in sectionParam.DataStructureDict) { foreach (DataStructure dataStructure in keyValuePair.Value) { // just insert if not already exists if (!DataStructureDict.TryGetValue(keyValuePair.Key, out List <DataStructure> finalDSList)) // initialize if not already exists { finalDSList = new List <DataStructure>(); DataStructureDict.Add(keyValuePair.Key, finalDSList); } DataStructure alreadyExistingDs = null; int i = 0; for (; i < finalDSList.Count; i++) { DataStructure tmpDs = finalDSList[i]; if (tmpDs.GetDatastructureName() == dataStructure.GetDatastructureName() && tmpDs.Realm == dataStructure.Realm) { alreadyExistingDs = tmpDs; break; } } if (alreadyExistingDs != null) { DataStructure mergedDs = alreadyExistingDs.Merge(dataStructure); if (mergedDs == null) { NeoDoc.WriteErrors("Merging issue", new List <string>() { "Tried to add an already existing '" + alreadyExistingDs.GetName() + "' datastructure ('" + alreadyExistingDs.GetDatastructureName() + "') while merging section '" + sectionParam.SectionName + "'!", "Existing datastructure source: '" + alreadyExistingDs.FoundPath + "' (ll. " + alreadyExistingDs.FoundLine + ")" }, dataStructure.FoundPath, dataStructure.FoundLine, (int)NeoDoc.ERROR_CODES.MERGING_ISSUE); } else if (mergedDs != alreadyExistingDs) // replace if new ds { finalDSList[i] = mergedDs; } continue; } finalDSList.Add(dataStructure); } } }
public abstract object GetData(); // returns data public virtual void ProcessDatastructure(FileParser fileParser) // used to set default data { bool foundRealm = false; // if param "@realm" or "@ignore" found if (ParamsList != null) { List <Param> copyParamList = new List <Param>(); for (int i = 0; i < ParamsList.Count; i++) { Param curParam = ParamsList[i]; if (curParam is RealmParam realmParam) { Realm = realmParam.Value; foundRealm = true; } else if (curParam is IgnoreParam) { Ignore = true; } else if (curParam is DescParam descParam) { if (!string.IsNullOrEmpty(descParam.Text)) // just add if desc is not empty { copyParamList.Add(curParam); } } else { copyParamList.Add(curParam); } } ParamsList = copyParamList.Count > 0 ? copyParamList : null; } if (!Ignore) { Process(fileParser); } if (!Ignore && !foundRealm) { NeoDoc.WriteErrors("Missing essential param", new List <string> { "Missing '@realm' in " + GetName() + " '" + GetDatastructureName() + "'" }, FoundPath, FoundLine, (int)NeoDoc.ERROR_CODES.MISSING_ESSENTIAL_PARAMS); } }
public override Dictionary <string, object> GetJSONData() { Dictionary <string, object> tmpData = GetData(); if (tmpData == null) // if there is no json data, settings will not make sense by default (like for a MarkParam), so those are excluded as well { if (SettingsDict != null && SettingsDict.Count > 0) { NeoDoc.WriteErrors("SettingsData detected in a non-json param", null, FoundPath, FoundLine, (int)NeoDoc.ERROR_CODES.NO_SETTINGS_PARAM); } return(null); } return(base.GetJSONData()); }
public override void Process(FileParser fileParser) { Line = fileParser.Lines[fileParser.CurrentLineCount]; string name = null; if (ParamsList != null && ParamsList.Count > 0) { for (int i = 0; i < ParamsList.Count; i++) { if (ParamsList[i] is NameParam nameParam) { name = nameParam.Value; ParamsList.RemoveAt(i); break; } } if (ParamsList.Count == 0) { ParamsList = null; } } Match splitMatch = GetRegex().Match(Line); if (splitMatch.NextMatch().Success) // there are multiple hooks in this line { NeoDoc.WriteErrors("Multiple datastructures found", null, fileParser.relPath, fileParser.CurrentLineCount + 1, (int)NeoDoc.ERROR_CODES.MULTIPLE_DS_IN_LINE); } string result = Line.Substring(splitMatch.Index, Line.Length - splitMatch.Index); bool mode = new Regex(@"\s*hook\.Run\s*\(").Match(Line).Success; // if false, "hook.Call(" is found List <string> tmpData = NeoDoc.GetEntriesFromString(result, out _); HookName = GlobalWrapper + ":" + (name ?? tmpData[0]).Trim('"'); HookData = HookName + "(" + string.Join(", ", tmpData.GetRange(mode ? 1 : 2, tmpData.Count - (mode ? 1 : 2)).ToArray()) + ")"; // "hook.Call( string eventName, table gamemodeTable, vararg args )" or "hook.Run( string eventName, vararg args )" }
public override void Check() { List <string> expectedParams = NeoDoc.GetEntriesFromString(FunctionData, out _); List <ParamParam> paramParams = new List <ParamParam>(); if (ParamsList != null) { foreach (Param param in ParamsList) { if (param is ParamParam paramParam) { paramParams.Add(paramParam); } } } if (paramParams.Count != expectedParams.Count) { List <string> errors = new List <string>() { "In '" + GetName() + "' datastructure ('" + FunctionData + "'), detected params (" + paramParams.Count + "): " }; foreach (ParamParam paramParam in paramParams) { errors.Add("- '" + paramParam.Name + "'"); } errors.Add("Expected Params (" + expectedParams.Count + "): "); foreach (string paramParamName in expectedParams) { errors.Add("- '" + paramParamName + "'"); } NeoDoc.WriteErrors("Param mismatch", errors, FoundPath, FoundLine, (int)NeoDoc.ERROR_CODES.PARAM_MISMATCH); } }
public void ProcessGlobals(SortedDictionary <string, SortedDictionary <string, List <DataStructure> > > globalsDict) { SortedDictionary <string, List <DataStructure> > finalDict = new SortedDictionary <string, List <DataStructure> >(); foreach (KeyValuePair <string, List <DataStructure> > keyValuePair in DataStructureDict) { List <DataStructure> finalDSList = new List <DataStructure>(); foreach (DataStructure dataStructure in keyValuePair.Value) { DataStructure alreadyExistingDs = null; if (!dataStructure.IsGlobal()) { foreach (DataStructure entry in finalDSList) { if (entry.GetDatastructureName() == dataStructure.GetDatastructureName() && entry.Realm == dataStructure.Realm) { alreadyExistingDs = entry; break; } } if (alreadyExistingDs != null) { NeoDoc.WriteErrors("Merging issue", new List <string>() { "Tried to add an already existing '" + alreadyExistingDs.GetName() + "' datastructure ('" + alreadyExistingDs.GetDatastructureName() + "') in the same section ('" + SectionName + "')!", "Existing datastructure source: '" + alreadyExistingDs.FoundPath + "' (ll. " + alreadyExistingDs.FoundLine + ")" }, dataStructure.FoundPath, dataStructure.FoundLine, (int)NeoDoc.ERROR_CODES.MERGING_ISSUE); continue; } finalDSList.Add(dataStructure); continue; } if (!globalsDict.TryGetValue(dataStructure.GetName(), out SortedDictionary <string, List <DataStructure> > dsList)) { dsList = new SortedDictionary <string, List <DataStructure> >(); globalsDict.Add(dataStructure.GetName(), dsList); } // just insert if not already exists if (!dsList.TryGetValue(dataStructure.GlobalWrapper, out List <DataStructure> dsWrapperList)) { dsWrapperList = new List <DataStructure>(); dsList.Add(dataStructure.GlobalWrapper, dsWrapperList); } int i = 0; for (; i < dsWrapperList.Count; i++) { DataStructure entry = dsWrapperList[i]; if (entry.GetDatastructureName() == dataStructure.GetDatastructureName() && entry.Realm == dataStructure.Realm) { alreadyExistingDs = entry; break; } } if (alreadyExistingDs != null) { DataStructure mergedDs = alreadyExistingDs.Merge(dataStructure); if (mergedDs == null) { NeoDoc.WriteErrors("Merging issue", new List <string>() { "Tried to add an already existing global '" + alreadyExistingDs.GetName() + "' datastructure ('" + alreadyExistingDs.GetDatastructureName() + "')!", "Existing datastructure source: '" + alreadyExistingDs.FoundPath + "' (ll. " + alreadyExistingDs.FoundLine + ")" }, dataStructure.FoundPath, dataStructure.FoundLine, (int)NeoDoc.ERROR_CODES.MERGING_ISSUE); } else if (mergedDs != alreadyExistingDs) // replace if new ds { dsWrapperList[i] = mergedDs; } continue; } dsWrapperList.Add(dataStructure); } if (finalDSList.Count > 0) { finalDict.Add(keyValuePair.Key, finalDSList); } } DataStructureDict = finalDict; }
public override void Process(FileParser fileParser) { if (Ignore) { return; } string[] typs = null; string typDesc = null; string name = null; bool local = false; if (ParamsList != null) { for (int i = 0; i < ParamsList.Count; i++) { List <Param> copyParamsList = new List <Param>(); Param currentParam = ParamsList[i]; if (currentParam is AccessorParam accessorParam) { typs = accessorParam.Typs; typDesc = accessorParam.Description; } else if (currentParam is NameParam nameParam) { name = nameParam.Value; } else if (currentParam is LocalParam) { local = true; } else { copyParamsList.Add(currentParam); } } if (ParamsList.Count == 0) { ParamsList = null; } } if (local) { Ignore = true; } string line = fileParser.Lines[fileParser.CurrentLineCount]; if (typs == null) { NeoDoc.WriteErrors("Missing essential param", new List <string> { "Missing '@accessor' in '" + GetName() + "' datastructure" }, fileParser.relPath, fileParser.CurrentLineCount + 1, (int)NeoDoc.ERROR_CODES.MISSING_ESSENTIAL_PARAMS); } Match splitMatch = GetRegex().Match(line); List <string> tmpData = NeoDoc.GetEntriesFromString(line.Substring(splitMatch.Index, line.Length - splitMatch.Index), out _); string wrapperName = tmpData[0].Trim(); string varName = tmpData[1].Trim('"'); string funcPartName = tmpData[2].Trim('"'); // create a setter func Function setterFunc = new Function { // set meta information FoundLine = fileParser.CurrentLineCount + 1, FoundPath = fileParser.relPath }; setterFunc.Line = line; setterFunc.Local = local; setterFunc.FunctionData = line; setterFunc.Name = wrapperName + ":" + "Set" + (name ?? funcPartName); List <Param> _tmpList; if (ParamsList == null) { _tmpList = new List <Param>(); } else { _tmpList = new List <Param>(ParamsList); } setterFunc.ParamsList = _tmpList; setterFunc.ParamsList.Add(new ParamParam() { Name = varName, Typs = typs, Description = typDesc }); // create a getter func Function getterFunc = new Function { // set meta information FoundLine = fileParser.CurrentLineCount + 1, FoundPath = fileParser.relPath }; getterFunc.Line = line; getterFunc.Local = local; getterFunc.FunctionData = line; getterFunc.Name = wrapperName + ":" + "Get" + (name ?? funcPartName); if (ParamsList == null) { _tmpList = new List <Param>(); } else { _tmpList = new List <Param>(ParamsList); } getterFunc.ParamsList = _tmpList; getterFunc.ParamsList.Add(new ReturnParam() { Typs = typs, Description = typDesc }); // now add the datastructure into the current section of the current container if (!fileParser.CurrentSection.DataStructureDict.TryGetValue(getterFunc.GetName(), out List <DataStructure> dsList)) { dsList = new List <DataStructure>(); fileParser.CurrentSection.DataStructureDict.Add(getterFunc.GetName(), dsList); } dsList.Add(setterFunc); dsList.Add(getterFunc); }