Esempio 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));
        }
Esempio n. 2
0
 public RegexCharacterClassAlteration(
     RegexCharacterUnitRange characterRange,
     RegexCharacterClass characterClass)
     : base(characterRange)
 {
     CharacterClass = characterClass;
     _hashCode      = ComputeHashCode();
 }
        private static INfa UnitRange(RegexCharacterUnitRange unitRange, bool negate)
        {
            switch (unitRange.NodeType)
            {
            case RegexNodeType.RegexCharacterUnitRange:
                return(Character(unitRange.StartCharacter, negate));

            case RegexNodeType.RegexCharacterRange:
                var range = unitRange as RegexCharacterRange;
                return(Range(range, negate));
            }
            throw new InvalidOperationException("Unreachable code detected.");
        }
Esempio n. 4
0
 public RegexCharacterClass(RegexCharacterUnitRange characterRange)
 {
     CharacterRange = characterRange;
     _hashCode      = ComputeHashCode();
 }