Exemplo n.º 1
0
        public static ExprRenderer GetExprRenderer(Parser.ExprMatchResult emr)
        {
            ExprRenderer exprRenderer = null;

            foreach (KeyValuePair<Regex, Type> regType in _exprRenderers)
            {
                ExprMatchTree emt = MatchExpr (emr, regType.Key);
                if (emt != null)
                {
                    exprRenderer = (ExprRenderer)Activator.CreateInstance (regType.Value, emr, emt);
                    break;
                }
            }

            if (exprRenderer == null)
                foreach (KeyValuePair<Regex, object[]> regEmpty in _emptyExprRenderers)
                {
                    ExprMatchTree emt = MatchExpr(emr, regEmpty.Key);
                    if (emt != null)
                    {
                        exprRenderer = new ExprEmptyRenderer(
                                        regEmpty.Value[0].ToString(),
                                        (ExprRenderType)regEmpty.Value[1],
                                        (ExprType)regEmpty.Value[2],
                                        emr,
                                        emt);
                        break;
                    }
                }

            if (exprRenderer != null)
                exprRenderer.BlockDef = GetExprBlockDefinition(exprRenderer);

            return exprRenderer;
        }
Exemplo n.º 2
0
        public UrlRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree)
            : base(exprMatchResult, exprMatchTree)
        {
            _urlNameVar = ExprMatchTree.GetFilteredVariable(GROUP_URL_NAME);
            _urlNamedArgsVar = ExprMatchTree.GetFilteredAssignmentList(GROUP_URL_NAMED_ARGS);
            _urlPositionalArgsVar = ExprMatchTree.GetFilteredVariableList(GROUP_URL_POSITIONAL_ARGS);

            _namedArgsCount = _urlNamedArgsVar != null ? _urlNamedArgsVar.Count : 0;
            _positionalArgsCount = _urlPositionalArgsVar != null ? _urlPositionalArgsVar.Count : 0;
        }
Exemplo n.º 3
0
 public IncludeRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree)
     : base(exprMatchResult, exprMatchTree)
 {
     _templatePathVar = ExprMatchTree.GetFilteredVariable(GROUP_TEMPLATE_FILE);
 }
Exemplo n.º 4
0
 public ExprRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree)
 {
     ExprMatchResult = exprMatchResult;
     ExprMatchTree = exprMatchTree;
 }
Exemplo n.º 5
0
 public ExprEmptyRenderer(string name, ExprRenderType renderType, ExprType type, Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree)
     : base(exprMatchResult, exprMatchTree)
 {
     _name = name;
     _renderType = renderType;
     _type = type;
 }
Exemplo n.º 6
0
 public ForLoopRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree)
     : base(exprMatchResult, exprMatchTree)
 {
     _listVar = ExprMatchTree.GetFilteredVariable(GROUP_FOR_LIST);
     _loopVariableName = ExprMatchTree.GetGroupValue(GROUP_FOR_VAR);
 }
Exemplo n.º 7
0
        protected static ExprMatchTree MatchExpr(Parser.ExprMatchResult pr, Regex re)
        {
            Match mc = re.Match(pr.Match);
            if (mc.Success)
            {
                return new ExprMatchTree(re, mc);
            }

            return null;
        }
Exemplo n.º 8
0
 public VariableRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree)
     : base(exprMatchResult, exprMatchTree)
 {
     _variable = ExprMatchTree.GetFilteredVariable(GROUP_VARIABLE_IDENT);
 }
Exemplo n.º 9
0
 public IfElseRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree)
     : base(exprMatchResult, exprMatchTree)
 {
 }
Exemplo n.º 10
0
 public FilterLoaderRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree)
     : base(exprMatchResult, exprMatchTree)
 {
     _filterName = ExprMatchTree.GetGroupValue(GROUP_FILTER_NAME);
 }
Exemplo n.º 11
0
        private bool ParseExpressions()
        {
            Parser parser = new Parser(BadrGrammar.RE_EXPR_INSTRUCTION,
                                       BadrGrammar.RE_EXPR_VARIABLE,
                                       BadrGrammar.RE_EXPR_SPECIAL_TAG);

            var list = new List<Parser.ExprMatchResult>();
            list.AddRange(parser.Match(TemplateContent, ExprType.INSTRUCTION, BadrGrammar.GROUP_INSTRUCTION));
            list.AddRange(parser.Match(TemplateContent, ExprType.VAR, BadrGrammar.GROUP_VARIABLE));
            list.AddRange(parser.Match(TemplateContent, ExprType.SPECIAL_TAG, BadrGrammar.GROUP_SPECIAL_TAG));

            if(list.Count == 0){
                _isStaticTemplate = true;
                return true;
            }

            ExprRenderers = new List<ExprRenderer>();

            foreach (Parser.ExprMatchResult emr in list)
            {
                ExprRenderer er = RenderManager.GetExprRenderer(emr);
                if (er != null)
                    ExprRenderers.Add(er);
                else
                {
                    Errors.Add(new TemplateError(emr.Line, string.Format(" near '{0}', line {1}", emr.Match, emr.Line)));
                }
            }

            if (ContainsErrors)
            {
                Errors.Insert(0, new TemplateError(-1, "Syntax error:"));
                return false;
            }

            ExprRenderers.Sort(new Comparison<ExprRenderer>((er1, er2) =>
            {
                return er1.ExprMatchResult.StartIndex.CompareTo(er2.ExprMatchResult.StartIndex);
            }));

            return true;
        }
Exemplo n.º 12
0
 public SpecialTagRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree)
     : base(exprMatchResult, exprMatchTree)
 {
     _specialTagName = ExprMatchTree.GetGroupValue(GROUP_SPE_TAG_NAME);
 }
Exemplo n.º 13
0
        public IfRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree)
            : base(exprMatchResult, exprMatchTree)
        {
            _oredConditions = new List<List<IfCondition>> ();

            List<IfCondition> andedConditions = new List<IfCondition> ();
            andedConditions.Add (new IfCondition (exprMatchTree.GetGroup(GROUP_IF_COND)));

            List<ExprMatchGroup> booleanOpIfCondition = exprMatchTree.GetGroupList (GROUP_IF_COND_BOOLEAN);
            if (booleanOpIfCondition != null)
            {
                foreach (ExprMatchGroup boolOpifConditionGroup in booleanOpIfCondition)
                {
                    if (boolOpifConditionGroup.GetGroupValue (GROUP_COND_BOOLEAN_OP) == "or")
                    {
                        _oredConditions.Add (andedConditions);
                        andedConditions = new List<IfCondition> ();
                    }

                    andedConditions.Add (new IfCondition (boolOpifConditionGroup.GetGroup(GROUP_IF_COND)));
                }

            }

            _oredConditions.Add (andedConditions);
        }