예제 #1
0
        /// <summary>
        /// Compiles this <see cref="Transducer{InputT, OutputT}" />
        /// </summary>
        /// <typeparam name="TTokenType"></typeparam>
        /// <typeparam name="OutputT"></typeparam>
        /// <param name="transducer"></param>
        /// <returns></returns>
        public static TokenReaderTransducer <TTokenType, OutputT> CompileWithTokenReaderAsInput <TTokenType, OutputT>(this Transducer <Token <TTokenType>, OutputT> transducer)
            where TTokenType : notnull
        {
            ParameterExpression reader  = Expression.Parameter(typeof(ITokenReader <TTokenType>), "reader");
            ParameterExpression output  = Expression.Parameter(typeof(OutputT).MakeByRefType(), "output");
            LabelTarget         @return = Expression.Label(typeof(Boolean));

            return(Expression.Lambda <TokenReaderTransducer <TTokenType, OutputT> >(
                       Expression.Block(
                           CompileState(transducer.InitialState, reader, output, @return, 0),
                           Expression.Label(@return, Expression.Constant(false))
                           ),
                       reader,
                       output
                       ).Compile());
        }