CFGLib.CFGParser.Production C# (CSharp) Метод

Production() публичный статический Метод

Turns a string like <X> -> <X> 'a' <X> into a production. Nonterminals must be surrounded by angled brackets, terminals must be surrounded by single quotes, and everything must be separated by spaces.
public static Production ( string s ) : Production
s string
Результат Production
		public static Production Production(string s) {
			var match = ProductionRegex.Match(s);
			if (!match.Success) {
				throw new Exception("Didn't find valid string");
			}

			var lhsMatch = match.Groups["lhs"];
			var ntMatch = match.Groups["nt"];
			var tMatch = match.Groups["t"];
			var weightMatch = match.Groups["weight"];

			if (!lhsMatch.Success) {
				throw new Exception("Didn't find LHS");
			}

			double weight;
			if (!double.TryParse(weightMatch.Value, out weight)) {
				weight = 1.0;
			}
			
			var rhsList = new SortedList<int, Word>();

			foreach (Capture capture in ntMatch.Captures) {
				var word = Nonterminal.Of(capture.Value);
				rhsList.Add(capture.Index, word);
			}
			foreach (Capture capture in tMatch.Captures) {
				var word = Terminal.Of(capture.Value);
				rhsList.Add(capture.Index, word);
			}
			var rhs = new Sentence(rhsList.Values);
			var lhs = Nonterminal.Of(lhsMatch.Value);

			var retval = new Production(lhs, rhs, weight);
			return retval;
		}
	}