Пример #1
0
            private static ClassExpression Class(INode node)
            {
                var parts = new List <ClassPartExpression>();

                foreach (var part in node.Children.Skip(1))
                {
                    switch (part.Name)
                    {
                    case "range":
                        parts.Add(ClassRangeExpression.From(part,
                                                            Char.ConvertToUtf32(DecodeChar(part[0]), 0),
                                                            Char.ConvertToUtf32(DecodeChar(part[1]), 0)));
                        break;

                    default:
                        parts.Add(ClassCharExpression.From(part, Char.ConvertToUtf32(DecodeChar(part), 0)));
                        break;
                    }
                }

                return(ClassExpression.From(node, node[0].Count != 0, parts));
            }
Пример #2
0
        private ClassPartExpression SingleOrRange(INode node)
        {
            if (node.Name == "single")
            {
                Debug.Assert(node.Count == 1);

                var c = Character(node[0]);
                Debug.Assert(c.Length == 1);
                return(ClassCharExpression.From(node, c[0]));
            }
            else if (node.Name == "range")
            {
                Debug.Assert(node.Count == 2);

                var c1 = Character(node[0]);
                Debug.Assert(c1.Length == 1);
                var c2 = Character(node[1]);
                Debug.Assert(c2.Length == 1);
                return(ClassRangeExpression.From(node, c1[0], c2[0]));
            }

            throw new NotImplementedException();
        }