Пример #1
0
 /// <summary>
 /// Returns a dictionary keyed by state, that contains all of the outgoing local input transitions, expressed as a series of ranges
 /// </summary>
 /// <param name="result">The dictionary to fill, or null to create one.</param>
 /// <returns>A dictionary containing the result of the query</returns>
 public IDictionary <CharFA <TAccept>, IList <CharRange> > FillInputTransitionRangesGroupedByState(IDictionary <CharFA <TAccept>, IList <CharRange> > result = null)
 {
     if (null == result)
     {
         result = new Dictionary <CharFA <TAccept>, IList <CharRange> >();
     }
     // using the optimized dictionary we have little to do here.
     foreach (var trns in (IDictionary <CharFA <TAccept>, ICollection <char> >)InputTransitions)
     {
         var sl = new List <char>(trns.Value);
         sl.Sort();
         result.Add(trns.Key, new List <CharRange>(CharRange.GetRanges(sl)));
     }
     return(result);
 }
        // build the character classes
        static IDictionary <string, IList <CharRange> > _GetCharacterClasses()
        {
            var result = new Dictionary <string, IList <CharRange> >();

            result.Add("alnum",
                       new List <CharRange>(
                           new CharRange[] {
                new CharRange('A', 'Z'),
                new CharRange('a', 'z'),
                new CharRange('0', '9')
            }));
            result.Add("alpha",
                       new List <CharRange>(
                           new CharRange[] {
                new CharRange('A', 'Z'),
                new CharRange('a', 'z')
            }));
            result.Add("ascii",
                       new List <CharRange>(
                           new CharRange[] {
                new CharRange('\0', '\x7F')
            }));
            result.Add("blank",
                       new List <CharRange>(
                           new CharRange[] {
                new CharRange(' ', ' '),
                new CharRange('\t', '\t')
            }));
            result.Add("cntrl",
                       new List <CharRange>(
                           new CharRange[] {
                new CharRange('\0', '\x1F'),
                new CharRange('\x7F', '\x7F')
            }));
            result.Add("digit",
                       new List <CharRange>(
                           new CharRange[] {
                new CharRange('0', '9')
            }));
            result.Add("^digit", new List <CharRange>(CharRange.NotRanges(result["digit"])));
            result.Add("graph",
                       new List <CharRange>(
                           new CharRange[] {
                new CharRange('\x21', '\x7E')
            }));
            result.Add("lower",
                       new List <CharRange>(
                           new CharRange[] {
                new CharRange('a', 'z')
            }));
            result.Add("print",
                       new List <CharRange>(
                           new CharRange[] {
                new CharRange('\x20', '\x7E')
            }));
            // [!"\#$%&'()*+,\-./:;<=>?@\[\\\]^_`{|}~]
            result.Add("punct",
                       new List <CharRange>(
                           CharRange.GetRanges("!\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~")
                           ));
            //[ \t\r\n\v\f]
            result.Add("space",
                       new List <CharRange>(
                           CharRange.GetRanges(" \t\r\n\v\f")
                           ));
            result.Add("^space", new List <CharRange>(CharRange.NotRanges(result["space"])));
            result.Add("upper",
                       new List <CharRange>(
                           new CharRange[] {
                new CharRange('A', 'Z')
            }));
            result.Add("word",
                       new List <CharRange>(
                           new CharRange[] {
                new CharRange('0', '9'),
                new CharRange('A', 'Z'),
                new CharRange('_', '_'),
                new CharRange('a', 'z')
            }));
            result.Add("^word", new List <CharRange>(CharRange.NotRanges(result["word"])));
            result.Add("xdigit",
                       new List <CharRange>(
                           new CharRange[] {
                new CharRange('0', '9'),
                new CharRange('A', 'F'),
                new CharRange('a', 'f')
            }));
            return(result);
        }