public static (Dictionary <int, IRule> ruleRegistry, List <string> messages) ParseInput(string[] inputs) { var ruleRegistry = new Dictionary <int, IRule>(); var messages = new List <string>(); var parsedRules = false; foreach (var input in inputs) { if (input == string.Empty) { if (parsedRules) { throw new Exception("Not expecting to see two empty lines?"); } parsedRules = true; } else if (!parsedRules) { var ruleElems = input.Split(":"); var ruleNumber = int.Parse(ruleElems[0]); var ruleBody = ruleElems[1].Trim(); if (ruleBody.Contains("\"")) { ruleRegistry[ruleNumber] = new LeafRule(ruleBody); } else { ruleRegistry[ruleNumber] = new BranchRule(ruleBody); } } else { messages.Add(input); } } return(ruleRegistry, messages); }
private string Dump(LeafRule.Substitution leafRule) { if (leafRule == null) return null; return string.Format("NonTerminal('{0}{1}')", leafRule.Expand, leafRule.Short); }
private string Dump(LeafRule.String leafRule) { if (leafRule == null) return null; if (_ignoredStrings.Contains(leafRule.Value)) { return null; } var escapeNsNames = Regex.Replace(leafRule.Value, "[\\w.]+\\.", String.Empty); return string.Format("Terminal('{0}')", escapeNsNames); }
private string Dump(LeafRule.NonTerminal leafRule) { if (leafRule == null) return null; if (_alwaysExpandRules.Contains(leafRule.Value)) { return DumpConcatRules(_globalRules.First(r => r.Name == leafRule.Value).Rules); } return string.Format("NonTerminal('{0}')", leafRule.Value); }
private string Dump(LeafRule.InsideRule leafRule) { if (leafRule == null) return null; return DumpConcatRules(leafRule.Rules.ToArray()); // return string.Format("NonTerminal('{0}')", leafRule.) }