Пример #1
0
        private RegexFactor VisitRegexFactorNode(IInternalTreeNode internalNode)
        {
            RegexAtom     atom     = null;
            RegexIterator?iterator = 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.Atom == childInternalNodeSymbolValue)
                {
                    atom = VisitRegexAtomNode(childInternalNode);
                }
                else if (RegexGrammar.Iterator == childInternalNodeSymbolValue)
                {
                    iterator = VisitRegexIteratorNode(childInternalNode);
                }
            }

            if (iterator.HasValue)
            {
                return(new RegexFactorIterator(
                           atom,
                           iterator.Value));
            }

            return(new RegexFactor(atom));
        }
Пример #2
0
        private static Nfa Atom(RegexAtom atom)
        {
            switch (atom)
            {
            case RegexAtomAny _:
                return(Any());

            case RegexAtomCharacter regexAtomCharacter:
                return(Character(regexAtomCharacter.Character));

            case RegexAtomExpression regexAtomExpression:
                return(Expression(regexAtomExpression.Expression));

            case RegexAtomSet regexAtomSet:
                return(Set(regexAtomSet));
            }

            throw new InvalidOperationException("Unrecognized regex atom");
        }
        private static INfa Atom(RegexAtom atom)
        {
            switch (atom.NodeType)
            {
            case RegexNodeType.RegexAtomAny:
                return(Any());

            case RegexNodeType.RegexAtomCharacter:
                var regexAtomCharacter = atom as RegexAtomCharacter;
                return(Character(regexAtomCharacter.Character));

            case RegexNodeType.RegexAtomExpression:
                var regexAtomExpression = atom as RegexAtomExpression;
                return(Expression(regexAtomExpression.Expression));

            case RegexNodeType.RegexAtomSet:
                var regexAtomSet = atom as RegexAtomSet;
                return(Set(regexAtomSet));
            }
            throw new InvalidOperationException("Unrecognized regex atom");
        }
        private static INfa Atom(RegexAtom atom)
        {
            switch (atom.NodeType)
            {
                case RegexNodeType.RegexAtomAny:
                    return Any();

                case RegexNodeType.RegexAtomCharacter:
                    var regexAtomCharacter = atom as RegexAtomCharacter;
                    return Character(regexAtomCharacter.Character);

                case RegexNodeType.RegexAtomExpression:
                    var regexAtomExpression = atom as RegexAtomExpression;
                    return Expression(regexAtomExpression.Expression);

                case RegexNodeType.RegexAtomSet:
                    var regexAtomSet = atom as RegexAtomSet;
                    return Set(regexAtomSet);
            }
            throw new InvalidOperationException("Unrecognized regex atom");
        }
Пример #5
0
        private IRegexFactor VisitRegexFactorNode(IInternalTreeNode node)
        {
            RegexAtom     atom     = null;
            RegexIterator?iterator = null;

            foreach (var internalNode in node.Children.OfType <IInternalTreeNode>())
            {
                if (internalNode.Is(RegexGrammar.Atom))
                {
                    atom = VisitRegexAtomNode(internalNode);
                }
                else if (internalNode.Is(RegexGrammar.Iterator))
                {
                    iterator = VisitRegexIteratorNode(internalNode);
                }
            }

            if (iterator.HasValue)
            {
                return(new RegexFactorIterator(atom, iterator.Value));
            }

            return(new RegexFactorAtom(atom));
        }
Пример #6
0
 public RegexFactor(RegexAtom atom)
 {
     Atom = atom;
     _hashCode = ComputeHashCode();
 }
Пример #7
0
 public RegexFactorIterator(RegexAtom atom, RegexIterator iterator)
     : base(atom)
 {
     Iterator = iterator;
     _hashCode = ComputeHashCode();
 }
Пример #8
0
 public RegexFactorIterator(RegexAtom atom, RegexIterator iterator)
 {
     Atom     = atom;
     Iterator = iterator;
 }
Пример #9
0
 public RegexFactorAtom(RegexAtom atom)
 {
     Atom = atom;
 }