コード例 #1
0
        public TemplateRewriterContext(IScriptOutput output, TemplateRewriterOptions options = default(TemplateRewriterOptions))
        {
            _isWhileLoop = new FastStack <bool>(4);
            Options      = options;
            if (options.Mode != ScriptMode.Default)
            {
                throw new ArgumentException(string.Format(RS.UnsupportedRenderMode, options.Mode));
            }

            _output = output;
        }
コード例 #2
0
ファイル: TemplateContext.cs プロジェクト: lizoc/textscript
        /// <summary>
        /// Initializes a new instance of the <see cref="TemplateContext" /> class.
        /// </summary>
        /// <param name="builtin">The builtin object used to expose builtin functions, default is <see cref="GetDefaultBuiltinObject"/>.</param>
        public TemplateContext(ScriptObject builtin)
        {
            BuiltinObject = builtin ?? GetDefaultBuiltinObject();
            EnableOutput  = true;
            EnableBreakAndContinueAsReturnOutsideLoop = false;
            LoopLimit      = 1000;
            RecursiveLimit = 100;
            MemberRenamer  = StandardMemberRenamer.Default;

            RegexTimeOut = TimeSpan.FromSeconds(10);

            TemplateLoaderParserOptions = new ParserOptions();
            TemplateLoaderLexerOptions  = LexerOptions.Default;

            _outputs = new FastStack <IScriptOutput>(4);
            _output  = new StringBuilderOutput();
            _outputs.Push(_output);

            _globalStores    = new FastStack <IScriptObject>(4);
            _localStores     = new FastStack <ScriptObject>(4);
            _loopStores      = new FastStack <ScriptObject>(4);
            _availableStores = new FastStack <ScriptObject>(4);
            _cultures        = new FastStack <CultureInfo>(4);
            _caseValues      = new FastStack <object>(4);

            _localTagsStack = new FastStack <Dictionary <object, object> >(1);
            _loopTagsStack  = new FastStack <Dictionary <object, object> >(1);
            _availableTags  = new FastStack <Dictionary <object, object> >(4);

            _sourceFiles = new FastStack <string>(4);

            _memberAccessors = new Dictionary <Type, IObjectAccessor>();
            _listAccessors   = new Dictionary <Type, IListAccessor>();
            _loops           = new FastStack <ScriptLoopStatementBase>(4);

            BlockDelegates = new FastStack <ScriptBlockStatement>(4);

            _availablePipeArguments = new FastStack <ScriptPipeArguments>(4);
            _pipeArguments          = new FastStack <ScriptPipeArguments>(4);

            _isFunctionCallDisabled = false;

            CachedTemplates = new Dictionary <string, Template>();

            Tags = new Dictionary <object, object>();

            PushPipeArguments();

            // Ensure that builtin is registered first
            PushGlobal(BuiltinObject);
        }
コード例 #3
0
ファイル: TemplateContext.cs プロジェクト: lizoc/textscript
        /// <summary>
        /// Pops a previous <see cref="ScriptVariableScope"/>.
        /// </summary>
        internal void PopVariableScope(ref FastStack <ScriptObject> stores)
        {
            if (stores.Count == 0)
            {
                // Should not happen at runtime
                throw new InvalidOperationException(RS.PopVariableScopeOverflow);
            }

            ScriptObject store = stores.Pop();

            // The store is cleanup once it is pushed back
            store.Clear();

            _availableStores.Push(store);
        }