Exemplo n.º 1
0
        internal Automaton <S> ConvertNode(RegexNode node)
        {
            //node = node.Reduce();
            switch (node._type)
            {
            case RegexNode.Alternate:
                return(this.automBuilder.MkUnion(node._children.ToArray()));

            case RegexNode.Beginning:
                return(this.automBuilder.MkBeginning());

            case RegexNode.Bol:
                return(this.automBuilder.MkBol(solver.MkCharConstraint('\n')));

            case RegexNode.Capture:      //paranthesis (...)
                return(ConvertNode(node.Child(0)));

            case RegexNode.Concatenate:
                return(this.automBuilder.MkConcatenate(node._children.ToArray()));

            case RegexNode.Empty:
                return(this.automBuilder.MkEmptyWord());

            case RegexNode.End:
            case RegexNode.EndZ:
                return(this.automBuilder.MkEnd());

            case RegexNode.Eol:
                return(this.automBuilder.MkEol(solver.MkCharConstraint('\n')));

            case RegexNode.Lazyloop:
            case RegexNode.Loop:
                return(automBuilder.MkLoop(node._children[0], node._m, node._n));

            case RegexNode.Multi:
                return(ConvertNodeMulti(node));

            case RegexNode.Notonelazy:
            case RegexNode.Notone:
                return(ConvertNodeNotone(node));

            case RegexNode.Notoneloop:
                return(ConvertNodeNotoneloop(node));

            case RegexNode.Onelazy:
            case RegexNode.One:
                return(ConvertNodeOne(node));

            case RegexNode.Oneloop:
                return(ConvertNodeOneloop(node));

            case RegexNode.Setlazy:
            case RegexNode.Set:
                return(ConvertNodeSet(node));

            case RegexNode.Setloop:
                return(ConvertNodeSetloop(node));

            case RegexNode.ECMABoundary:
            case RegexNode.Boundary:
                return(automBuilder.MkWordBoundary());

            case RegexNode.Nothing:
                return(automBuilder.MkEmptyAutomaton());

            //currently not supported cases
            //case RegexNode.Lazyloop:
            //throw new AutomataException("Regex construct not supported: lazy constructs *? +? ?? {,}?");
            //case RegexNode.Notonelazy:
            //    throw new AutomataException("Regex construct not supported: lazy construct .*?");
            //case RegexNode.Onelazy:
            //    throw new AutomataException("Regex construct not supported: lazy construct a*?");
            //case RegexNode.Setlazy:
            //    throw new AutomataException(@"Regex construct not supported: lazy construct \d*?");
            case RegexNode.Nonboundary:
            case RegexNode.NonECMABoundary:
                throw new AutomataException(@"Regex construct not supported: \B");

            case RegexNode.Greedy:
                throw new AutomataException("Regex construct not supported: greedy constructs (?>) (?<)");

            case RegexNode.Group:
                throw new AutomataException("Regex construct not supported: grouping (?:)");

            case RegexNode.Prevent:
                throw new AutomataException("Regex construct not supported: prevent constructs (?!) (?<!)");

            case RegexNode.Require:
                throw new AutomataException("Regex construct not supported: require constructs (?=) (?<=)");

            case RegexNode.Testgroup:
                throw new AutomataException("Regex construct not supported: test construct (?(...) | )");

            case RegexNode.Testref:
                throw new AutomataException("Regex construct not supported: test cosntruct (?(n) | )");

            case RegexNode.Ref:
                throw new AutomataException(@"Regex construct not supported: references \1");

            case RegexNode.Start:
                throw new AutomataException(@"Regex construct not supported: \G");

            default:
                throw new AutomataException(AutomataExceptionKind.UnrecognizedRegex);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Convert to automaton
 /// </summary>
 public Automaton <S> ToAutomaton(RegexToAutomatonBuilder <ILikeNode, S> builder, ICharAlgebra <S> solver)
 {
     return(builder.MkLoop(new LikeAny(), 0, int.MaxValue));
 }