/// <summary>The translation of this syntax tree into NFA instruction code.</summary>
 /// <param name="builder">Data needed to construct an NFA.</param>
 /// <returns>The <see cref="NFA.Instruction"/> implementing this AST.</returns>
 public override NFA.Instruction ToInstruction(NFABuilder builder)
 {
     return new NFA.Instruction {
         test = NFA.TestCode.BoolProperty,
         arg1 = (int)Unicode7.Property.AnyChar,
     };
 }
Пример #2
0
        internal NFA(NFABuilder builder)
        {
            this.sameFinal = new Match.SameFinal();
            this.Pending = new int[builder.TestDepth];
            this.PendingTop = 0;
            this.Undos = new UndoStep[builder.MaxUndos + 2];
            this.UndoTop = 0;

            AtomicCount = builder.ParseInfo.nAtomics;
            GroupNames = builder.ParseInfo.captures.ToArray();
            QuantDepth = builder.ParseInfo.quantDepth;
            Anchored = builder.ParseInfo.anchor;
            Backrefs = builder.ParseInfo.backrefs;
            Instructions = builder.Instructions.ToArray();

            nTransitions = 0;
            List<Transition[]> stateList = new List<Transition[]>();
            foreach (List<Transition> transList in builder.States)
            {
                stateList.Add(transList.ToArray());
                nTransitions += transList.Count;
            }
            States = stateList.ToArray();
            FinalState = builder.FinalState;
            FirstTest = builder.FirstTest;
            FixedPrefix = builder.FixedPrefix;
        }
Пример #3
0
 /// <summary>The translation of this syntax tree into NFA instruction code.</summary>
 /// <param name="builder">Data needed to construct an NFA.</param>
 /// <returns>The <see cref="NFA.Instruction"/> implementing this AST.</returns>
 public override NFA.Instruction ToInstruction(NFABuilder builder)
 {
     return new NFA.Instruction
     {
         test = Source.FoldsCase ? NFA.TestCode.BackrefCheckFC : NFA.TestCode.BackrefCheck,
         arg1 = Source.CaptureID,
     };
 }
Пример #4
0
 /// <summary>The translation of this syntax tree into NFA instruction code.</summary>
 /// <param name="builder">Data needed to construct an NFA.</param>
 /// <returns>The <see cref="NFA.Instruction"/> implementing this AST.</returns>
 public override NFA.Instruction ToInstruction(NFABuilder builder)
 {
     return new NFA.Instruction
     {
         test = NFA.TestCode.And,
         arg1 = builder.AddInstructions(Left),
         arg2 = builder.AddInstructions(Right),
     };
 }
Пример #5
0
 /// <summary>The translation of this syntax tree into NFA instruction code.</summary>
 /// <param name="builder">Data needed to construct an NFA.</param>
 /// <returns>The <see cref="NFA.Instruction"/> implementing this AST.</returns>
 public override NFA.Instruction ToInstruction(NFABuilder builder)
 {
     return new NFA.Instruction
     {
         test = IsExtended ? NFA.TestCode.ScriptExt : NFA.TestCode.Script,
         arg1 = (int)Script,
     };
 }
Пример #6
0
 /// <summary>The translation of this syntax tree into NFA instruction code.</summary>
 /// <param name="builder">Data needed to construct an NFA.</param>
 /// <returns>The <see cref="NFA.Instruction"/> implementing this AST.</returns>
 public override NFA.Instruction ToInstruction(NFABuilder builder)
 {
     return new NFA.Instruction { test = NFA.TestCode.Category, arg1 = (int)Category, };
 }
Пример #7
0
 /// <summary>The translation of this syntax tree into NFA instruction code.</summary>
 /// <param name="builder">Data needed to construct an NFA.</param>
 /// <returns>The <see cref="NFA.Instruction"/> implementing this AST.</returns>
 public override NFA.Instruction ToInstruction(NFABuilder builder)
 {
     return new NFA.Instruction
     {
         test = NFA.TestCode.Not,
         arg1 = builder.AddInstructions(Argument),
     };
 }
Пример #8
0
 /// <summary>The translation of this syntax tree into NFA instruction code.</summary>
 /// <param name="builder">Data needed to construct an NFA.</param>
 /// <returns>The <see cref="NFA.Instruction"/> implementing this AST.</returns>
 public abstract NFA.Instruction ToInstruction(NFABuilder builder);
Пример #9
0
        /// <summary>Initializes and compiles a regular expression, with options that modify the pattern.</summary>
        /// <param name="rep">The pattern to be compiled.</param>
        /// <param name="opts">The options desired.</param>
        /// <exception cref="ArgumentException"><paramref name="rep"/> is an ill-formed pattern.</exception>
        public Regex(string rep, RegexOptions opts)
        {
            this.rep = rep;
            this.opts = opts;
            NFABuilder builder = new NFABuilder(rep, opts);
            Debug.WriteLine(String.Format("Parsed /{0}/{1}", rep, this.Options));

            builder.Traverse();
            Debug.WriteLine(String.Format("Canonical form = {0}, NFA:", builder.CanonicalForm));

            nfa = new NFA(builder);
            #if DEBUG
            Debug.Indent();
            Debug.WriteLine(String.Format("{0:d} non-* quantifiers, {1:d} atomic groups, {2}captures = ({3})",
                nfa.QuantDepth, nfa.AtomicCount, nfa.Anchored ? "anchored, " : "", String.Join(", ", nfa.GroupNames)));
            Debug.WriteLine(String.Format("Fixed prefix of match = \"{0}\", first character in {1}",
                nfa.FixedPrefix == null ? "" : nfa.FixedPrefix.Needle, nfa.InstructionString(nfa.FirstTest)));
            for (int s = 0; s < nfa.States.Length; s++)
            {
                Debug.Write(s);
                if (s == nfa.FinalState)
                    Debug.Write(" accepts");
                foreach (NFA.Transition tr in nfa.States[s])
                    Debug.Write(String.Format(", {0} -> {1:d}", nfa.InstructionString(tr.instruction), tr.target));
                Debug.WriteLine("");
            }
            Debug.Unindent();
            #endif
        }
Пример #10
0
 /// <summary>The translation of this syntax tree into NFA instruction code.</summary>
 /// <param name="builder">Data needed to construct an NFA.</param>
 /// <returns>The <see cref="NFA.Instruction"/> implementing this AST.</returns>
 public override NFA.Instruction ToInstruction(NFABuilder builder)
 {
     return new NFA.Instruction { test = NFA.TestCode.BackrefEmpty, arg1 = Source.CaptureID, };
 }
Пример #11
0
 /// <summary>The translation of this syntax tree into NFA instruction code.</summary>
 /// <param name="builder">Data needed to construct an NFA.</param>
 /// <returns>The <see cref="NFA.Instruction"/> implementing this AST.</returns>
 public override NFA.Instruction ToInstruction(NFABuilder builder)
 {
     return new NFA.Instruction
     {
         test = FoldsCase ? NFA.TestCode.RangeFC : NFA.TestCode.Range,
         arg1 = Min,
         arg2 = Max,
     };
 }
Пример #12
0
 /// <summary>The translation of this syntax tree into NFA instruction code.</summary>
 /// <param name="builder">Data needed to construct an NFA.</param>
 /// <returns>The <see cref="NFA.Instruction"/> implementing this AST.</returns>
 public override NFA.Instruction ToInstruction(NFABuilder builder)
 {
     return new NFA.Instruction
     {
         test = FoldsCase ? NFA.TestCode.CharacterFC : NFA.TestCode.Character,
         arg1 = Character,
     };
 }
Пример #13
0
 /// <summary>The translation of this syntax tree into NFA instruction code.</summary>
 /// <param name="builder">Data needed to construct an NFA.</param>
 /// <exception cref="NotImplementedException">The method should never be called.</exception>
 public override NFA.Instruction ToInstruction(NFABuilder builder)
 {
     throw new NotImplementedException();
 }
Пример #14
0
 /// <summary>The translation of this syntax tree into NFA instruction code.</summary>
 /// <param name="builder">Data needed to construct an NFA.</param>
 /// <returns>The <see cref="NFA.Instruction"/> implementing this AST.</returns>
 public override NFA.Instruction ToInstruction(NFABuilder builder)
 {
     return new NFA.Instruction { test = NFA.TestCode.CaptCheck, arg1 = Index, };
 }