예제 #1
0
        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);
        }
예제 #2
0
 private string Dump(LeafRule.Substitution leafRule)
 {
     if (leafRule == null) return null;
     return string.Format("NonTerminal('{0}{1}')", leafRule.Expand, leafRule.Short);
 }
예제 #3
0
        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);
        }
예제 #4
0
 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);
 }
예제 #5
0
 private string Dump(LeafRule.InsideRule leafRule)
 {
     if (leafRule == null) return null;
     return DumpConcatRules(leafRule.Rules.ToArray());
     // return string.Format("NonTerminal('{0}')", leafRule.)
 }