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; }
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; }
public IncludeRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree) : base(exprMatchResult, exprMatchTree) { _templatePathVar = ExprMatchTree.GetFilteredVariable(GROUP_TEMPLATE_FILE); }
public ExprRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree) { ExprMatchResult = exprMatchResult; ExprMatchTree = exprMatchTree; }
public ExprEmptyRenderer(string name, ExprRenderType renderType, ExprType type, Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree) : base(exprMatchResult, exprMatchTree) { _name = name; _renderType = renderType; _type = type; }
public ForLoopRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree) : base(exprMatchResult, exprMatchTree) { _listVar = ExprMatchTree.GetFilteredVariable(GROUP_FOR_LIST); _loopVariableName = ExprMatchTree.GetGroupValue(GROUP_FOR_VAR); }
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; }
public VariableRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree) : base(exprMatchResult, exprMatchTree) { _variable = ExprMatchTree.GetFilteredVariable(GROUP_VARIABLE_IDENT); }
public IfElseRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree) : base(exprMatchResult, exprMatchTree) { }
public FilterLoaderRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree) : base(exprMatchResult, exprMatchTree) { _filterName = ExprMatchTree.GetGroupValue(GROUP_FILTER_NAME); }
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; }
public SpecialTagRenderer(Parser.ExprMatchResult exprMatchResult, ExprMatchTree exprMatchTree) : base(exprMatchResult, exprMatchTree) { _specialTagName = ExprMatchTree.GetGroupValue(GROUP_SPE_TAG_NAME); }
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); }