Ejemplo n.º 1
0
        private RegexCharacterClass VisitCharacterClassNode(IInternalTreeNode internalNode)
        {
            RegexCharacterUnitRange characterRange = null;
            RegexCharacterClass     characterClass = null;

            for (var c = 0; c < internalNode.Children.Count; c++)
            {
                var child = internalNode.Children[c];
                if (child.NodeType != TreeNodeType.Internal)
                {
                    continue;
                }
                var childInternalNode            = child as IInternalTreeNode;
                var childInternalNodeSymbolValue = childInternalNode.Symbol.Value;

                if (RegexGrammar.CharacterRange == childInternalNodeSymbolValue)
                {
                    characterRange = VisitCharacterRangeNode(childInternalNode);
                }

                else if (RegexGrammar.CharacterClass == childInternalNodeSymbolValue)
                {
                    characterClass = VisitCharacterClassNode(childInternalNode);
                }
            }
            if (characterClass != null)
            {
                return(new RegexCharacterClassAlteration(
                           characterRange,
                           characterClass));
            }

            return(new RegexCharacterClass(characterRange));
        }
Ejemplo n.º 2
0
 public RegexCharacterClassAlteration(
     RegexCharacterUnitRange characterRange,
     RegexCharacterClass characterClass)
     : base(characterRange)
 {
     CharacterClass = characterClass;
     _hashCode      = ComputeHashCode();
 }
        private static INfa CharacterClass(RegexCharacterClass characterClass, bool negate)
        {
            switch (characterClass.NodeType)
            {
            case RegexNodeType.RegexCharacterClass:
                return(UnitRange(characterClass.CharacterRange, negate));

            case RegexNodeType.RegexCharacterClassAlteration:
                var alteration = characterClass as RegexCharacterClassAlteration;
                return(Union(
                           UnitRange(alteration.CharacterRange, negate),
                           CharacterClass(alteration.CharacterClass, negate)));
            }
            throw new InvalidOperationException("Unreachable code detected.");
        }
Ejemplo n.º 4
0
        private RegexCharacterClass VisitCharacterClassNode(IInternalTreeNode node)
        {
            RegexCharacters     characterRange = null;
            RegexCharacterClass characterClass = null;

            foreach (var internalNode in node.Children.OfType <IInternalTreeNode>())
            {
                if (internalNode.Is(RegexGrammar.CharacterRange))
                {
                    characterRange = VisitCharacterRangeNode(internalNode);
                }
                else if (internalNode.Is(RegexGrammar.CharacterClass))
                {
                    characterClass = VisitCharacterClassNode(internalNode);
                }
            }

            if (characterClass == null)
            {
                return(new RegexCharacterClass(characterRange));
            }

            return(new RegexCharacterClassAlteration(characterRange, characterClass));
        }
Ejemplo n.º 5
0
 public RegexSet(bool negate, RegexCharacterClass characterClass)
 {
     Negate         = negate;
     CharacterClass = characterClass;
     _hashCode      = ComputeHashCode();
 }