Example #1
0
        /// <summary>
        /// Parse rules with given string format of line
        /// </summary>
        /// <param name="line">String format of line</param>
        public void ParseLine(string line)
        {
            // Split before ':' and after
            var parts      = line.Split(':');
            var definition = parts[0];
            var rest       = parts[1].Trim();

            var rule = new Rule {
                Definition = definition
            };

            // Parse word e.g. transcends
            var regex = new Regex("([a-z]+)\\|*");

            foreach (var w in regex.Matches(rest))
            {
                rule.AddWord(w.ToString().Replace("|", ""));
            }


            // Parse reference e.g. <PREPOSITION>
            regex = new Regex("<(?<rule>[A-Z]+)>");
            foreach (var reference in regex.Matches(rest))
            {
                var refName = reference.ToString();

                // remove first and last char
                refName = refName.Substring(1, refName.Length - 2);

                rule.AddRefRule(refName);
            }


            // Parse keyword e.g. $END
            regex = new Regex("\\$[A-Z]+");
            foreach (var k in regex.Matches(rest))
            {
                rule.AddKeyword(k.ToString());
            }

            // Add to map
            this.Map.Add(definition, rule);
        }