public void InitPlugins()
        {
            var totalPlugins = _context.Plugins.Total();
            var tokenIt      = _parser.TokenIt;
            var lexer        = _parser.Lexer;

            if (!_pluginsInitialized)
            {
                // 2. Register default methods if not present.
                Tokens.Default();
                ErrorCodes.Init();
                LTypesLookup.Init();
                _context.Methods.RegisterIfNotPresent(LTypes.Array, new LJSArrayMethods());
                _context.Methods.RegisterIfNotPresent(LTypes.Date, new LJSDateMethods());
                _context.Methods.RegisterIfNotPresent(LTypes.String, new LJSStringMethods());
                _context.Methods.RegisterIfNotPresent(LTypes.Time, new LJSTimeMethods());
                _context.Methods.RegisterIfNotPresent(LTypes.Map, new LJSMapMethods());
                _context.Methods.RegisterIfNotPresent(LTypes.Table, new LJSTableMethods());
            }

            if (!_pluginsInitialized || totalPlugins > _lastInitializationPluginCount)
            {
                // 3. Initialize the plugins.
                var expParser = new ExprParser();
                expParser._parser           = _parser;
                _context.PluginsMeta.Parser = expParser;
                _context.Plugins.RegisterAllSystem();
                _context.Plugins.ForEach <IExprPlugin>(plugin =>
                {
                    plugin.Init(_parser, tokenIt);
                    plugin.Ctx       = _context;
                    plugin.ExpParser = expParser;
                });

                _context.Plugins.ForEach <ITokenPlugin>(plugin => { plugin.Init(_parser, tokenIt); });
                _context.Plugins.ForEach <ILexPlugin>(plugin => { plugin.Init(lexer); plugin.Ctx = _context; });
                _context.Plugins.ExecuteSetupPlugins(_context);

                PreprocessHelper.Ctx           = _context;
                _lastInitializationPluginCount = _context.Plugins.Total();
            }
            _pluginsInitialized = true;
        }
Exemple #2
0
        public void InitPlugins()
        {
            var totalPlugins = _context.Plugins.Total();
            var tokenIt = _parser.TokenIt;
            var lexer = _parser.Lexer;

            if (!_pluginsInitialized)
            {
                // 2. Register default methods if not present.
                Tokens.Default();
                ErrorCodes.Init();
                LTypesLookup.Init();
                _context.Methods.RegisterIfNotPresent(LTypes.Array, new LJSArrayMethods());
                _context.Methods.RegisterIfNotPresent(LTypes.Date, new LJSDateMethods());
                _context.Methods.RegisterIfNotPresent(LTypes.String, new LJSStringMethods());
                _context.Methods.RegisterIfNotPresent(LTypes.Time, new LJSTimeMethods());
                _context.Methods.RegisterIfNotPresent(LTypes.Map, new LJSMapMethods());
                _context.Methods.RegisterIfNotPresent(LTypes.Table, new LJSTableMethods());
            }

            if (!_pluginsInitialized || totalPlugins > _lastInitializationPluginCount)
            {
                // 3. Initialize the plugins.
                var expParser = new ExprParser();
                expParser._parser = _parser;
                _context.PluginsMeta.Parser = expParser;
                _context.Plugins.RegisterAllSystem();
                _context.Plugins.ForEach<IExprPlugin>(plugin =>
                                                          {
                                                              plugin.Init(_parser, tokenIt);
                                                              plugin.Ctx = _context;
                                                              plugin.ExpParser = expParser;
                                                          });

                _context.Plugins.ForEach<ITokenPlugin>(plugin => { plugin.Init(_parser, tokenIt); });
                _context.Plugins.ForEach<ILexPlugin>(plugin => { plugin.Init(lexer); plugin.Ctx = _context; });
                _context.Plugins.ExecuteSetupPlugins(_context);

                PreprocessHelper.Ctx = _context;
                _lastInitializationPluginCount = _context.Plugins.Total();
            }
            _pluginsInitialized = true;
        }