/// <summary> /// Reads representation string and divides it into modules and content in brackets that follows each name /// (or null if there is no bracket) /// </summary> /// <param name="representation"> /// string containing only module names and possibly one bracket behind each name /// </param> /// <returns>List of doubles, first item contains module name, second content of it bracket</returns> /// <exception cref="ParserException">Thrown if representation doesn't contain valid modules represenation</exception> internal List <Tuple <string, string> > SeparateModulesRepresentations(string representation) { if (representation == null) { return(new List <Tuple <string, string> >()); } var modules = new List <Tuple <string, string> >(); try { int index = 0; while (index < representation.Length) { string name = HelperMethods.ReadModuleName(representation, index, out index); index++; string details = null; if (index < representation.Length && representation[index] == '(') { details = HelperMethods.ReadBracketContent(representation, index, out index); index++; } modules.Add(new Tuple <string, string>(name, details)); } return(modules); } catch (ArgumentException) { throw new ParserException("representation cannot be parsed into modules"); } }
/// <summary> /// Parser source module ID and param names based on its representation /// </summary> /// <param name="representation">string containing one module name and up to one bracket with param names</param> /// <param name="sourceId">id of module in representation</param> /// <param name="paramNames">names of param in bracket if present</param> /// <exception cref="ParserException">Thrown if unknown symbols are found</exception> internal void ParseSourceModule(string representation, out int sourceId, out string[] paramNames) { string moduleName = HelperMethods.ReadModuleName(representation, 0, out int endIndex); sourceId = _moduleParser.GetModuleId(moduleName); endIndex++; if (endIndex < representation.Length && representation[endIndex] == '(') { string param = HelperMethods.ReadBracketContent(representation, endIndex, out endIndex); if (endIndex != representation.Length - 1) { throw new ParserException("Unknown content at source module at index: " + (endIndex + 1)); } paramNames = param.Split(','); } else { paramNames = new string[0]; } }