Esempio n. 1
0
        public override Node Evaluate(Env env)
        {
            if(Evaluated) return this;

            try
            {
                env = env ?? new Env();

                env.Frames.Push(this);
                NodeHelper.ExpandNodes<Import>(env, Rules);
                env.Frames.Pop();

                var clone = new Root(new NodeList(Rules), Error, OriginalRuleset);

                clone = DoVisiting(clone, env, VisitorPluginType.BeforeEvaluation);

                clone.ReducedFrom<Root>(this);
                clone.EvaluateRules(env);
                clone.Evaluated = true;

                clone = DoVisiting(clone, env, VisitorPluginType.AfterEvaluation);
                return clone;
            }
            catch (ParsingException e)
            {
                throw Error(e);
            }
        }
Esempio n. 2
0
        public override Node Evaluate(Env env)
        {
            env = env ?? new Env();

            NodeHelper.ExpandNodes<Import>(env, this.Rules);

            Root clone = new Root(new NodeList(Rules), Error, OriginalRuleset).ReducedFrom<Root>(this);
            clone.EvaluateRules(env);

            return clone;
        }
Esempio n. 3
0
        private Root DoVisiting(Root node, Env env, VisitorPluginType pluginType)
        {
            return env.VisitorPlugins
                .Where(p => p.AppliesTo == pluginType)
                .Aggregate(node, (current, plugin) => 
                {
                    try
                    {
                        plugin.OnPreVisiting(env);
                        Root r = plugin.Apply(current);
                        plugin.OnPostVisiting(env);
                        return r;
                    }
                    catch (Exception ex)
                    {
                        string message = string.Format("Plugin '{0}' failed during visiting with error '{1}'", plugin.GetName(), ex.Message);
                        throw new ParserException(message, ex);
                    }
                });

        }
    public Ruleset Parse(string input, string fileName, Env env)
    {
      Ruleset root = null;
      FileName = fileName;

      try
      {
        Tokenizer.SetupInput(input, fileName);

        var parsers = new CartoParsers(NodeProvider, env);
        root = new Root(parsers.Primary(this), e => GenerateParserError(e));
      }
      catch (ParsingException e)
      {
        throw GenerateParserError(e);
      }

      if (!Tokenizer.HasCompletedParsing())
        throw GenerateParserError(new ParsingException("Content after finishing parsing (missing opening bracket?)", Tokenizer.GetNodeLocation(Tokenizer.Location.Index)));

      return root;
    }