Example #1
0
 /// <summary>
 /// Creates a new <see cref="StateInterfaceBuilder"/> given
 /// a state, the alphabet of the automata and a mapping
 /// between the states to their <see cref="CodeTypeDeclaration"/>.
 /// </summary>
 /// <param name="state">The given state.</param>
 /// <param name="alphabet">The given automata's alphabet.</param>
 /// <param name="stateToType">The mapping between the automata's
 /// states to their <see cref="CodeTypeDeclaration"/>s.</param>
 public StateInterfaceBuilder(IAutomataState<MethodInfo> state,
                              IEnumerable<MethodInfo> alphabet,
                              IDictionary<IAutomataState<MethodInfo>, CodeTypeDeclaration> stateToType)
 {
     mState = state;
     mAlphabet = alphabet;
     mStateToType = stateToType;
     mStateTypeDeclaration = mStateToType[mState];
 }
Example #2
0
        /// <summary>
        /// Creates a linear sub automata for a string
        /// </summary>
        /// <param name="c"></param>
        /// <param name="noWhitespace"></param>
        /// <param name="indexShift">Index to shift</param>
        /// <returns></returns>
        protected IAutomataState <char>[] CreateSingleStateAutomata(string c, bool noWhitespace, int indexShift = 0)
        {
            IAutomataState <char>[] automata = new IAutomataState <char> [c.Length
                                                                          + (noWhitespace ? 0: 1)];
            for (int i = 0; i < c.Length; i++)
            {
                automata[i] = new MultiAutomataState <char>(c[i], noWhitespace &&
                                                            i == c.Length - 1 ? FINISHED : i + 1 + indexShift);
            }
            if (!noWhitespace)
            {
                automata[c.Length] = new WhiteSpaceAutomataState(FINISHED);
            }

            return(automata);
        }
        /// <summary>
        /// Creates an empty <see cref="CodeTypeDeclaration"/> representing a given
        /// <see cref="IAutomataState{T}"/> of <see cref="MethodInfo"/>.
        /// </summary>
        /// <param name="state">The give state.</param>
        /// <param name="typeGenericParameters">The generic types of the
        /// interface.</param>
        /// <returns>An empty <see cref="CodeTypeDeclaration"/> representing the given
        /// <see cref="IAutomataState{T}"/>.</returns>
        private CodeTypeDeclaration CreateTypeDeclaration(IAutomataState<MethodInfo> state,
                                                          IEnumerable<Type> typeGenericParameters)
        {
            // Finds all the methods in the alphabet that
            // are generic and transit the current state to a valid state
            // These methods declare the generic types of the state.
            CodeTypeDeclaration result =
                new CodeTypeDeclaration("IState" + state.Id);

            result.IsInterface = true;

            result.TypeParameters.AddRange
                (typeGenericParameters.Select(x => x.ToTypeParameter()).ToArray());

            return result;
        }