/// <param name="lines"></param> /// <param name="startIndex">Index of the first SETTING</param> /// <returns></returns> private int ProcessSettingsBlock(string[] lines, int startIndex, RMPropSetting setting) { int i = startIndex + 1; //move directly to the first OPTION or END for (; i < lines.Length && lines[i].Trim().ToUpper() != "END"; i++) { Console.WriteLine("ProcessSettingsBlock @ ln" + i); string line = lines[i].Trim(); string[] lineParts = line.QASS(' '); //The only valid statement is OPTION. The second parameter can be DEFAULT only. if (lineParts[0].ToUpper() != "OPTION") { throw new Exception("Expected OPTION statement inside SETTING block @ line " + i); } else if (lineParts.Length < 2) //only OPTION on the line { throw new Exception("Expected OPTION statement followed by either DEFAULT or [option's text] @ line " + i); } else { if (lineParts[1] == "DEFAULT" && lineParts.Length == 3) //OPTION DEFAULT [text] { setting.AddOption(lineParts[2], true); } else { setting.AddOption(lineParts[1], false); } } } return(i); }
/// <param name="lines"></param> /// <param name="startIndex">The index of the OPTIONS block</param> /// <returns>index of last END</returns> private int ProcessOptionsBlock(string[] lines, int startIndex) { int i = startIndex + 1; //Move to the first SETTING or END for (; i < lines.Length && lines[i].Trim().ToUpper() != "END";) { Console.WriteLine("ProcessOptionsBlock @ ln" + i); string line = lines[i].Trim(); string[] lineParts = line.QASS(' '); //The only valid statement inside of a OPTIONS block is either "end" or "setting" if (lineParts.Length > 0) { if (lineParts[0].ToUpper() != "SETTING") { throw new Exception("Expected SETTING block inside OPTIONS block @ line " + i); } else { RMPropSetting setting; if (lineParts.Length >= 4) { setting = new RMPropSetting(lineParts[1], lineParts[2], lineParts[3]); } else { setting = new RMPropSetting(lineParts[1], lineParts[2], ""); } i = ProcessSettingsBlock(lines, i, setting) + 1; Console.WriteLine(i); Settings.Add(setting); } } else { i++; } } return(i); }
/// <param name="lines"></param> /// <param name="startIndex">Index of the first SETTING</param> /// <returns></returns> private int ProcessSettingsBlock(string[] lines, int startIndex, RMPropSetting setting) { int i = startIndex + 1; //move directly to the first OPTION or END for (; i < lines.Length && lines[i].Trim().ToUpper() != "END"; i++) { Console.WriteLine("ProcessSettingsBlock @ ln" + i); string line = lines[i].Trim(); string[] lineParts = line.QASS(' '); //The only valid statement is OPTION. The second parameter can be DEFAULT only. if (lineParts[0].ToUpper() != "OPTION") throw new Exception("Expected OPTION statement inside SETTING block @ line " + i); else if(lineParts.Length < 2) //only OPTION on the line throw new Exception("Expected OPTION statement followed by either DEFAULT or [option's text] @ line " + i); else { if (lineParts[1] == "DEFAULT" && lineParts.Length == 3) //OPTION DEFAULT [text] setting.AddOption(lineParts[2], true); else setting.AddOption(lineParts[1], false); } } return i; }
/// <param name="lines"></param> /// <param name="startIndex">The index of the OPTIONS block</param> /// <returns>index of last END</returns> private int ProcessOptionsBlock(string[] lines, int startIndex) { int i = startIndex + 1; //Move to the first SETTING or END for (; i < lines.Length && lines[i].Trim().ToUpper() != "END";) { Console.WriteLine("ProcessOptionsBlock @ ln" + i); string line = lines[i].Trim(); string[] lineParts = line.QASS(' '); //The only valid statement inside of a OPTIONS block is either "end" or "setting" if (lineParts.Length > 0) { if (lineParts[0].ToUpper() != "SETTING") throw new Exception("Expected SETTING block inside OPTIONS block @ line " + i); else { RMPropSetting setting; if (lineParts.Length >= 4) setting = new RMPropSetting(lineParts[1], lineParts[2], lineParts[3]); else setting = new RMPropSetting(lineParts[1], lineParts[2], ""); i = ProcessSettingsBlock(lines, i, setting) + 1; Console.WriteLine(i); Settings.Add(setting); } } else { i++; } } return i; }